Models: Bug: if input_config.WhichOneof('input_reader') == 'tf_record_input_reader': AttributeError: 'list' object has no attribute 'WhichOneof'

Created on 18 Dec 2018  路  14Comments  路  Source: tensorflow/models

System information

  • What is the top-level directory of the model you are using: tensorflow/models/research/object_detection
  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No, using stock from git
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux 4.19.8-arch1-1-ARCH Antergos
  • Python version: Python 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 19:16:44)
  • TensorFlow installed from (source or binary): N/A
  • TensorFlow version (use command below): 1.12
  • Bazel version (if compiling from source): N/A
  • CUDA/cuDNN version: 10.0/7.4
  • GPU model and memory: Nvidia Quadro K2100M 2GB
  • Exact command to reproduce:
python object_detection/metrics/offline_eval_map_corloc.py metrics/offline_eval_map_corloc.py --eval_dir=/home/user/PycharmProjects/SomeProject/eval_metrics --eval_config_path=/home/user/PycharmProjects/SomeProject/config/test_eval_config.pbtxt --input_config_path=/home/user/PycharmProjects/SomeProject/config/test_input_config.pbtxt

Describe the problem

Getting error if input_config.WhichOneof('input_reader') == 'tf_record_input_reader': AttributeError: 'list' object has no attribute 'WhichOneof' while trying to run the Computing evaluation measures example from https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/oid_inference_and_evaluation.md

also fixed a typo line 162 offline_eval_map_corloc.py input_config = configs['eval_input_configs'] (eval_input_configs), at least for coco_metrics

Source code / logs

Traceback

/home/user/anaconda3/envs/tensorflow_gpuenv/bin/python /opt/JetBrains/apps/PyCharm-P/ch-0/183.4284.139/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 35603 --file /home/user/anaconda3/envs/tensorflow_gpuenv/lib/python3.6/site-packages/tensorflow/models/research/object_detection/metrics/offline_eval_map_corloc.py --eval_dir=/home/user/PycharmProjects/SomeProject/eval_metrics --eval_config_path=/home/user/PycharmProjects/SomeProject/config/test_eval_config.pbtxt --input_config_path=/home/user/PycharmProjects/SomeProject/config/test_input_config.pbtxt
pydev debugger: process 6999 is connecting

Connected to pydev debugger (build 183.4284.139)
/home/user/anaconda3/envs/tensorflow_gpuenv/lib/python3.6/site-packages/tensorflow/models/research/object_detection/utils/visualization_utils.py:26: UserWarning: matplotlib.pyplot as already been imported, this call will have no effect.
  import matplotlib; matplotlib.use('Agg')  # pylint: disable=multiple-statements
Traceback (most recent call last):
  File "/opt/JetBrains/apps/PyCharm-P/ch-0/183.4284.139/helpers/pydev/pydevd.py", line 1689, in <module>
    main()
  File "/opt/JetBrains/apps/PyCharm-P/ch-0/183.4284.139/helpers/pydev/pydevd.py", line 1683, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/opt/JetBrains/apps/PyCharm-P/ch-0/183.4284.139/helpers/pydev/pydevd.py", line 1083, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/opt/JetBrains/apps/PyCharm-P/ch-0/183.4284.139/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/user/anaconda3/envs/tensorflow_gpuenv/lib/python3.6/site-packages/tensorflow/models/research/object_detection/metrics/offline_eval_map_corloc.py", line 171, in <module>
    tf.app.run(main)
  File "/home/user/anaconda3/envs/tensorflow_gpuenv/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "/home/user/anaconda3/envs/tensorflow_gpuenv/lib/python3.6/site-packages/tensorflow/models/research/object_detection/metrics/offline_eval_map_corloc.py", line 164, in main
    metrics = read_data_and_evaluate(input_config, eval_config)
  File "/home/user/anaconda3/envs/tensorflow_gpuenv/lib/python3.6/site-packages/tensorflow/models/research/object_detection/metrics/offline_eval_map_corloc.py", line 91, in read_data_and_evaluate
    if input_config.WhichOneof('input_reader') == 'tf_record_input_reader':
AttributeError: 'list' object has no attribute 'WhichOneof'

Process finished with exit code 1

Contents of test_eval_config.pbtxt

metrics_set: 'coco_detection_metrics'

Contents of test_input_config.pbtxt

label_map_path: "/home/user/PycharmProjects/SomeProject/config/mscoco_label_map.pbtxt"

tf_record_input_reader: {
    input_path: "/home/user/PycharmProjects/SomeProject/eval/detections.tfrecord"
}

If more info is needed please don't hesitate,
Thanks

research bug

Most helpful comment

In utils/config_util.py , there is a function called get_configs_from_mutilple_files. Then delete 's' in the end of 'eval_input_config' and delete the square bracket of eval_input_config. It will ke OK

All 14 comments

Realized that input_config = configs['eval_input_configs'] returns a list instead of maybe an InputReader ? not sure, will play around a bit and update if I manage something

