I have 142 Nifti CT images of the brain, I converted them from Dicom. Every NIfti file has the dimension of 512×512×40. My plan is to work with 3d Conv Neural Network for multi-class classification. How should I feed Nifti images in a 3d CNN?
If you wish to use TensorFlow, you might consider the folowing steps:
train_loader = tf.data.Dataset.from_tensor_slices((x_train, y_train)) validation_loader = tf.data.Dataset.from_tensor_slices((x_val, y_val))
Apply your preprocessing steps
train_dataset = (
train_loader.shuffle(len(x_train))
.map(train_preprocessing)
.batch(1)
.prefetch(2))
validation_dataset = (
validation_loader.shuffle(len(x_val))
.map(validation_preprocessing)
.batch(1)
.prefetch(2)
)
Build your 3D CNN model:
def 3D_model(width= 512, height= 512, depth=40):
inputs = keras.Input((width, height, depth, 1))
x = layers.Conv3D(filters=84, kernel_size=3, activation="relu")(inputs)
x = layers.MaxPool3D(pool_size=2,padding="same")(x)
x = layers.BatchNormalization()(x)
x = layers.Conv3D(filters=64, kernel_size=3, activation="relu")(x)
x = layers.MaxPool3D(pool_size=2,padding="same")(x)
x = layers.BatchNormalization()(x)
outputs = layers.Dense(units=n_classes, activation="softmax")(x)
model = keras.Model(inputs, outputs)
return model
model = get_model(width=512, height=512, depth=40)
3D_model.compile(..) 3D_model.fit( train_dataset, validation_data=validation_dataset, epochs=epochs, shuffle=True)
You can also refer to this example