facebookresearch / mmf

A modular framework for vision & language multimodal research from Facebook AI Research (FAIR)
https://mmf.sh/
Other
5.5k stars 939 forks source link

KeyError: 'targets' on inference #696

Closed JoshuaPlacidi closed 3 years ago

JoshuaPlacidi commented 3 years ago

❓ Questions and Help

I ran the command in windows cmd: mmf_run config=projects/hateful_memes/configs/unimodal/image.yaml model=unimodal_image dataset=hateful_memes

While training I got the following warning every time a checkpoint was saved: WARNING 2020-11-23T20:36:26 | py.warnings: c:\python38\lib\site-packages\torch\optim\lr_scheduler.py:200: UserWarning: Please also save or load the state of the optimzer when saving or loading the scheduler. warnings.warn(SAVE_STATE_WARNING, UserWarning)

The model started inference on test set but failed with multiple warnings:

2020-11-24T11:25:37 | mmf.trainers.mmf_trainer: Starting inference on test set
  0%|                                                                                                                                                        | 0/63 [00:00<?, ?it/s]WARNING 2020-11-24T11:25:54 | py.warnings: f:\mmf\mmf\modules\losses.py:98: UserWarning: Sample list has not field 'targets', are you sure that your ImDB has labels? you may have wanted to run with evaluation.predict=true
  warnings.warn(

WARNING 2020-11-24T11:25:54 | py.warnings: f:\mmf\mmf\modules\losses.py:98: UserWarning: Sample list has not field 'targets', are you sure that your ImDB has labels? you may have wanted to run with evaluation.predict=true
  warnings.warn(

  2%|██▎                                                                                                                                             | 1/63 [00:16<16:34, 16.05s/it]WARNING 2020-11-24T11:25:54 | py.warnings: f:\mmf\mmf\common\report.py:80: UserWarning: targets not found in report. Metrics calculation might not work as expected.
  warnings.warn(

WARNING 2020-11-24T11:25:54 | py.warnings: f:\mmf\mmf\common\report.py:80: UserWarning: targets not found in report. Metrics calculation might not work as expected.
  warnings.warn(

100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 63/63 [00:34<00:00,  1.84it/s]
Traceback (most recent call last):
  File "C:\Python38\Scripts\mmf_run-script.py", line 33, in <module>
    sys.exit(load_entry_point('mmf', 'console_scripts', 'mmf_run')())
  File "f:\mmf\mmf_cli\run.py", line 122, in run
    main(configuration, predict=predict)
  File "f:\mmf\mmf_cli\run.py", line 56, in main
    trainer.train()
  File "f:\mmf\mmf\trainers\mmf_trainer.py", line 126, in train
    self.inference()
  File "f:\mmf\mmf\trainers\mmf_trainer.py", line 143, in inference
    report, meter = self.evaluation_loop(
  File "f:\mmf\mmf\trainers\core\evaluation_loop.py", line 45, in evaluation_loop
    combined_report.metrics = self.metrics(combined_report, combined_report)
  File "f:\mmf\mmf\modules\metrics.py", line 144, in __call__
    values[key] = metric_object._calculate_with_checks(
  File "f:\mmf\mmf\modules\metrics.py", line 207, in _calculate_with_checks
    value = self.calculate(*args, **kwargs)
  File "f:\mmf\mmf\modules\metrics.py", line 234, in calculate
    expected = sample_list["targets"]
KeyError: 'targets'

The same happens when I try to run_type=inference on the trained model

hackgoofer commented 3 years ago

Hi! Thanks for using mmf 😄

Try adding: evaluation.predict=true in the command of mmf_run. Adding this converts the command to mmf_predict

Feel free to refer to the tutorial on BUTD on here to see how to run predict.