Update app.py
Browse files
app.py
CHANGED
@@ -145,30 +145,31 @@ def detect(opt, save_img=False):
|
|
145 |
print(f'{s}Done. ({(1E3 * (t2 - t1)):.1f}ms) Inference, ({(1E3 * (t3 - t2)):.1f}ms) NMS')
|
146 |
|
147 |
# Stream results
|
148 |
-
if view_img:
|
149 |
-
|
150 |
-
|
151 |
|
152 |
# Save results (image with detections)
|
153 |
if save_img:
|
154 |
if dataset.mode == 'image':
|
155 |
-
Image.fromarray(im0).
|
156 |
-
|
|
|
157 |
print(f" The image with the result is saved in: {save_path}")
|
158 |
-
else: # 'video' or 'stream'
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
|
173 |
if save_txt or save_img:
|
174 |
s = f"\n{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}" if save_txt else ''
|
@@ -207,12 +208,12 @@ def get_output(image):
|
|
207 |
opt = options(weights='logo_detection.pt',source=source)
|
208 |
bbox = None
|
209 |
with torch.no_grad():
|
210 |
-
if opt.update: # update all models (to fix SourceChangeWarning)
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
else:
|
215 |
-
|
216 |
return Image.open(output_path)
|
217 |
|
218 |
gr.Interface(fn=get_output,
|
|
|
145 |
print(f'{s}Done. ({(1E3 * (t2 - t1)):.1f}ms) Inference, ({(1E3 * (t3 - t2)):.1f}ms) NMS')
|
146 |
|
147 |
# Stream results
|
148 |
+
# if view_img:
|
149 |
+
# cv2.imshow(str(p), im0)
|
150 |
+
# cv2.waitKey(1) # 1 millisecond
|
151 |
|
152 |
# Save results (image with detections)
|
153 |
if save_img:
|
154 |
if dataset.mode == 'image':
|
155 |
+
Image.fromarray(im0).show()
|
156 |
+
im0.save(save_path)
|
157 |
+
# cv2.imwrite(save_path, im0)
|
158 |
print(f" The image with the result is saved in: {save_path}")
|
159 |
+
# else: # 'video' or 'stream'
|
160 |
+
# if vid_path != save_path: # new video
|
161 |
+
# vid_path = save_path
|
162 |
+
# if isinstance(vid_writer, cv2.VideoWriter):
|
163 |
+
# vid_writer.release() # release previous video writer
|
164 |
+
# if vid_cap: # video
|
165 |
+
# fps = vid_cap.get(cv2.CAP_PROP_FPS)
|
166 |
+
# w = int(vid_cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
167 |
+
# h = int(vid_cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
168 |
+
# else: # stream
|
169 |
+
# fps, w, h = 30, im0.shape[1], im0.shape[0]
|
170 |
+
# save_path += '.mp4'
|
171 |
+
# vid_writer = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h))
|
172 |
+
# vid_writer.write(im0)
|
173 |
|
174 |
if save_txt or save_img:
|
175 |
s = f"\n{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}" if save_txt else ''
|
|
|
208 |
opt = options(weights='logo_detection.pt',source=source)
|
209 |
bbox = None
|
210 |
with torch.no_grad():
|
211 |
+
# if opt.update: # update all models (to fix SourceChangeWarning)
|
212 |
+
# for opt.weights in ['yolov7.pt']:
|
213 |
+
# bbox,output_path = detect(opt)
|
214 |
+
# strip_optimizer(opt.weights)
|
215 |
+
# else:
|
216 |
+
bbox,output_path = detect(opt)
|
217 |
return Image.open(output_path)
|
218 |
|
219 |
gr.Interface(fn=get_output,
|