Skip to content

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

@onurbagoren

Description

@onurbagoren

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'
  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions