AbdullahAj2000 commited on
Commit
6a61728
·
1 Parent(s): ecae1b3
Files changed (6) hide show
  1. .gitignore +7 -0
  2. README.md +4 -3
  3. app.py +69 -0
  4. models/VGG19_32_onnx.onnx +3 -0
  5. models/last_Vgg19.h5 +3 -0
  6. requirements.txt +17 -0
.gitignore ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ flagged/
2
+ *.pt
3
+ *.png
4
+ *.jpg
5
+ *.mp4
6
+ *.mkv
7
+ gradio_cached_examples/
README.md CHANGED
@@ -1,12 +1,13 @@
1
  ---
2
- title: Test1
3
- emoji: 👁
4
- colorFrom: green
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: 4.16.0
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Classification
3
+ emoji: 😻
4
+ colorFrom: blue
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: 4.16.0
8
  app_file: app.py
9
  pinned: false
10
+ license: mit
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #import tensorflow as tf
2
+ import onnx
3
+ import onnxruntime as ort
4
+ import numpy as np
5
+ from keras.preprocessing.image import img_to_array, load_img
6
+ import cv2
7
+ import gradio as gr
8
+
9
+
10
+ #model = tf.keras.models.load_model("./models/last_Vgg19.h5")\
11
+ model = ort.InferenceSession('./models/VGG19_32_onnx.onnx')
12
+
13
+ def mux(pred):
14
+ index = np.array(pred).argmax()
15
+ if index ==0:
16
+ return "Ajloun Castle",max(pred)
17
+ elif index == 1 or index == 2:
18
+ return "Jerash",max(pred)
19
+ elif index == 3:
20
+ return "Petra",max(pred)
21
+ elif index == 4:
22
+ return "Roman amphitheater",max(pred)
23
+ elif index == 5:
24
+ return "Umm Qais",max(pred)
25
+ elif index == 6:
26
+ return "Wadi Rum",max(pred)
27
+
28
+ def show_preds_image(image_path):
29
+ img = load_img(image_path, target_size=(224, 224, 3))
30
+ img_array = img_to_array(img)
31
+ img_array = np.expand_dims(img_array, axis=0)
32
+ img_array /= 255.0
33
+
34
+ input_name = model.get_inputs()[0].name
35
+ output_name = model.get_outputs()[0].name
36
+
37
+
38
+ outputs = model.run(None, {input_name: img_array})
39
+
40
+
41
+ predicted_class_index = np.argmax(outputs[0][0])
42
+
43
+
44
+ classes = ['Ajloun Castle', 'Jerash', 'Jerash', 'Petra', 'Roman amphitheater', 'Roman amphitheater', 'Wadi Rum']
45
+ predicted_class = classes[predicted_class_index]
46
+
47
+ img = cv2.imread(image_path)
48
+ img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
49
+ mux_value = str(predicted_class)+":"+str(max(outputs[0][0]))
50
+ height, width, _ = img.shape
51
+ text_x = int((width - len(mux_value) * 10) / 2)
52
+ text_y = int(height / 2)
53
+ font_scale = 2
54
+ cv2.putText(img, f'{mux_value}', (text_x, text_y), cv2.FONT_HERSHEY_SIMPLEX, font_scale, (255, 0, 0), 2, cv2.LINE_AA)
55
+
56
+ return img
57
+
58
+ inputs_image = [
59
+ gr.components.Image(type="filepath", label="Input Image"),
60
+ ]
61
+ outputs_image = [
62
+ gr.components.Image(type="numpy", label="Output Image"),
63
+ ]
64
+ interface_image = gr.Interface(
65
+ fn=show_preds_image,
66
+ inputs=inputs_image,
67
+ outputs=outputs_image,
68
+ title="image classification",
69
+ )
models/VGG19_32_onnx.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:76df853dcf543b040ea6abd9c8c04221952b13cd0a451fb6f8d5a7a489e11500
3
+ size 558407469
models/last_Vgg19.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2fdfa5781ef13f61b89f76333160fb2408dc96eadd9a1a04b73074509520bda0
3
+ size 558724680
requirements.txt ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ matplotlib>=3.2.2
2
+ numpy>=1.18.5
3
+ opencv-python>=4.1.1
4
+ PyYAML>=5.3.1
5
+ scipy>=1.4.1
6
+ torch>=1.7.0
7
+ torchvision>=0.8.1
8
+ tqdm>=4.64.0
9
+ keras==2.15.0
10
+ onnx==1.15.0
11
+ onnxruntime==1.16.3
12
+ tensorflow
13
+ tensorflow_hub
14
+ matplotlib
15
+ numpy
16
+ tensorboard>=2.4.1
17
+ huggingface-hub