Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -180,14 +180,14 @@ def preprocess_for_removal(images, masks):
|
|
180 |
return torch.from_numpy(arr_images).half().to(device), torch.from_numpy(arr_masks).half().to(device)
|
181 |
|
182 |
@spaces.GPU(duration=200)
|
183 |
-
def inference_and_return_video(dilation_iterations, num_inference_steps, video_state
|
184 |
if video_state["origin_images"] is None or video_state["masks"] is None:
|
185 |
return None
|
186 |
images = video_state["origin_images"]
|
187 |
masks = video_state["masks"]
|
188 |
|
189 |
-
|
190 |
-
|
191 |
print(f"line 191 images shape:{images.shape},masks shape:{masks.shape}")
|
192 |
#line 191 images shape:(1, 1024, 1820, 3),masks shape:(1, 1024, 1820), which should be (16, 1024, 1820, 3) and (16, 1024, 1820, 3)
|
193 |
img_tensor, mask_tensor = preprocess_for_removal(images, masks)
|
@@ -242,7 +242,7 @@ def track_video(n_frames, video_state):
|
|
242 |
W_ = int(H_ * images[0].shape[1] / images[0].shape[0])
|
243 |
|
244 |
images = [cv2.resize(img, (W_, H_)) for img in images]
|
245 |
-
video_state["origin_images"] =
|
246 |
images = np.array(images)
|
247 |
inference_state = video_predictor.init_state(images=images/255, device=device)
|
248 |
video_state["inference_state"] = inference_state
|
@@ -279,7 +279,7 @@ def track_video(n_frames, video_state):
|
|
279 |
painted = np.uint8(np.clip(painted * 255, 0, 255))
|
280 |
output_frames.append(painted)
|
281 |
print(f"line 281 len(output_frames)={len(output_frames)}, painted shape:{painted.shape}")
|
282 |
-
video_state["masks"] =
|
283 |
print(f'line 283 len video_state["masks"]:{len(video_state["masks"])}')
|
284 |
print(f'line 284 video_state["masks"][0].shape:{video_state["masks"][0].shape}')
|
285 |
video_file = f"/tmp/{time.time()}-{random.random()}-tracked_output.mp4"
|
|
|
180 |
return torch.from_numpy(arr_images).half().to(device), torch.from_numpy(arr_masks).half().to(device)
|
181 |
|
182 |
@spaces.GPU(duration=200)
|
183 |
+
def inference_and_return_video(dilation_iterations, num_inference_steps, video_state):
|
184 |
if video_state["origin_images"] is None or video_state["masks"] is None:
|
185 |
return None
|
186 |
images = video_state["origin_images"]
|
187 |
masks = video_state["masks"]
|
188 |
|
189 |
+
images = np.array(images)
|
190 |
+
masks = np.array(masks)
|
191 |
print(f"line 191 images shape:{images.shape},masks shape:{masks.shape}")
|
192 |
#line 191 images shape:(1, 1024, 1820, 3),masks shape:(1, 1024, 1820), which should be (16, 1024, 1820, 3) and (16, 1024, 1820, 3)
|
193 |
img_tensor, mask_tensor = preprocess_for_removal(images, masks)
|
|
|
242 |
W_ = int(H_ * images[0].shape[1] / images[0].shape[0])
|
243 |
|
244 |
images = [cv2.resize(img, (W_, H_)) for img in images]
|
245 |
+
video_state["origin_images"] = images
|
246 |
images = np.array(images)
|
247 |
inference_state = video_predictor.init_state(images=images/255, device=device)
|
248 |
video_state["inference_state"] = inference_state
|
|
|
279 |
painted = np.uint8(np.clip(painted * 255, 0, 255))
|
280 |
output_frames.append(painted)
|
281 |
print(f"line 281 len(output_frames)={len(output_frames)}, painted shape:{painted.shape}")
|
282 |
+
video_state["masks"] =mask_frames
|
283 |
print(f'line 283 len video_state["masks"]:{len(video_state["masks"])}')
|
284 |
print(f'line 284 video_state["masks"][0].shape:{video_state["masks"][0].shape}')
|
285 |
video_file = f"/tmp/{time.time()}-{random.random()}-tracked_output.mp4"
|