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?
Asked
Active
Viewed 1,068 times
1 Answers
1
If you wish to use TensorFlow, you might consider the folowing steps:
- Load your dataset using tf.data
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)
- Train your model:
3D_model.compile(..) 3D_model.fit( train_dataset, validation_data=validation_dataset, epochs=epochs, shuffle=True)
You can also refer to this example

Mohamed Berrimi
- 130
- 10
-
Got it. Could you tell me how to feed Nifti files from folders in case of multi-label classification? Maybe I've missed it, but I've never seen feeding images from a hard drive in case of multi-label classification. – Ornob Rahman Mar 20 '22 at 12:45
-
1You didn't give description about your labels. After loading your scans, make sure to load your labels in a way that matches the images. The data in the end should be similar to: scan_1.nifti — label 1 — label 2 – Mohamed Berrimi Mar 21 '22 at 13:11