Tensorflow错误:InvalidArgumentError:不同数量的组件类型。

karl_TUM

我想输入一批经过混洗的图像进行训练,然后根据TensorVision中的通用输入图像编写代码,但是出现错误。我无法弄清楚哪里出了问题。这是我的代码:

import os
import tensorflow as tf


def read_labeled_image_list(image_list_file):
    """
    Read a .txt file containing pathes and labeles.
    Parameters
    ----------
     image_list_file : a .txt file with one /path/to/image per line
     label : optionally, if set label will be pasted after each line
    Returns
    -------
       List with all filenames in file image_list_file
    """
    f = open(image_list_file, 'r')
    filenames = []
    labels = []
    for line in f:
        filename, label = line[:-1].split(' ')
        filenames.append(filename)
        labels.append(int(label))
    return filenames, labels

def read_images_from_disk(input_queue):
    """Consumes a single filename and label as a ' '-delimited string.
    Parameters
    ----------
      filename_and_label_tensor: A scalar string tensor.
    Returns
    -------
      Two tensors: the decoded image, and the string label.
    """
    label = input_queue[1]
    file_contents = tf.read_file(input_queue[0])
    example = tf.image.decode_png(file_contents, channels=3)
#    example = rescale_image(example)
    # processed_label = label
    return example, label

def random_resize(image, lower_size, upper_size):
    """Randomly resizes an image
    Parameters
    ----------
    lower_size:
    upper_size:
    Returns
    -------
      a randomly resized image
    """

    new_size = tf.to_int32(
        tf.random_uniform([], lower_size, upper_size))

    return tf.image.resize_images(image, new_size, new_size,
                                  method=0)
def _input_pipeline(filename, batch_size,
                    processing_image=lambda x: x,
                    processing_label=lambda y: y,
                    num_epochs=None):
    """The input pipeline for reading images classification data.
    The data should be stored in a single text file of using the format:
     /path/to/image_0 label_0
     /path/to/image_1 label_1
     /path/to/image_2 label_2
     ...
     Args:
       filename: the path to the txt file
       batch_size: size of batches produced
       num_epochs: optionally limited the amount of epochs
    Returns:
       List with all filenames in file image_list_file
    """

    # Reads pfathes of images together with there labels
    image_list, label_list = read_labeled_image_list(filename)

    images = tf.convert_to_tensor(image_list, dtype=tf.string)
    labels = tf.convert_to_tensor(label_list, dtype=tf.int32)

    # Makes an input queue
    input_queue = tf.train.slice_input_producer([images, labels],
                                                num_epochs=num_epochs,
                                                shuffle=True)

    # Reads the actual images from
    image, label = read_images_from_disk(input_queue)
    pr_image = processing_image(image)
    pr_label = processing_label(label)

    image_batch, label_batch = tf.train.batch([pr_image, pr_label],
                                              batch_size=batch_size, 
                                              shapes = [256,256,3])

    # Display the training images in the visualizer.
    tensor_name = image.op.name
    tf.image_summary(tensor_name + 'images', image_batch)
    return image_batch, label_batch
def test_pipeline():
    data_folder = '/home/kang/Documents/work_code_PC1/data/UCLandUsedImages/'
    data_file = 'UCImage_Labels.txt'

    filename = os.path.join(data_folder, data_file)

    image_batch, label_batch = _input_pipeline(filename, 75)

    # Create the graph, etc.
    init_op = tf.initialize_all_variables()
    sess = tf.InteractiveSession()
    sess.run(init_op)
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(sess=sess, coord=coord)

    a = sess.run([image_batch, label_batch])

    coord.request_stop()
    coord.join(threads)
    print("Finish Test")
    return a

if __name__ == '__main__':
#    aa = test_preprocc()
#    matplotlib.pyplot.imshow(aa[1])
    a1 = test_pipeline()
    a2 = test_pipeline()

但是它出了一个错误,很长一段时间让我感到困惑:

Traceback (most recent call last):

  File "<ipython-input-7-e24901ce3365>", line 1, in <module>
    runfile('/home/kang/Documents/work_code_PC1/VGG_tensorflow_UCMerced/readUClandUsedImagetxt1.py', wdir='/home/kang/Documents/work_code_PC1/VGG_tensorflow_UCMerced')

  File "/usr/local/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 714, in runfile
    execfile(filename, namespace)

  File "/usr/local/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile
    builtins.execfile(filename, *where)

  File "/home/kang/Documents/work_code_PC1/VGG_tensorflow_UCMerced/readUClandUsedImagetxt1.py", line 254, in <module>
    a1 = test_pipeline()

  File "/home/kang/Documents/work_code_PC1/VGG_tensorflow_UCMerced/readUClandUsedImagetxt1.py", line 244, in test_pipeline
    a = sess.run([image_batch, label_batch])

  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 340, in run
    run_metadata_ptr)

  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 564, in _run
    feed_dict_string, options, run_metadata)

  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 637, in _do_run
    target_list, options, run_metadata)

  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 659, in _do_call
    e.code)

