original_docstring: Generate optical flow using dense flow.
  
      Args:
          vid_item (list): Video item containing video full path,
              video (short) path, video id.
  
      Returns:
          bool: Whether generate optical flow successfully.
      
docstring: Generate optical flow using dense flow.
docstring_tokens: Generate optical flow using dense flow .
code: def extract_frame(vid_item):
      """Generate optical flow using dense flow.
  
      Args:
          vid_item (list): Video item containing video full path,
              video (short) path, video id.
  
      Returns:
          bool: Whether generate optical flow successfully.
      """
      full_path, vid_path, vid_id, method, task, out_format = vid_item
      gpu_idx = '$(python cusel.py -m 400)'
      # print('Video info: {}'.format(vid_item))
  
      if '/' in vid_path:
          act_name = osp.basename(osp.dirname(vid_path))
          out_full_path = osp.join(args.out_dir, act_name)
      else:
          out_full_path = args.out_dir
  
      if task == 'rgb':
          if args.use_opencv:
              # Not like using denseflow,
              # Use OpenCV will not make a sub directory with the video name
              video_name = osp.splitext(osp.basename(vid_path))[0]
              out_full_path = osp.join(out_full_path, video_name)
  
              vr = mmcv.VideoReader(full_path)
              for i in range(len(vr)):
                  if vr[i] is not None:
                      w, h, c = np.shape(vr[i])
                      if args.new_short == 0:
                          if args.new_width == 0 or args.new_height == 0:
                              # Keep original shape
                              out_img = vr[i]
                          else:
                              out_img = mmcv.imresize(vr[i], (args.new_width,
                                                              args.new_height))
                      else:
                          if min(h, w) == h:
                              new_h = args.new_short
                              new_w = int((new_h / h) * w)
                          else:
                              new_w = args.new_short
                              new_h = int((new_w / w) * h)
                          out_img = mmcv.imresize(vr[i], (new_h, new_w))
                      mmcv.imwrite(out_img,
                                   f'{out_full_path}/img_{i + 1:05d}.jpg')
                  else:
                      warnings.warn(
                          'Length inconsistent!'
                          f'Early stop with {i + 1} out of {len(vr)} frames.')
                      break
          else:
              if args.new_short == 0:
                  cmd = osp.join(
                      f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -b=20 -s=0 -o='{out_full_path}'"
                      f' -nw={args.new_width} -nh={args.new_height} -v --st={out_format}')
              else:
                  cmd = osp.join(
                      f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -b=20 -s=0 -o='{out_full_path}'"
                      f' -ns={args.new_short} -v --st={out_format}')
              os.system(cmd)
      elif task == 'flow':
          if args.input_frames:
              if args.new_short == 0:
                  cmd = osp.join(
                      f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -a={method} -b=20 -s=1 -o='{out_full_path}'"  # noqa: E501
                      f' -nw={args.new_width} --nh={args.new_height} -v --if --st={out_format}')
              else:
                  cmd = osp.join(
                      f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -a={method} -b=20 -s=1 -o='{out_full_path}'"  # noqa: E501
                      f' -ns={args.new_short} -v --if --st={out_format}')
          else:
              if args.new_short == 0:
                  cmd = osp.join(
                      f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -a={method} -b=20 -s=1 -o='{out_full_path}'"  # noqa: E501
                      f' -nw={args.new_width} --nh={args.new_height} -v --st={out_format}')
              else:
                  cmd = osp.join(
                      f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -a={method} -b=20 -s=1 -o='{out_full_path}'"  # noqa: E501
                      f' -ns={args.new_short} -v --st={out_format}')
          os.system(cmd)
      else:
          if args.new_short == 0:
              cmd_rgb = osp.join(
                  f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -b=20 -s=0 -o='{out_full_path}'"
                  f' -nw={args.new_width} -nh={args.new_height} -v --st={out_format}')
              cmd_flow = osp.join(
                  f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -a={method} -b=20 -s=1 -o='{out_full_path}'"  # noqa: E501
                  f' -nw={args.new_width} -nh={args.new_height} -v --st={out_format}')
          else:
              cmd_rgb = osp.join(
                  f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -b=20 -s=0 -o='{out_full_path}'"
                  f' -ns={args.new_short} -v --st={out_format}')
              cmd_flow = osp.join(
                  f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -a={method} -b=20 -s=1 -o='{out_full_path}'"  # noqa: E501
                  f' -ns={args.new_short} -v --st={out_format}')
          os.system(cmd_rgb)
          os.system(cmd_flow)
  
      if out_format == 'h5':
  
          # print(f'------------{out_full_path}------------{vid_path}------{vid_id}')
          cmd_compress = f"python wrap_hdf5.py -sp {os.path.join(out_full_path, vid_path.split('.')[0])} -tp {out_full_path} --single_video; rm -r {os.path.join(out_full_path, vid_path.split('.')[0])}"
          os.system(cmd_compress)
      
      print(f'{task} {vid_id} {vid_path} {method} done')
      sys.stdout.flush()
      return True
