Spaces:
Sleeping
Sleeping
Supisss commited on
Commit ·
200ba6a
1
Parent(s): 24be3be
trying other model again
Browse files- app.py +7 -7
- cnn_kfold_best_model_v2.h5 → model_vgg16.h5 +2 -2
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import numpy as np
|
|
| 4 |
from PIL import Image
|
| 5 |
import io
|
| 6 |
import sys
|
| 7 |
-
from tensorflow.keras.applications.
|
| 8 |
|
| 9 |
# 1. Inisialisasi Aplikasi
|
| 10 |
app = FastAPI(title="Ashoka Hipospadia Classifier API")
|
|
@@ -12,7 +12,7 @@ app = FastAPI(title="Ashoka Hipospadia Classifier API")
|
|
| 12 |
# 2. Load Model
|
| 13 |
print("Sedang memuat model...")
|
| 14 |
try:
|
| 15 |
-
model = tf.keras.models.load_model('
|
| 16 |
print("Model berhasil dimuat!")
|
| 17 |
except Exception as e:
|
| 18 |
print(f"Error memuat model: {e}")
|
|
@@ -24,10 +24,10 @@ class_names = ['normal', 'buried']
|
|
| 24 |
# 3. Fungsi Preprocessing
|
| 25 |
def prepare_image(image_bytes):
|
| 26 |
"""
|
| 27 |
-
Preprocessing gambar untuk model
|
| 28 |
- Konversi ke RGB (3 channel)
|
| 29 |
- Resize ke 224x224
|
| 30 |
-
- Preprocessing
|
| 31 |
"""
|
| 32 |
try:
|
| 33 |
img = Image.open(io.BytesIO(image_bytes))
|
|
@@ -35,7 +35,7 @@ def prepare_image(image_bytes):
|
|
| 35 |
# Paksa ubah ke RGB agar PNG transparan tidak error
|
| 36 |
img = img.convert("RGB")
|
| 37 |
|
| 38 |
-
# Resize ke ukuran input model (224x224 untuk
|
| 39 |
img = img.resize((224, 224))
|
| 40 |
|
| 41 |
# Convert ke numpy array
|
|
@@ -44,7 +44,7 @@ def prepare_image(image_bytes):
|
|
| 44 |
# Tambah batch dimension
|
| 45 |
img_array = np.expand_dims(img_array, axis=0)
|
| 46 |
|
| 47 |
-
# Preprocessing
|
| 48 |
img_array = preprocess_input(img_array)
|
| 49 |
|
| 50 |
return img_array
|
|
@@ -104,7 +104,7 @@ def home():
|
|
| 104 |
"""Endpoint root untuk testing API"""
|
| 105 |
return {
|
| 106 |
"message": "Ashoka Hipospadia Classifier API Online! 🚀\n",
|
| 107 |
-
"model": "
|
| 108 |
"classes": class_names
|
| 109 |
}
|
| 110 |
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
import io
|
| 6 |
import sys
|
| 7 |
+
from tensorflow.keras.applications.vgg16 import preprocess_input
|
| 8 |
|
| 9 |
# 1. Inisialisasi Aplikasi
|
| 10 |
app = FastAPI(title="Ashoka Hipospadia Classifier API")
|
|
|
|
| 12 |
# 2. Load Model
|
| 13 |
print("Sedang memuat model...")
|
| 14 |
try:
|
| 15 |
+
model = tf.keras.models.load_model('model_vgg16_final.h5')
|
| 16 |
print("Model berhasil dimuat!")
|
| 17 |
except Exception as e:
|
| 18 |
print(f"Error memuat model: {e}")
|
|
|
|
| 24 |
# 3. Fungsi Preprocessing
|
| 25 |
def prepare_image(image_bytes):
|
| 26 |
"""
|
| 27 |
+
Preprocessing gambar untuk model VGG16
|
| 28 |
- Konversi ke RGB (3 channel)
|
| 29 |
- Resize ke 224x224
|
| 30 |
+
- Preprocessing VGG16
|
| 31 |
"""
|
| 32 |
try:
|
| 33 |
img = Image.open(io.BytesIO(image_bytes))
|
|
|
|
| 35 |
# Paksa ubah ke RGB agar PNG transparan tidak error
|
| 36 |
img = img.convert("RGB")
|
| 37 |
|
| 38 |
+
# Resize ke ukuran input model (224x224 untuk VGG16)
|
| 39 |
img = img.resize((224, 224))
|
| 40 |
|
| 41 |
# Convert ke numpy array
|
|
|
|
| 44 |
# Tambah batch dimension
|
| 45 |
img_array = np.expand_dims(img_array, axis=0)
|
| 46 |
|
| 47 |
+
# Preprocessing VGG16 (HARUS sama dengan training!)
|
| 48 |
img_array = preprocess_input(img_array)
|
| 49 |
|
| 50 |
return img_array
|
|
|
|
| 104 |
"""Endpoint root untuk testing API"""
|
| 105 |
return {
|
| 106 |
"message": "Ashoka Hipospadia Classifier API Online! 🚀\n",
|
| 107 |
+
"model": "VGG16 Binary Classification\n",
|
| 108 |
"classes": class_names
|
| 109 |
}
|
| 110 |
|
cnn_kfold_best_model_v2.h5 → model_vgg16.h5
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fcdb25632467509be0a2ffa43e7c9df0d3021b746d582157decbd0b5e0b01d68
|
| 3 |
+
size 60534752
|