Nineylia commited on
Commit
e696b45
1 Parent(s): c93581f

Upload 3 files

Browse files
.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_transfer_learning.keras filter=lfs diff=lfs merge=lfs -text
Pokemon_transfer_learning.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:afe180bd42b6f226d6a8554dcc9231f01e4d0fa85604f534581b321b6e9b86af
3
+ size 250560250
app.ipynb ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 7,
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": 8,
18
+ "metadata": {},
19
+ "outputs": [],
20
+ "source": [
21
+ "model_path = \"Pokemon_transfer_learning.keras\"\n",
22
+ "model = tf.keras.models.load_model(model_path)"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": 9,
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 28x28 and converts it to gray scale\n",
37
+ " image = np.array(image)\n",
38
+ " image = np.expand_dims(image, axis=0) # same as image[None, ...]\n",
39
+ " \n",
40
+ " # Predict\n",
41
+ " prediction = model.predict(image)\n",
42
+ " \n",
43
+ " # No need to apply sigmoid, as the output layer already uses softmax\n",
44
+ " # Convert the probabilities to rounded values\n",
45
+ " prediction = np.round(prediction, 2)\n",
46
+ " \n",
47
+ " # Separate the probabilities for each class\n",
48
+ " p_pikachu = prediction[0][0] # Probability for class 'articuno'\n",
49
+ " p_rattata = prediction[0][1] # Probability for class 'moltres'\n",
50
+ " p_zubat = prediction[0][2] # Probability for class 'zapdos'\n",
51
+ " \n",
52
+ " return {'pikachu': p_pikachu, 'rattata': p_rattata, 'zubat': p_zubat}"
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "execution_count": 13,
58
+ "metadata": {},
59
+ "outputs": [
60
+ {
61
+ "name": "stdout",
62
+ "output_type": "stream",
63
+ "text": [
64
+ "Running on local URL: http://127.0.0.1:7861\n",
65
+ "\n",
66
+ "To create a public link, set `share=True` in `launch()`.\n"
67
+ ]
68
+ },
69
+ {
70
+ "data": {
71
+ "text/html": [
72
+ "<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
73
+ ],
74
+ "text/plain": [
75
+ "<IPython.core.display.HTML object>"
76
+ ]
77
+ },
78
+ "metadata": {},
79
+ "output_type": "display_data"
80
+ },
81
+ {
82
+ "data": {
83
+ "text/plain": []
84
+ },
85
+ "execution_count": 13,
86
+ "metadata": {},
87
+ "output_type": "execute_result"
88
+ }
89
+ ],
90
+ "source": [
91
+ "# Create the Gradio interface\n",
92
+ "input_image = gr.Image()\n",
93
+ "iface = gr.Interface(\n",
94
+ " fn=predict_pokemon,\n",
95
+ " inputs=input_image,\n",
96
+ " outputs=gr.Label(),\n",
97
+ " examples=[\"images/pikachu1.jpg\", \"images/pikachu2.jpg\", \"images/pikachu3.jpg\", \"images/rattata1.jpg\", \"images/rattata2.jpg\", \"images/rattata3.jpg\", \"images/zubat1.jpg\", \"images/zubat2.jpg\", \"images/zubat3.jpg\"], \n",
98
+ " description=\"TEST.\")\n",
99
+ "\n",
100
+ "iface.launch()\n"
101
+ ]
102
+ }
103
+ ],
104
+ "metadata": {
105
+ "kernelspec": {
106
+ "display_name": "venv_new",
107
+ "language": "python",
108
+ "name": "python3"
109
+ },
110
+ "language_info": {
111
+ "codemirror_mode": {
112
+ "name": "ipython",
113
+ "version": 3
114
+ },
115
+ "file_extension": ".py",
116
+ "mimetype": "text/x-python",
117
+ "name": "python",
118
+ "nbconvert_exporter": "python",
119
+ "pygments_lexer": "ipython3",
120
+ "version": "3.11.8"
121
+ }
122
+ },
123
+ "nbformat": 4,
124
+ "nbformat_minor": 2
125
+ }
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ tensorflow