I'm trying to predict a diabetic retiopathy by using densenet121
model from keras
.
I have a 5 folder that contain 0:3647 images 1:750 images 2:1105 images 3:305 images 4:193 images
train data have 6000 image
and validate data have 1000 image and test data have 25 to test a little bit
I use keras imagedatagenerator to preprocess image and augmented it,size of image is (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,224),
color_mode='grayscale',
)
val = validation_datagen.flow_from_directory(
'train/validate_deep/',
target_size=(224,224),
color_mode='grayscale',
batch_size = 20,
)
I use a densenet121 model from keras to compile
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
)
but when I try to predict
#predict
pred=model.predict_generator(test,
steps=25,)
print(pred)
They predict all are 3 my predict image
problems that I am facing.
1.I try to change a weight of my image because it a imbalance data but, it still doesn't work:
2.Estimate time use 6-7 minutes per epoch that take too much time if I want to train more epoch like 50 epoch what should I do??
Edit
1. I print an array of my 25 predict image and they show
[[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 ]]
I see some image are in 0 but they show 3 in all prediction,So why it show that?
2. I change some line of code a little bit in model densenet121 , I remove a external top layer and change a predict code for more easy to see.