Keras预测糖尿病性视网膜病变

我正在尝试通过使用densenet121中的keras模型来预测糖尿病性视网膜病变。 我有一个5文件夹,其中包含0:3647图像1:750图像2:1105图像3:305图像4:193图像 火车数据有6000张图像 并验证数据有1000张图片,测试数据有25张图片进行测试 我使用keras imagedatagenerator预处理图像并将其放大,图像大小为(224,224)

def HE(img):
      img_eq = exposure.equalize_hist(img)
      return img_eq
train_datagen = ImageDataGenerator(
    rescale=1./255,rotation_range=90,width_shift_range=0,height_shift_range=0,shear_range=0,zoom_range=0,horizontal_flip=True,fill_mode='nearest',preprocessing_function=HE,)
validation_datagen = ImageDataGenerator(
    rescale=1./255
)
test_datagen = ImageDataGenerator(
    rescale=1./255
)

train = train_datagen.flow_from_directory(
'train/train_deep/',target_size=(224,224),color_mode='grayscale',class_mode='categorical',batch_size = 20,)
test = test_datagen.flow_from_directory(
    'test_deep/',batch_size=1,target_size = (224,)

val = validation_datagen.flow_from_directory(
    'train/validate_deep/',)

我使用来自keras的densitynet121模型进行编译

model = DenseNet121(include_top=True,weights=None,input_tensor=None,input_shape=(224,224,3),pooling=None,classes=5)
model.compile(loss='categorical_crossentropy',optimizer='rmsprop',metrics=['accuracy'])
model.summary()
filepath="weights-improvement-{epoch:02d}-{val_loss:.2f}.hdf5"
checkpointer = ModelCheckpoint(filepath,monitor='val_loss',verbose=1,save_best_only=True,save_weights_only=True)
lr_reduction = ReduceLROnPlateau(monitor='val_loss',patience=5,verbose=2,factor=0.5)
callbacks_list = [checkpointer,lr_reduction]
history = model.fit_generator(
          train,epochs=Epoch,validation_data=val,class_weight={0:1,1:10.57,2:4.88,3:29,4:35},use_multiprocessing = False,workers = 16,callbacks=callbacks_list
        )

但是当我尝试预测

#predict

pred=model.predict_generator(test,steps=25,)

print(pred)

他们预测全部为3 my predict image

我面临的问题。

1。我尝试更改图像的权重,因为它的数据不平衡,但是仍然无法正常工作:

2。估计时间每个纪元要花费6-7分钟,如果我想训练更多的纪元(如50个纪元),我会花太多时间?

修改
1.我打印了我的25张预测图像的阵列,它们显示了

[[0.2718658  0.21595034 0.29440382 0.12089088 0.0968892 ]
 [0.2732306  0.22084573 0.29103383 0.11724534 0.0976444 ]
 [0.27060518 0.22559224 0.2952135  0.11220136 0.09638774]
 [0.27534768 0.21236925 0.28757185 0.12544192 0.09926935]
 [0.27870545 0.22124214 0.27978882 0.11854914 0.1017144 ]
 [0.2747815  0.22287942 0.28961015 0.11473729 0.09799159]
 [0.27190813 0.22454649 0.29327467 0.11331796 0.09695279]
 [0.27190694 0.22116153 0.27061856 0.12831333 0.10799967]
 [0.27871644 0.21939436 0.28575435 0.11689039 0.09924441]
 [0.27156618 0.22850358 0.27458736 0.11895953 0.10638336]
 [0.27199408 0.22443996 0.29326025 0.11337796 0.09692782]
 [0.27737287 0.22283535 0.28601763 0.11459836 0.09917582]
 [0.2719294  0.22462222 0.29477262 0.11228184 0.09639395]
 [0.27496076 0.22619417 0.24634513 0.12380602 0.12869397]
 [0.27209386 0.23049556 0.27982628 0.11399914 0.10358524]
 [0.2763851  0.22362126 0.27667257 0.11974224 0.10357884]
 [0.28445077 0.22687359 0.22116113 0.12310001 0.14441448]
 [0.27552167 0.22341767 0.28794768 0.11433118 0.09878179]
 [0.27714184 0.22157396 0.26033664 0.12819317 0.11275442]
 [0.27115697 0.22615613 0.29698634 0.10981857 0.09588206]
 [0.27108756 0.22484282 0.29557163 0.11230227 0.09619577]
 [0.2713721  0.22606659 0.29634616 0.11017173 0.09604342]
 [0.27368984 0.22699612 0.28083235 0.11586079 0.10262085]
 [0.2698808  0.22924589 0.29770645 0.10761821 0.0955487 ]
 [0.27016872 0.23090932 0.2694938  0.11959692 0.1098313 ]]

我看到一些图像在0中,但是在所有预测中它们都显示3,那么为什么显示呢?
2.我在模型densitynet121中稍微更改了一些代码行,删除了外部顶层并更改了预测代码,以便于查看。

YJX690271813 回答:Keras预测糖尿病性视网膜病变

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3045932.html

大家都在问