tensorflow / models

Models and examples built with TensorFlow
Other
76.79k stars 45.84k forks source link

hparams = contrib_training.HParams( NameError: name 'contrib_training' is not defined #9298

Open agnieszkajust opened 3 years ago

agnieszkajust commented 3 years ago

https://github.com/tensorflow/models/tree/r2.3.0/research/object_detection

Describe:

After run: python model_main_tf2.py --model_dir=$MODEL_DIR --num_train_steps=$NUM_TRAIN_STEPS --sample_1_of_n_eval_examples=$SAMPLE_1_OF_N_EVAL_EXAMPLES --pipeline_config_path=$PIPELINE_CONFIG_PATH --alsologtostderr I got: hparams = contrib_training.HParams( NameError: name 'contrib_training' is not defined

System information:

How can I solve it?

Harirai commented 3 years ago

Hi I'm new to TensorFlow community, can anyone guide me how to approach/get started with issues like this? (I tried to replicate it but I'm getting a different error) Thanks in advance! :) Screenshot from 2020-09-25 23-46-56

agnieszkajust commented 3 years ago

go to the research directory and type:

export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim

Harirai commented 3 years ago

Hi, @agnieszkajust thanks for helping me, now it is showing cannot import 'model_lib_v2' . I tried to fix that by running

python setup.py build 
python setup.py install

but it wasn't working. I printed the contents of the object_detection package, model_lib_v2 was not present in it. Can you please suggest what should I do?

Screenshot from 2020-09-28 23-02-38

agnieszkajust commented 3 years ago

What version of tensorflow and which branch 'tensorflow/models' do you have?

Harirai commented 3 years ago

@agnieszkajust I have Tensorflow 2.3.0 and working on the r2.3.0 branch of "tensorflow/models". After reinstalling above errors didn't occur. But now I'm getting

Traceback (most recent call last):  
  File "model_main_tf2.py", line 112, in <module>  
    tf.app.run()  
AttributeError: module 'tensorflow.compat.v2' has no attribute 'app'

Tf2 doesn't have attribute "app", do I have to change it to tf.compat.v1.app.run(), why this change is not merged into branch r2.3.0?

agnieszkajust commented 3 years ago

I don't know, but I also changed to tf.compat.v1.app.run().

Zrufy commented 3 years ago

@agnieszkajust how do you solve the problem of name 'contrib_training' is not defined

agnieszkajust commented 3 years ago

I don't solve it.

advaza commented 3 years ago

My workaround in utils/autoaugment_utils.py :

from tensorflow_addons import image as contrib_image
from collections import namedtuple
# pylint: disable=g-import-not-at-top
# try:
#   from tensorflow.contrib import image as contrib_image
#   from tensorflow.contrib import training as contrib_training
# except ImportError:
#   # TF 2.0 doesn't ship with contrib.
#   pass
# pylint: enable=g-import-not-at-top

...

def hparams(**kwargs):
    return namedtuple("HParams", kwargs.keys())(*kwargs.values())

  # Line 1670
  augmentation_hparams = hparams(
      cutout_max_pad_fraction=0.75,
      cutout_bbox_replace_with_mean=False,
      cutout_const=100,
      translate_const=250,
      cutout_bbox_const=50,
      translate_bbox_const=120)