Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,24 +23,21 @@ num_classes = len(labels)
|
|
| 23 |
base_dir = './classify_image/'
|
| 24 |
|
| 25 |
# 載入並檢視訓練完成的模型。
|
| 26 |
-
|
| 27 |
model = load_model('my_cnn_model.h5') # Loading the Tensorflow Saved Model (PB)
|
| 28 |
print(model.summary())
|
| 29 |
|
| 30 |
# 注意現在主函數做辨識只有五個種類。而且是使用我們自行訓練的 model!
|
| 31 |
-
|
| 32 |
def classify_image(inp):
|
| 33 |
inp = inp.reshape((-1, 256, 256, 3))
|
| 34 |
inp = preprocess_input(inp)
|
| 35 |
prediction = model.predict(inp).flatten()
|
| 36 |
-
return {labels[i]: float(prediction[i]) for i in range(
|
| 37 |
|
| 38 |
image = gr.Image(shape=(256, 256), label="栗喉蜂虎、藍孔雀、戴勝、鱟及歐亞水獺照片")
|
| 39 |
label = gr.Label(num_top_classes=num_classes, label="AI ResNet50V2遷移式學習辨識結果")
|
| 40 |
some_text="我能辨識金門栗喉蜂虎、藍孔雀、戴勝、鱟及歐亞水獺。找張金門栗喉蜂虎、藍孔雀、戴勝、鱟及歐亞水獺照片來考我吧!"
|
| 41 |
|
| 42 |
# 我們將金門栗喉蜂虎、藍孔雀、戴勝、鱟及歐亞水獺數據庫中的圖片拿出來當作範例圖片讓使用者使用
|
| 43 |
-
|
| 44 |
sample_images = []
|
| 45 |
for i in range(num_classes):
|
| 46 |
thedir = base_dir + image_folders[i]
|
|
@@ -50,7 +47,6 @@ for i in range(num_classes):
|
|
| 50 |
sample_images.append(base_dir + image_folders[i] + '/' + file)
|
| 51 |
|
| 52 |
# 最後,將所有東西組裝在一起,就大功告成了!
|
| 53 |
-
|
| 54 |
iface = gr.Interface(fn=classify_image,
|
| 55 |
inputs=image,
|
| 56 |
outputs=label,
|
|
|
|
| 23 |
base_dir = './classify_image/'
|
| 24 |
|
| 25 |
# 載入並檢視訓練完成的模型。
|
|
|
|
| 26 |
model = load_model('my_cnn_model.h5') # Loading the Tensorflow Saved Model (PB)
|
| 27 |
print(model.summary())
|
| 28 |
|
| 29 |
# 注意現在主函數做辨識只有五個種類。而且是使用我們自行訓練的 model!
|
|
|
|
| 30 |
def classify_image(inp):
|
| 31 |
inp = inp.reshape((-1, 256, 256, 3))
|
| 32 |
inp = preprocess_input(inp)
|
| 33 |
prediction = model.predict(inp).flatten()
|
| 34 |
+
return {labels[i]: float(prediction[i]) for i in range(num_classes)}
|
| 35 |
|
| 36 |
image = gr.Image(shape=(256, 256), label="栗喉蜂虎、藍孔雀、戴勝、鱟及歐亞水獺照片")
|
| 37 |
label = gr.Label(num_top_classes=num_classes, label="AI ResNet50V2遷移式學習辨識結果")
|
| 38 |
some_text="我能辨識金門栗喉蜂虎、藍孔雀、戴勝、鱟及歐亞水獺。找張金門栗喉蜂虎、藍孔雀、戴勝、鱟及歐亞水獺照片來考我吧!"
|
| 39 |
|
| 40 |
# 我們將金門栗喉蜂虎、藍孔雀、戴勝、鱟及歐亞水獺數據庫中的圖片拿出來當作範例圖片讓使用者使用
|
|
|
|
| 41 |
sample_images = []
|
| 42 |
for i in range(num_classes):
|
| 43 |
thedir = base_dir + image_folders[i]
|
|
|
|
| 47 |
sample_images.append(base_dir + image_folders[i] + '/' + file)
|
| 48 |
|
| 49 |
# 最後,將所有東西組裝在一起,就大功告成了!
|
|
|
|
| 50 |
iface = gr.Interface(fn=classify_image,
|
| 51 |
inputs=image,
|
| 52 |
outputs=label,
|