繁体   English   中英

TensorFlow TypeError:传递给参数输入的值的 DataType uint8 不在允许值列表中:float16、float32

[英]TensorFlow TypeError: Value passed to parameter input has DataType uint8 not in list of allowed values: float16, float32

我试图让一个简单的 CNN 训练过去 3 天。

首先,我设置了一个输入管道/队列配置,它从目录树中读取图像并准备批处理。

我在这个链接上得到了这个代码。 所以,我现在需要将train_image_batchtrain_label_batch提供给我的 CNN。

train_image_batch, train_label_batch = tf.train.batch(
        [train_image, train_label],
        batch_size=BATCH_SIZE
        # ,num_threads=1
    )

我无法弄清楚如何。 我正在使用此链接中给出的 CNN 代码。

# Input Layer
input_layer = tf.reshape(train_image_batch, [-1, IMAGE_HEIGHT, IMAGE_WIDTH, NUM_CHANNELS])

# Convolutional Layer #1
conv1 = new_conv_layer(input_layer, NUM_CHANNELS, 5, 32, 2)

 # Pooling Layer #1
pool1 = new_pooling_layer(conv1, 2, 2)

打印的 input_layer 显示了这一点

Tensor("Reshape:0", shape=(5, 120, 120, 3), dtype=uint8)

下一行因 TypeError 而崩溃; conv1 = new_conv_layer(...)。 下面给出了 new_conv_layer 函数的主体

def new_conv_layer(input,              # The previous layer.
               num_input_channels, # Num. channels in prev. layer.
               filter_size,        # Width and height of each filter.
               num_filters,        # Number of filters.
               stride):

# Shape of the filter-weights for the convolution.
# This format is determined by the TensorFlow API.
shape = [filter_size, filter_size, num_input_channels, num_filters]

# Create new weights aka. filters with the given shape.
weights = tf.Variable(tf.truncated_normal(shape, stddev=0.05))

# Create new biases, one for each filter.
biases = tf.Variable(tf.constant(0.05, shape=[num_filters]))

# Create the TensorFlow operation for convolution.
# Note the strides are set to 1 in all dimensions.
# The first and last stride must always be 1,
# because the first is for the image-number and
# the last is for the input-channel.
# But e.g. strides=[1, 2, 2, 1] would mean that the filter
# is moved 2 pixels across the x- and y-axis of the image.
# The padding is set to 'SAME' which means the input image
# is padded with zeroes so the size of the output is the same.
layer = tf.nn.conv2d(input=input,
                     filter=weights,
                     strides=[1, stride, stride, 1],
                     padding='SAME')

# Add the biases to the results of the convolution.
# A bias-value is added to each filter-channel.
layer += biases

# Rectified Linear Unit (ReLU).
# It calculates max(x, 0) for each input pixel x.
# This adds some non-linearity to the formula and allows us
# to learn more complicated functions.
layer = tf.nn.relu(layer)

# Note that ReLU is normally executed before the pooling,
# but since relu(max_pool(x)) == max_pool(relu(x)) we can
# save 75% of the relu-operations by max-pooling first.

# We return both the resulting layer and the filter-weights
# because we will plot the weights later.
return layer, weights

准确地说,它在tf.nn.conv2d崩溃并出现此错误

类型错误:传递给参数“输入”的值的数据类型 uint8 不在允许值列表中:float16、float32

输入管道中的图像类型为“uint8”,您需要将其类型转换为“float32”,您可以在图像 jpeg 解码器之后执行此操作:

image = tf.image.decode_jpeg(...
image = tf.cast(image, tf.float32)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:TypeError:传递给参数“输入”的值的 DataType uint8 不在允许值列表中:float16、bfloat16、float32、float64、int32 类型错误:传递给参数“输入”的值的数据类型布尔值不在允许值列表中:float32、float64、int32、uint8、int16、int8 TypeError:传递给参数'input'的值的数据类型float64不在允许的值列表中:float16,bfloat16,float32 错误:传递给参数“输入”的值的数据类型 int64 不在允许值列表中:float16、bfloat16、float32、float64? TypeError:传递给参数'ref'的值的DataType int64不在允许的值列表中:float32,int32,qint8,quint8,qint32 Tensorflow类型错误:传递给参数'shape'的值具有DataType float32不在允许值列表中:int32,int64 传递给参数“shape”的值的 DataType float32 不在允许值列表中:int32、int64 KERAS 自定义丢失中的错误“类型错误:传递给参数 'reduction_indices' 的值的数据类型 float32 不在允许值列表中:int32,int64” 了解 Keras 错误:TypeError:传递给参数“shape”的值的 DataType float32 不在允许值列表中:int32、int64 ArgumentError:uint8 的 attr 'T' 的值不在允许值列表中:half、bfloat16、float、double、int32
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM