nathanjc commited on
Commit
79c1525
·
1 Parent(s): fc8ca5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -25
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
- 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).resize((300,250)).show()
156
- cv2.imwrite(save_path, im0)
 
157
  print(f" The image with the result is saved in: {save_path}")
158
- else: # 'video' or 'stream'
159
- if vid_path != save_path: # new video
160
- vid_path = save_path
161
- if isinstance(vid_writer, cv2.VideoWriter):
162
- vid_writer.release() # release previous video writer
163
- if vid_cap: # video
164
- fps = vid_cap.get(cv2.CAP_PROP_FPS)
165
- w = int(vid_cap.get(cv2.CAP_PROP_FRAME_WIDTH))
166
- h = int(vid_cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
167
- else: # stream
168
- fps, w, h = 30, im0.shape[1], im0.shape[0]
169
- save_path += '.mp4'
170
- vid_writer = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h))
171
- vid_writer.write(im0)
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
- for opt.weights in ['yolov7.pt']:
212
- bbox,output_path = detect(opt)
213
- strip_optimizer(opt.weights)
214
- else:
215
- bbox,output_path = detect(opt)
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,