【问题标题】:How to label images for training using numpy如何使用 numpy 标记图像以进行训练
【发布时间】:2021-11-19 15:06:49
【问题描述】:

我有自己的数据集,其中包含我想要标记的 2000 张图像。起初,我创建了包含标签(0 或 1)的 numpy 数组。例如,对于 image[0],对应的标签是 label[0]。请注意,我不确定这是否是正确的标记方式。

model= VGG16(include_top=False, input_shape= (32,32,3))
model.summary()

model.compile(optimizer="Adam", loss="binary_crossentropy" , metrics=['accuracy'])
epochs = 10
history = model.fit(x=training_ds, y=training_lb , epochs=epochs, validation_data= (testing_ds, testing_lb) )

training_ds 包含所有形状为 (n,32,32,3) 的图像 training_lb 包含形状为 (n,1) 的标签

测试也一样。

运行代码后我得到错误,损失非常高,它没有学到任何东西。我的标签错了吗?

输出:

【问题讨论】:

    标签: python tensorflow machine-learning docker-compose classification


    【解决方案1】:

    我认为您的准确度为 0,因为您的模型没有输出密集层。像这样使用它:

    import tensorflow as tf
    
    base_model= VGG16(include_top=False, input_shape= (32,32,3))
    
    model = tf.keras.models.Sequential()
    model.add(base_model)
    model.add(tf.keras.layers.Flatten())
    model.add(tf.keras.layers.Dropout(0.2))
    model.add(tf.keras.layers.Dense(1, activation='sigmoid'))
    

    而且我不认为你的标签有什么问题。但这非常耗时。相反,您可以创建两个不同的文件夹并将这些文件夹重命名为标签,即 1 和 0。然后将这些图像添加到特定文件夹中。然后使用 TensorFlow 的ImageDataGenerator 来加载它们。

    【讨论】:

    • 谢谢!这很有帮助。我可以使用 ImageDataGenerator 而不使用 image_dataset_from_directory 吗?我的图片是 TIF,不幸的是还没有完全支持。
    • ImageDataGenerator 支持所有格式,包括 TIF 图像。在how to use image data generator 上检查此 Stack Exchange 问题
    猜你喜欢
    • 2018-03-01
    • 1970-01-01
    • 2021-05-18
    • 2020-02-02
    • 2014-02-21
    • 2022-10-24
    • 2015-09-09
    • 2018-05-29
    • 1970-01-01
    相关资源
    最近更新 更多