why google colab dont run all of codes related to mmflow toolbox?

61 Views Asked by At

hi i have tried python codes related to optical flow algorithms using MMFlow toolbox in google colab. i have 50 images frames that extracted from river flow video.i use pwc-net deep learning model. my codes are below:

!pip install mmcv-full
!pip install mmflow
!pip install opencv-python
from mmcv.utils import config
import os.path as osp
from argparse import ArgumentParser
import cv2
import mmcv
# use the pre-trained model for the whole PWC-Net
load_from = 'https://download.openmmlab.com/mmflow/pwcnet/pwcnet_8x1_sfine_flyingthings3d_subset_384x768.pth'  # model path can be found in model zoo
from mmflow.apis import inference_model, init_model
from mmflow.datasets import visualize_flow, write_flow
parser = ArgumentParser()
 frame_folder = '/content/drive/My Drive/resizedImages_river'
frame_count = 50;
 if __name__ == '__main__':
   for i in range(1,frame_count):
     frame1_path = f'{frame_folder}/frame{i}.jpg'
     frame2_path = f'{frame_folder}/frame{i+1}.jpg'
     frame1 = cv2.imread(frame1_path)
     frame2 = cv2.imread(frame2_path)
    img1=frame1
    img2=frame2
    config='configs/pwcnet/pwcnet_8x1_slong_flyingchairs_384x448.py'
    checkpoint='checkpoints/pwcnet_8x1_slong_flyingchairs_384x448.pth'
    flowmap='D:\flowmap'
    parser.add_argument('--img1', help='Image1 file')
    parser.add_argument('--img2', help='Image2 file')
    parser.add_argument('--valid',help='Valid file. If the predicted flow 
    is''sparse, valid mask will filter the output flow map.')
    parser.add_argument('--config', help='Config file')
    parser.add_argument('--checkpoint', help='Checkpoint file')
    parser.add_argument('--D:\flowmap', help='Path of directory to save flow map 
    and flow file')
    parser.add_argument('--out_prefix',help='The prefix for the output results 
    ''including flow file and visualized flow map',default='flow')
   parser.add_argument('--device', default='cuda:0', help='Device used for 
   inference')
   #args = parser.parse_args()
   args, unknown = parser.parse_known_args()
   # return args
   def main(args):
  # build the model from a config file and a checkpoint file
   model = init_model(args.config, args.checkpoint, device=args.device)
  # test a single image
  result = inference_model(model, args.img1, args.img2)
  result = inference_model(model, args.img1, args.img2, valids=args.valid)
  # save the results
   mmcv.mkdir_or_exist(flowmap)
   visualize_flow(result, osp.join(args.flowmap, f'{args.out_prefix}.jpg'))

google colab processes and run to line: frame2 = cv2.imread(frame2_path) and colab dont run rest of codes and process finishes in a few seconds(example 15 seconds) and colab dont show any error or output. please help me.

0

There are 0 best solutions below