open-mmlab / mmflow

OpenMMLab optical flow toolbox and benchmark
https://mmflow.readthedocs.io/en/latest/
Apache License 2.0
958 stars 115 forks source link

Inference with tensor input #273

Open DelinQu opened 1 year ago

DelinQu commented 1 year ago

Thanks for your error report and we appreciate it a lot.

Checklist

  1. I have searched related issues but cannot get the expected help.
  2. I have read the FAQ documentation but cannot get the expected help.
  3. The bug has not been fixed in the latest version.

Describe the bug I use mmflow as a third-party package and install it with pip. I want use the mmflow's specific model such as FlowNet, GMA or RAFT ... as a flow estimator without the need to train or fine-tune. But instead of providing as image path or ndarray to the function inference_model, I want to Inference with tensor input:

config_file = osp.join(MIN_CACHE, 'pwcnet_ft_4x1_300k_sintel_final_384x768.py')
checkpoint_file = osp.join(MIN_CACHE, 'pwcnet_ft_4x1_300k_sintel_final_384x768.pth')

model = init_model(config_file, checkpoint_file, device=device)
# [x] flow = inference_model(model, osp.join(ROOT, 'data/Wall/img1.png'), osp.join(ROOT, 'data/Wall/img2.png'))

# Inference with tensor input:
img1, img2 = get_image_tensor(osp.join(ROOT, 'data/Wall/img1.png')), get_image_tensor(osp.join(ROOT, 'data/Wall/img2.png'))
flow = model(image1, img2)

res = visualize_flow(flow, osp.join(ROOT, 'res', 'test.png'))

However the error catchs me: image

could you please provide any suggestions? Thanks in advance!

sjokic commented 1 year ago

I think the reason it doesn't work is because the images need to first be passed through a data pipeline that applies various transformations to the images before they can be used as input to the model (cf. inference_model function, in particular test_pipeline = Compose(cfg.pipeline)). This pipeline appears to be applied to each image one by one, rather than processing the whole batch, and also seems to have been implemeted for numpy arrays only. This is very unfortunate, because I would also like inference to work with batches of tensors... :/