ntsc207 commited on
Commit
d1302f4
·
verified ·
1 Parent(s): 369825f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -10,7 +10,6 @@ import numpy as np
10
  import threading
11
 
12
  should_continue = True
13
- os.environ["GRADIO_CACHE_EXAMPLES"] = "lazy"
14
 
15
  @spaces.GPU(duration=120)
16
  def yolov9_inference(model_id, img_path=None, vid_path=None, tracking_algorithm = None):
@@ -31,7 +30,7 @@ def yolov9_inference(model_id, img_path=None, vid_path=None, tracking_algorithm
31
  img.save(img_path)
32
  input_path = img_path
33
  print(input_path)
34
- output_path = run(weights=model_id, imgsz=(image_size,image_size), conf_thres=conf_threshold, iou_thres=iou_threshold, source=input_path, device='cpu', hide_conf= True)
35
  elif vid_path is not None:
36
  vid_name = 'output.mp4'
37
 
@@ -68,11 +67,12 @@ def yolov9_inference(model_id, img_path=None, vid_path=None, tracking_algorithm
68
  out.release()
69
  input_path = vid_name
70
  if tracking_algorithm == 'deep_sort':
71
- output_path = run_deepsort(weights=model_id, imgsz=(image_size,image_size), conf_thres=conf_threshold, iou_thres=iou_threshold, source=input_path, device='cpu', draw_trails=True)
72
  elif tracking_algorithm == 'strong_sort':
73
- output_path = run_strongsort(yolo_weights=model_id, imgsz=(image_size,image_size), conf_thres=conf_threshold, iou_thres=iou_threshold, source=input_path, device='cpu', strong_sort_weights = "osnet_x0_25_msmt17.pt", hide_conf= True)
 
74
  else:
75
- output_path = run(weights=model_id, imgsz=(image_size,image_size), conf_thres=conf_threshold, iou_thres=iou_threshold, source=input_path, device='cpu', hide_conf= True)
76
  # Assuming output_path is the path to the output file
77
  _, output_extension = os.path.splitext(output_path)
78
  if output_extension.lower() in img_extensions:
@@ -108,8 +108,8 @@ def app():
108
  ],
109
  value="None"
110
  )
111
- gr.Examples(['camera1_A_133.png'], inputs=img_path,label = "Image Example")
112
- gr.Examples(['test.mp4'], inputs=vid_path, label = "Video Example")
113
  yolov9_infer = gr.Button(value="Inference")
114
  with gr.Column():
115
  gr.HTML("<h2>Output</h2>")
 
10
  import threading
11
 
12
  should_continue = True
 
13
 
14
  @spaces.GPU(duration=120)
15
  def yolov9_inference(model_id, img_path=None, vid_path=None, tracking_algorithm = None):
 
30
  img.save(img_path)
31
  input_path = img_path
32
  print(input_path)
33
+ output_path = run(weights=model_id, imgsz=(image_size,image_size), conf_thres=conf_threshold, iou_thres=iou_threshold, source=input_path, device='0', hide_conf= True)
34
  elif vid_path is not None:
35
  vid_name = 'output.mp4'
36
 
 
67
  out.release()
68
  input_path = vid_name
69
  if tracking_algorithm == 'deep_sort':
70
+ output_path = run_deepsort(weights=model_id, imgsz=(image_size,image_size), conf_thres=conf_threshold, iou_thres=iou_threshold, source=input_path, device='0', draw_trails=True)
71
  elif tracking_algorithm == 'strong_sort':
72
+ device_strongsort = torch.device('cuda:0')
73
+ output_path = run_strongsort(yolo_weights=model_id, imgsz=(image_size,image_size), conf_thres=conf_threshold, iou_thres=iou_threshold, source=input_path, device=device_strongsort, strong_sort_weights = "osnet_x0_25_msmt17.pt", hide_conf= True)
74
  else:
75
+ output_path = run(weights=model_id, imgsz=(image_size,image_size), conf_thres=conf_threshold, iou_thres=iou_threshold, source=input_path, device='0', hide_conf= True)
76
  # Assuming output_path is the path to the output file
77
  _, output_extension = os.path.splitext(output_path)
78
  if output_extension.lower() in img_extensions:
 
108
  ],
109
  value="None"
110
  )
111
+ gr.Examples(['camera1_A_133.png'], inputs=img_path,label = "Image Example", cache_examples = False)
112
+ gr.Examples(['test.mp4'], inputs=vid_path, label = "Video Example", cache_examples = False)
113
  yolov9_infer = gr.Button(value="Inference")
114
  with gr.Column():
115
  gr.HTML("<h2>Output</h2>")