NVIDIA / flownet2-pytorch

Pytorch implementation of FlowNet 2.0: Evolution of Optical Flow Estimation with Deep Networks
Other
3.08k stars 738 forks source link

Error when running Inference: forward call is outdated and returns an error when called. #268

Open onurbagoren opened 2 years ago

onurbagoren commented 2 years ago

Hello, I am attempting to run the inference using the model. I run the provided command of

$ python3 main.py --inference --model FlowNet2 --save_flow --inference_dataset MpiSintelClean \
 --inference_dataset_root $INFERENCE_DATASET --resume $CHECKPOINTS_DIR

I get an error at line 374 of main.py

RuntimeError: Legacy autograd function with non-static forward method is deprecated. 
Please use new-style autograd function with static forward method. (Example: https://pytorch.org/docs/stable/autograd.html#torch.autograd.Function)

I followed the instructions from the provided link and added @staticmethod to the forward function. I now get a new error regarding the number of parameters in the model(data[0], target[0], inference=True) call at line 374 of main.py.

I tried several solutions:

  1. Explicitly call `model.forward(data[0], target[0], inference=True) This did not work and returned the error:
    Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/home/$HOME/.local/lib/python3.8/site-packages/torch/nn/parallel/data_parallel.py", line 166, in forward
    return self.module(*inputs[0], **kwargs[0])
    File "/home/$HOME/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
    TypeError: forward() missing 1 required positional argument: 'target'
  2. I then tried to name the parameters that are defined in the forward call from the model ModelAndLoss like so: model.forward(data=data[0], target=target[0], inference=True) I then received the following error:
    Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/home/$HOME/.local/lib/python3.8/site-packages/torch/nn/parallel/data_parallel.py", line 166, in forward
    return self.module(*inputs[0], **kwargs[0])
    File "/home/$HOME/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
    TypeError: forward() missing 1 required positional argument: 'self'

    This implies that the object call to its own instance is required somehow in order to make this a valid call, so I tried:

  3. model.forward(self=model, data=data[0], target=target[0], inference=True) and this then returned the error:
    Traceback (most recent call last):
    File "<string>", line 1, in <module>
    TypeError: forward() got multiple values for argument 'self'

I am at a lost of ideas, any recommendations on how to fix this would be greatly appreciated.

To add some more references, I used the changes made in the pull request in #254 in order to install the custom layers, as my compiler is c++14.

Besides this, I have not made any other changes. Any maintainers help would be greatly appreciated!!

Thank you