model file
Browse files- model.ipynb +121 -0
model.ipynb
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 82,
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"outputs": [],
|
| 8 |
+
"source": [
|
| 9 |
+
"import numpy as np\n",
|
| 10 |
+
"import tensorflow_datasets as tfds\n",
|
| 11 |
+
"import tensorflow as tf\n",
|
| 12 |
+
"import tensorflow_hub as hub\n",
|
| 13 |
+
"import sklearn\n",
|
| 14 |
+
"import random\n",
|
| 15 |
+
"from glob import glob\n",
|
| 16 |
+
"import matplotlib.pyplot as plt\n",
|
| 17 |
+
"import requests"
|
| 18 |
+
]
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"cell_type": "code",
|
| 22 |
+
"execution_count": 83,
|
| 23 |
+
"metadata": {},
|
| 24 |
+
"outputs": [
|
| 25 |
+
{
|
| 26 |
+
"name": "stdout",
|
| 27 |
+
"output_type": "stream",
|
| 28 |
+
"text": [
|
| 29 |
+
"TF version: 2.9.2\n",
|
| 30 |
+
"Hub version: 0.12.0\n",
|
| 31 |
+
"GPU is available\n"
|
| 32 |
+
]
|
| 33 |
+
}
|
| 34 |
+
],
|
| 35 |
+
"source": [
|
| 36 |
+
"print(\"TF version:\", tf.__version__)\n",
|
| 37 |
+
"print(\"Hub version:\", hub.__version__)\n",
|
| 38 |
+
"print(\"GPU is\", \"available\" if tf.config.list_physical_devices('GPU') else \"NOT AVAILABLE\")"
|
| 39 |
+
]
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"cell_type": "code",
|
| 43 |
+
"execution_count": 94,
|
| 44 |
+
"metadata": {},
|
| 45 |
+
"outputs": [
|
| 46 |
+
{
|
| 47 |
+
"name": "stdout",
|
| 48 |
+
"output_type": "stream",
|
| 49 |
+
"text": [
|
| 50 |
+
"Downloading data from https://storage.googleapis.com/keras-applications/efficientnetb7.h5\n",
|
| 51 |
+
"268326632/268326632 [==============================] - 13s 0us/step\n"
|
| 52 |
+
]
|
| 53 |
+
}
|
| 54 |
+
],
|
| 55 |
+
"source": [
|
| 56 |
+
"\n",
|
| 57 |
+
"inception_net = tf.keras.applications.EfficientNetB7()\n"
|
| 58 |
+
]
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"cell_type": "code",
|
| 62 |
+
"execution_count": 100,
|
| 63 |
+
"metadata": {},
|
| 64 |
+
"outputs": [],
|
| 65 |
+
"source": [
|
| 66 |
+
"import requests\n",
|
| 67 |
+
"\n",
|
| 68 |
+
"response = requests.get(\"https://git.io/JJkYN\")\n",
|
| 69 |
+
"labels = response.text.split(\"\\n\")\n",
|
| 70 |
+
"\n",
|
| 71 |
+
"def classify_image(inp):\n",
|
| 72 |
+
" inp = inp.reshape((-1, 600, 600, 3))\n",
|
| 73 |
+
" inp = tf.keras.applications.efficientnet_v2.preprocess_input(inp)\n",
|
| 74 |
+
" prediction = inception_net.predict(inp).flatten()\n",
|
| 75 |
+
" confidences = {labels[i]: float(prediction[i]) for i in range(1000)}\n",
|
| 76 |
+
" return confidences\n"
|
| 77 |
+
]
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"cell_type": "code",
|
| 81 |
+
"execution_count": 105,
|
| 82 |
+
"metadata": {},
|
| 83 |
+
"outputs": [],
|
| 84 |
+
"source": [
|
| 85 |
+
"import gradio as gr\n",
|
| 86 |
+
"\n",
|
| 87 |
+
"gr.Interface(fn=classify_image, \n",
|
| 88 |
+
" inputs=gr.Image(shape=(600, 600)),\n",
|
| 89 |
+
" outputs=gr.Label(num_top_classes=3),\n",
|
| 90 |
+
" examples=[\"data/animals/animals/antelope/0a37838e99.jpg\", \"data/animals/animals/starfish/0a63e965c2.jpg\"]).launch(share=True)\n"
|
| 91 |
+
]
|
| 92 |
+
}
|
| 93 |
+
],
|
| 94 |
+
"metadata": {
|
| 95 |
+
"kernelspec": {
|
| 96 |
+
"display_name": "Python 3.8.13 ('work')",
|
| 97 |
+
"language": "python",
|
| 98 |
+
"name": "python3"
|
| 99 |
+
},
|
| 100 |
+
"language_info": {
|
| 101 |
+
"codemirror_mode": {
|
| 102 |
+
"name": "ipython",
|
| 103 |
+
"version": 3
|
| 104 |
+
},
|
| 105 |
+
"file_extension": ".py",
|
| 106 |
+
"mimetype": "text/x-python",
|
| 107 |
+
"name": "python",
|
| 108 |
+
"nbconvert_exporter": "python",
|
| 109 |
+
"pygments_lexer": "ipython3",
|
| 110 |
+
"version": "3.8.13"
|
| 111 |
+
},
|
| 112 |
+
"orig_nbformat": 4,
|
| 113 |
+
"vscode": {
|
| 114 |
+
"interpreter": {
|
| 115 |
+
"hash": "59f0528c0641d303038c15eb2f7ee076b3157354b9138799665619ae8b3de89f"
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
},
|
| 119 |
+
"nbformat": 4,
|
| 120 |
+
"nbformat_minor": 2
|
| 121 |
+
}
|