【发布时间】:2021-07-11 10:23:31
【问题描述】:
我正在尝试实施用于 MRI 扫描诊断的机器学习模型。 我有形状 (x, 256, 256, 3) 的输入,其中我们有 3 个颜色通道,其中 x 是序列中的切片数。 我阅读了MRNet 论文,我想在 TensorFlow Keras 中实现类似的架构。我不想使用 AlexNet 特征提取器,而是使用 VGG16。
论文中的模型架构:
我们的预测系统的主要构建块是 MRNet,一个卷积 神经网络 (CNN) 将 3 维 MRI 系列映射到概率 [15](图 2)。这 MRNet 的输入尺寸为 s × 3 × 256 × 256,其中 s 是 MRI 中的图像数量 系列(3 是颜色通道的数量)。首先,每个二维 MRI 图像切片 通过基于 AlexNet 的特征提取器获得一个 s × 256 × 7 × 7 的张量,其中包含每个切片的特征。然后应用全局平均池化层将这些特征减少到 s × 256。然后我们在切片之间应用最大池化以获得 256 维 向量,它被传递给一个全连接层和 sigmoid 激活函数 获得 0 到 1 范围内的预测。
到目前为止一切顺利。我有一个顺序模型,第一步添加了特征提取器,然后应用 GlobalAveragePooling2D() 将特征简化为形状(x,512)。然后我必须跨切片使用 MaxPool,但我没有办法解决这个问题。
feature_extractor = VGG16(weights='imagenet', include_top=False, input_shape=(256, 256, 3))
model = Sequential()
model.add(feature_extractor) #output shape: (x, 8, 8, 512)
model.add(GlobalAveragePooling2D()) #output shape: (x, 512)
# Here i have to add a Layer witch Pools over the slices.
model.add( ) #output shape(1, 512)
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
示例 Scan 的形状为 (44, 256, 256, 3)。当它通过 VGG16 时,其特征的维度为 (44, 8, 8, 512)。在 GlobalAverage Pooling 之后,我得到了 (44, 512)。然后,这个二维数组必须以某种方式转换为 (1, 512) 的形状。我的意思是,如果我在一个简单的二维 NumPy 数组上进行操作,我需要一个像 np.max 这样的函数在 0 轴上
np.max(x, axis=0)
也许您可以给我一个提示或为此提供一种方法。 非常感谢您的帮助:)
############################################## ################################# 编辑:01.05.2021
我玩弄了你的方法@Aaron Keesing,但拟合模型并不能以某种方式训练它。在 25 个 epochs 之后,我仍然具有相同的精度。准确率是我的 2 个班级的分布(我只是在冠状平面上训练并且异常)
在这种情况下,例如我有 500 个病例,80% 的病例确实有异常,而 20% 没有。
# Dataset train, overall 500 cases
Absolute:
abnormal acl meniscus
1 0 0 184
1 118
0 0 0 100
1 1 1 63
0 35
dtype: int64
Relative:
abnormal acl meniscus
1 0 0 0.368
1 0.236
0 0 0 0.200
1 1 1 0.126
0 0.070
###########################################################
# Dataset valid, overall 100 cases
Absolute:
abnormal acl meniscus
1 1 1 27
0 0 0 25
1 1 0 23
0 0 20
1 5
dtype: int64
Relative:
abnormal acl meniscus
1 1 1 0.27
0 0 0 0.25
1 1 0 0.23
0 0 0.20
1 0.05
【问题讨论】:
标签: python tensorflow machine-learning keras