ZFTurbo / classification_models_3D

Set of models for classifcation of 3D volumes
MIT License
155 stars 29 forks source link

Input-shape #21

Open doaaobeidat opened 10 months ago

doaaobeidat commented 10 months ago

Hi, If I want to use CT scans , so the width is 128, length 128 and the depth for example 96, how can I use Resnet

ZFTurbo commented 10 months ago

Like this:

from classification_models_3D.tfkeras import Classifiers

ResNet18, preprocess_input = Classifiers.get('resnet18')
model = ResNet18(input_shape=(128, 128, 96, 1), weights='imagenet')
doaaobeidat commented 10 months ago

When I made what you have mentioned it gives me error about unequal axis, how can I can use these models if I want to use input_shape=(128, 128, 96, 1) and input_shape=(128, 128, 96, 3)

ZFTurbo commented 10 months ago

I need more details about your error.

doaaobeidat commented 10 months ago

From what I gather from your explanation, it seems that I can utilize your pretrained models, which have already undergone the conversion of image weights from 2D to 3D. Therefore, my implementation would look something like this: from keras_applications import Classifiers from tensorflow.keras.layers import GlobalAveragePooling3D, Dense, Dropout from tensorflow.keras.models import Model

Retrieve the DenseNet121 model and its associated preprocessing function

densenet121, preprocess_input = Classifiers.get('densenet121')

Create my model architecture based on the pretrained DenseNet121

model = densenet121(input_shape=(96, 96, 96, 1), weights=None, include_top=False) x = GlobalAveragePooling3D()(model.output) x = Dense(units=256, activation="relu")(x) x = Dropout(0.7)(x) outputs = Dense(units=1, activation="sigmoid")(x)

Assemble the final model

model = Model(model.input, outputs=outputs, name="densenet121")

code error input
ZFTurbo commented 10 months ago

To use imagenet weights you need to use shape which has 3 channels: "(96, 96, 96, 3)", it's actually not to much complicate model - only 1st layer changed. You can duplicate input 3 times with x = np.stack([x, x, x], axis=-1)