Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,21 +7,26 @@ from PIL import Image
|
|
7 |
#subprocess.run(["mv","content/custom_data.yaml","./yolov5/data"])
|
8 |
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
model = torch.hub.load('ultralytics/yolov5', 'custom', path='Content/best.pt')
|
12 |
-
model.conf = 0.38
|
13 |
-
model.hide_conf=True
|
14 |
#, force_reload=True
|
15 |
def detect(inp):
|
16 |
#g = (size / max(inp.size)) # gain
|
17 |
#im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
|
18 |
-
|
19 |
results = model(inp,size=640) # inference
|
20 |
results.render() # updates results.imgs with boxes and labels
|
21 |
return Image.fromarray(results.imgs[0])
|
22 |
|
23 |
|
24 |
-
inp = gr.inputs.Image(type=
|
25 |
output = gr.outputs.Image(type="pil", label="Output Image")
|
26 |
|
27 |
|
|
|
7 |
#subprocess.run(["mv","content/custom_data.yaml","./yolov5/data"])
|
8 |
|
9 |
|
10 |
+
def load_model():
|
11 |
+
'''
|
12 |
+
Loading hub model & setting the preferences for the model
|
13 |
+
'''
|
14 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', path='Content/best.pt')
|
15 |
+
model.conf = 0.38
|
16 |
+
model.hide_conf=True
|
17 |
+
return model
|
18 |
|
|
|
|
|
|
|
19 |
#, force_reload=True
|
20 |
def detect(inp):
|
21 |
#g = (size / max(inp.size)) # gain
|
22 |
#im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
|
23 |
+
model=load_model()
|
24 |
results = model(inp,size=640) # inference
|
25 |
results.render() # updates results.imgs with boxes and labels
|
26 |
return Image.fromarray(results.imgs[0])
|
27 |
|
28 |
|
29 |
+
inp = gr.inputs.Image(type="pil", label="Original Image")
|
30 |
output = gr.outputs.Image(type="pil", label="Output Image")
|
31 |
|
32 |
|