Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -73,8 +73,8 @@ def sigmoid(x):
|
|
| 73 |
|
| 74 |
|
| 75 |
def preprocess_image(img, img_size):
|
| 76 |
-
img = square_pad_opencv(img)
|
| 77 |
-
img = cv2.resize(img, (img_size, img_size), interpolation=cv2.INTER_CUBIC)
|
| 78 |
img = Image.fromarray(img)
|
| 79 |
transforms_list = []
|
| 80 |
transforms_list.append(transforms.ToTensor())
|
|
@@ -116,10 +116,12 @@ def inference(x, count_only_api, api_key,
|
|
| 116 |
frame = all_frames[-1] # padding will be with last frame
|
| 117 |
break
|
| 118 |
frame = cv2.cvtColor(np.uint8(frame), cv2.COLOR_BGR2RGB)
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
| 123 |
all_frames.append(frame)
|
| 124 |
frame_i += 1
|
| 125 |
cap.release()
|
|
@@ -136,7 +138,7 @@ def inference(x, count_only_api, api_key,
|
|
| 136 |
batch_list = []
|
| 137 |
idx_list = []
|
| 138 |
inference_futures = []
|
| 139 |
-
with concurrent.futures.ThreadPoolExecutor() as executor:
|
| 140 |
for i in tqdm(range(0, length + stride_length - stride_pad, stride_length)):
|
| 141 |
batch = all_frames[i:i + seq_len]
|
| 142 |
Xlist = []
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
def preprocess_image(img, img_size):
|
| 76 |
+
#img = square_pad_opencv(img)
|
| 77 |
+
#img = cv2.resize(img, (img_size, img_size), interpolation=cv2.INTER_CUBIC)
|
| 78 |
img = Image.fromarray(img)
|
| 79 |
transforms_list = []
|
| 80 |
transforms_list.append(transforms.ToTensor())
|
|
|
|
| 116 |
frame = all_frames[-1] # padding will be with last frame
|
| 117 |
break
|
| 118 |
frame = cv2.cvtColor(np.uint8(frame), cv2.COLOR_BGR2RGB)
|
| 119 |
+
frame = cv2.resize(frame, (resize_size, resize_size), interpolation=cv2.INTER_CUBIC)
|
| 120 |
+
frame_center_x = frame.shape[1] // 2
|
| 121 |
+
frame_center_y = frame.shape[0] // 2
|
| 122 |
+
crop_x = frame_center_x - img_size // 2
|
| 123 |
+
crop_y = frame_center_y - img_size // 2
|
| 124 |
+
frame = frame[crop_y:crop_y+img_size, crop_x:crop_x+img_size]
|
| 125 |
all_frames.append(frame)
|
| 126 |
frame_i += 1
|
| 127 |
cap.release()
|
|
|
|
| 138 |
batch_list = []
|
| 139 |
idx_list = []
|
| 140 |
inference_futures = []
|
| 141 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
|
| 142 |
for i in tqdm(range(0, length + stride_length - stride_pad, stride_length)):
|
| 143 |
batch = all_frames[i:i + seq_len]
|
| 144 |
Xlist = []
|