InvalidArgumentError: Different number of component types.  Types: uint8, int32, Shapes: [[256,256,3]]
     [[Node: batch_11/fifo_queue = FIFOQueue[capacity=32, component_types=[DT_UINT8, DT_INT32], container="", shapes=[[256,256,3]], shared_name="", _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Caused by op u'batch_11/fifo_queue', defined at:
奥利维尔·莫恩德罗(Olivier Moindrot)

该错误是由于shapesfunction的参数错误tf.train.batch该参数shapes应保留为默认值,或者应为:

形状:(可选)每个示例的形状。默认为tensor_list的推断形状

在这里,您要给出shapes = [256, 256, 3],但是您应该在pr_imagepr_label列表中给出形状

image_batch, label_batch = tf.train.batch(
    [pr_image, pr_label],
    batch_size=batch_size,
    shapes = [[256,256,3], pr_label.get_shape()])

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

TensorFlow InvalidArgumentError/Value 错误随着代码的微小变化而发生

来自分类Dev

Tensorflow:占位符的InvalidArgumentError

来自分类Dev

导致类型错误的不同子句

来自分类Dev

InvalidArgumentError:无法序列化 tensorflow.GraphDef 类型的协议缓冲区

来自分类Dev

意外的类型推断失败:类型参数数量错误

来自分类Dev

Tensorflow InvalidArgumentError:找到2个根本错误。index [28,0] = 11292不在[0,11272)

来自分类Dev

通过不同的事件类型时,来自 JPanel 的组件的不同值

来自分类Dev

对结构使用Trait对象-错误:类型参数的数量错误

来自分类Dev

调用过程时错误的数量或类型的参数错误

来自分类Dev

错误的参数数量或类型,PL/SQL 中的错误

来自分类Dev

为什么ActionEvent组件的类型错误?

来自分类Dev

通用高阶React组件产生类型错误

来自分类Dev

React.ForwardRef TypeScript组件类型错误

来自分类Dev

样式组件和 Typescript 类型错误

来自分类Dev

tensorflow 中 softmax 上的 InvalidArgumentError

来自分类Dev

方法参数数量可变,每种参数类型不同

来自分类Dev

具有不同数量和参数类型的模板功能

来自分类Dev

方法参数的数量可变,每种参数的类型不同

来自分类Dev

MySQL错误:使用的SELECT语句具有不同数量的列

来自分类Dev

错误:“ det”的方程式具有不同数量的参数

来自分类Dev

Boost :: units ::数量“不完整类型”错误

来自分类Dev

nPLS-00306:调用中参数的数量或类型错误

来自分类Dev

类型参数数量错误:应该为1,但找到0

来自分类Dev

Oracle 过程 - PLS-00306:参数数量或类型错误

来自分类Dev

R中不同类型的错误

来自分类Dev

InvalidArgumentError 设置或代码错误吗?

来自分类Dev

Tensorflow:带有MNIST的InvalidArgumentError,[55000]与[10000]

来自分类Dev

Javascript /本机代码不同步(参数数量不同)错误

来自分类Dev

React:如何动态地将不同类型的子组件附加到父组件中?

Related 相关文章

  1. 1

    TensorFlow InvalidArgumentError/Value 错误随着代码的微小变化而发生

  2. 2

    Tensorflow:占位符的InvalidArgumentError

  3. 3

    导致类型错误的不同子句

  4. 4

    InvalidArgumentError:无法序列化 tensorflow.GraphDef 类型的协议缓冲区

  5. 5

    意外的类型推断失败:类型参数数量错误

  6. 6

    Tensorflow InvalidArgumentError:找到2个根本错误。index [28,0] = 11292不在[0,11272)

  7. 7

    通过不同的事件类型时,来自 JPanel 的组件的不同值

  8. 8

    对结构使用Trait对象-错误:类型参数的数量错误

  9. 9

    调用过程时错误的数量或类型的参数错误

  10. 10

    错误的参数数量或类型,PL/SQL 中的错误

  11. 11

    为什么ActionEvent组件的类型错误?

  12. 12

    通用高阶React组件产生类型错误

  13. 13

    React.ForwardRef TypeScript组件类型错误

  14. 14

    样式组件和 Typescript 类型错误

  15. 15

    tensorflow 中 softmax 上的 InvalidArgumentError

  16. 16

    方法参数数量可变,每种参数类型不同

  17. 17

    具有不同数量和参数类型的模板功能

  18. 18

    方法参数的数量可变,每种参数的类型不同

  19. 19

    MySQL错误:使用的SELECT语句具有不同数量的列

  20. 20

    错误:“ det”的方程式具有不同数量的参数

  21. 21

    Boost :: units ::数量“不完整类型”错误

  22. 22

    nPLS-00306:调用中参数的数量或类型错误

  23. 23

    类型参数数量错误:应该为1,但找到0

  24. 24

    Oracle 过程 - PLS-00306:参数数量或类型错误

  25. 25

    R中不同类型的错误

  26. 26

    InvalidArgumentError 设置或代码错误吗?

  27. 27

    Tensorflow:带有MNIST的InvalidArgumentError,[55000]与[10000]

  28. 28

    Javascript /本机代码不同步(参数数量不同)错误

  29. 29

    React:如何动态地将不同类型的子组件附加到父组件中?

热门标签

归档