我正在尝试构建机器学习程序,以在猫和狗的图像之间进行比较,并成功创建了TFRecords文件。现在,当我尝试读取文件进行训练时,出现以下错误。这是我的代码:
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
data_path = 'train.tfrecords'
with tf.Session() as sess:
feature = {'train/image': tf.FixedLenFeature([],tf.string),
'train/label': tf.FixedLenFeature([],tf.int64)}
filename_queue = tf.train.string_input_producer([data_path],num_epochs=1000)
reader = tf.TFRecordReader()
serialized_example = reader.read(queue=filename_queue,name=None)
features = tf.parse_single_example(serialized_example,features=feature)
image = tf.decode_raw(features['train/image'], tf.float32)
label = tf.cast(features['train/label'], tf.int32)
image = tf.reshape(image, [224, 224, 3])
images, labels = tf.train.shuffle_batch([image, label], batch_size=10, capacity=30, num_threads=1,
min_after_dequeue=10)
init_op = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
sess.run(init_op)
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
for batch_index in range(5):
img, lbl = sess.run([images, labels])
img = img.astype(np.uint8)
for j in range(6):
plt.subplot(2, 3, j + 1)
plt.imshow(img[j, ...])
plt.title('cat' if lbl[j] == 0 else 'dog')
pl t.show()
coord.request_stop()
coord.join(threads)
sess.close()
我收到此错误
C:\Users\snklp\Anaconda3\envs\untitled\python.exe C/Users/snklp/PycharmProjects/untitled/read_tfrecords.py
2018-07-24 14:58:44.870802: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
Traceback (most recent call last):
File "C:/Users/snklp/PycharmProjects/untitled/read_tfrecords.py", line 18, in <module>
serialized_example = tf.TFRecordReader.read(queue=filename_queue,name=None)
TypeError: read() missing 1 required positional argument: 'self'
Process finished with exit code 1
我试图在read()函数中创建一个带有self参数的Read类,但没有任何反应。我没有收到此错误。有人可以帮我吗?