EasyWinter commited on
Commit
05a7235
·
verified ·
1 Parent(s): 659edd4

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +3 -4
main.py CHANGED
@@ -15,8 +15,7 @@ os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
15
  app = FastAPI()
16
 
17
 
18
- #model = load_model("foodnutrition.h5")
19
- model = load_model("my_model4.h5")
20
 
21
  CLASS_NAMES = [
22
  'Ayam Bakar', 'Ayam Geprek', 'Ayam Goreng', 'Ayam Tepung', 'Bakso', 'Bakwan',
@@ -82,7 +81,7 @@ async def hello():
82
  async def predict(file: UploadFile = File(...)):
83
  img_bytes = await file.read()
84
  img = PIL.Image.open(io.BytesIO(img_bytes)).convert('RGB')
85
- img = img.resize((224, 224))
86
 
87
  img_array = np.array(img).astype("float32") / 255.0
88
  img_array = np.expand_dims(img_array, axis=0)
@@ -94,7 +93,7 @@ async def predict(file: UploadFile = File(...)):
94
 
95
  probability = {}
96
  for i, prob in enumerate(preds[0]):
97
- probability[CLASS_NAMES[i]] = float(prob)
98
 
99
  data_nutrisi = get_nutrition_data(predicted_label)
100
 
 
15
  app = FastAPI()
16
 
17
 
18
+ model = load_model("foodnutrition.keras", compile=False)
 
19
 
20
  CLASS_NAMES = [
21
  'Ayam Bakar', 'Ayam Geprek', 'Ayam Goreng', 'Ayam Tepung', 'Bakso', 'Bakwan',
 
81
  async def predict(file: UploadFile = File(...)):
82
  img_bytes = await file.read()
83
  img = PIL.Image.open(io.BytesIO(img_bytes)).convert('RGB')
84
+ img = img.resize((244, 244))
85
 
86
  img_array = np.array(img).astype("float32") / 255.0
87
  img_array = np.expand_dims(img_array, axis=0)
 
93
 
94
  probability = {}
95
  for i, prob in enumerate(preds[0]):
96
+ probability[CLASS_NAMES[i]] = round(float(prob) * 100, 2)
97
 
98
  data_nutrisi = get_nutrition_data(predicted_label)
99