MrGiovanni / UNetPlusPlus

[IEEE TMI] Official Implementation for UNet++
Other
2.26k stars 538 forks source link

Some question in training #36

Open sanersbug opened 4 years ago

sanersbug commented 4 years ago

The following is the train print. Anyone meet the same situation? the val_binary_accuracy is always 1. 25/25 [==============================] - 42s 2s/step - loss: 0.3984 - binary_accuracy: 0.8856 - val_loss: 0.0573 - val_binary_accuracy: 0.9995

Epoch 00001: saving model to D:/wcs/UNetPlusPlus-master/weights/road_001.h5 Epoch 2/50 25/25 [==============================] - 25s 991ms/step - loss: 0.0611 - binary_accuracy: 1.0000 - val_loss: 0.0041 - val_binary_accuracy: 1.0000

Epoch 00002: saving model to D:/wcs/UNetPlusPlus-master/weights/road_002.h5 Epoch 3/50 25/25 [==============================] - 24s 965ms/step - loss: 0.0200 - binary_accuracy: 1.0000 - val_loss: 0.0364 - val_binary_accuracy: 1.0000

Epoch 00003: saving model to D:/wcs/UNetPlusPlus-master/weights/road_003.h5 Epoch 4/50 25/25 [==============================] - 24s 978ms/step - loss: 0.0106 - binary_accuracy: 1.0000 - val_loss: 0.0312 - val_binary_accuracy: 1.0000

Epoch 00004: saving model to D:/wcs/UNetPlusPlus-master/weights/road_004.h5 Epoch 5/50 25/25 [==============================] - 25s 988ms/step - loss: 0.0071 - binary_accuracy: 1.0000 - val_loss: 0.0221 - val_binary_accuracy: 1.0000

Epoch 00005: saving model to D:/wcs/UNetPlusPlus-master/weights/road_005.h5 Epoch 6/50 25/25 [==============================] - 25s 984ms/step - loss: 0.0052 - binary_accuracy: 1.0000 - val_loss: 0.0155 - val_binary_accuracy: 1.0000

Epoch 00006: saving model to D:/wcs/UNetPlusPlus-master/weights/road_006.h5 Epoch 7/50 25/25 [==============================] - 25s 982ms/step - loss: 0.0040 - binary_accuracy: 1.0000 - val_loss: 0.0108 - val_binary_accuracy: 1.0000

Epoch 00007: saving model to D:/wcs/UNetPlusPlus-master/weights/road_007.h5 Epoch 8/50 25/25 [==============================] - 24s 974ms/step - loss: 0.0033 - binary_accuracy: 1.0000 - val_loss: 0.0079 - val_binary_accuracy: 1.0000

Epoch 00008: saving model to D:/wcs/UNetPlusPlus-master/weights/road_008.h5 Epoch 9/50 25/25 [==============================] - 25s 988ms/step - loss: 0.0028 - binary_accuracy: 1.0000 - val_loss: 0.0060 - val_binary_accuracy: 1.0000

Epoch 00009: saving model to D:/wcs/UNetPlusPlus-master/weights/road_009.h5 Epoch 10/50 25/25 [==============================] - 25s 982ms/step - loss: 0.0025 - binary_accuracy: 1.0000 - val_loss: 0.0047 - val_binary_accuracy: 1.0000

Epoch 00010: saving model to D:/wcs/UNetPlusPlus-master/weights/road_010.h5 Epoch 11/50 25/25 [==============================] - 25s 981ms/step - loss: 0.0022 - binary_accuracy: 1.0000 - val_loss: 0.0038 - val_binary_accuracy: 1.0000

Epoch 00011: saving model to D:/wcs/UNetPlusPlus-master/weights/road_011.h5 Epoch 12/50 25/25 [==============================] - 25s 983ms/step - loss: 0.0019 - binary_accuracy: 1.0000 - val_loss: 0.0030 - val_binary_accuracy: 1.0000

Epoch 00012: saving model to D:/wcs/UNetPlusPlus-master/weights/road_012.h5 Epoch 13/50 25/25 [==============================] - 25s 988ms/step - loss: 0.0017 - binary_accuracy: 1.0000 - val_loss: 0.0025 - val_binary_accuracy: 1.0000

Epoch 00013: saving model to D:/wcs/UNetPlusPlus-master/weights/road_013.h5 Epoch 14/50 25/25 [==============================] - 25s 983ms/step - loss: 0.0015 - binary_accuracy: 1.0000 - val_loss: 0.0022 - val_binary_accuracy: 1.0000