code_tokens: def extract_frame ( vid_item ) : full_path , vid_path , vid_id , method , task , out_format = vid_item gpu_idx = '$(python cusel.py -m 400)' if '/' in vid_path : act_name = osp . basename ( osp . dirname ( vid_path ) ) out_full_path = osp . join ( args . out_dir , act_name ) else : out_full_path = args . out_dir if task == 'rgb' : if args . use_opencv : video_name = osp . splitext ( osp . basename ( vid_path ) ) [ 0 ] out_full_path = osp . join ( out_full_path , video_name ) vr = mmcv . VideoReader ( full_path ) for i in range ( len ( vr ) ) : if vr [ i ] is not None : w , h , c = np . shape ( vr [ i ] ) if args . new_short == 0 : if args . new_width == 0 or args . new_height == 0 : out_img = vr [ i ] else : out_img = mmcv . imresize ( vr [ i ] , ( args . new_width , args . new_height ) ) else : if min ( h , w ) == h : new_h = args . new_short new_w = int ( ( new_h / h ) * w ) else : new_w = args . new_short new_h = int ( ( new_w / w ) * h ) out_img = mmcv . imresize ( vr [ i ] , ( new_h , new_w ) ) mmcv . imwrite ( out_img , f'{out_full_path}/img_{i + 1:05d}.jpg' ) else : warnings . warn ( 'Length inconsistent!' f'Early stop with {i + 1} out of {len(vr)} frames.' ) break else : if args . new_short == 0 : cmd = osp . join ( f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -b=20 -s=0 -o='{out_full_path}'" f' -nw={args.new_width} -nh={args.new_height} -v --st={out_format}' ) else : cmd = osp . join ( f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -b=20 -s=0 -o='{out_full_path}'" f' -ns={args.new_short} -v --st={out_format}' ) os . system ( cmd ) elif task == 'flow' : if args . input_frames : if args . new_short == 0 : cmd = osp . join ( f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -a={method} -b=20 -s=1 -o='{out_full_path}'" f' -nw={args.new_width} --nh={args.new_height} -v --if --st={out_format}' ) else : cmd = osp . join ( f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -a={method} -b=20 -s=1 -o='{out_full_path}'" f' -ns={args.new_short} -v --if --st={out_format}' ) else : if args . new_short == 0 : cmd = osp . join ( f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -a={method} -b=20 -s=1 -o='{out_full_path}'" f' -nw={args.new_width} --nh={args.new_height} -v --st={out_format}' ) else : cmd = osp . join ( f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -a={method} -b=20 -s=1 -o='{out_full_path}'" f' -ns={args.new_short} -v --st={out_format}' ) os . system ( cmd ) else : if args . new_short == 0 : cmd_rgb = osp . join ( f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -b=20 -s=0 -o='{out_full_path}'" f' -nw={args.new_width} -nh={args.new_height} -v --st={out_format}' ) cmd_flow = osp . join ( f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -a={method} -b=20 -s=1 -o='{out_full_path}'" f' -nw={args.new_width} -nh={args.new_height} -v --st={out_format}' ) else : cmd_rgb = osp . join ( f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -b=20 -s=0 -o='{out_full_path}'" f' -ns={args.new_short} -v --st={out_format}' ) cmd_flow = osp . join ( f"CUDA_VISIBLE_DEVICES={gpu_idx} denseflow '{full_path}' -a={method} -b=20 -s=1 -o='{out_full_path}'" f' -ns={args.new_short} -v --st={out_format}' ) os . system ( cmd_rgb ) os . system ( cmd_flow ) if out_format == 'h5' : cmd_compress = f"python wrap_hdf5.py -sp {os.path.join(out_full_path, vid_path.split('.')[0])} -tp {out_full_path} --single_video; rm -r {os.path.join(out_full_path, vid_path.split('.')[0])}" os . system ( cmd_compress ) print ( f'{task} {vid_id} {vid_path} {method} done' ) sys . stdout . flush ( ) return True
short_docstring: Generate optical flow using dense flow.
short_docstring_tokens: Generate optical flow using dense flow .
comment: """Generate optical flow using dense flow.
  
      Args:
          vid_item (list): Video item containing video full path,
              video (short) path, video id.
  
      Returns:
          bool: Whether generate optical flow successfully.
      """$SEP$# print('Video info: {}'.format(vid_item))$SEP$# Not like using denseflow,$SEP$# Use OpenCV will not make a sub directory with the video name$SEP$# Keep original shape$SEP$# noqa: E501$SEP$# noqa: E501$SEP$# noqa: E501$SEP$# noqa: E501$SEP$# noqa: E501$SEP$# noqa: E501$SEP$# print(f'------------{out_full_path}------------{vid_path}------{vid_id}')