limit video infer memory occupy
Browse files64 unmodified lines6566676869708 unmodified lines7980818283848513 unmodified lines9910010110210310410564 unmodified linesreturn depth.squeeze(1).unflatten(0, (B, T)) # return shape [B, T, H, W]def infer_video_depth(self, frames, target_fps, input_size=518, device='cuda'):transform = Compose([Resize(width=input_size,8 unmodified linesPrepareForNet(),])frame_size = frames[0].shape[:2]frame_list = [frames[i] for i in range(frames.shape[0])]frame_step = INFER_LEN - OVERLAPorg_video_len = len(frame_list)13 unmodified lineswith torch.no_grad():depth = self.forward(cur_input) # depth shape: [1, T, H, W]depth = F.interpolate(depth.flatten(0,1).unsqueeze(1), size=frame_size, mode='bilinear', align_corners=True)depth_list += [depth[i][0].cpu().numpy() for i in range(depth.shape[0])]pre_input = cur_input64 unmodified lines6566676869707172737475768 unmodified lines85868788899013 unmodified lines10410510610710810911064 unmodified linesreturn depth.squeeze(1).unflatten(0, (B, T)) # return shape [B, T, H, W]def infer_video_depth(self, frames, target_fps, input_size=518, device='cuda'):frame_height, frame_width = frames[0].shape[:2]ratio = max(frame_height, frame_width) / min(frame_height, frame_width)if ratio > 1.78:input_size = int(input_size * 1.78 / ratio)input_size = round(input_size / 14) * 14transform = Compose([Resize(width=input_size,8 unmodified linesPrepareForNet(),])frame_list = [frames[i] for i in range(frames.shape[0])]frame_step = INFER_LEN - OVERLAPorg_video_len = len(frame_list)13 unmodified lineswith torch.no_grad():depth = self.forward(cur_input) # depth shape: [1, T, H, W]depth = F.interpolate(depth.flatten(0,1).unsqueeze(1), size=(frame_height, frame_width), mode='bilinear', align_corners=True)depth_list += [depth[i][0].cpu().numpy() for i in range(depth.shape[0])]pre_input = cur_input
video_depth_anything/video_depth.py+7-2