简体   繁体   English

类型错误:传递给参数“输入”的值的数据类型布尔值不在允许值列表中:float32、float64、int32、uint8、int16、int8

[英]TypeError: Value passed to parameter 'input' has DataType bool not in list of allowed values: float32, float64, int32, uint8, int16, int8

I have a dataset with 5 labels我有一个带有 5 个标签的数据集

def get_label(file_path):
  # convert the path to a list of path components
  parts = tf.strings.split(file_path, os.path.sep)
  class_names = ['daisy' 'dandelion' 'roses' 'sunflowers' 'tulips']
  # The second to last is the class-directory
  one_hot = parts[-2] == class_names
  # Integer encode the label
  return tf.argmax(one_hot)

def decode_img(img):
  # convert the compressed string to a 3D uint8 tensor
  img = tf.image.decode_jpeg(img, channels=3)
  # resize the image to the desired size
  return tf.image.resize(img, [img_height, img_width])

def process_path(file_path):
  label = get_label(file_path)
  # load the raw data from the file as a string
  img = tf.io.read_file(file_path)
  img = decode_img(img)
  return img, label

train_ds = train_ds.map(process_path, num_parallel_calls=AUTOTUNE)

If I change this code with other dataset having 2 labels, class_names = ['dog', 'cat'] I find this error TypeError: Value passed to parameter 'input' has DataType bool not in list of allowed values: float32, float64, int32, uint8, int16, int8, complex64, int64, qint8, quint8, qint32, bfloat16, uint16, complex128, float16, uint32, uint64 So how I can update def get_label(file_path)如果我使用具有 2 个标签的其他数据集更改此代码,则class_names = ['dog', 'cat']我发现此错误TypeError: Value passed to parameter 'input' has DataType bool not in list of allowed values: float32, float64, int32, uint8, int16, int8, complex64, int64, qint8, quint8, qint32, bfloat16, uint16, complex128, float16, uint32, uint64那么我如何更新def get_label(file_path)

I was having the same problem.我遇到了同样的问题。 Following the idea of ​​the last post:继上个帖子的思路:

one_hot = tf.dtypes.cast(parts[-2] == class_names, dtype = tf.int16)

My guess would be that tf.argmax requires one of these data-types (I can't test this right now)我的猜测是 tf.argmax 需要这些数据类型之一(我现在无法测试)

float32, float64, int32, uint8, int16, int8, complex64, int64, qint8, quint8, qint32, bfloat16, uint16, complex128, float16, uint32, uint64

so all you need to do is convert the output of所以你需要做的就是转换输出

one_hot = parts[-2] == class_names

to int, the "==" evaluates to True/False which is probably not allowed.对于 int,“==”的计算结果为 True/False,这可能是不允许的。

I think in this line img = tf.io.read_file(file_path) , img is image name instead of actual image.我认为在这一行img = tf.io.read_file(file_path) , img 是图像名称而不是实际图像。 To resolve this problem you can refer to here要解决此问题,您可以参考这里

It worked for me.它对我有用。 Let me know!让我知道!

暂无
暂无

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

相关问题 错误:TypeError:传递给参数“输入”的值的 DataType uint8 不在允许值列表中:float16、bfloat16、float32、float64、int32 - Error: TypeError: Value passed to parameter 'input' has DataType uint8 not in list of allowed values: float16, bfloat16, float32, float64, int32 错误:传递给参数“输入”的值的数据类型 int64 不在允许值列表中:float16、bfloat16、float32、float64? - Error : Value passed to parameter 'input' has DataType int64 not in list of allowed values: float16, bfloat16, float32, float64? TensorFlow TypeError:传递给参数输入的值的 DataType uint8 不在允许值列表中:float16、float32 - TensorFlow TypeError: Value passed to parameter input has DataType uint8 not in list of allowed values: float16, float32 传递给参数“shape”的值的 DataType float32 不在允许值列表中:int32、int64 - Value passed to parameter 'shape' has DataType float32 not in list of allowed values: int32, int64 TypeError:传递给参数'ref'的值的DataType int64不在允许的值列表中:float32,int32,qint8,quint8,qint32 - TypeError: Value passed to parameter 'ref' has DataType int64 not in list of allowed values: float32, int32, qint8, quint8, qint32 了解 Keras 错误:TypeError:传递给参数“shape”的值的 DataType float32 不在允许值列表中:int32、int64 - Understanding a Keras Error: TypeError: Value passed to parameter 'shape' has DataType float32 not in list of allowed values: int32, int64 KERAS 自定义丢失中的错误“类型错误:传递给参数 'reduction_indices' 的值的数据类型 float32 不在允许值列表中:int32,int64” - ERROR IN KERAS CUSTOM LOSS “TypeError: Value passed to parameter 'reduction_indices' has DataType float32 not in list of allowed values: int32, int64” TypeError:传递给参数'input'的值的数据类型float64不在允许的值列表中:float16,bfloat16,float32 - TypeError: Value passed to parameter 'input' has DataType float64 not in list of allowed values: float16, bfloat16, float32 TypeError:DataType float32 for attr'Tindices'不在允许值列表中:int32,int64 - TypeError:DataType float32 for attr 'Tindices' not in list of allowed values: int32, int64 Tensorflow类型错误:传递给参数'shape'的值具有DataType float32不在允许值列表中:int32,int64 - Tensorflow Type Error: Value passed to parameter 'shape' has DataType float32 not in list of allowed values: int32, int64
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM