Upload 5 files
Browse files- app.py +49 -0
- best_int8_openvino_model/best.bin +3 -0
- best_int8_openvino_model/best.xml +0 -0
- best_int8_openvino_model/metadata.yaml +20 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Description: This is the main file to run the Gradio interface for the object detection model.
|
2 |
+
from ultralytics import YOLO
|
3 |
+
from PIL import Image
|
4 |
+
import gradio as gr
|
5 |
+
from huggingface_hub import snapshot_download
|
6 |
+
import os
|
7 |
+
|
8 |
+
model_path = "best_int8_openvino_model"
|
9 |
+
|
10 |
+
|
11 |
+
# Load the model
|
12 |
+
def load_model(repo_id):
|
13 |
+
download_dir = snapshot_download(repo_id) # download the model from the Hugging Face Hub
|
14 |
+
print(download_dir)
|
15 |
+
path = os.path.join(download_dir, "best_int8_openvino_model") # path to the model
|
16 |
+
print(path)
|
17 |
+
detection_model = YOLO(path, task='classify') # load the model
|
18 |
+
return detection_model
|
19 |
+
|
20 |
+
# Predict the image
|
21 |
+
def predict(pilimg):
|
22 |
+
source = pilimg
|
23 |
+
# x = np.asarray(pilimg)
|
24 |
+
# print(x.shape)
|
25 |
+
result = detection_model.predict(source, conf=0.5) # confidence threshold, intersection over union threshold
|
26 |
+
|
27 |
+
#print("Result: ", result)
|
28 |
+
if not result or len(result[0].boxes) == 0: # if no object detected
|
29 |
+
gr.Warning("Image not recognized for classfication!")
|
30 |
+
else:
|
31 |
+
img_bgr = result[0].plot() # plot the image
|
32 |
+
out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB-order PIL image
|
33 |
+
|
34 |
+
return out_pilimg
|
35 |
+
|
36 |
+
REPO_ID = "best_int8_openvino_model" # The repo ID of the model
|
37 |
+
|
38 |
+
detection_model = load_model(model_path)
|
39 |
+
|
40 |
+
title = "Classify whether the image is Defective or Good"
|
41 |
+
interface = gr.Interface(
|
42 |
+
fn=predict,
|
43 |
+
inputs=gr.Image(type="pil", label="Input Image"),
|
44 |
+
outputs=gr.Image(type="pil", label="Classified Imamge"),
|
45 |
+
title=title,
|
46 |
+
)
|
47 |
+
|
48 |
+
# Launch the interface
|
49 |
+
interface.launch(share=True)
|
best_int8_openvino_model/best.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ce4c0c2066e9d667e75619de15e56c37adc58d74ea82896384ce4ec4203378cf
|
3 |
+
size 5116820
|
best_int8_openvino_model/best.xml
ADDED
The diff for this file is too large to render.
See raw diff
|
|
best_int8_openvino_model/metadata.yaml
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
description: Ultralytics YOLOv8s-cls model trained on datasets
|
2 |
+
author: Ultralytics
|
3 |
+
date: '2025-01-22T14:57:03.572451'
|
4 |
+
version: 8.3.62
|
5 |
+
license: AGPL-3.0 License (https://ultralytics.com/license)
|
6 |
+
docs: https://docs.ultralytics.com
|
7 |
+
stride: 1
|
8 |
+
task: classify
|
9 |
+
batch: 1
|
10 |
+
imgsz:
|
11 |
+
- 224
|
12 |
+
- 224
|
13 |
+
names:
|
14 |
+
0: Defective
|
15 |
+
1: Good
|
16 |
+
args:
|
17 |
+
batch: 1
|
18 |
+
half: false
|
19 |
+
int8: true
|
20 |
+
dynamic: false
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
ultralytics
|
2 |
+
gradio
|
3 |
+
huggingface_hub
|
4 |
+
pillow
|
5 |
+
ffmpeg-python
|