Open henbucuoshanghai opened 5 years ago
You should pass your folder path to the demo.py as a parameter. For example, I put my images into the "my_test" folder under the "data" directory. So I can run the demo.py like this: python ../../tools/demo.py --base_path='../../data/my_test/images' --resume SiamMask_DAVIS.pth --config config_davis.json
I have to split the video to frames???and 30fps???
Yes, you should split them.
the state of the art why cant i use it to the video directly??? and how to write the code?????
Code requires opencv for reading video. base_path now targets your desired video.
# Setup device
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
torch.backends.cudnn.benchmark = True
# Setup Model
cfg = load_config(args)
from custom import Custom
siammask = Custom(anchors=cfg['anchors'])
if args.resume:
assert isfile(args.resume), 'Please download {} first.'.format(args.resume)
siammask = load_pretrain(siammask, args.resume)
siammask.eval().to(device)
# Parse Video file
video_path = args.base_path
video = cv2.VideoCapture(video_path)
ret, frame = video.read()
video.set(cv2.CAP_PROP_POS_FRAMES, 0)
# Select ROI
cv2.namedWindow("SiamMask", cv2.WND_PROP_FULLSCREEN)
# cv2.setWindowProperty("SiamMask", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
try:
init_rect = cv2.selectROI('SiamMask', frame, False, False)
x, y, w, h = init_rect
except:
exit()
toc = 0
frame_number = 0
while video.isOpened():
ret, im = video.read()
tic = cv2.getTickCount()
if not ret:
break
if frame_number == 0: # init
target_pos = np.array([x + w / 2, y + h / 2])
target_sz = np.array([w, h])
state = siamese_init(im, target_pos, target_sz, siammask, cfg['hp'], device=device) # init tracker
elif frame_number > 0: # tracking
state = siamese_track(state, im, mask_enable=True, refine_enable=True, device=device) # track
location = state['ploygon'].flatten()
mask = state['mask'] > state['p'].seg_thr
im[:, :, 2] = (mask > 0) * 255 + (mask == 0) * im[:, :, 2]
cv2.polylines(im, [np.int0(location).reshape((-1, 1, 2))], True, (0, 255, 0), 3)
cv2.imshow('SiamMask', im)
key = cv2.waitKey(1)
if key > 0:
break
frame_number += 1
toc += cv2.getTickCount() - tic
toc /= cv2.getTickFrequency()
fps = frame_number / toc
print('SiamMask Time: {:02.1f}s Speed: {:3.1f}fps (with visulization!)'.format(toc, fps))
I tried to run the demo.py with the idea provided in @Marjanmoodi's comment by inputting only 20 frames but got the following error. Please help what to do now.
this is the output i get
the code is wrong???????
Could you please explain why? I add nothing to the actual code just followed the instructions provided.
@SamihaSara Did you run the command from this path: 'SiamMask/experiments/siammask_sharp' ?
@Marjanmoodi yes I did run from this path still faced the error.
@SArham Thank you for the video version. It helped a lot. :+1:
how to use it with my own video?