Closed Manticore425 closed 1 year ago
pip install imageio==2.5.0
pip install imageio==2.5.0
Thank you, but that doesn't help.
I have changed back to:
imageio. mimsave (io_args ['output_gif '], masked_pred_list, fps=fps)
It reports:
SegTracker has been initialized
Click
Start tracking !
processed frame 49, obj_num 2
finished
frame 49 writed
/home/weedy/Projects/Segment-and-Track-Anything/tracking_results/blackswan/blackswan_seg.mp4 saved
finished
/home/weedy/Projects/Segment-and-Track-Anything/tracking_results/blackswan/blackswan_seg.gif saved
sh: 1: zip: not found
/home/weedy/miniconda3/envs/samtrack/lib/python3.10/site-packages/gradio/components.py:2239: UserWarning: Video does not have browser-compatible container or codec. Converting to mp4
warnings.warn(
Traceback (most recent call last):
File "/home/weedy/miniconda3/envs/samtrack/lib/python3.10/site-packages/gradio/routes.py", line 422, in run_predict
output = await app.get_blocks().process_api(
File "/home/weedy/miniconda3/envs/samtrack/lib/python3.10/site-packages/gradio/blocks.py", line 1326, in process_api
data = self.postprocess_data(fn_index, result["prediction"], state)
File "/home/weedy/miniconda3/envs/samtrack/lib/python3.10/site-packages/gradio/blocks.py", line 1260, in postprocess_data
prediction_value = block.postprocess(prediction_value)
File "/home/weedy/miniconda3/envs/samtrack/lib/python3.10/site-packages/gradio/components.py", line 2824, in postprocess
"name": self.make_temp_copy_if_needed(y),
File "/home/weedy/miniconda3/envs/samtrack/lib/python3.10/site-packages/gradio/components.py", line 259, in make_temp_copy_if_needed
temp_dir = self.hash_file(file_path)
File "/home/weedy/miniconda3/envs/samtrack/lib/python3.10/site-packages/gradio/components.py", line 223, in hash_file
with open(file_path, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: '/home/weedy/Projects/Segment-and-Track-Anything/tracking_results/blackswan/blackswan_pred_mask.zip'
pip install imageio==2.5.0
Thank you, but that doesn't help. I have changed back to:
imageio. mimsave (io_args ['output_gif '], masked_pred_list, fps=fps)
It reports:
SegTracker has been initialized Click Start tracking ! processed frame 49, obj_num 2 finished frame 49 writed /home/weedy/Projects/Segment-and-Track-Anything/tracking_results/blackswan/blackswan_seg.mp4 saved finished /home/weedy/Projects/Segment-and-Track-Anything/tracking_results/blackswan/blackswan_seg.gif saved sh: 1: zip: not found /home/weedy/miniconda3/envs/samtrack/lib/python3.10/site-packages/gradio/components.py:2239: UserWarning: Video does not have browser-compatible container or codec. Converting to mp4 warnings.warn( Traceback (most recent call last): File "/home/weedy/miniconda3/envs/samtrack/lib/python3.10/site-packages/gradio/routes.py", line 422, in run_predict output = await app.get_blocks().process_api( File "/home/weedy/miniconda3/envs/samtrack/lib/python3.10/site-packages/gradio/blocks.py", line 1326, in process_api data = self.postprocess_data(fn_index, result["prediction"], state) File "/home/weedy/miniconda3/envs/samtrack/lib/python3.10/site-packages/gradio/blocks.py", line 1260, in postprocess_data prediction_value = block.postprocess(prediction_value) File "/home/weedy/miniconda3/envs/samtrack/lib/python3.10/site-packages/gradio/components.py", line 2824, in postprocess "name": self.make_temp_copy_if_needed(y), File "/home/weedy/miniconda3/envs/samtrack/lib/python3.10/site-packages/gradio/components.py", line 259, in make_temp_copy_if_needed temp_dir = self.hash_file(file_path) File "/home/weedy/miniconda3/envs/samtrack/lib/python3.10/site-packages/gradio/components.py", line 223, in hash_file with open(file_path, "rb") as f: FileNotFoundError: [Errno 2] No such file or directory: '/home/weedy/Projects/Segment-and-Track-Anything/tracking_results/blackswan/blackswan_pred_mask.zip'
sh: 1: zip: not found
please install zip at first
Update seg_track_anything.py The mp4 files generated by imageio.mimsave() can be played in gradio video
https://github.com/gptbert/Segment-and-Track-Anything/blob/main/seg_track_anything.py
##################
# Visualization
##################
# draw pred mask on frame and save as a video
cap = cv2.VideoCapture(input_video)
fps = cap.get(cv2.CAP_PROP_FPS)
# width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
# height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
# num_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
# fourcc = cv2.VideoWriter_fourcc(*"mp4v")
# if input_video[-3:]=='mp4':
# fourcc = cv2.VideoWriter_fourcc(*"mp4v")
# elif input_video[-3:] == 'avi':
# fourcc = cv2.VideoWriter_fourcc(*"MJPG")
# # fourcc = cv2.VideoWriter_fourcc(*"XVID")
# else:
# fourcc = int(cap.get(cv2.CAP_PROP_FOURCC))
# out = cv2.VideoWriter(io_args["output_video"], fourcc, fps, (width, height))
frame_idx = 0
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
pred_mask = pred_list[frame_idx]
masked_frame = draw_mask(frame, pred_mask)
cv2.imwrite(
f"{io_args['output_masked_frame_dir']}/{str(frame_idx).zfill(5)}.png",
masked_frame[:, :, ::-1],
)
masked_pred_list.append(masked_frame)
# masked_frame = cv2.cvtColor(masked_frame, cv2.COLOR_RGB2BGR)
# out.write(masked_frame)
print(f"frame {frame_idx} writed", end="\r")
frame_idx += 1
# out.release()
cap.release()
imageio.mimsave(io_args["output_video"], masked_pred_list, fps=fps)
print("\n{} saved".format(io_args["output_video"]))
print("\nfinished")
Update seg_track_anything.py The mp4 files generated by imageio.mimsave() can be played in gradio video
https://github.com/gptbert/Segment-and-Track-Anything/blob/main/seg_track_anything.py
################## # Visualization ################## # draw pred mask on frame and save as a video cap = cv2.VideoCapture(input_video) fps = cap.get(cv2.CAP_PROP_FPS) # width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) # height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) # num_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) # fourcc = cv2.VideoWriter_fourcc(*"mp4v") # if input_video[-3:]=='mp4': # fourcc = cv2.VideoWriter_fourcc(*"mp4v") # elif input_video[-3:] == 'avi': # fourcc = cv2.VideoWriter_fourcc(*"MJPG") # # fourcc = cv2.VideoWriter_fourcc(*"XVID") # else: # fourcc = int(cap.get(cv2.CAP_PROP_FOURCC)) # out = cv2.VideoWriter(io_args["output_video"], fourcc, fps, (width, height)) frame_idx = 0 while cap.isOpened(): ret, frame = cap.read() if not ret: break frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) pred_mask = pred_list[frame_idx] masked_frame = draw_mask(frame, pred_mask) cv2.imwrite( f"{io_args['output_masked_frame_dir']}/{str(frame_idx).zfill(5)}.png", masked_frame[:, :, ::-1], ) masked_pred_list.append(masked_frame) # masked_frame = cv2.cvtColor(masked_frame, cv2.COLOR_RGB2BGR) # out.write(masked_frame) print(f"frame {frame_idx} writed", end="\r") frame_idx += 1 # out.release() cap.release() imageio.mimsave(io_args["output_video"], masked_pred_list, fps=fps) print("\n{} saved".format(io_args["output_video"])) print("\nfinished")
Thank you very much! The problem has been resolved.
When I import a video to WebUI, WebUI cannot display the tracking results. At first, the program will report an error:
So I changed the 196th line of the file "seg_track_anything. py":
imageio. mimsave (io_args ['output_gif '], masked_pred_list, fps=fps)
toimageio. mimsave (io_args [" output_gif "], masked_pred_list, duration=int (1000/fps))
But WebUI still cannot output results. It will report an error:
How should I fix that bug?