Brain-tumor-segmentation icon indicating copy to clipboard operation
Brain-tumor-segmentation copied to clipboard

TypeError: can only concatenate list (not "int") to list

Open chengjianhong opened this issue 6 years ago • 5 comments

Hi, I found the TypeError while run train.py. the detail is as follows:

Traceback (most recent call last): File "train.py", line 108, in brain_seg = Training(batch_size=4,nb_epoch=3,load_model_resume_training=model_to_load) File "train.py", line 42, in init unet =Unet_model(img_shape=(128,128,4)) File "/root/userfolder/workspace/Brain-tumor-segmentation/model.py", line 21, in init self.model =self.compile_unet() File "/root/userfolder/workspace/Brain-tumor-segmentation/model.py", line 37, in compile_unet model.compile(loss=gen_dice_loss, optimizer=sgd, metrics=[dice_whole_metric,dice_core_metric,dice_en_metric]) File "/usr/local/lib/python3.5/dist-packages/keras/engine/training.py", line 451, in compile handle_metrics(output_metrics) File "/usr/local/lib/python3.5/dist-packages/keras/engine/training.py", line 420, in handle_metrics mask=masks[i]) File "/usr/local/lib/python3.5/dist-packages/keras/engine/training_utils.py", line 404, in weighted score_array = fn(y_true, y_pred) File "/root/userfolder/workspace/Brain-tumor-segmentation/losses.py", line 47, in dice_core_metric y_core=K.sum(y_true_f[:,[1,3]],axis=1) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/array_ops.py", line 490, in _slice_helper end.append(s + 1) TypeError: can only concatenate list (not "int") to list

chengjianhong avatar Dec 12 '18 15:12 chengjianhong

I have the same error

shaktichetan avatar Jan 16 '19 05:01 shaktichetan

hello I have also the same error !!!

takrouni avatar Feb 06 '19 15:02 takrouni

Anyone solved it?

muween avatar Apr 30 '19 07:04 muween

I solved this by using

 y_core=K.sum(tf.gather(y_true_f, [1,3],axis =1),axis=1)
 p_core=K.sum(tf.gather(y_pred_f, [1,3],axis =1),axis=1)

instead of

y_core=K.sum(y_true_f[:,[1,3]],axis=1)
p_core=K.sum(y_pred_f[:,[1,3]],axis=1)

in losses.py

muween avatar Apr 30 '19 08:04 muween

I solved this by using

 y_core=K.sum(tf.gather(y_true_f, [1,3],axis =1),axis=1)
 p_core=K.sum(tf.gather(y_pred_f, [1,3],axis =1),axis=1)

instead of

y_core=K.sum(y_true_f[:,[1,3]],axis=1)
p_core=K.sum(y_pred_f[:,[1,3]],axis=1)

in losses.py

I'm still get the error, with Keras 2.1.5 what version you are using?

gusleo avatar Sep 30 '19 17:09 gusleo