如何在 3d CNN 中输入 Nifti 图像进行分类?
How to feed Nifti Images in 3d CNN for classification?
我有 142 张 Nifti 大脑 CT 图像,我从 Dicom 转换而来。每个 NIfti 文件的尺寸为 512×512×40。我的计划是使用 3d Conv Neural Network 进行 multi-class classification。我应该如何在 3d CNN 中输入 Nifti 图像?
如果您想使用 TensorFlow,您可以考虑以下步骤:
- 使用 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))
应用您的预处理步骤
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)
)
构建您的 3D CNN 模型:
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)
你也可以参考这个example
我有 142 张 Nifti 大脑 CT 图像,我从 Dicom 转换而来。每个 NIfti 文件的尺寸为 512×512×40。我的计划是使用 3d Conv Neural Network 进行 multi-class classification。我应该如何在 3d CNN 中输入 Nifti 图像?
如果您想使用 TensorFlow,您可以考虑以下步骤:
- 使用 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))
应用您的预处理步骤
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) )
构建您的 3D CNN 模型:
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)
你也可以参考这个example