Upload 9 files
Browse files- .gitattributes +1 -0
- app.ipynb +184 -0
- pokemon_examples/charmander.png +0 -0
- pokemon_examples/charmander1.jpg +0 -0
- pokemon_examples/eevee.png +0 -0
- pokemon_examples/eevee1.jpg +0 -0
- pokemon_examples/pika.png +0 -0
- pokemon_examples/pika1.jpg +0 -0
- requirements.txt +1 -0
- transferlearning_pokemon.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 |
+
transferlearning_pokemon.keras filter=lfs diff=lfs merge=lfs -text
|
app.ipynb
ADDED
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 12,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"import gradio as gr\n",
|
10 |
+
"import tensorflow as tf\n",
|
11 |
+
"import numpy as np\n",
|
12 |
+
"from PIL import Image"
|
13 |
+
]
|
14 |
+
},
|
15 |
+
{
|
16 |
+
"cell_type": "code",
|
17 |
+
"execution_count": 13,
|
18 |
+
"metadata": {},
|
19 |
+
"outputs": [],
|
20 |
+
"source": [
|
21 |
+
"model_path = \"transferlearning_pokemon.keras\"\n",
|
22 |
+
"model = tf.keras.models.load_model(model_path)"
|
23 |
+
]
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"cell_type": "code",
|
27 |
+
"execution_count": 16,
|
28 |
+
"metadata": {},
|
29 |
+
"outputs": [],
|
30 |
+
"source": [
|
31 |
+
"# Define the core prediction function\n",
|
32 |
+
"def predict_pokemon(image):\n",
|
33 |
+
" # Preprocess image\n",
|
34 |
+
" print(type(image))\n",
|
35 |
+
" image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image\n",
|
36 |
+
" image = image.resize((150, 150)) # Resize the image to 150x150\n",
|
37 |
+
" image = np.array(image)\n",
|
38 |
+
" image = np.expand_dims(image, axis=0) # Expand dimensions to match the model input shape\n",
|
39 |
+
" \n",
|
40 |
+
" # Predict\n",
|
41 |
+
" prediction = model.predict(image)\n",
|
42 |
+
" \n",
|
43 |
+
" # Print the shape of the prediction to debug\n",
|
44 |
+
" print(f\"Prediction shape: {prediction.shape}\")\n",
|
45 |
+
" \n",
|
46 |
+
" # Assuming the output is already softmax probabilities\n",
|
47 |
+
" probabilities = prediction[0]\n",
|
48 |
+
" \n",
|
49 |
+
" # Print the probabilities array to debug\n",
|
50 |
+
" print(f\"Probabilities: {probabilities}\")\n",
|
51 |
+
" \n",
|
52 |
+
" # Assuming your model was trained with these class names\n",
|
53 |
+
" class_names = ['charmander', 'eevee', 'pikachuu'] # Replace 'another_pokemon' with your third class name\n",
|
54 |
+
" \n",
|
55 |
+
" # Create a dictionary of class probabilities\n",
|
56 |
+
" result = {class_names[i]: float(probabilities[i]) for i in range(len(class_names))}\n",
|
57 |
+
" \n",
|
58 |
+
" return result"
|
59 |
+
]
|
60 |
+
},
|
61 |
+
{
|
62 |
+
"cell_type": "code",
|
63 |
+
"execution_count": 19,
|
64 |
+
"metadata": {},
|
65 |
+
"outputs": [
|
66 |
+
{
|
67 |
+
"name": "stdout",
|
68 |
+
"output_type": "stream",
|
69 |
+
"text": [
|
70 |
+
"Running on local URL: http://127.0.0.1:7866\n",
|
71 |
+
"\n",
|
72 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
73 |
+
]
|
74 |
+
},
|
75 |
+
{
|
76 |
+
"data": {
|
77 |
+
"text/html": [
|
78 |
+
"<div><iframe src=\"http://127.0.0.1:7866/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
79 |
+
],
|
80 |
+
"text/plain": [
|
81 |
+
"<IPython.core.display.HTML object>"
|
82 |
+
]
|
83 |
+
},
|
84 |
+
"metadata": {},
|
85 |
+
"output_type": "display_data"
|
86 |
+
},
|
87 |
+
{
|
88 |
+
"data": {
|
89 |
+
"text/plain": []
|
90 |
+
},
|
91 |
+
"execution_count": 19,
|
92 |
+
"metadata": {},
|
93 |
+
"output_type": "execute_result"
|
94 |
+
},
|
95 |
+
{
|
96 |
+
"name": "stdout",
|
97 |
+
"output_type": "stream",
|
98 |
+
"text": [
|
99 |
+
"<class 'numpy.ndarray'>\n",
|
100 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 140ms/step\n",
|
101 |
+
"Prediction shape: (1, 3)\n",
|
102 |
+
"Probabilities: [9.1263162e-31 1.1169604e-30 1.0000000e+00]\n",
|
103 |
+
"<class 'numpy.ndarray'>\n",
|
104 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 90ms/step\n",
|
105 |
+
"Prediction shape: (1, 3)\n",
|
106 |
+
"Probabilities: [4.4493477e-06 8.4401548e-01 1.5598010e-01]\n",
|
107 |
+
"<class 'numpy.ndarray'>\n",
|
108 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 70ms/step\n",
|
109 |
+
"Prediction shape: (1, 3)\n",
|
110 |
+
"Probabilities: [9.9999964e-01 1.0916104e-07 1.8336594e-07]\n",
|
111 |
+
"<class 'numpy.ndarray'>\n",
|
112 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 78ms/step\n",
|
113 |
+
"Prediction shape: (1, 3)\n",
|
114 |
+
"Probabilities: [5.0329237e-04 8.8987160e-01 1.0962512e-01]\n",
|
115 |
+
"<class 'numpy.ndarray'>\n",
|
116 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 82ms/step\n",
|
117 |
+
"Prediction shape: (1, 3)\n",
|
118 |
+
"Probabilities: [9.1263162e-31 1.1169604e-30 1.0000000e+00]\n",
|
119 |
+
"<class 'numpy.ndarray'>\n",
|
120 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 69ms/step\n",
|
121 |
+
"Prediction shape: (1, 3)\n",
|
122 |
+
"Probabilities: [4.4493477e-06 8.4401548e-01 1.5598010e-01]\n",
|
123 |
+
"<class 'numpy.ndarray'>\n",
|
124 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 68ms/step\n",
|
125 |
+
"Prediction shape: (1, 3)\n",
|
126 |
+
"Probabilities: [5.0329237e-04 8.8987160e-01 1.0962512e-01]\n",
|
127 |
+
"<class 'numpy.ndarray'>\n",
|
128 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 66ms/step\n",
|
129 |
+
"Prediction shape: (1, 3)\n",
|
130 |
+
"Probabilities: [5.0329237e-04 8.8987160e-01 1.0962512e-01]\n",
|
131 |
+
"<class 'numpy.ndarray'>\n",
|
132 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 74ms/step\n",
|
133 |
+
"Prediction shape: (1, 3)\n",
|
134 |
+
"Probabilities: [9.9999964e-01 1.0916104e-07 1.8336594e-07]\n",
|
135 |
+
"<class 'numpy.ndarray'>\n",
|
136 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 71ms/step\n",
|
137 |
+
"Prediction shape: (1, 3)\n",
|
138 |
+
"Probabilities: [4.0465540e-22 8.3268744e-22 1.0000000e+00]\n",
|
139 |
+
"<class 'numpy.ndarray'>\n",
|
140 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 75ms/step\n",
|
141 |
+
"Prediction shape: (1, 3)\n",
|
142 |
+
"Probabilities: [9.9999964e-01 1.0916104e-07 1.8336594e-07]\n",
|
143 |
+
"<class 'numpy.ndarray'>\n",
|
144 |
+
"\u001b[1m1/1\u001b[0m \u001b[32mββββββββββββββββββββ\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 66ms/step\n",
|
145 |
+
"Prediction shape: (1, 3)\n",
|
146 |
+
"Probabilities: [5.0329237e-04 8.8987160e-01 1.0962512e-01]\n"
|
147 |
+
]
|
148 |
+
}
|
149 |
+
],
|
150 |
+
"source": [
|
151 |
+
"# Create the Gradio interface\n",
|
152 |
+
"input_image = gr.Image()\n",
|
153 |
+
"iface = gr.Interface(\n",
|
154 |
+
" fn=predict_pokemon,\n",
|
155 |
+
" inputs=input_image, \n",
|
156 |
+
" outputs=gr.Label(),\n",
|
157 |
+
" examples=[\"pokemon_examples/charmander.png\", \"pokemon_examples/charmander1.jpg\", \"pokemon_examples/eevee.png\", \"pokemon_examples/eevee1.jpg\", \"pokemon_examples/pika.png\", \"pokemon_examples/pika1.jpg\"], \n",
|
158 |
+
" description=\"A simple mlp classification model for image classification using the mnist dataset.\")\n",
|
159 |
+
"iface.launch()"
|
160 |
+
]
|
161 |
+
}
|
162 |
+
],
|
163 |
+
"metadata": {
|
164 |
+
"kernelspec": {
|
165 |
+
"display_name": "venv_new",
|
166 |
+
"language": "python",
|
167 |
+
"name": "python3"
|
168 |
+
},
|
169 |
+
"language_info": {
|
170 |
+
"codemirror_mode": {
|
171 |
+
"name": "ipython",
|
172 |
+
"version": 3
|
173 |
+
},
|
174 |
+
"file_extension": ".py",
|
175 |
+
"mimetype": "text/x-python",
|
176 |
+
"name": "python",
|
177 |
+
"nbconvert_exporter": "python",
|
178 |
+
"pygments_lexer": "ipython3",
|
179 |
+
"version": "3.11.8"
|
180 |
+
}
|
181 |
+
},
|
182 |
+
"nbformat": 4,
|
183 |
+
"nbformat_minor": 2
|
184 |
+
}
|
pokemon_examples/charmander.png
ADDED
![]() |
pokemon_examples/charmander1.jpg
ADDED
![]() |
pokemon_examples/eevee.png
ADDED
![]() |
pokemon_examples/eevee1.jpg
ADDED
![]() |
pokemon_examples/pika.png
ADDED
![]() |
pokemon_examples/pika1.jpg
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
tensorflow
|
transferlearning_pokemon.keras
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:563a61546dce4eaa9f2f0e206f709de37518ecc0fd81baea33a299b27e598f95
|
3 |
+
size 250560275
|