我正在尝试从图像列表创建一个数据集,以使用 Tensorflow 训练深度学习模型,但我遇到了标签问题。
我的目标是检测每张图像中的多个对象,所以我创建了这样的东西:
labels =
# Image 1
[
[100, 50], # Object 1 attributes (x, y)
[250, 100], # Object 2 attributes
],
# Image 2
[
[50, 60], # Object 1 attributes
[200, 70], # Object 2 attributes
[450, 40], # Object 3 attributes
],
...
]
当只检测一个对象时,我已经成功地训练了一个模型,但当我尝试检测多个对象时,却没有成功。我试过这个:
dataset = tf.data.Dataset.from_tensor_slices((X, tf.ragged.constant(label)))
model = tf.keras.Sequential([
tfl.ZeroPadding2D(padding=(10, 10), input_shape=(535, 535, 4)),
tfl.Conv2D(32, (7, 7)),
tfl.BatchNormalization(axis=-1),
tfl.ReLU(),
tfl.MaxPool2D(),
tfl.Flatten(),
tfl.Dense(2, activation='linear')
])
model.compile(optimizer='adam', loss='mae', metrics=['mse', 'mae'])
Error:
TypeError: Some of the inputs are not tf.RaggedTensor. Input received: [tf.RaggedTensor(values=tf.RaggedTensor(values=Tensor("Cast_20:0", shape=(None,), dtype=float32), row_splits=Tensor("RaggedFromVariant/RaggedTensorFromVariant:1", shape=(None,), dtype=int64)), row_splits=Tensor("RaggedFromVariant/RaggedTensorFromVariant:0", shape=(None,), dtype=int64)), <tf.Tensor 'sequential_24/dense_24/BiasAdd:0' shape=(None, 2) dtype=float32>]
请帮忙=)
您必须将标签的值放入字典中,这样就可以了。
labels = [
# Image 1
[
{100, 50}, # Object 1 attributes (x, y)
{250, 100}, # Object 2 attributes
],
# Image 2
[
{50, 60}, # Object 1 attributes
{200, 70}, # Object 2 attributes
{450, 40}, # Object 3 attributes
],
...
]