Upload 2 files
Browse files- .gitattributes +1 -0
- app.ipynb +247 -0
- pokemon-model.keras +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
pokemon-model.keras filter=lfs diff=lfs merge=lfs -text
|
app.ipynb
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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": "stream",
|
| 11 |
+
"text": [
|
| 12 |
+
"Running on local URL: http://127.0.0.1:7869\n",
|
| 13 |
+
"\n",
|
| 14 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
| 15 |
+
]
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"data": {
|
| 19 |
+
"text/html": [
|
| 20 |
+
"<div><iframe src=\"http://127.0.0.1:7869/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 21 |
+
],
|
| 22 |
+
"text/plain": [
|
| 23 |
+
"<IPython.core.display.HTML object>"
|
| 24 |
+
]
|
| 25 |
+
},
|
| 26 |
+
"metadata": {},
|
| 27 |
+
"output_type": "display_data"
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"data": {
|
| 31 |
+
"text/plain": []
|
| 32 |
+
},
|
| 33 |
+
"execution_count": 21,
|
| 34 |
+
"metadata": {},
|
| 35 |
+
"output_type": "execute_result"
|
| 36 |
+
}
|
| 37 |
+
],
|
| 38 |
+
"source": [
|
| 39 |
+
"import gradio as gr\n",
|
| 40 |
+
"import numpy as np\n",
|
| 41 |
+
"from tensorflow.keras.models import load_model\n",
|
| 42 |
+
"from tensorflow.keras.applications.resnet50 import preprocess_input\n",
|
| 43 |
+
"from PIL import Image\n",
|
| 44 |
+
"\n",
|
| 45 |
+
"# Load the pre-trained Keras model\n",
|
| 46 |
+
"model = load_model('pokemon-model.keras')\n",
|
| 47 |
+
"\n",
|
| 48 |
+
"# Define the class labels\n",
|
| 49 |
+
"class_labels = ['Bulbasaur', 'Glumanda', 'Pikachu'] # Ensure this matches the training order\n",
|
| 50 |
+
"\n",
|
| 51 |
+
"# Define the image processing and prediction function\n",
|
| 52 |
+
"def predict_image(img):\n",
|
| 53 |
+
" # Ensure the image is a PIL image\n",
|
| 54 |
+
" if not isinstance(img, Image.Image):\n",
|
| 55 |
+
" img = Image.fromarray(img)\n",
|
| 56 |
+
" \n",
|
| 57 |
+
" # Resize the image to the size expected by ResNet50\n",
|
| 58 |
+
" img = img.resize((224, 224))\n",
|
| 59 |
+
" \n",
|
| 60 |
+
" # Convert the image to a numpy array\n",
|
| 61 |
+
" img_array = np.array(img)\n",
|
| 62 |
+
" \n",
|
| 63 |
+
" # Convert the image array to a batch of size 1 (1, 224, 224, 3)\n",
|
| 64 |
+
" img_array = np.expand_dims(img_array, axis=0)\n",
|
| 65 |
+
" \n",
|
| 66 |
+
" # Preprocess the image array using ResNet50's preprocessing\n",
|
| 67 |
+
" img_array = preprocess_input(img_array)\n",
|
| 68 |
+
"\n",
|
| 69 |
+
" # Make prediction\n",
|
| 70 |
+
" prediction = model.predict(img_array)\n",
|
| 71 |
+
" \n",
|
| 72 |
+
" # Get the label with the highest probability\n",
|
| 73 |
+
" predicted_index = int(np.argmax(prediction))\n",
|
| 74 |
+
" predicted_label = class_labels[predicted_index]\n",
|
| 75 |
+
" \n",
|
| 76 |
+
" return predicted_label\n",
|
| 77 |
+
"\n",
|
| 78 |
+
"# Create the Gradio interface with multiple examples\n",
|
| 79 |
+
"iface = gr.Interface(\n",
|
| 80 |
+
" fn=predict_image, \n",
|
| 81 |
+
" inputs=gr.Image(image_mode='RGB'),\n",
|
| 82 |
+
" outputs='label',\n",
|
| 83 |
+
" examples=[['00000015.jpg'], ['20.png'], ['glumanda.jpg'], ['j67j7.png'], ['pikachu.jpg']],\n",
|
| 84 |
+
" title=\"PokΓ©mon Classification\",\n",
|
| 85 |
+
" description=\"Upload an image of a PokΓ©mon to classify it using the pre-trained model.\"\n",
|
| 86 |
+
")\n",
|
| 87 |
+
"\n",
|
| 88 |
+
"# Launch the interface inline in the Jupyter Notebook\n",
|
| 89 |
+
"iface.launch(inline=True)\n"
|
| 90 |
+
]
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
"cell_type": "code",
|
| 94 |
+
"execution_count": 22,
|
| 95 |
+
"metadata": {},
|
| 96 |
+
"outputs": [
|
| 97 |
+
{
|
| 98 |
+
"data": {
|
| 99 |
+
"text/html": [
|
| 100 |
+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">Model: \"sequential_12\"</span>\n",
|
| 101 |
+
"</pre>\n"
|
| 102 |
+
],
|
| 103 |
+
"text/plain": [
|
| 104 |
+
"\u001b[1mModel: \"sequential_12\"\u001b[0m\n"
|
| 105 |
+
]
|
| 106 |
+
},
|
| 107 |
+
"metadata": {},
|
| 108 |
+
"output_type": "display_data"
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"data": {
|
| 112 |
+
"text/html": [
|
| 113 |
+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">βββββββββββββββββββββββββββββββββββ³βββββββββββββββββββββββββ³ββββββββββββββββ\n",
|
| 114 |
+
"β<span style=\"font-weight: bold\"> Layer (type) </span>β<span style=\"font-weight: bold\"> Output Shape </span>β<span style=\"font-weight: bold\"> Param # </span>β\n",
|
| 115 |
+
"β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©\n",
|
| 116 |
+
"β resnet50 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Functional</span>) β (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">7</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">7</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">2048</span>) β <span style=\"color: #00af00; text-decoration-color: #00af00\">23,587,712</span> β\n",
|
| 117 |
+
"βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββ€\n",
|
| 118 |
+
"β global_average_pooling2d_10 β (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">2048</span>) β <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> β\n",
|
| 119 |
+
"β (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">GlobalAveragePooling2D</span>) β β β\n",
|
| 120 |
+
"βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββ€\n",
|
| 121 |
+
"β batch_normalization_4 β (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">2048</span>) β <span style=\"color: #00af00; text-decoration-color: #00af00\">8,192</span> β\n",
|
| 122 |
+
"β (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) β β β\n",
|
| 123 |
+
"βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββ€\n",
|
| 124 |
+
"β dropout_4 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dropout</span>) β (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">2048</span>) β <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> β\n",
|
| 125 |
+
"βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββ€\n",
|
| 126 |
+
"β dense_9 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dense</span>) β (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">3</span>) β <span style=\"color: #00af00; text-decoration-color: #00af00\">6,147</span> β\n",
|
| 127 |
+
"βββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββ΄ββββββββββββββββ\n",
|
| 128 |
+
"</pre>\n"
|
| 129 |
+
],
|
| 130 |
+
"text/plain": [
|
| 131 |
+
"βββββββββββββββββββββββββββββββββββ³βββββββββββββββββββββββββ³ββββββββββββββββ\n",
|
| 132 |
+
"β\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0mβ\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0mβ\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0mβ\n",
|
| 133 |
+
"β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ©\n",
|
| 134 |
+
"β resnet50 (\u001b[38;5;33mFunctional\u001b[0m) β (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m7\u001b[0m, \u001b[38;5;34m7\u001b[0m, \u001b[38;5;34m2048\u001b[0m) β \u001b[38;5;34m23,587,712\u001b[0m β\n",
|
| 135 |
+
"βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββ€\n",
|
| 136 |
+
"β global_average_pooling2d_10 β (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m2048\u001b[0m) β \u001b[38;5;34m0\u001b[0m β\n",
|
| 137 |
+
"β (\u001b[38;5;33mGlobalAveragePooling2D\u001b[0m) β β β\n",
|
| 138 |
+
"βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββ€\n",
|
| 139 |
+
"β batch_normalization_4 β (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m2048\u001b[0m) β \u001b[38;5;34m8,192\u001b[0m β\n",
|
| 140 |
+
"β (\u001b[38;5;33mBatchNormalization\u001b[0m) β β β\n",
|
| 141 |
+
"ββββββββββββββββββββββββββββββοΏ½οΏ½ββββΌβββββββββββββββββββββββββΌββββββββββββββββ€\n",
|
| 142 |
+
"β dropout_4 (\u001b[38;5;33mDropout\u001b[0m) β (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m2048\u001b[0m) β \u001b[38;5;34m0\u001b[0m β\n",
|
| 143 |
+
"βββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββββββββ€\n",
|
| 144 |
+
"β dense_9 (\u001b[38;5;33mDense\u001b[0m) β (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m3\u001b[0m) β \u001b[38;5;34m6,147\u001b[0m β\n",
|
| 145 |
+
"βββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββ΄ββββββββββββββββ\n"
|
| 146 |
+
]
|
| 147 |
+
},
|
| 148 |
+
"metadata": {},
|
| 149 |
+
"output_type": "display_data"
|
| 150 |
+
},
|
| 151 |
+
{
|
| 152 |
+
"data": {
|
| 153 |
+
"text/html": [
|
| 154 |
+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Total params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">62,528,395</span> (238.53 MB)\n",
|
| 155 |
+
"</pre>\n"
|
| 156 |
+
],
|
| 157 |
+
"text/plain": [
|
| 158 |
+
"\u001b[1m Total params: \u001b[0m\u001b[38;5;34m62,528,395\u001b[0m (238.53 MB)\n"
|
| 159 |
+
]
|
| 160 |
+
},
|
| 161 |
+
"metadata": {},
|
| 162 |
+
"output_type": "display_data"
|
| 163 |
+
},
|
| 164 |
+
{
|
| 165 |
+
"data": {
|
| 166 |
+
"text/html": [
|
| 167 |
+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">19,463,171</span> (74.25 MB)\n",
|
| 168 |
+
"</pre>\n"
|
| 169 |
+
],
|
| 170 |
+
"text/plain": [
|
| 171 |
+
"\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m19,463,171\u001b[0m (74.25 MB)\n"
|
| 172 |
+
]
|
| 173 |
+
},
|
| 174 |
+
"metadata": {},
|
| 175 |
+
"output_type": "display_data"
|
| 176 |
+
},
|
| 177 |
+
{
|
| 178 |
+
"data": {
|
| 179 |
+
"text/html": [
|
| 180 |
+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Non-trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">4,138,880</span> (15.79 MB)\n",
|
| 181 |
+
"</pre>\n"
|
| 182 |
+
],
|
| 183 |
+
"text/plain": [
|
| 184 |
+
"\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m4,138,880\u001b[0m (15.79 MB)\n"
|
| 185 |
+
]
|
| 186 |
+
},
|
| 187 |
+
"metadata": {},
|
| 188 |
+
"output_type": "display_data"
|
| 189 |
+
},
|
| 190 |
+
{
|
| 191 |
+
"data": {
|
| 192 |
+
"text/html": [
|
| 193 |
+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Optimizer params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">38,926,344</span> (148.49 MB)\n",
|
| 194 |
+
"</pre>\n"
|
| 195 |
+
],
|
| 196 |
+
"text/plain": [
|
| 197 |
+
"\u001b[1m Optimizer params: \u001b[0m\u001b[38;5;34m38,926,344\u001b[0m (148.49 MB)\n"
|
| 198 |
+
]
|
| 199 |
+
},
|
| 200 |
+
"metadata": {},
|
| 201 |
+
"output_type": "display_data"
|
| 202 |
+
},
|
| 203 |
+
{
|
| 204 |
+
"name": "stdout",
|
| 205 |
+
"output_type": "stream",
|
| 206 |
+
"text": [
|
| 207 |
+
"None\n"
|
| 208 |
+
]
|
| 209 |
+
},
|
| 210 |
+
{
|
| 211 |
+
"name": "stdout",
|
| 212 |
+
"output_type": "stream",
|
| 213 |
+
"text": [
|
| 214 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m3s\u001b[0m 3s/step\n",
|
| 215 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 165ms/step\n",
|
| 216 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 299ms/step\n"
|
| 217 |
+
]
|
| 218 |
+
}
|
| 219 |
+
],
|
| 220 |
+
"source": [
|
| 221 |
+
"# Print model summary to verify input shape\n",
|
| 222 |
+
"print(model.summary())\n"
|
| 223 |
+
]
|
| 224 |
+
}
|
| 225 |
+
],
|
| 226 |
+
"metadata": {
|
| 227 |
+
"kernelspec": {
|
| 228 |
+
"display_name": "venv_new",
|
| 229 |
+
"language": "python",
|
| 230 |
+
"name": "python3"
|
| 231 |
+
},
|
| 232 |
+
"language_info": {
|
| 233 |
+
"codemirror_mode": {
|
| 234 |
+
"name": "ipython",
|
| 235 |
+
"version": 3
|
| 236 |
+
},
|
| 237 |
+
"file_extension": ".py",
|
| 238 |
+
"mimetype": "text/x-python",
|
| 239 |
+
"name": "python",
|
| 240 |
+
"nbconvert_exporter": "python",
|
| 241 |
+
"pygments_lexer": "ipython3",
|
| 242 |
+
"version": "3.9.13"
|
| 243 |
+
}
|
| 244 |
+
},
|
| 245 |
+
"nbformat": 4,
|
| 246 |
+
"nbformat_minor": 2
|
| 247 |
+
}
|
pokemon-model.keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:181468828df84cfa5b53ce025281ed4d58943d7c89c5e136da4ff7eea4c10550
|
| 3 |
+
size 250797031
|