AndyWangON / Brain-tumor-segmentation-using-deep-learning

#BRATS2015 #BRATS2018 #deep learning #fully automatic brain tumor segmentation #U-net # tensorflow #Keras
54 stars 29 forks source link

your article #6

Closed motahareaghalari closed 5 years ago

motahareaghalari commented 5 years ago

Hello I have error: C:\Users\pars.conda\envs\tensorflow\lib\site-packages\ipykernel_launcher.py:22: UserWarning: The merge function is deprecated and will be removed after 08/2017. Use instead layers from keras.layers.merge, e.g. add, concatenate, etc. C:\Users\pars.conda\envs\tensorflow\lib\site-packages\keras\legacy\layers.py:465: UserWarning: The Merge layer is deprecated and will be removed after 08/2017. Use instead layers from keras.layers.merge, e.g. add, concatenate, etc. name=name)

ValueError Traceback (most recent call last)

in () 3 num = 31100 4 ----> 5 model = unet_model() in unet_model() 20 conv5 = Conv2D(512, (3, 3), activation='relu', padding='same')(conv5) 21 ---> 22 up6 = merge([UpSampling2D(size=(2, 2))(conv5), conv4], mode='concat', concat_axis=1) 23 conv6 = Conv2D(256, (3, 3), activation='relu', padding='same')(up6) 24 conv6 = Conv2D(256, (3, 3), activation='relu', padding='same')(conv6) ~\.conda\envs\tensorflow\lib\site-packages\keras\legacy\layers.py in merge(inputs, mode, concat_axis, dot_axes, output_shape, output_mask, arguments, name) 463 node_indices=node_indices, 464 tensor_indices=tensor_indices, --> 465 name=name) 466 return merge_layer._inbound_nodes[0].output_tensors[0] 467 else: ~\.conda\envs\tensorflow\lib\site-packages\keras\legacy\layers.py in __init__(self, layers, mode, concat_axis, dot_axes, output_shape, output_mask, arguments, node_indices, tensor_indices, name) 116 self._arguments_validation(layers, mode, 117 concat_axis, dot_axes, --> 118 node_indices, tensor_indices) 119 self.built = True 120 input_tensors = [] ~\.conda\envs\tensorflow\lib\site-packages\keras\legacy\layers.py in _arguments_validation(self, layers, mode, concat_axis, dot_axes, node_indices, tensor_indices) 196 'layers with matching ' 197 'output shapes except for the concat axis. ' --> 198 'Layer shapes: %s' % (input_shapes)) 199 200 def call(self, inputs, mask=None): ValueError: "concat" mode can only merge layers with matching output shapes except for the concat axis. Layer shapes: [(None, 512, 14, 14), (None, 256, 15, 15)] can you help me?
motahareaghalari commented 5 years ago

I run brats2015.py and have this error.

csrvictory commented 5 years ago

try following code in place of def of unet mode

def unet_model(): inputs = Input((2, img_size, img_size)) conv1 = Conv2D(64, (3, 3), activation='relu', padding='same') (inputs) batch1 = BatchNormalization(axis=1)(conv1) conv1 = Conv2D(64, (3, 3), activation='relu', padding='same') (batch1) batch1 = BatchNormalization(axis=1)(conv1) pool1 = MaxPooling2D((2, 2)) (batch1)

conv2 = Conv2D(128, (3, 3), activation='relu', padding='same') (pool1)
batch2 = BatchNormalization(axis=1)(conv2)
conv2 = Conv2D(128, (3, 3), activation='relu', padding='same') (batch2)
batch2 = BatchNormalization(axis=1)(conv2)
pool2 = MaxPooling2D((2, 2)) (batch2)

conv3 = Conv2D(256, (3, 3), activation='relu', padding='same') (pool2)
batch3 = BatchNormalization(axis=1)(conv3)
conv3 = Conv2D(256, (3, 3), activation='relu', padding='same') (batch3)
batch3 = BatchNormalization(axis=1)(conv3)
pool3 = MaxPooling2D((2, 2)) (batch3)

