Skip to content

Commit 5c72fd0

Browse files
committed
Gemaakt met Colaboratory
1 parent 78b2e48 commit 5c72fd0

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

SigLIP/Inference_with_(multilingual)_SigLIP,_a_better_CLIP_model.ipynb

+50-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"metadata": {
55
"colab": {
66
"provenance": [],
7-
"authorship_tag": "ABX9TyNiCJitZw07PsgK/m4d0hNo",
7+
"authorship_tag": "ABX9TyML/Sgx5/cEAkxsyW+WQDVc",
88
"include_colab_link": true
99
},
1010
"kernelspec": {
@@ -2573,11 +2573,59 @@
25732573
"id": "j40VtILbJmbd"
25742574
}
25752575
},
2576+
{
2577+
"cell_type": "markdown",
2578+
"source": [
2579+
"## Pipeline API\n",
2580+
"\n",
2581+
"If you don't bother about details of pre- and postprocessing, we have the [pipelines](https://huggingface.co/docs/transformers.js/pipelines) which make inference very easy!"
2582+
],
2583+
"metadata": {
2584+
"id": "lDw5QpSjNidk"
2585+
}
2586+
},
2587+
{
2588+
"cell_type": "code",
2589+
"source": [
2590+
"from transformers import pipeline\n",
2591+
"from PIL import Image\n",
2592+
"import requests\n",
2593+
"\n",
2594+
"# load pipe\n",
2595+
"image_classifier = pipeline(task=\"zero-shot-image-classification\", model=\"google/siglip-so400m-patch14-384\")\n",
2596+
"\n",
2597+
"# load image\n",
2598+
"url = 'http://images.cocodataset.org/val2017/000000039769.jpg'\n",
2599+
"image = Image.open(requests.get(url, stream=True).raw)\n",
2600+
"\n",
2601+
"# inference\n",
2602+
"outputs = image_classifier(image, candidate_labels=[\"2 cats\", \"a plane\", \"a remote\"])\n",
2603+
"outputs = [{\"score\": round(output[\"score\"], 4), \"label\": output[\"label\"] } for output in outputs]\n",
2604+
"print(outputs)"
2605+
],
2606+
"metadata": {
2607+
"colab": {
2608+
"base_uri": "https://localhost:8080/"
2609+
},
2610+
"id": "jqAmisBiJX_n",
2611+
"outputId": "e75ad0df-66bb-4bcc-bb11-88b0cc7a422d"
2612+
},
2613+
"execution_count": 9,
2614+
"outputs": [
2615+
{
2616+
"output_type": "stream",
2617+
"name": "stdout",
2618+
"text": [
2619+
"[{'score': 0.5089, 'label': '2 cats'}, {'score': 0.0, 'label': 'a remote'}, {'score': 0.0, 'label': 'a plane'}]\n"
2620+
]
2621+
}
2622+
]
2623+
},
25762624
{
25772625
"cell_type": "code",
25782626
"source": [],
25792627
"metadata": {
2580-
"id": "jqAmisBiJX_n"
2628+
"id": "Yw4locEcNplK"
25812629
},
25822630
"execution_count": null,
25832631
"outputs": []

0 commit comments

Comments
 (0)