CNN每层卷积结果视觉展示(3Dircadb肝脏数据为例)

本文最后更新于:2023年4月7日 下午

试着展示了肝脏每层卷积之后的结果。代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import torch
import torch.nn as nn
import SimpleITK as sitk
import numpy as np

def change_indenty(ct):
ct[ct < 40] = 40
ct[ct > 400] = 400
return ct

class Dialte(nn.Module):
def __init__(self, num):
super(Dialte, self).__init__()
self.num= num
self.act = nn.ReLU(inplace=False)
self.norm = nn.BatchNorm3d
self.conv1 = nn.Sequential(
nn.Conv3d(1,1, kernel_size=3, stride=1, padding=1),
self.act,
self.norm(1)
)

def forward(self, x):
for i in range(self.num):
x = self.conv1(x)
return x

if __name__ == "__main__":
path = r"D:\myProject\HDC_vessel_seg\datasets\nii\image_2.nii"
image = sitk.ReadImage(path)
img_num = sitk.GetArrayFromImage(image)
img_num = change_indenty(img_num)
img_num = np.expand_dims(np.expand_dims(img_num, axis=0), axis=0).astype(np.float32)
img_num = torch.from_numpy(img_num)
print(img_num.shape)

# image = torch.randn(1*3*8*8*8).reshape(1,3,8,8,8)
model = Dialte(num=5)
x = model(img_num)
# x = img_num # 展示原始图像
x = x[0,0,...]
x = x.cpu().data.numpy()
print("x",x.shape)
predict_seg = sitk.GetImageFromArray(x)
predict_seg.SetSpacing(image.GetSpacing())
predict_seg.SetOrigin(image.GetOrigin())
predict_seg.SetDirection(image.GetDirection())
# sitk.WriteImage(predict_seg, path.replace("vessel", "dialte"))
sitk.WriteImage(predict_seg, path.replace("image", "pre_image"))

  结果:

原始

 

第一层:

 

第二层:

 

第三层:

 

第四层:

 

第五层:

 


打赏支持
“如果你觉得我的文章不错,不妨鼓励我继续写作。”

CNN每层卷积结果视觉展示(3Dircadb肝脏数据为例)
https://dreamoneyou.github.io/2022/CNN每层卷积结果视觉展示(3Dircadb肝脏数据为例)/
作者
九叶草
发布于
2022年5月16日
更新于
2023年4月7日
许可协议