conv4 = Conv2D(512, (3, 3), activation='relu', padding='same') (pool3)
batch4 = BatchNormalization(axis=1)(conv4)
conv4 = Conv2D(512, (3, 3), activation='relu', padding='same') (batch4)
batch4 = BatchNormalization(axis=1)(conv4)
pool4 = MaxPooling2D(pool_size=(2, 2)) (batch4)

conv5 = Conv2D(1024, (3, 3), activation='relu', padding='same') (pool4)
batch5 = BatchNormalization(axis=1)(conv5)
conv5 = Conv2D(1024, (3, 3), activation='relu', padding='same') (batch5)
batch5 = BatchNormalization(axis=1)(conv5)

up6 = Conv2DTranspose(512, (2, 2), strides=(2, 2), padding='same') (batch5)
up6 = concatenate([up6, conv4], axis=1)
conv6 = Conv2D(512, (3, 3), activation='relu', padding='same') (up6)
batch6 = BatchNormalization(axis=1)(conv6)
conv6 = Conv2D(512, (3, 3), activation='relu', padding='same') (batch6)
batch6 = BatchNormalization(axis=1)(conv6)

up7 = Conv2DTranspose(256, (2, 2), strides=(2, 2), padding='same') (batch6)
up7 = concatenate([up7, conv3], axis=1)
conv7 = Conv2D(256, (3, 3), activation='relu', padding='same') (up7)
batch7 = BatchNormalization(axis=1)(conv7)
conv7 = Conv2D(256, (3, 3), activation='relu', padding='same') (batch7)
batch7 = BatchNormalization(axis=1)(conv7)

up8 = Conv2DTranspose(128, (2, 2), strides=(2, 2), padding='same') (batch7)
up8 = concatenate([up8, conv2], axis=1)
conv8 = Conv2D(128, (3, 3), activation='relu', padding='same') (up8)
batch8 = BatchNormalization(axis=1)(conv8)
conv8 = Conv2D(128, (3, 3), activation='relu', padding='same') (batch8)
batch8 = BatchNormalization(axis=1)(conv8)

up9 = Conv2DTranspose(64, (2, 2), strides=(2, 2), padding='same') (batch8)
up9 = concatenate([up9, conv1], axis=1)
conv9 = Conv2D(64, (3, 3), activation='relu', padding='same') (up9)
batch9 = BatchNormalization(axis=1)(conv9)
conv9 = Conv2D(64, (3, 3), activation='relu', padding='same') (batch9)
batch9 = BatchNormalization(axis=1)(conv9)

conv10 = Conv2D(1, (1, 1), activation='sigmoid')(batch9)

model = Model(inputs=[inputs], outputs=[conv10])

model.compile(optimizer=Adam(lr=LR), loss=dice_coef_loss, metrics=[dice_coef])

return model
motahareaghalari commented 5 years ago

Thank you i change image_size=240 and change create_data('/E:/brats2015/BRATS2015_Training/HGG/', '/Flair.mha', label=False, resize=(155,img_size,img_size)) create_data('/E:/brats2015/BRATS2015_Training/HGG/', '/OT.mha', label=True, resize=(155,img_size,img_size))

%%

load numpy array data

x = np.load('E:/tamrinspython/x{}.npy'.format(img_size)) y = np.load('E:/tamrinspython/y{}.npy'.format(img_size))

%%

training

num = 31100

model = unet_model() history = model.fit(x, y, batch_size=16, validation_split=0.2 ,nb_epoch= num_epoch, verbose=1, shuffle=True) but i have another error:

ValueError: Error when checking input: expected input_8 to have 4 dimensions, but got array with shape (0, 1)

ninjakx commented 5 years ago

Take input size in the power of 2( 2^x where x is +ve integer) take input size as 128.

ValueError: "concat" mode can only merge layers with matching output shapes except for the concat axis. Layer shapes: [(None, 512, 14, 14), (None, 256, 15, 15)]

can be solved by downgrading the keras version to 2.0.5 #22 Or by using from keras.layers import concatenate concatenate([up6, conv4], axis=1)