为 Tensorflow 创建数据集以检测多个对象

Create Dataset for Tensorflow to Detect Multiple objects

提问人:claudioflores 提问时间:11/9/2023 最后编辑:claudioflores 更新时间:11/21/2023 访问量:31

问:

我正在尝试从图像列表创建一个数据集,以使用 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>]

请帮忙=)

TensorFlow 数据集 conv-neural-network

评论


答:

0赞 masterclass 11/21/2023 #1

您必须将我们标签的值放在字典中,这样就可以了。

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
    ],
    ...
]