Tried hacking my way around by modifying def main(...)

  from google.protobuf import text_format
  from object_detection.protos import input_reader_pb2

  input_config = input_reader_pb2.InputReader()
  with tf.gfile.GFile(FLAGS.input_config_path, "r") as f:
    text_format.Merge(f.read(), input_config)
    configs["eval_input_config"] = input_config

  eval_config = configs['eval_config']
  #input_config = input_reader_pb2.InputReader(configs['eval_input_configs'])

  metrics = read_data_and_evaluate(input_config, eval_config)

but I'm afraid that this is going to turn into a real goose chase...

Traceback (most recent call last):
  File "/home/user/anaconda3/envs/tensorflow_gpuenv/lib/python3.6/site-packages/tensorflow/models/research/object_detection/metrics/offline_eval_map_corloc.py", line 181, in <module>
    tf.app.run(main)
  File "/home/user/anaconda3/envs/tensorflow_gpuenv/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "/home/user/anaconda3/envs/tensorflow_gpuenv/lib/python3.6/site-packages/tensorflow/models/research/object_detection/metrics/offline_eval_map_corloc.py", line 174, in main
    metrics = read_data_and_evaluate(input_config, eval_config)
  File "/home/user/anaconda3/envs/tensorflow_gpuenv/lib/python3.6/site-packages/tensorflow/models/research/object_detection/metrics/offline_eval_map_corloc.py", line 117, in read_data_and_evaluate
    decoded_dict = data_parser.parse(example)
  File "/home/user/anaconda3/envs/tensorflow_gpuenv/lib/python3.6/site-packages/tensorflow/models/research/object_detection/metrics/tf_example_parser.py", line 153, in parse
    results_dict[key] = parser.parse(tf_example)
  File "/home/user/anaconda3/envs/tensorflow_gpuenv/lib/python3.6/site-packages/tensorflow/models/research/object_detection/metrics/tf_example_parser.py", line 49, in parse
    self.field_name].HasField("bytes_list") else None
TypeError: sequence item 0: expected str instance, bytes found

Process finished with exit code 1

I should also add that I can use these similarly formatted tfrecords for training through model_main.py, so I dont think that they are the problem

also added the following changes to lines 212 and 355 of object_detection_evaluation.py

            import sys
            if sys.version_info < (3, 0):
                category_name = unicode(category_name, 'utf-8')
            else:
                category_name = str(category_name, 'utf-8')

and changed line 47 of tf_example_parser.py
from

return "".join(tf_example.features.feature[

to

return b"".join(tf_example.features.feature[

it now works, if I can figure out how to properly setup pycharm to make a pull request I'll be glad to help

@msymp thanks for checking this issue out. I have a PR #5931 regarding this issue, just waiting for a review for merge.
Cheers

In utils/config_util.py , there is a function called get_configs_from_mutilple_files. Then delete 's' in the end of 'eval_input_config' and delete the square bracket of eval_input_config. It will ke OK

hi, i don't find thoses line and i have this error when i launch the train

File "/home/tensorflow/models/research/object_detection/utils/config_util.py", line 99, in get_configs_from_pipeline_file
return create_configs_from_pipeline_proto(pipeline_config)
File "/home/tensorflow/models/research/object_detection/utils/config_util.py", line 123, in create_configs_from_pipeline_proto
configs["eval_input_config"] = configs["eval_input_configs"][0]
TypeError: 'InputReader' object does not support indexing

any idea ? it is from the new pull today of tensorflow

@SYangDong what line ? i think in new version there is not what you talking about.

No one faces this issue too ?

@leccyril in line 236. I check the code of its new version. I think the bug still exists.

for me i change configs["eval_input_config"] = configs["eval_input_configs"][0]

to

configs["eval_input_config"] = configs["eval_input_configs"]

but i don't know if it make the trick

@SYangDong

i am not a python or tensorflow expert, could you explain with detail what file to change what lines and for example what replace with what , indeed no confusion

@leccyril As @SYangDong mentioned, in file utils/config_util.py in function get_configs_from_multiple_files change line 236 from
configs["eval_input_configs"] = [eval_input_config]
to
configs["eval_input_config"] = eval_input_config
This worked for me!

ok it is more clear, i make the revert on my modification and tried this one , i launched my train to see if it was better...

wuile launching eval i had an error with unicode utf8 ...

In utils/config_util.py , there is a function called get_configs_from_mutilple_files. Then delete 's' in the end of 'eval_input_config' and delete the square bracket of eval_input_config. It will ke OK

Thanks @SYangDong . It works for me. But the AP for all results is -1.0.
All the images are skipped.

@gfjiyue maybe something wrong with your evaluating metrics. Because COCO evaluation is not supported in the code. if you still want to use coco evaluation, you should change the format of your tfrecord due to the keys' limitation in the codes.

@gfjiyue maybe something wrong with your evaluating metrics. Because COCO evaluation is not supported in the code. if you still want to use coco evaluation, you should change the format of your tfrecord due to the keys' limitation in the codes.

i also meet this error All the images are skipped , Do you have solve this problem?

Was this page helpful?
0 / 5 - 0 ratings