1. 报错:
Traceback (most recent call last):
File "create_tf_record.py", line 319, in <module>
batch_test(train_record_output,resize_height, resize_width)
File "create_tf_record.py", line 274, in batch_test
tf_image,tf_label = read_records(record_file,resize_height,resize_width,type='normalization')
File "create_tf_record.py", line 149, in read_records
filename_queue = tf.train.string_input_producer([filename])
AttributeError: module 'tensorflow._api.v2.train' has no attribute 'string_input_producer'
2. 解决:
这是tensorflow版本问题,现在使用2.x版本,很多1.x版本的内容不会被2.x支持了,如果需要用到tensorflow1.x写的代码,需要把
import tensorflow as tf
改为
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
之后还遇到诸如以下的报错:
AttributeError: module ‘tensorflow‘ has no attribute ‘contrib‘
AttributeError: module ‘tensorflow_core._api.v2.train‘ has no attribute
最后直接用回tensorflow1.x版本,报错全部消失。