请告诉我哪里出错了。我正在研究 Kaggle 狗品种分类挑战,我想尝试 one-hot 编码与标签编码。图像未在图像目录中拆分,因此我无法将“推断”与 tf.keras.utils.image_dataset_from_directory 一起使用,标签位于单独的 csv 文件中,我将其放入 df (label_int) 中。
cat_count = 120 #depth or the number of categories
oh_input = tf.one_hot(label_int, cat_count) #apply one-hot encoding
label_int 是我的所有标签的整数形式的列表,其顺序与目录中的图像相同。 oh_input 是一个 one-hot 向量列表。
batch_size = 32
img_height = 224
img_width = 224
train_ds = tf.keras.utils.image_dataset_from_directory(train_dir,labels = oh_input,label_mode = 'categorical',validation_split=0.2,subset="training",seed=123,image_size=(img_height, img_width),batch_size=batch_size)
val_ds = tf.keras.utils.image_dataset_from_directory(train_dir,labels = oh_input,label_mode = 'categorical',validation_split=0.2,subset="validation",seed=123,image_size=(img_height, img_width),batch_size=batch_size)
错误:
154 if kwargs:
155 raise TypeError(f'Unknown keywords argument(s): {tuple(kwargs.keys())}') --> 156 if labels not in ('inferred', None):
...
100 dtype = dtypes.as_dtype(dtype).as_datatype_enum 101 ctx.ensure_initialized() --> 102 return ops.EagerTensor(value, ctx.device_name, dtype) TypeError: Cannot convert 'inferred' to EagerTensor of dtype int64
我在 tf.one_hot 函数中尝试了其他数据类型,但没有一个有效。我猜我只是错过了一些基本的语法错误。
https://www.tensorflow.org/api_docs/python/tf/keras/utils/image_dataset_from_directory https://www.tensorflow.org/api_docs/python/tf/keras/utils/image_dataset_from_directory
我还尝试过 labels= *(a numpy array of integer value) 和 label_mode =int ,这给了我另一个错误。我还尝试了 labels = None ,它显示“找到属于 1 个类的 10222 个文件。”所以我不确定是否可以稍后将标签添加到拟合函数中。