python - tensorflow 错误 : TypeError: __init__() got an unexpected keyword argument 'dct_method'

标签 python tensorflow machine-learning neural-network object-detection

<分区>

运行 Tensorflow Object Detection API 时在当前版本的 Tensorflow-Gpu (1.5) 中,尝试训练一组自定义图像时会抛出以下错误。

INFO:tensorflow:Scale of 0 disables regularizer.
INFO:tensorflow:Scale of 0 disables regularizer.
WARNING:tensorflow:From C:\tensorflow1\models\research\object_detection\trainer.py:228: create_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Please switch to tf.train.create_global_step
Traceback (most recent call last):
  File "train.py", line 167, in <module>
    tf.app.run()
  File "C:\Users\Vic-10-3\AppData\Local\Continuum\anaconda3\envs\tensorflow1\lib\site-packages\tensorflow\python\platform\app.py", line 124, in run
    _sys.exit(main(argv))
  File "train.py", line 163, in main
    worker_job_name, is_chief, FLAGS.train_dir)
  File "C:\tensorflow1\models\research\object_detection\trainer.py", line 235, in train
    train_config.prefetch_queue_capacity, data_augmentation_options)
  File "C:\tensorflow1\models\research\object_detection\trainer.py", line 59, in create_input_queue
    tensor_dict = create_tensor_dict_fn()
  File "train.py", line 120, in get_next
    dataset_builder.build(config)).get_next()
  File "C:\tensorflow1\models\research\object_detection\builders\dataset_builder.py", line 138, in build
    label_map_proto_file=label_map_proto_file)
  File "C:\tensorflow1\models\research\object_detection\data_decoders\tf_example_decoder.py", line 110, in __init__
    dct_method=dct_method),
TypeError: __init__() got an unexpected keyword argument 'dct_method'

预期的行为是运行实际训练,但显然有些东西与最新版本不兼容。

重现错误的说明:Follow the tutorial并在自定义数据集上进行训练。

最佳答案

此错误是由于文件 tf_example_decoder.py 与安装的 Tensorflow 不兼容造成的。

在文件 models/research/object_detection/data_decoders/tf_example_decoder.py 中:

第 28 行:

slim_example_decoder = tf.contrib.slim.tfexample_decoder

第 104 行:

self.items_to_handlers = {
    fields.InputDataFields.image:
        slim_example_decoder.Image(
            image_key='image/encoded',
            format_key='image/format',
            channels=3,
            dct_method=dct_method),....
            .....
            ....
            ..
            .
            }

slim_example_decoder.Image 是 tf.contrib.slim.tfexample_decoder.Image

在 Tensorflow 1.5 源代码中,tf.contrib.slim.tfexample_decoder.Image 没有 dct_method 参数。因此,当 dct_method 参数被传递时,它会抛出一个错误。

一个简单的技巧就是不传递这个参数。所以编辑 tf_example_decoder.py 第 110 行以删除 dct_method=dct_method。我试过了,它起作用了,对训练没有任何影响。

关于python - tensorflow 错误 : TypeError: __init__() got an unexpected keyword argument 'dct_method' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48920762/

相关文章:

python - 如何在 Windows 10 上运行 TensorFlow?我有 GPU Geforce gtx 1650。我可以在上面运行 TensorFlow 吗?如果是,那么如何?

尽管 cuda 的 deviceQuery 返回 "PASS"结果,GPU : no known devices, 上的 tensorflow

tensorflow - 将层的输出作为特征向量(KERAS)

machine-learning - 如何防止 weka 中的雪球词干分析器将 "awful"词干提取到 "aw"?

python - 使用机器学习解码回溯

python - 测量集群内的差异 - Kmodes

python - Python 中带有 4 个面板 (2 x 2) 的 Seaborn 直方图

python - 对于学习 Python 函数式编程,推荐哪些好的家庭作业式教程?

python - ConfigurationError : Server at 127. 0.0.1 :27017 reports wire version 0, 但是这个版本的 PyMongo 至少需要 2 个(MongoDB 2.6)

apache-spark - 如何在spark中缓存随机森林模型