Idhammz commited on
Commit
13a34a0
·
verified ·
1 Parent(s): 0a60855

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -9,9 +9,13 @@ from keras.models import load_model
9
  from keras.utils import img_to_array
10
  from tensorflow.keras.utils import load_img, img_to_array
11
  import uvicorn
 
12
 
13
- # Load the Keras model
14
- model = load_model('./modelMobileNetNew.h5')
 
 
 
15
 
16
  app = FastAPI()
17
 
@@ -78,7 +82,7 @@ async def predict(image_data: ImageData):
78
  hasil_prob = "{:.2f}".format(100 * np.max(pred))
79
  return {'message': 'Berhasil melakukan prediksi', 'nama': hasil_label, 'probability': hasil_prob}
80
  except Exception as e:
81
- print("EXCEPTION in Predict POST")
82
  return {'message': str(e), 'nama': '', 'probability': ''}
83
 
84
  if __name__ == "__main__":
 
9
  from keras.utils import img_to_array
10
  from tensorflow.keras.utils import load_img, img_to_array
11
  import uvicorn
12
+ from keras.layers import BatchNormalization
13
 
14
+ # Memuat model Keras dengan menangani objek kustom
15
+ try:
16
+ model = load_model('./modelMobileNetNew.h5', custom_objects={'BatchNormalization': BatchNormalization})
17
+ except Exception as e:
18
+ print(f"Error loading model: {e}")
19
 
20
  app = FastAPI()
21
 
 
82
  hasil_prob = "{:.2f}".format(100 * np.max(pred))
83
  return {'message': 'Berhasil melakukan prediksi', 'nama': hasil_label, 'probability': hasil_prob}
84
  except Exception as e:
85
+ print(f"EXCEPTION in Predict POST: {e}")
86
  return {'message': str(e), 'nama': '', 'probability': ''}
87
 
88
  if __name__ == "__main__":