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

2023-12-31

我读过很多与我相似的问题,但它们都与我的不同。

for itr in xrange(MAX_ITERATION):
            train_images, train_annotations = train_dataset_reader.next_batch(batch_size)

#            train_images=tf.image.convert_image_dtype(train_images,np.float32) 
#            train_annotations=tf.image.convert_image_dtype(train_annotations,np.float32) 
#            print(train_images_.get_shape(),train_annotations_.get_shape())
#            train_images=tf.cast(train_images,tf.float32)   
#            train_images = tf.to_float(train_images)
#            train_annotations = tf.to_float(train_annotations)
            #train_images, train_annotations = py_func(selftrans, [train_images_, train_annotations_], [tf.float32], grad=None)
            print(train_images.dtype)
#            train_annotations=tf.cast(train_annotations,tf.float32)
#            train_images,train_annotations = sess.run([train_images,train_annotations])
#            train_images = train_images.astype('float32')
#            train_annotations = train_annotations.astype('float32')
#            print(train_annotations.dtype)
            feed_dict = {image: train_images, annotation: train_annotations, keep_probability: 1}

            sess.run(train_op, feed_dict=feed_dict)

问题是:我使用自己的数据(血管分割,这是一个二分类问题)后,使用next_batch读取到的数据是float64,而feed_dict()需要float32。通常,像这样的代码tf.cast or tf.tp_float可用于将我的数据转换为 float32。然而,使用这些转换代码后,我发现错误变成了TypeError:提要的值不能是 tf.Tensor 对象。可接受的 feed 值包括 Python 标量、字符串、列表、numpy ndarray 或 TensorHandles。最后,我尝试使用 sess.run 来抵消它的 tf.Tensor 形式。错误改为原来的,这意味着我的数据被转换回float64。因此,这似乎是一个无限循环。“如果不进行转换,则不会接受 float64。转换后,Tf.Tensor 也不会被接受。要使用 sess run 偏移 tf.Tensor 形式,数据将同时转换回 float64” 我该如何解决此问题?我期待您的回复!类似的问题在这里, TensorFlow TypeError:传递给参数输入的值的 DataType uint8 不在允许值列表中:float16、float32 https://stackoverflow.com/questions/44822999/tensorflow-typeerror-value-passed-to-parameter-input-has-datatype-uint8-not-in?answertab=oldest#tab-top


我认为这是我的配置环境造成的。一旦我按照告知安装了环境(在此输入链接描述 https://github.com/shekkizh/FCN.tensorflow),代码变得可行。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

类型错误:传递给参数“输入”的值的数据类型 float64 不在允许值列表中:float16、bfloat16、float32 的相关文章

随机推荐