Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input dimension #14

Open
sepidhk opened this issue Jun 7, 2022 · 17 comments
Open

input dimension #14

sepidhk opened this issue Jun 7, 2022 · 17 comments

Comments

@sepidhk
Copy link

sepidhk commented Jun 7, 2022

my input data has the shape of (118, 224, 224, 35), 118 3D nii images, width: 224, height: 224 and depth (#of slices) 35. My question is what would be the correct order of input shape? is the order of (#images, width, height, #slices) correct? Some examples use the shape of (#images, width, height, #slices, 1). Should I set the last dimension to 1 as channel dimension?

@ZFTurbo
Copy link
Owner

ZFTurbo commented Jun 7, 2022

Shape must be (#images, width, height, #slices, 1). Last 1 is needed.

@sepidhk
Copy link
Author

sepidhk commented Jun 7, 2022

I have followed the recommended input shape and getting error of ValueError: axes don't match array or ValueError: Input 0 of layer "model_3" is incompatible with the layer: expected shape=(None, 96, 224, 224, 35), found shape=(1, 224, 224, 35, 1).

@ZFTurbo
Copy link
Owner

ZFTurbo commented Jun 7, 2022

You put input shape:
input_shape=(96, 224, 224, 35)

Do you have 35 channels?

If you have 1 channel use:

input_shape=(224, 224, 35, 1)

@sepidhk
Copy link
Author

sepidhk commented Jun 7, 2022

Yes, that was my thought, then I got this error: ValueError: Input 0 of layer "zero_padding3d" is incompatible with the layer: expected ndim=5, found ndim=6. Full shape received: (None, 96, 224, 224, 35, 1)

@ZFTurbo
Copy link
Owner

ZFTurbo commented Jun 7, 2022

Shape must be: (width, height, depth, channels). What is 96?

@sepidhk
Copy link
Author

sepidhk commented Jun 7, 2022

96 is the number of images.

@ZFTurbo
Copy link
Owner

ZFTurbo commented Jun 7, 2022

You don't need to specify it. None is used for this. It means it can be any for model

@sepidhk
Copy link
Author

sepidhk commented Jun 7, 2022

Thanks for the reply. Now with Linknet and densenet121 I have this error: ValueError: Inputs have incompatible shapes. Received shapes (56, 56, 8, 128) and (56, 56, 9, 128) and with UNet and densenet121 , I have the following error: ValueError: A Concatenate layer requires inputs with matching shapes except for the concatenation axis. Received: input_shape=[(None, 56, 56, 8, 128), (None, 56, 56, 9, 128)] - Is this because of the depth (#slices) not divisable by 32?

@ZFTurbo
Copy link
Owner

ZFTurbo commented Jun 7, 2022

Yes. Each dimension must be divisible on 32. I think I should add warning message for this case.

@ZFTurbo
Copy link
Owner

ZFTurbo commented Jun 7, 2022

I need to think how to make it work for any value of dimensions.

@Ek-Ram
Copy link

Ek-Ram commented Nov 1, 2023

Hi,
I got the error : ValueError: axes don't match array. My input shape is (128,128,128, 4).
model = sm.Unet(
'resnet50',
input_shape=(128, 128, 128, 4),
encoder_weights='imagenet',
classes=3,
activation='softmax'
)
is there any solution ?

@ZFTurbo
Copy link
Owner

ZFTurbo commented Nov 1, 2023

Can you provide exact error message?

@Ek-Ram
Copy link

Ek-Ram commented Nov 1, 2023

Yes,
Downloading data from https://github.com/ZFTurbo/classification_models_3D/releases/download/v1.0.4/resnet50_inp_channel_3_tch_0_top_False.h5
185458688/185458584 [==============================] - 3s 0us/step
185466880/185458584 [==============================] - 3s 0us/step

ValueError Traceback (most recent call last)
in <cell line: 2>()
1 #Fit the model
----> 2 model = sm.Unet(
3 'resnet50',
4 input_shape=(128, 128, 128, 4),
5 encoder_weights='imagenet',

10 frames
/usr/local/lib/python3.10/dist-packages/segmentation_models_3D/init.py in wrapper(*args, **kwargs)
32 kwargs['models'] = _KERAS_MODELS
33 kwargs['utils'] = _KERAS_UTILS
---> 34 return func(*args, **kwargs)
35
36 return wrapper

/usr/local/lib/python3.10/dist-packages/segmentation_models_3D/models/unet.py in Unet(backbone_name, input_shape, classes, activation, weights, encoder_weights, encoder_freeze, encoder_features, decoder_block_type, decoder_filters, decoder_use_batchnorm, dropout, **kwargs)
224 'Got: {}'.format(decoder_block_type))
225
--> 226 backbone = Backbones.get_backbone(
227 backbone_name,
228 input_shape=input_shape,

/usr/local/lib/python3.10/dist-packages/segmentation_models_3D/backbones/backbones_factory.py in get_backbone(self, name, *args, **kwargs)
100 def get_backbone(self, name, *args, **kwargs):
101 model_fn, _ = self.get(name)
--> 102 model = model_fn(*args, **kwargs)
103 return model
104

/usr/local/lib/python3.10/dist-packages/classification_models_3D/models_factory.py in wrapper(*args, **kwargs)
101 modules_kwargs = self.get_kwargs()
102 new_kwargs = dict(list(kwargs.items()) + list(modules_kwargs.items()))
--> 103 return func(*args, **new_kwargs)
104
105 return wrapper

/usr/local/lib/python3.10/dist-packages/classification_models_3D/models/resnet.py in ResNet50(input_shape, input_tensor, weights, classes, stride_size, init_filters, include_top, repetitions, **kwargs)
420 **kwargs
421 ):
--> 422 return ResNet(
423 MODELS_PARAMS['resnet50'],
424 input_shape=input_shape,

/usr/local/lib/python3.10/dist-packages/classification_models_3D/models/resnet.py in ResNet(model_params, input_shape, input_tensor, include_top, pooling, classes, stride_size, init_filters, weights, repetitions, **kwargs)
338 model.load_weights(weights)
339 else:
--> 340 load_model_weights(model, model_params.model_name,
341 weights, classes, include_top, **kwargs)
342

/usr/local/lib/python3.10/dist-packages/classification_models_3D/weights.py in load_model_weights(model, model_name, dataset, classes, include_top, **kwargs)
30 )
31
---> 32 model.load_weights(weights_path)
33
34 else:

/usr/local/lib/python3.10/dist-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.traceback)
---> 67 raise e.with_traceback(filtered_tb) from None
68 finally:
69 del filtered_tb

/usr/local/lib/python3.10/dist-packages/numpy/core/overrides.py in transpose(*args, **kwargs)

/usr/local/lib/python3.10/dist-packages/numpy/core/fromnumeric.py in transpose(a, axes)
658
659 """
--> 660 return _wrapfunc(a, 'transpose', axes)
661
662

/usr/local/lib/python3.10/dist-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
55
56 try:
---> 57 return bound(*args, **kwds)
58 except TypeError:
59 # A TypeError occurs if the object does have such a method in its

ValueError: axes don't match array

@ZFTurbo
Copy link
Owner

ZFTurbo commented Nov 1, 2023

Try encoder_weights=None

@Ek-Ram
Copy link

Ek-Ram commented Nov 1, 2023

I tried encoder_weights=None, and it works.
but it initializes weight randomly. I prefer to use 'imagenet' weights.
is there any solution?

@ZFTurbo
Copy link
Owner

ZFTurbo commented Nov 1, 2023

Try to do this:

pip install classification-models-3D==1.0.6

@Ek-Ram
Copy link

Ek-Ram commented Nov 1, 2023

Try to do this:

pip install classification-models-3D==1.0.6

Unfortunately same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants