我想预测糖尿病性视网膜病变。
我在班级0:3647,班级1:750,班级2:1105,班级3:305,班级4:193分别有6000个训练数据集
我有1000个验证数据集,分别在班0:427,班1:142,班2:202,班3:148,班4:81
我使用imagedatagenerator进行增强
train_datagen = ImageDataGenerator(
rescale=1. / 255,
rotation_range=40,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest',
preprocessing_function=HE,
)
validation_datagen = ImageDataGenerator(
rescale=1./255
)
test_datagen = ImageDataGenerator(
rescale=1./255
)
#get image and label with augmentation
train = train_datagen.flow_from_directory(
'train/train_deep/',
target_size=(224,224),
class_mode='categorical',
shuffle=False,
batch_size = 20,
)
test = test_datagen.flow_from_directory(
'test_deep/',
batch_size=1,
class_mode=None,
shuffle=False,
target_size = (224,224),
)
val = validation_datagen.flow_from_directory(
'train/validate_deep/',
target_size=(224,224),
batch_size = 1,
shuffle=False,
class_mode='categorical'
)
我使用sklearn和模型densitynet121计算fit_generator的权重
history = model.fit_generator(
train,
epochs=Epoch,
steps_per_epoch=int(6000/32),
class_weight=class_weight,
validation_data=val,
validation_steps=int(1000/32),
use_multiprocessing = False,
max_queue_size=100,
workers = 16,
callbacks=callbacks_list
)
但是当我训练时,它们显示出奇怪的val_loss
Epoch 00001: val_loss improved from inf to 11363.97366, saving model to weight/weights-improvement-01-11363.97.hdf5
187/187 [==============================] - 203s 1s/step - loss: 2.0711 - categorical_accuracy: 0.1313 - val_loss: 11363.9737 - val_categorical_accuracy: 0.0000e+00
我不知道为什么它们的损失价值很高。
在50个时代
Epoch 00050: val_loss did not improve from 0.00000
187/187 [==============================] - 802s 4s/step - loss: 1.6423 - categorical_accuracy: 0.4567 - val_loss: 795.2247 - val_categorical_accuracy: 0.0000e+00
当我打印验证数据的混淆矩阵时,它显示出许多错误的预测
Confusion Matrix
[[ 0 0 5 422 0]
[ 0 0 5 137 0]
[ 0 0 4 198 0]
[ 0 0 6 142 0]
[ 0 0 1 80 0]]
precision recall f1-score support
No DR 0.00 0.00 0.00 427
Mild 0.00 0.00 0.00 142
Moderate 0.19 0.02 0.04 202
Severe 0.15 0.96 0.25 148
Proliferative DR 0.00 0.00 0.00 81
accuracy 0.15 1000
macro avg 0.07 0.20 0.06 1000
weighted avg 0.06 0.15 0.04 1000
我预测一个测试数据集,我有25个测试数据集用于小预测,但显示全部为3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
问题
1.为什么val_loss损失太大,该怎么办?
2.如果我想要一个好的预测,我应该增加训练的时间或其他方法吗?
这是30个时代的准确性和损失
acc in 30 epoch
loss in 30 epoch
这是50个纪元内的准确性和损失
acc in 50 epoch
loss in 50 epoch