Skip to content

Commit 9a0901d

Browse files
committed
update files
1 parent e51ad35 commit 9a0901d

File tree

20 files changed

+228
-40
lines changed

20 files changed

+228
-40
lines changed

examples/JSRT/config/train_test.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[dataset]
22

3-
root_dir = data/JSRT
3+
root_dir = /home/disk2t/data/JSRT
44
train_csv = config/jsrt_train.csv
55
valid_csv = config/jsrt_valid.csv
66
test_csv = config/jsrt_test.csv
@@ -45,6 +45,7 @@ in_chns = 1
4545
feature_chns = [4, 16, 32, 64, 128]
4646
acti_func = leakyrelu
4747
leakyrelu_negative_slope = 0.01
48+
dropout = 0.2
4849

4950
[training]
5051
# device name" cuda:n or cpu

examples/fetal_hc/config/train_test.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[dataset]
22

3-
root_dir = data/Fetal_HC
3+
root_dir = /home/disk2t/data/Fetal_HC
44
train_csv = config/fetal_hc_train_train.csv
55
valid_csv = config/fetal_hc_train_valid.csv
66
test_csv = config/fetal_hc_train_test.csv
@@ -53,6 +53,7 @@ in_chns = 1
5353
feature_chns = [4, 16, 32, 64, 128]
5454
acti_func = leakyrelu
5555
leakyrelu_negative_slope = 0.01
56+
dropout = 0.2
5657

5758
[training]
5859
# device name" cuda:n or cpu

examples/prostate/config/train_test.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[dataset]
22

3-
root_dir = data/promise12/preprocess
3+
root_dir = /home/disk2t/data/prostate/promise12/preprocess/train
44
train_csv = config/data/image_train.csv
55
valid_csv = config/data/image_valid.csv
66
test_csv = config/data/image_test.csv
@@ -50,7 +50,7 @@ in_chns = 1
5050
feature_chns = [16, 24, 32, 48]
5151
acti_func = leakyrelu
5252
leakyrelu_negative_slope = 0.1
53-
dropout = True
53+
dropout = 0.2
5454

5555
[training]
5656
# device name cuda:n or cpu

pymic/__init__.py

Whitespace-only changes.

pymic/io/__init__.py

Whitespace-only changes.

pymic/io/transform3d.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from scipy import ndimage
1111
from pymic.util.image_process import *
12+
import matplotlib.pyplot as plt
1213

