Suphawan commited on
Commit
7e64213
·
verified ·
1 Parent(s): 4392ff7

Upload 5 files

Browse files
Custom_CNN_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6f54181c11298ee4f4b6715703375b6c05a9b47c5ead4d04e1bc947ab9d2d5f3
3
+ size 286930648
ResNet50_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f2a5663bda0f150db9e72cc6ef2224c878e8b9ae81dd31310f8d4d52663c9931
3
+ size 98091912
VGG16_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e0e2ef9c9aa645a295dcc48d39801df472e19dee4d1ec16e15308fe5727a3d71
3
+ size 59745168
app_py.ipynb ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "provenance": []
7
+ },
8
+ "kernelspec": {
9
+ "name": "python3",
10
+ "display_name": "Python 3"
11
+ },
12
+ "language_info": {
13
+ "name": "python"
14
+ }
15
+ },
16
+ "cells": [
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": null,
20
+ "metadata": {
21
+ "id": "jaqWRbrAqXI2"
22
+ },
23
+ "outputs": [],
24
+ "source": [
25
+ "import gradio as gr\n",
26
+ "import tensorflow as tf\n",
27
+ "import numpy as np\n",
28
+ "from PIL import Image\n",
29
+ "\n",
30
+ "# ขนาดภาพที่ใช้ในโมเดล\n",
31
+ "IMG_SIZE = (224, 224)\n",
32
+ "\n",
33
+ "# สร้าง Dictionary ที่เก็บชื่อโมเดลและ path ไฟล์ .h5\n",
34
+ "model_paths = {\n",
35
+ " \"Custom CNN\": \"Custom_CNN_model.h5\",\n",
36
+ " \"VGG16\": \"VGG16_model.h5\",\n",
37
+ " \"ResNet50\": \"ResNet50_model.h5\"\n",
38
+ "}\n",
39
+ "\n",
40
+ "# ฟังก์ชันเตรียมข้อมูลภาพ\n",
41
+ "def preprocess_image(image):\n",
42
+ " image = image.resize(IMG_SIZE) # Resize\n",
43
+ " image = np.array(image) / 255.0 # Normalize\n",
44
+ " image = np.expand_dims(image, axis=0) # เพิ่ม batch dimension\n",
45
+ " return image\n",
46
+ "\n",
47
+ "# ฟังก์ชันทำนาย โดยเลือกโมเดล\n",
48
+ "def predict_with_model(image, model_name):\n",
49
+ " # โหลดโมเดลที่เลือก\n",
50
+ " model = tf.keras.models.load_model(model_paths[model_name])\n",
51
+ "\n",
52
+ " # เตรียมภาพ\n",
53
+ " processed_image = preprocess_image(image)\n",
54
+ "\n",
55
+ " # ทำนายผล\n",
56
+ " prediction = model.predict(processed_image)[0][0] # ได้ค่าความน่าจะเป็น\n",
57
+ " class_name = \"Stroke\" if prediction > 0.5 else \"Non-Stroke\"\n",
58
+ " confidence = round(float(prediction if prediction > 0.5 else 1 - prediction) * 100, 2)\n",
59
+ "\n",
60
+ " # คืนผลลัพธ์\n",
61
+ " return f\"Class: {class_name} (Confidence: {confidence}%)\"\n",
62
+ "\n",
63
+ "# Gradio Interface\n",
64
+ "interface = gr.Interface(\n",
65
+ " fn=predict_with_model,\n",
66
+ " inputs=[\n",
67
+ " gr.Image(type=\"pil\", label=\"Upload Face Image\"),\n",
68
+ " gr.Dropdown(choices=[\"Custom CNN\", \"VGG16\", \"ResNet50\"], label=\"Select Model\")\n",
69
+ " ],\n",
70
+ " outputs=\"text\",\n",
71
+ " title=\"Stroke Face Classification\",\n",
72
+ " description=\"Upload a face image to predict whether the person has stroke or not. Select model to classify.\"\n",
73
+ ")\n",
74
+ "\n",
75
+ "# Run app\n",
76
+ "if __name__ == \"__main__\":\n",
77
+ " interface.launch()\n"
78
+ ]
79
+ }
80
+ ]
81
+ }
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ tensorflow
2
+ gradio
3
+ numpy
4
+ pillow