diff --git a/.gitattributes b/.gitattributes index a6344aac8c09253b3b630fb776ae94478aa0275b..da9542a50a58b164a63c8831a552eb7d817bdb1f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text *.zip filter=lfs diff=lfs merge=lfs -text *.zst filter=lfs diff=lfs merge=lfs -text *tfevents* filter=lfs diff=lfs merge=lfs -text +pokemon-model_transferlearning.keras filter=lfs diff=lfs merge=lfs -text +pokemon/train/Jolteon/00000036.jpg filter=lfs diff=lfs merge=lfs -text +pokemon/val/Jolteon/00000036.jpg filter=lfs diff=lfs merge=lfs -text diff --git a/app.ipynb b/app.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..b0a41bd87af85ef67a4566a7241543cbaa5d094a --- /dev/null +++ b/app.ipynb @@ -0,0 +1,229 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "import gradio as gr\n", + "import tensorflow as tf\n", + "import numpy as np\n", + "from PIL import Image" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "# Define the core prediction function\n", + "def predict_cat_dog(image):\n", + " # Preprocess image\n", + " print(type(image))\n", + " image = Image.fromarray(image.astype('uint8')) # Convert numpy array to PIL image\n", + " image = image.resize((150, 150)) #resize the image to 28x28 and converts it to gray scale\n", + " image = np.array(image)\n", + " image = np.expand_dims(image, axis=0) # same as image[None, ...]\n", + " \n", + " # Predict\n", + " prediction = model.predict(image)\n", + " \n", + " # Because the output layer was dense(0) without an activation function, we need to apply sigmoid to get the probability\n", + " # we could also change the output layer to dense(1, activation='sigmoid')\n", + " prediction = np.round(float(tf.sigmoid(prediction)), 2)\n", + " p_jolteon = prediction\n", + " p_eevee = (1 - prediction)\n", + " p_dratini = (2 - prediction)\n", + " return {'jolteon': p_jolteon, 'eevee': p_eevee, 'dratini': p_dratini}" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Running on local URL: http://127.0.0.1:7862\n", + "\n", + "To create a public link, set `share=True` in `launch()`.\n" + ] + }, + { + "data": { + "text/html": [ + "
Model: \"functional_1\"\n", + "
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━┓\n", + "┃ Layer (type) ┃ Output Shape ┃ Param # ┃ Trai… ┃\n", + "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━┩\n", + "│ input_layer_1 (InputLayer) │ (None, 150, 150, 3) │ 0 │ - │\n", + "├─────────────────────────────┼───────────────────────┼────────────┼───────┤\n", + "│ rescaling (Rescaling) │ (None, 150, 150, 3) │ 0 │ - │\n", + "├─────────────────────────────┼───────────────────────┼────────────┼───────┤\n", + "│ xception (Functional) │ (None, 5, 5, 2048) │ 20,861,480 │ N │\n", + "├─────────────────────────────┼───────────────────────┼────────────┼───────┤\n", + "│ global_average_pooling2d │ (None, 2048) │ 0 │ - │\n", + "│ (GlobalAveragePooling2D) │ │ │ │\n", + "├─────────────────────────────┼───────────────────────┼────────────┼───────┤\n", + "│ dropout (Dropout) │ (None, 2048) │ 0 │ - │\n", + "├─────────────────────────────┼───────────────────────┼────────────┼───────┤\n", + "│ dense (Dense) │ (None, 3) │ 6,147 │ Y │\n", + "└─────────────────────────────┴───────────────────────┴────────────┴───────┘\n", + "
Total params: 20,867,627 (79.60 MB)\n", + "
Trainable params: 6,147 (24.01 KB)\n", + "
Non-trainable params: 20,861,480 (79.58 MB)\n", + "
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━┓\n", + "┃ Layer (type) ┃ Output Shape ┃ Param # ┃ Trai… ┃\n", + "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━┩\n", + "│ input_layer_1 (InputLayer) │ (None, 150, 150, 3) │ 0 │ - │\n", + "├─────────────────────────────┼───────────────────────┼────────────┼───────┤\n", + "│ rescaling (Rescaling) │ (None, 150, 150, 3) │ 0 │ - │\n", + "├─────────────────────────────┼───────────────────────┼────────────┼───────┤\n", + "│ xception (Functional) │ (None, 5, 5, 2048) │ 20,861,480 │ Y │\n", + "├─────────────────────────────┼───────────────────────┼────────────┼───────┤\n", + "│ global_average_pooling2d │ (None, 2048) │ 0 │ - │\n", + "│ (GlobalAveragePooling2D) │ │ │ │\n", + "├─────────────────────────────┼───────────────────────┼────────────┼───────┤\n", + "│ dropout (Dropout) │ (None, 2048) │ 0 │ - │\n", + "├─────────────────────────────┼───────────────────────┼────────────┼───────┤\n", + "│ dense (Dense) │ (None, 3) │ 6,147 │ Y │\n", + "└─────────────────────────────┴───────────────────────┴────────────┴───────┘\n", + "
Total params: 20,879,923 (79.65 MB)\n", + "
Trainable params: 20,813,099 (79.40 MB)\n", + "
Non-trainable params: 54,528 (213.00 KB)\n", + "
Optimizer params: 12,296 (48.04 KB)\n", + "