Epoch 00014: saving model to D:/wcs/UNetPlusPlus-master/weights/road_014.h5 Epoch 15/50 25/25 [==============================] - 25s 981ms/step - loss: 0.0014 - binary_accuracy: 1.0000 - val_loss: 0.0018 - val_binary_accuracy: 1.0000

Epoch 00015: saving model to D:/wcs/UNetPlusPlus-master/weights/road_015.h5 Epoch 16/50 25/25 [==============================] - 25s 981ms/step - loss: 0.0013 - binary_accuracy: 1.0000 - val_loss: 0.0016 - val_binary_accuracy: 1.0000

Epoch 00016: saving model to D:/wcs/UNetPlusPlus-master/weights/road_016.h5 Epoch 17/50 25/25 [==============================] - 25s 988ms/step - loss: 0.0011 - binary_accuracy: 1.0000 - val_loss: 0.0014 - val_binary_accuracy: 1.0000

Epoch 00017: saving model to D:/wcs/UNetPlusPlus-master/weights/road_017.h5 Epoch 18/50 25/25 [==============================] - 25s 982ms/step - loss: 0.0010 - binary_accuracy: 1.0000 - val_loss: 0.0012 - val_binary_accuracy: 1.0000

Epoch 00018: saving model to D:/wcs/UNetPlusPlus-master/weights/road_018.h5 Epoch 19/50 25/25 [==============================] - 25s 982ms/step - loss: 9.5877e-04 - binary_accuracy: 1.0000 - val_loss: 0.0011 - val_binary_accuracy: 1.0000

Epoch 00019: saving model to D:/wcs/UNetPlusPlus-master/weights/road_019.h5 Epoch 20/50 25/25 [==============================] - 25s 980ms/step - loss: 8.8322e-04 - binary_accuracy: 1.0000 - val_loss: 0.0010 - val_binary_accuracy: 1.0000

Epoch 00020: saving model to D:/wcs/UNetPlusPlus-master/weights/road_020.h5 Epoch 21/50 25/25 [==============================] - 25s 989ms/step - loss: 8.1642e-04 - binary_accuracy: 1.0000 - val_loss: 9.1734e-04 - val_binary_accuracy: 1.0000

Epoch 00021: saving model to D:/wcs/UNetPlusPlus-master/weights/road_021.h5 Epoch 22/50 25/25 [==============================] - 25s 983ms/step - loss: 7.5695e-04 - binary_accuracy: 1.0000 - val_loss: 8.3885e-04 - val_binary_accuracy: 1.0000

Epoch 00022: saving model to D:/wcs/UNetPlusPlus-master/weights/road_022.h5 Epoch 23/50 25/25 [==============================] - 25s 982ms/step - loss: 7.0407e-04 - binary_accuracy: 1.0000 - val_loss: 7.6486e-04 - val_binary_accuracy: 1.0000

Epoch 00023: saving model to D:/wcs/UNetPlusPlus-master/weights/road_023.h5 Epoch 24/50 25/25 [==============================] - 25s 980ms/step - loss: 6.5629e-04 - binary_accuracy: 1.0000 - val_loss: 7.1081e-04 - val_binary_accuracy: 1.0000

Epoch 00024: saving model to D:/wcs/UNetPlusPlus-master/weights/road_024.h5 Epoch 25/50 25/25 [==============================] - 25s 986ms/step - loss: 6.1347e-04 - binary_accuracy: 1.0000 - val_loss: 6.5125e-04 - val_binary_accuracy: 1.0000

Epoch 00025: saving model to D:/wcs/UNetPlusPlus-master/weights/road_025.h5 Epoch 26/50 25/25 [==============================] - 25s 983ms/step - loss: 5.7442e-04 - binary_accuracy: 1.0000 - val_loss: 6.0789e-04 - val_binary_accuracy: 1.0000

Epoch 00026: saving model to D:/wcs/UNetPlusPlus-master/weights/road_026.h5 Epoch 27/50 25/25 [==============================] - 25s 982ms/step - loss: 5.3929e-04 - binary_accuracy: 1.0000 - val_loss: 5.6109e-04 - val_binary_accuracy: 1.0000

Epoch 00027: saving model to D:/wcs/UNetPlusPlus-master/weights/road_027.h5 Epoch 28/50 25/25 [==============================] - 25s 980ms/step - loss: 5.0707e-04 - binary_accuracy: 1.0000 - val_loss: 5.2836e-04 - val_binary_accuracy: 1.0000

Epoch 00028: saving model to D:/wcs/UNetPlusPlus-master/weights/road_028.h5 Epoch 29/50 25/25 [==============================] - 25s 990ms/step - loss: 4.7771e-04 - binary_accuracy: 1.0000 - val_loss: 4.9583e-04 - val_binary_accuracy: 1.0000

