SciStalk commited on
Commit
d6a1bbc
1 Parent(s): c77fa91

Start commit

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. app.py +47 -0
  3. requirements.txt +3 -0
  4. train_cls_best_small.pt +3 -0
.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
+ train_cls_best_small.pt filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import cv2
4
+ import numpy as np
5
+ from ultralytics import YOLO
6
+
7
+ image_directory = 'home/user/app/example_images'
8
+
9
+ img_files = [file for file in os.listdir(
10
+ image_directory) if file.lower().endswith('.jpg') or file.lower().endswith('.png')]
11
+
12
+ path = [os.path.join(image_directory, filename) for filename in img_files]
13
+
14
+ model = YOLO('home/user/app/train_cls_best_small.pt')
15
+
16
+ inputs_image = [
17
+ gr.components.Image(type="filepath", label="Input Image"),
18
+ ]
19
+ outputs_text = [
20
+ gr.components.Textbox(type="text", label="Model predict"),
21
+ ]
22
+
23
+
24
+ def show_preds_image(image_path):
25
+
26
+ results = model(image_path)
27
+
28
+ names_dict = results[0].names
29
+
30
+ probs = results[0].probs.data.tolist()
31
+
32
+ return names_dict[np.argmax(probs)], np.max(probs)
33
+
34
+
35
+ interface_image = gr.Interface(
36
+ fn=show_preds_image,
37
+ inputs=inputs_image,
38
+ outputs=outputs_text,
39
+ title="Cat vs Dog",
40
+ examples=path,
41
+ cache_examples=False,
42
+ )
43
+
44
+ gr.TabbedInterface(
45
+ [interface_image],
46
+ tab_names=['Image Inference'],
47
+ ).queue().launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ opencv-python
2
+ gradio
3
+ ultralytics
train_cls_best_small.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5f40a9723131ab60b2ab621c023d1b534385055bd39b99bb3b90e7dc1ade0ade
3
+ size 10382048