Spaces:
Runtime error
Runtime error
Pull the existing models from the model hub
#6
by
NimaBoscarino
- opened
app.py
CHANGED
|
@@ -1,10 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
os.system("wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt")
|
| 5 |
-
os.system("wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-e6e.pt")
|
| 6 |
-
os.system("wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-e6.pt")
|
| 7 |
-
|
| 8 |
import argparse
|
| 9 |
import time
|
| 10 |
from pathlib import Path
|
|
@@ -22,12 +18,24 @@ from utils.plots import plot_one_box
|
|
| 22 |
from utils.torch_utils import select_device, load_classifier, time_synchronized, TracedModel
|
| 23 |
from PIL import Image
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
def detect(img,model):
|
| 29 |
parser = argparse.ArgumentParser()
|
| 30 |
-
parser.add_argument('--weights', nargs='+', type=str, default=model
|
| 31 |
parser.add_argument('--source', type=str, default='Inference/', help='source') # file/folder, 0 for webcam
|
| 32 |
parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
|
| 33 |
parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold')
|
|
@@ -183,4 +191,4 @@ def detect(img,model):
|
|
| 183 |
return Image.fromarray(im0[:,:,::-1])
|
| 184 |
|
| 185 |
|
| 186 |
-
gr.Interface(detect,[gr.Image(type="pil"),gr.Dropdown(choices=
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import argparse
|
| 5 |
import time
|
| 6 |
from pathlib import Path
|
|
|
|
| 18 |
from utils.torch_utils import select_device, load_classifier, time_synchronized, TracedModel
|
| 19 |
from PIL import Image
|
| 20 |
|
| 21 |
+
from huggingface_hub import hf_hub_download
|
| 22 |
+
|
| 23 |
+
def load_model(model_name):
|
| 24 |
+
model_path = hf_hub_download(repo_id=f"Yolov7/{model_name}", filename=f"{model_name}.pt"), None)
|
| 25 |
+
|
| 26 |
+
return model_path
|
| 27 |
+
|
| 28 |
|
| 29 |
+
model_names = [
|
| 30 |
+
"yolov7",
|
| 31 |
+
"yolov7-e6e",
|
| 32 |
+
"yolov7-e6",
|
| 33 |
+
]
|
| 34 |
|
| 35 |
|
| 36 |
def detect(img,model):
|
| 37 |
parser = argparse.ArgumentParser()
|
| 38 |
+
parser.add_argument('--weights', nargs='+', type=str, default=load_model(model), help='model.pt path(s)')
|
| 39 |
parser.add_argument('--source', type=str, default='Inference/', help='source') # file/folder, 0 for webcam
|
| 40 |
parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
|
| 41 |
parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold')
|
|
|
|
| 191 |
return Image.fromarray(im0[:,:,::-1])
|
| 192 |
|
| 193 |
|
| 194 |
+
gr.Interface(detect,[gr.Image(type="pil"),gr.Dropdown(choices=model_names)], gr.Image(type="pil"),title="Yolov7",examples=[["horses.jpeg", "yolov7"]],description="demo for <a href='https://github.com/WongKinYiu/yolov7' style='text-decoration: underline' target='_blank'>WongKinYiu/yolov7</a> Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors").launch()
|