Epoch 00029: saving model to D:/wcs/UNetPlusPlus-master/weights/road_029.h5 Epoch 30/50 25/25 [==============================] - 25s 984ms/step - loss: 4.5094e-04 - binary_accuracy: 1.0000 - val_loss: 4.6588e-04 - val_binary_accuracy: 1.0000

Epoch 00030: saving model to D:/wcs/UNetPlusPlus-master/weights/road_030.h5 Epoch 31/50 25/25 [==============================] - 24s 980ms/step - loss: 4.2627e-04 - binary_accuracy: 1.0000 - val_loss: 4.3289e-04 - val_binary_accuracy: 1.0000

Epoch 00031: saving model to D:/wcs/UNetPlusPlus-master/weights/road_031.h5 Epoch 32/50 25/25 [==============================] - 25s 983ms/step - loss: 4.0358e-04 - binary_accuracy: 1.0000 - val_loss: 4.1187e-04 - val_binary_accuracy: 1.0000

Epoch 00032: saving model to D:/wcs/UNetPlusPlus-master/weights/road_032.h5 Epoch 33/50 25/25 [==============================] - 25s 985ms/step - loss: 3.8265e-04 - binary_accuracy: 1.0000 - val_loss: 3.8633e-04 - val_binary_accuracy: 1.0000

Epoch 00033: saving model to D:/wcs/UNetPlusPlus-master/weights/road_033.h5 Epoch 34/50 25/25 [==============================] - 25s 984ms/step - loss: 3.6333e-04 - binary_accuracy: 1.0000 - val_loss: 3.7233e-04 - val_binary_accuracy: 1.0000

Epoch 00034: saving model to D:/wcs/UNetPlusPlus-master/weights/road_034.h5 Epoch 35/50 25/25 [==============================] - 25s 982ms/step - loss: 3.4537e-04 - binary_accuracy: 1.0000 - val_loss: 3.4674e-04 - val_binary_accuracy: 1.0000

Epoch 00035: saving model to D:/wcs/UNetPlusPlus-master/weights/road_035.h5 Epoch 36/50 25/25 [==============================] - 25s 982ms/step - loss: 3.2872e-04 - binary_accuracy: 1.0000 - val_loss: 3.3457e-04 - val_binary_accuracy: 1.0000

Epoch 00036: saving model to D:/wcs/UNetPlusPlus-master/weights/road_036.h5 Epoch 37/50 25/25 [==============================] - 25s 984ms/step - loss: 3.1336e-04 - binary_accuracy: 1.0000 - val_loss: 3.1528e-04 - val_binary_accuracy: 1.0000

Epoch 00037: saving model to D:/wcs/UNetPlusPlus-master/weights/road_037.h5 Epoch 38/50 25/25 [==============================] - 25s 984ms/step - loss: 2.9885e-04 - binary_accuracy: 1.0000 - val_loss: 3.0221e-04 - val_binary_accuracy: 1.0000

Epoch 00038: saving model to D:/wcs/UNetPlusPlus-master/weights/road_038.h5 Epoch 39/50 25/25 [==============================] - 25s 982ms/step - loss: 2.8693e-04 - binary_accuracy: 1.0000 - val_loss: 2.8710e-04 - val_binary_accuracy: 1.0000

Epoch 00039: saving model to D:/wcs/UNetPlusPlus-master/weights/road_039.h5 Epoch 40/50 25/25 [==============================] - 24s 980ms/step - loss: 2.7742e-04 - binary_accuracy: 1.0000 - val_loss: 2.8069e-04 - val_binary_accuracy: 1.0000

Epoch 00040: saving model to D:/wcs/UNetPlusPlus-master/weights/road_040.h5 Epoch 41/50 25/25 [==============================] - 25s 987ms/step - loss: 2.6816e-04 - binary_accuracy: 1.0000 - val_loss: 2.7068e-04 - val_binary_accuracy: 1.0000

Epoch 00041: saving model to D:/wcs/UNetPlusPlus-master/weights/road_041.h5 Epoch 42/50 25/25 [==============================] - 24s 980ms/step - loss: 2.5939e-04 - binary_accuracy: 1.0000 - val_loss: 2.5856e-04 - val_binary_accuracy: 1.0000

Epoch 00042: saving model to D:/wcs/UNetPlusPlus-master/weights/road_042.h5 Epoch 43/50 25/25 [==============================] - 25s 985ms/step - loss: 2.5100e-04 - binary_accuracy: 1.0000 - val_loss: 2.5420e-04 - val_binary_accuracy: 1.0000

