Tensorflow TypeError:read()缺少1个必需的位置参数:';自我';

Tensorflow TypeError:read()缺少1个必需的位置参数:';自我';,tensorflow,machine-learning,Tensorflow,Machine Learning,我正在尝试建立机器学习程序,以比较猫和狗的图像,并已成功创建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.Fixe

我正在尝试建立机器学习程序,以比较猫和狗的图像,并已成功创建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
C:\Users\snklp\Anaconda3\envs\untitled\python.exe C/Users/snklp/pycharm项目/untitled/read\tfrecords.py
2018-07-24 14:58:44.870802:I tensorflow/core/platform/cpu\u feature\u guard.cc:140]您的cpu支持该tensorflow二进制文件未编译为使用的指令:AVX AVX2
回溯(最近一次呼叫最后一次):
文件“C:/Users/snklp/PycharmProjects/untitled/read_tfrecords.py”,第18行,在
序列化的\u示例=tf.TFRecordReader.read(队列=文件名\u队列,名称=无)
TypeError:read()缺少1个必需的位置参数:“self”
进程已完成,退出代码为1

我试图在Read()函数中创建一个带有自参数的Read类,但什么也没发生。我没有得到这个错误。有人能帮我吗?

你发布的代码不是引发错误的代码。在导致错误的代码中,您缺少
TFRecordReader
后面的括号(即,您没有创建类的实际实例)。@xdurch0错误与此代码的第18行有关,因此您发布的代码段中的第18行怎么可能是空行。