1314
class Rescale(object):
1415
"""Rescale the image in a sample to a given size.
@@ -386,7 +387,11 @@ def __call__(self, sample):
386387
mask = np.zeros_like(label)
387388
for temp_lab in self.mask_label:
388389
mask = np.maximum(mask, label == temp_lab)
389-
bb_min, bb_max = get_ND_bounding_box(mask)
390+
if(mask.sum() == 0):
391+
bb_min = [0] * (input_dim + 1)
392+
bb_max = mask.shape
393+
else:
394+
bb_min, bb_max = get_ND_bounding_box(mask)
390395
bb_min, bb_max = bb_min[1:], bb_max[1:]
391396
crop_min = [random.randint(bb_min[i], bb_max[i]) - int(self.output_size[i]/2) \
392397
for i in range(input_dim)]

pymic/layer/__init__.py

Whitespace-only changes.

pymic/layer/activation.py

100644100755
File mode changed.

pymic/layer/convolution.py

100644100755
Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,91 @@
77
class ConvolutionLayer(nn.Module):
88
"""
99
A compose layer with the following components:
10-
convolution -> (batch_norm) -> activation -> (dropout)
10+
convolution -> (batch_norm / layer_norm / group_norm / instance_norm) -> activation -> (dropout)
1111
batch norm and dropout are optional
1212
"""
1313
def __init__(self, in_channels, out_channels, kernel_size, dim = 3,
14-
stride = 1, padding = 0, dilation =1, groups = 1, bias = True,
15-
batch_norm = True, acti_func = None):
14+
stride = 1, padding = 0, dilation = 1, conv_group = 1, bias = True,
15+
norm_type = 'batch_norm', norm_group = 1, acti_func = None):
1616
super(ConvolutionLayer, self).__init__()
1717
self.n_in_chns = in_channels
1818
self.n_out_chns = out_channels
19-
self.batch_norm = batch_norm
19+
self.norm_type = norm_type
20+
self.norm_group = norm_group
2021
self.acti_func = acti_func
2122

2223
assert(dim == 2 or dim == 3)
2324
if(dim == 2):
2425
self.conv = nn.Conv2d(in_channels, out_channels,
25-
kernel_size, stride, padding, dilation, groups, bias)
26-
if(self.batch_norm):
26+
kernel_size, stride, padding, dilation, conv_group, bias)
27+
if(self.norm_type == 'batch_norm'):
2728
self.bn = nn.modules.BatchNorm2d(out_channels)
29+
elif(self.norm_type == 'group_norm'):
30+
self.bn = nn.GroupNorm(self.norm_group, out_channels)
31+
else:
32+
raise ValueError("unsupported normalization method {0:}".format(norm_type))
2833
else:
2934
self.conv = nn.Conv3d(in_channels, out_channels,
30-
kernel_size, stride, padding, dilation, groups, bias)
31-
if(self.batch_norm):
35+
kernel_size, stride, padding, dilation, conv_group, bias)
36+
if(self.norm_type == 'batch_norm'):
3237
self.bn = nn.modules.BatchNorm3d(out_channels)
38+
elif(self.norm_type == 'group_norm'):
39+
self.bn = nn.GroupNorm(self.norm_group, out_channels)
40+
else:
41+
raise ValueError("unsupported normalization method {0:}".format(norm_type))
3342

3443
def forward(self, x):
3544
f = self.conv(x)
36-
if(self.batch_norm):
45+
if(self.norm_type is not None):
46+
f = self.bn(f)
47+
if(self.acti_func is not None):
48+
f = self.acti_func(f)
49+
return f
50+
51+
class DepthSeperableConvolutionLayer(nn.Module):
52+
"""
53+
A compose layer with the following components:
54+
convolution -> (batch_norm) -> activation -> (dropout)
55+
batch norm and dropout are optional
56+
"""
57+
def __init__(self, in_channels, out_channels, kernel_size, dim = 3,
58+
stride = 1, padding = 0, dilation =1, conv_group = 1, bias = True,
59+
norm_type = 'batch_norm', norm_group = 1, acti_func = None):
60+
super(DepthSeperableConvolutionLayer, self).__init__()
61+
self.n_in_chns = in_channels
62+
self.n_out_chns = out_channels
63+
self.norm_type = norm_type
64+
self.norm_group = norm_group
65+
self.acti_func = acti_func
66+
67+
assert(dim == 2 or dim == 3)
68+
if(dim == 2):
69+
self.conv = nn.Conv2d(in_channels, in_channels,
70+
kernel_size, stride, padding, dilation, groups = in_channels, bias = bias)
71+
self.conv1x1 = nn.Conv2d(in_channels, out_channels,
72+
kernel_size = 1, stride = stride, padding = 0, dilation = dilation, groups = conv_group, bias = bias)
73+
if(self.norm_type == 'batch_norm'):
74+
self.bn = nn.modules.BatchNorm2d(out_channels)
75+
elif(self.norm_type == 'group_norm'):
76+
self.bn = nn.GroupNorm(self.norm_group, out_channels)
77+
else:
78+
raise ValueError("unsupported normalization method {0:}".format(norm_type))
79+
else:
80+
self.conv = nn.Conv3d(in_channels, in_channels,
81+
kernel_size, stride, padding, dilation, groups = in_channels, bias = bias)
82+
self.conv1x1 = nn.Conv3d(in_channels, out_channels,
83+
kernel_size = 1, stride = 0, padding = 0, dilation = 0, groups = conv_group, bias = bias)
84+
if(self.norm_type == 'batch_norm'):
85+
self.bn = nn.modules.BatchNorm3d(out_channels)
86+
elif(self.norm_type == 'group_norm'):
87+
self.bn = nn.GroupNorm(self.norm_group, out_channels)
88+
else:
89+
raise ValueError("unsupported normalization method {0:}".format(norm_type))
90+
91+
def forward(self, x):
92+
f = self.conv(x)
93+
f = self.conv1x1(f)
94+
if(self.norm_type is not None):
3795
f = self.bn(f)
3896
if(self.acti_func is not None):
3997
f = self.acti_func(f)

pymic/layer/deconvolution.py

100644100755
File mode changed.

0 commit comments

Comments
 (0)