Epoch 00043: saving model to D:/wcs/UNetPlusPlus-master/weights/road_043.h5 Epoch 44/50 25/25 [==============================] - 25s 981ms/step - loss: 2.4295e-04 - binary_accuracy: 1.0000 - val_loss: 2.4528e-04 - val_binary_accuracy: 1.0000

Epoch 00044: saving model to D:/wcs/UNetPlusPlus-master/weights/road_044.h5 Epoch 45/50 25/25 [==============================] - 25s 985ms/step - loss: 2.3524e-04 - binary_accuracy: 1.0000 - val_loss: 2.3748e-04 - val_binary_accuracy: 1.0000

Epoch 00045: saving model to D:/wcs/UNetPlusPlus-master/weights/road_045.h5 Epoch 46/50 25/25 [==============================] - 25s 980ms/step - loss: 2.2876e-04 - binary_accuracy: 1.0000 - val_loss: 2.3000e-04 - val_binary_accuracy: 1.0000

Epoch 00046: saving model to D:/wcs/UNetPlusPlus-master/weights/road_046.h5 Epoch 47/50 25/25 [==============================] - 25s 986ms/step - loss: 2.2333e-04 - binary_accuracy: 1.0000 - val_loss: 2.2572e-04 - val_binary_accuracy: 1.0000

Epoch 00047: saving model to D:/wcs/UNetPlusPlus-master/weights/road_047.h5 Epoch 48/50 25/25 [==============================] - 24s 979ms/step - loss: 2.1811e-04 - binary_accuracy: 1.0000 - val_loss: 2.1949e-04 - val_binary_accuracy: 1.0000

Epoch 00048: saving model to D:/wcs/UNetPlusPlus-master/weights/road_048.h5 Epoch 49/50 25/25 [==============================] - 25s 985ms/step - loss: 2.1302e-04 - binary_accuracy: 1.0000 - val_loss: 2.1420e-04 - val_binary_accuracy: 1.0000

Epoch 00049: saving model to D:/wcs/UNetPlusPlus-master/weights/road_049.h5 Epoch 50/50 25/25 [==============================] - 25s 984ms/step - loss: 2.0808e-04 - binary_accuracy: 1.0000 - val_loss: 2.1072e-04 - val_binary_accuracy: 1.0000

Epoch 00050: saving model to D:/wcs/UNetPlusPlus-master/weights/road_050.h5

my train code is : from utils2 import * from keras.optimizers import Adam from keras.callbacks import ModelCheckpoint, LearningRateScheduler, ReduceLROnPlateau, TensorBoard from segmentation_models import Unet, Nestnet, Xnet

prepare model

model = Xnet(backbone_name='resnet50', encoder_weights='imagenet', decoder_block_type='transpose') # build UNet++

model.summary() model.compile(optimizer=Adam(lr=1.0e-3), loss='binary_crossentropy', metrics=['binary_accuracy'])

train model

batch_size = 4 img_size = 512 epochs = 50 train_im_path,train_mask_path = 'D:/xxx/unet_plus/road_test/train/imgs/','D:/xxx/unet_plus/road_test/train/labels/' val_im_path,val_mask_path = 'D:/xxx/unet_plus/road_test/val/imgs/','D:/xxx/unet_plus/road_test/val/labels/' train_set = get_train_val(train_im_path) val_set = get_train_val(val_im_path) train_number = len(train_set) val_number = len(val_set)

training_generator = DataGenerator(train_im_path = train_im_path, train_mask_path=train_mask_path, img_size=img_size) validation_generator = DataGenerator(train_im_path = val_im_path, train_mask_path=val_mask_path, img_size=img_size)

model_path = 'D:/xxx/UNetPlusPlus-master/weights/' modelname = 'road{epoch:03d}.h5' model_file = os.path.join(model_path, model_name) model_checkpoint = ModelCheckpoint(model_file, monitor='val_loss', verbose=1, save_best_only=False, mode='max') lr_reducer = ReduceLROnPlateau(monitor='val_loss', factor=np.sqrt(0.5625), cooldown=0, patience=5, min_lr=0.5e-6) callable = [model_checkpoint, lr_reducer, TensorBoard(log_dir='./log')]

history = model.fit_generator(generator=training_generator, validation_data=validation_generator, steps_per_epoch=train_number//batch_size, validation_steps=val_number//batch_size,
use_multiprocessing=False, epochs=epochs,verbose=1, callbacks=callable)

zoegavrilovic commented 4 years ago

Sir, thank you for your code, it's helpful. Could you please tell me what are the dimensions/shapes of your train and validation sets? Is there a way you could share the code of your DataGenerator? My teammate and I are having problems with loading a dataset, which consists of an array of images, and an array of arrays of all masks per image.