【问题标题】:How to increase data training bias in Keras?如何增加 Keras 中的数据训练偏差?
【发布时间】:2020-04-22 06:03:18
【问题描述】:

我目前正在使用大约 15k 图像(50% 好和坏)使用 Keras 进行二元模型训练。但是,我的坏数据集是有限的。所以我添加了增强。尽管如此,我还是想强制模型将即使是好的也识别为坏的,如果它是轻微的或接近坏的。

Y_train = train_generator.classes
from sklearn.utils import class_weight
class_weight = class_weight.compute_class_weight('balanced'
                                               ,np.unique(Y_train)
                                               ,Y_train)
class_weight
class_weight = dict(zip(np.unique(Y_train), class_weight))
class_weight

输出:

{0: 1.0015690376569037, 1: 0.9984358706986444}

我想对坏数据集进行比好的数据集更多的训练。是否可以将类(0 - 差)权重增加到 10?

培训:

print(colored('Training initiaited. please wait........', 'blue',))
model.fit_generator(train_generator,
                         epochs = epochs,
                         validation_data = validation_generator,
                         class_weight = class_weight, 
                         steps_per_epoch=int(train_generator.samples/batch_size),
                         callbacks=callbacks_list, 
                         validation_steps = int(validation_generator.samples/batch_size)
                           ) 

强制模型在不良数据集上进行更多训练的最佳方法是什么? (如果这不是最好的方法(不幸的是我没有任何不好的数据,但我确实有很多好的数据点))

跟随“平衡”有什么办法吗?

class_weight.compute_class_weight('balanced'
                                               ,np.unique(Y_train)
                                               ,Y_train)

【问题讨论】:

    标签: tensorflow machine-learning keras


    【解决方案1】:

    对误报进行更严格限制的一种简单方法是在分类期间提高阈值。即,假设您的模型抛出0.65 的输出,同时为图像类做出决定,这通常类似于

    threshold = 0.5
    if output<threshold:
        print("Class 0")
    else:
        print("Class 1")
    

    它输出为class 0,但通过增加阈值0.80,您可以更严格地确定真阳性。仅当您的模型抛出与类概率相对应的输出时,上述内容才有用。

    But the correct way would be to choose the correct metric, for example in your case going with precision is a better option.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-22
      • 2020-01-27
      • 2020-03-09
      • 2020-07-13
      • 2016-03-10
      • 2019-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多