google / automl

Google Brain AutoML
Apache License 2.0
6.18k stars 1.45k forks source link

efficientnetV2 | AttributeError: '_UserObject' object has no attribute 'cfg' #1167

Closed shuyuelan closed 1 year ago

shuyuelan commented 1 year ago

Hi, I tried to run python3 infer.py --mode tf2bm --model_name efficientnetv2-s --model_dir ../../efficientnetv2-s/ --export_dir ../../efficientnetv2-s/saved_model with pretrained models and got the following errors:

Traceback (most recent call last):
  File "infer.py", line 205, in <module>
    app.run(main)
  File "/home/shuyuel/.cache/turtle/test_venv/lib/python3.8/site-packages/absl/app.py", line 312, in run
    _run_main(main, args)
  File "/home/shuyuel/.cache/turtle/test_venv/lib/python3.8/site-packages/absl/app.py", line 258, in _run_main
    sys.exit(main(argv))
  File "infer.py", line 195, in main
    tf2_benchmark()
  File "infer.py", line 100, in tf2_benchmark
    if model.cfg.model.data_format == 'channels_first':
AttributeError: '_UserObject' object has no attribute 'cfg'

Here are the reproducing steps:

  1. Set up TF2.5 along with other required dependencies.
  2. get efficientnetv2-s ckpt from wget https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/v2/efficientnetv2-s.tgz
  3. git clone https://github.com/google/automl
  4. cd /path/to/automl/efficientnetv2
    python3 infer.py \
    --mode tf2bm \
    --model_name efficientnetv2-s \
    --model_dir ../../efficientnetv2-s/ \
    --export_dir ../../efficientnetv2-s/saved_model

Looks like the regression is due to the recent change in automl about channels_first. After reverting this change, the case could proceed.

commit 5b2b61005c54efe72f97cf7d0e924afed6a62a60 (HEAD -> master, origin/master, origin/HEAD)
Author: Mingxing Tan <tanmingxing@google.com>
Date:   Mon Jul 11 10:18:52 2022 -0700

    Add support for channels_first.

    Fix #1162
mingxingtan commented 1 year ago

Thanks for reporting the issue. it should be fixed now.