我有图像的数据集,并且正在对其上实现数据增强方法。实现第一个(使用np.fliplr
)后,模型运行良好。但是,当我尝试对数据实施对比度拉伸时,我的损失立即变成NaN
。我试图通过更改学习率/批量大小等解决问题,但没有成功。
这是我的代码的一部分:
# Contrast stretching function
from skimage import exposure, color
def contrast_stretching(img):
p2, p98 = np.percentile(img, (2, 98))
img_rescale = exposure.rescale_intensity(img, in_range=(p2, p98))
return img_rescale
# Implement my function over the data
x_train = np.append(x_train, [contrast_stretching(x) for x in x_train], axis=0)
y_train = np.append(y_train, [contrast_stretching(x) for x in y_train], axis=0)
# Training...
early_stopping = EarlyStopping(patience=10, verbose=1)
model_checkpoint = ModelCheckpoint("D:/...", save_best_only=True, verbose=1)
reduce_lr = ReduceLROnPlateau(factor=0.1, patience=5, min_lr=0.00001, verbose=1)
epochs = 5
batch_size = 32
history = model.fit(x_train, y_train,
validation_data=[x_valid, y_valid],
epochs=epochs,
batch_size=batch_size,
callbacks=[early_stopping, model_checkpoint, reduce_lr])
我不想要的输出示例:
ETA:1:05-损失:nan-均值:0.382-ETA:1:06-损失:nan- 均值:0.382-预计ETA:1:04-损失:nan-均值:0.382-预计ETA:1:04 -损失:nan-均值:0.382-预计收入:1:03-损失:nan-均值:0.382-ETA:1:03-损失:nan-均值:0.382-ETA:1:03-损失:nan
任何帮助将不胜感激!