Как исправить «Построение tf.Module без вызова супер-конструктора не поддерживается» в object-detection-api.model_main.py - PullRequest
1 голос
/ 10 июня 2019

Я новичок в объекте-обнаружения-API, успешно установил API, python object_detection_tutorial.ipynb работал нормально. но когда последовал этот урок , я получаю ValueError из tenorflow / python / module / module.py

- это руководство , iv'e удалось сделать все до последнего шага "модель тренинга", чем когда я запускаю эту команду:

python model_main.py --logtostderr --train_dir=training/ --pipeline_config_path=training/faster_rcnn_inception_v2_pets.config

(все пути верны) Я получаю эту ошибку:

ValueError:
Constructing a tf.Module without calling the super constructor is not supported. Add the following as the first line in your __init__ method:

super(FasterRCNNMetaArch, self).__init__()

Я не нашел никакой помощи в этом, я попробовал новую установку API обнаружения объектов, но не помог.

У меня та же ошибка, после этого models / research / object_detection / g3doc / installation.md учебник.

При попытке запустить:

python object_detection/builders/model_builder_test.py

Я ожидал, что модель начнет свою работу, как в учебнике. но получил это вместо:

/ home / gal.

WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
  * https://github.com/tensorflow/addons
If you depend on functionality not listed there, please file an issue.

W0610 17:22:52.758328 140705573046080 model_lib.py:615] Forced number of epochs for all eval validations to be 1.
I0610 17:22:52.758429 140705573046080 config_util.py:484] Maybe overwriting train_steps: None
I0610 17:22:52.758468 140705573046080 config_util.py:484] Maybe overwriting sample_1_of_n_eval_examples: 1
I0610 17:22:52.758504 140705573046080 config_util.py:484] Maybe overwriting use_bfloat16: False
I0610 17:22:52.758536 140705573046080 config_util.py:484] Maybe overwriting eval_num_epochs: 1
I0610 17:22:52.758566 140705573046080 config_util.py:484] Maybe overwriting load_pretrained: True
I0610 17:22:52.758595 140705573046080 config_util.py:494] Ignoring config override key: load_pretrained
W0610 17:22:52.758645 140705573046080 model_lib.py:631] Expected number of evaluation epochs is 1, but instead encountered `eval_on_train_input_config.num_epochs` = 0. Overwriting `num_epochs` to 1.
I0610 17:22:52.758683 140705573046080 model_lib.py:666] create_estimator_and_inputs: use_tpu False, export_to_tpu False
W0610 17:22:52.758958 140705573046080 estimator.py:1758] Using temporary folder as model directory: /tmp/tmp1lw9am0f
I0610 17:22:52.759102 140705573046080 estimator.py:202] Using config: {'_model_dir': '/tmp/tmp1lw9am0f', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': allow_soft_placement: true
graph_options {
  rewrite_options {
    meta_optimizer_iterations: ONE
  }
}
, '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_device_fn': None, '_protocol': None, '_eval_distribute': None, '_experimental_distribute': None, '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x7ff8060b5f28>, '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1}
W0610 17:22:52.759208 140705573046080 estimator.py:1931] Estimator's model_fn (<function create_model_fn.<locals>.model_fn at 0x7ff8060c6158>) includes params argument, but params are not passed to Estimator.
I0610 17:22:52.759698 140705573046080 estimator_training.py:186] Not using Distribute Coordinator.
I0610 17:22:52.759793 140705573046080 training.py:612] Running training and evaluation locally (non-distributed).
I0610 17:22:52.759924 140705573046080 training.py:700] Start train and evaluate loop. The evaluate will happen after every checkpoint. Checkpoint frequency is determined based on RunConfig arguments: save_checkpoints_steps None or save_checkpoints_secs 600.
W0610 17:22:52.763085 140705573046080 deprecation.py:323] From /home/gal/.virtualenvs/dl4cv/lib/python3.6/site-packages/tensorflow/python/training/training_util.py:238: Variable.initialized_value (from tensorflow.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Use Variable.read_value. Variables in 2.X are initialized automatically both in eager and graph (inside tf.defun) contexts.
Traceback (most recent call last):
  File "/home/gal/TensorFlow/models/research/object_detection/model_main.py", line 109, in <module>
    tf.app.run(main)
  File "/home/gal/.virtualenvs/dl4cv/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "/home/gal/.virtualenvs/dl4cv/lib/python3.6/site-packages/absl/app.py", line 300, in run
    _run_main(main, args)
  File "/home/gal/.virtualenvs/dl4cv/lib/python3.6/site-packages/absl/app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "/home/gal/TensorFlow/models/research/object_detection/model_main.py", line 105, in main
    tf.estimator.train_and_evaluate(estimator, train_spec, eval_specs[0])
  File "/home/gal/.virtualenvs/dl4cv/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/training.py", line 473, in train_and_evaluate
    return executor.run()
  File "/home/gal/.virtualenvs/dl4cv/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/training.py", line 613, in run
    return self.run_local()
  File "/home/gal/.virtualenvs/dl4cv/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/training.py", line 714, in run_local
    saving_listeners=saving_listeners)
  File "/home/gal/.virtualenvs/dl4cv/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 359, in train
    loss = self._train_model(input_fn, hooks, saving_listeners)
  File "/home/gal/.virtualenvs/dl4cv/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1132, in _train_model
    return self._train_model_default(input_fn, hooks, saving_listeners)
  File "/home/gal/.virtualenvs/dl4cv/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1159, in _train_model_default
    input_fn, ModeKeys.TRAIN))
  File "/home/gal/.virtualenvs/dl4cv/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1000, in _get_features_and_labels_from_input_fn
    self._call_input_fn(input_fn, mode))
  File "/home/gal/.virtualenvs/dl4cv/lib/python3.6/site-packages/tensorflow_estimator/python/estimator/estimator.py", line 1087, in _call_input_fn
    return input_fn(**kwargs)
  File "/home/gal/TensorFlow/models/research/object_detection/inputs.py", line 446, in _train_input_fn
    params=params)
  File "/home/gal/TensorFlow/models/research/object_detection/inputs.py", line 512, in train_input
    model_config, is_training=True).preprocess
  File "/home/gal/TensorFlow/models/research/object_detection/builders/model_builder.py", line 135, in build
    add_summaries)
  File "/home/gal/TensorFlow/models/research/object_detection/builders/model_builder.py", line 597, in _build_faster_rcnn_model
    **common_kwargs)
  File "/home/gal/.virtualenvs/dl4cv/lib/python3.6/site-packages/tensorflow/python/module/module.py", line 109, in __call__
    "super(%s, self).__init__()" % cls.__name__)
