piperod91 commited on
Commit
7b5103c
·
1 Parent(s): 70b8d29

adding failsafe for high resolution images

Browse files
Files changed (2) hide show
  1. app.py +8 -1
  2. metrics.py +2 -2
app.py CHANGED
@@ -135,6 +135,7 @@ def draw_cockpit(frame, top_pred,cnt):
135
 
136
 
137
  def process_video(input_video, out_fps = 'auto', skip_frames = 7):
 
138
  cap = cv2.VideoCapture(input_video)
139
 
140
  output_path = "output.mp4"
@@ -147,6 +148,10 @@ def process_video(input_video, out_fps = 'auto', skip_frames = 7):
147
 
148
  width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
149
  height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
 
 
 
 
150
 
151
  video = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*"mp4v"), fps, (width, height))
152
 
@@ -157,6 +162,7 @@ def process_video(input_video, out_fps = 'auto', skip_frames = 7):
157
  print('overall count ', cnt)
158
 
159
  if (cnt % skip_frames) == 0:
 
160
  print('starting Frame: ', cnt)
161
  # flip frame vertically
162
  display_frame, result = inference_frame_serial(frame)
@@ -189,6 +195,7 @@ def process_video(input_video, out_fps = 'auto', skip_frames = 7):
189
  print(pred_dashbord.shape)
190
  print(frame.shape)
191
  print(prediction_frame.shape)
 
192
  yield frame , None
193
 
194
  cnt += 1
@@ -217,4 +224,4 @@ demo.queue()
217
  if os.getenv('SYSTEM') == 'spaces':
218
  demo.launch(width='40%',auth=(os.environ.get('SHARK_USERNAME'), os.environ.get('SHARK_PASSWORD')))
219
  else:
220
- demo.launch()
 
135
 
136
 
137
  def process_video(input_video, out_fps = 'auto', skip_frames = 7):
138
+ print('Processing video: ')
139
  cap = cv2.VideoCapture(input_video)
140
 
141
  output_path = "output.mp4"
 
148
 
149
  width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
150
  height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
151
+
152
+ if width > 1920 or height > 1080:
153
+ width = int(width//4)
154
+ height = int(height//4)
155
 
156
  video = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*"mp4v"), fps, (width, height))
157
 
 
162
  print('overall count ', cnt)
163
 
164
  if (cnt % skip_frames) == 0:
165
+ frame = cv2.resize(frame, (int(width), int(height)))
166
  print('starting Frame: ', cnt)
167
  # flip frame vertically
168
  display_frame, result = inference_frame_serial(frame)
 
195
  print(pred_dashbord.shape)
196
  print(frame.shape)
197
  print(prediction_frame.shape)
198
+ print(width, height)
199
  yield frame , None
200
 
201
  cnt += 1
 
224
  if os.getenv('SYSTEM') == 'spaces':
225
  demo.launch(width='40%',auth=(os.environ.get('SHARK_USERNAME'), os.environ.get('SHARK_PASSWORD')))
226
  else:
227
+ demo.launch(debug=True)
metrics.py CHANGED
@@ -106,7 +106,7 @@ def add_class_sizes(top_pred = {}, class_sizes = None):
106
 
107
  top_pred['pred_above_thresh_sizes'] = size_list
108
 
109
- if top_pred['shark_n'] > 0:
110
  top_pred['biggest_shark_size'] = np.max(shark_size_list)
111
  else:
112
  top_pred['biggest_shark_size'] = None
@@ -132,7 +132,7 @@ def add_class_weights(top_pred = {}, class_weights = None):
132
 
133
  top_pred['pred_above_thresh_weights'] = weight_list
134
 
135
- if top_pred['shark_n'] > 0:
136
  top_pred['biggest_shark_weight'] = np.max(shark_weight_list)
137
  else:
138
  top_pred['biggest_shark_weight'] = None
 
106
 
107
  top_pred['pred_above_thresh_sizes'] = size_list
108
 
109
+ if top_pred['shark_n'] > 0 and len(shark_size_list) > 0:
110
  top_pred['biggest_shark_size'] = np.max(shark_size_list)
111
  else:
112
  top_pred['biggest_shark_size'] = None
 
132
 
133
  top_pred['pred_above_thresh_weights'] = weight_list
134
 
135
+ if top_pred['shark_n'] > 0 and len(shark_weight_list) > 0:
136
  top_pred['biggest_shark_weight'] = np.max(shark_weight_list)
137
  else:
138
  top_pred['biggest_shark_weight'] = None