我正在尝试使用 ArcFace 层实现模型: https ://github.com/4uiiurz1/keras-arcface
为此,我创建了一个 tf.data.dataset,如下所示:
images= tf.data.Dataset.from_tensor_slices(train.A_image.to_numpy())
target = tf.keras.utils.to_categorical(
train.Label.to_numpy(), num_classes=n_class, dtype='float32'
)
target = tf.data.Dataset.from_tensor_slices(target)
images= images.map(transform_img)
dataset = tf.data.Dataset.zip((images, target, target))
当我打电话时model.fit(dataset)
我收到以下错误:
ValueError: Layer model expects 2 input(s), but it received 1 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=<unknown> dtype=float32>]
但这应该根据:
有人能指出我的愚蠢吗?
谢谢!
编辑:这解决了一些问题:
#reads in filepaths to images from dataframe train
images = tf.data.Dataset.from_tensor_slices(train.image.to_numpy())
#converts labels to one hot encoding vector
target = tf.keras.utils.to_categorical(train.Label.to_numpy(), num_classes=n_class, dtype='float32')
#reads in the image and resizes it
images= images.map(transform_img)
input_1 = tf.data.Dataset.zip((anchors, target))
dataset = tf.data.Dataset.zip((input_1, target))
我认为这是我们正在尝试的。但是我得到目标的形状错误,它是 (n_class, 1) 而不仅仅是 (n_class,)
即 fit 方法抛出此错误
ValueError: Shapes (n_class, 1) and (n_class, n_class) are incompatible
和这个警告
input expected is (None, n_class) but received an input of (n_class, 1)