ValueError: Constructing a tf.Module without calling the super constructor is not supported. Add the following as the first line in your __init__ method:

super(FasterRCNNMetaArch, self).__init__()

После некоторых раскопок я обнаружил, что в:

/TensorFlow/models/research/object_detection/meta_architectures/faster_rcnn_meta_arch.py

В строке 466:

    super(FasterRCNNMetaArch, self).__init__(num_classes=num_classes)

так что, возможно, это не так. После некоторой точки останова iv'e foune, которая в строке 97 ('finally') в:

/home/gal/.virtualenvs/dl4cv/lib/python3.6/site-packages/tensorflow/python/module/module.py

есть эта часть, которая вызывает ValueError:

    finally:
      # The base Module constructor enters the modules name scope before
      # returning such that other functionality in the ctor happens within the
      # modules name scope.
      scope = getattr(module, "_ctor_name_scope", None)
      exc_info = sys.exc_info()
      if scope is None:
        if exc_info[0] is None:
          raise ValueError(
              "Constructing a tf.Module without calling the super constructor "
              "is not supported. Add the following as the first line in your "
              "__init__ method:\n\n"
              "super(%s, self).__init__()" % cls.__name__)
      else:
        scope.__exit__(*exc_info)
        del module._ctor_name_scope

Когда я бегу, scope - это None, а также exc_info[0] - это Нет.

Есть идеи? спасибо

1 Ответ

0 голосов
/ 11 июня 2019

ОК,

, посоветовавшись с некоторыми друзьями, похоже, что это ошибка python3 / python2, а не ошибка tenor-flow_object_detection_API ....

Я перешел на Python 2.7, и все работает хорошо :)

Так что я не знаю, в чем проблема, но я обошел ее.

Надеюсь, это кому-нибудь поможет. Приветствия, Гал.

...