ccwu0918 commited on
Commit
5e1cacd
1 Parent(s): 978ca54

Upload 32 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ classify_image/Image03/Image_03_10.jpg filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import numpy as np
4
+ import pandas as pd
5
+ import matplotlib.pyplot as plt
6
+
7
+ from tensorflow.keras.applications import ResNet50V2
8
+ from tensorflow.keras.models import Sequential, load_model
9
+ from tensorflow.keras.layers import Dense
10
+ from tensorflow.keras.utils import to_categorical
11
+ from tensorflow.keras.applications.resnet_v2 import preprocess_input
12
+ from tensorflow.keras.preprocessing.image import load_img, img_to_array
13
+
14
+ # 金門具有代表性的栗喉蜂虎、藍孔雀、戴勝、鱟及歐亞水獺五種物種。我們來挑戰五種類別總共用五十張照片, 看能不能打造一個神經網路學會辨識這五種類別。
15
+ # 讀入栗喉蜂虎、藍孔雀、戴勝、鱟及歐亞水獺資料圖檔
16
+ image_folders = ['Image01', 'Image02', 'Image03']
17
+
18
+ # 為了後面的需要,我們將五種類別照片的答案用 `labels` 呈現
19
+ labels = ["栗喉蜂虎", "戴勝", "鸕鶿"]
20
+
21
+ num_classes = len(labels)
22
+
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]
44
+ for file in os.listdir(thedir):
45
+ if file == ".git" or file == ".ipynb_checkpoints":
46
+ continue
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,
53
+ title="AI 栗喉蜂虎、戴勝及鸕鶿辨識機",
54
+ description=some_text,
55
+ examples=sample_images, live=True)
56
+
57
+ iface.launch()
classify_image/Image01/Image_01_01.jpg ADDED
classify_image/Image01/Image_01_02.jpg ADDED
classify_image/Image01/Image_01_03.jpg ADDED
classify_image/Image01/Image_01_04.jpg ADDED
classify_image/Image01/Image_01_05.jpg ADDED
classify_image/Image01/Image_01_06.jpg ADDED
classify_image/Image01/Image_01_07.jpg ADDED
classify_image/Image01/Image_01_08.jpg ADDED
classify_image/Image01/Image_01_09.jpg ADDED
classify_image/Image01/Image_01_10.jpg ADDED
classify_image/Image02/Image_02_01.jpg ADDED
classify_image/Image02/Image_02_02.jpg ADDED
classify_image/Image02/Image_02_03.jpg ADDED
classify_image/Image02/Image_02_04.jpg ADDED
classify_image/Image02/Image_02_05.jpg ADDED
classify_image/Image02/Image_02_06.jpg ADDED
classify_image/Image02/Image_02_07.jpg ADDED
classify_image/Image02/Image_02_08.jpg ADDED
classify_image/Image02/Image_02_09.jpg ADDED
classify_image/Image02/Image_02_10.jpg ADDED
classify_image/Image03/Image_03_01.jpg ADDED
classify_image/Image03/Image_03_02.jpg ADDED
classify_image/Image03/Image_03_03.jpg ADDED
classify_image/Image03/Image_03_04.jpg ADDED
classify_image/Image03/Image_03_05.jpg ADDED
classify_image/Image03/Image_03_06.jpg ADDED
classify_image/Image03/Image_03_07.jpg ADDED
classify_image/Image03/Image_03_08.jpg ADDED
classify_image/Image03/Image_03_09.jpg ADDED
classify_image/Image03/Image_03_10.jpg ADDED

Git LFS Details

  • SHA256: 00b3292133c72cfe43e9c96d607a09b52740292e1a10afee5f11081dfbb1bc60
  • Pointer size: 132 Bytes
  • Size of remote file: 1.17 MB
my_cnn_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f4c39eec74cac34f5820440f4e6e5abcb9265e0c36064c421f41fb359fbd7e68
3
+ size 94652064