def sample_outer_surface(volume, shape): # surface = F.max_pool3d(volume[None, None].float(), kernel_size=3, stride=1, padding=1)[0, 0] - volume.float() # outer surface # surface = F.max_pool3d(-volume[None, None].float(), kernel_size=3, stride=1, padding=1)[0, 0] + volume.float() # inner surface # inner surface # a = F.max_pool3d(-volume[None,None].float(), kernel_size=(3,1,1), stride=1, padding=(1, 0, 0))[0] # b = F.max_pool3d(-volume[None,None].float(), kernel_size=(1,3, 1), stride=1, padding=(0, 1, 0))[0] # c = F.max_pool3d(-volume[None,None].float(), kernel_size=(1,1,3), stride=1, padding=(0, 0, 1))[0] # border, _ = torch.max(torch.cat([a,b,c],dim=0),dim=0) # surface = border + volume.float() # outer surface a = F.max_pool3d(volume[None, None].float(), kernel_size=(3, 1, 1), stride=1, padding=(1, 0, 0))[0] b = F.max_pool3d(volume[None, None].float(), kernel_size=(1, 3, 1), stride=1, padding=(0, 1, 0))[0] c = F.max_pool3d(volume[None, None].float(), kernel_size=(1, 1, 3), stride=1, padding=(0, 0, 1))[0] border, _ = torch.max(torch.cat([a, b, c], dim=0), dim=0) surface = border - volume.float() surface_points = torch.nonzero(surface) surface_points = torch.flip(surface_points, dims=[1]).float() # convert z,y,x -> x, y, z surface_points = normalize_vertices(surface_points, shape) return surface_points
def forward(self, x): x = F.relu(self.bn11(self.conv11(x))) x = F.relu(self.bn12(self.conv12(x))) size1 = x.size() x, ind1 = F.max_pool3d(x, kernel_size=2, stride=2, return_indices=True) # x,ind1 = self.pool1(F.relu(self.bn12(self.conv12(x)))) x = F.relu(self.bn21(self.conv21(x))) x = F.relu(self.bn22(self.conv22(x))) size2 = x.size() x, ind2 = F.max_pool3d(x, kernel_size=2, stride=2, return_indices=True) # x,ind2 = self.pool2(F.relu(self.bn22(self.conv22(x)))) x = F.relu(self.bn31(self.conv31(x))) x = F.relu(self.bn32(self.conv32(x))) x = F.max_unpool3d(x, ind2, kernel_size=2, stride=2, output_size=size2) # x = F.relu(self.bn41(self.conv41(self.unpool2(x,ind2)))) x = F.relu(self.bn41(self.conv41(x))) x = F.relu(self.bn42(self.conv42(x))) x = F.max_unpool3d(x, ind1, kernel_size=2, stride=2, output_size=size1) # x = F.relu(self.bn51(self.conv51(self.unpool1(x,ind1)))) x = F.relu(self.bn51(self.conv51(x))) x = F.tanh(self.bn52(self.conv52(x))) return x
def forward(self, x): # x shape (N, 1, 256, 256, 150) x = F.max_pool3d(F.relu(self.conv1(x)), 2) # x shape (4, 125, 125, 72) <-- (4, 250, 250, 144) x = F.max_pool3d(F.relu(self.conv2(x)), 2) # x shape (8, 60, 60, 34) <-- (8, 121, 121, 68) x = F.max_pool3d(F.relu(self.conv3(x)), 2) # x shape (16, 29, 29, 16) <-- (16, 58, 58, 32) x = F.max_pool3d(F.relu(self.conv4(x)), 2) # x shape (32, 13, 13, 7) <-- (32, 27, 27, 14) x = F.max_pool3d(F.relu(self.conv5(x)), 2) # x shape (64, 5, 5, 2) <-- (64, 11, 11, 5) x = x.view(x.shape[0], -1) # x shape (3200,) x = F.relu(self.fc1(x)) # x shape (600,) x = F.relu(self.fc2(x)) # x shape (100,) x = F.relu(self.fc3(x)) # x shape (10,) x = torch.sigmoid(self.fc4(x)) # x shape (1,) return x # net = Net() # print(net) # params = list(net.parameters()) # print(len(params)) # print(params[1].size()) # conv1's .weight
def forward(self, x): x = self.conv_layer1(x) # Max pooling over a (2, 2, 2) window x = F.max_pool3d(x, (2, 2, 2)) x = self.conv_layer2(x) x = self.conv_layer3(x) categorical_branch = F.max_pool3d(x, (4, 4, 4)) categorical_branch = GradientReversalLayer.apply(categorical_branch, self.alpha) categorical_branch = self.flatten(categorical_branch) categorical_branch = self.linear1(categorical_branch) categorical_branch = torch.relu(categorical_branch) categorical_branch = self.linear2(categorical_branch) categorical_branch = torch.relu(categorical_branch) categorical_branch = self.linear3(categorical_branch) x = self.conv_layer4(x) x = self.conv_layer5(x) x = self.conv_layer6(x) x = self.conv_layer7(x) x = self.final_layer(x) x = torch.sigmoid(x) return x, categorical_branch
def forward(self, x): out = F.max_pool3d(torch.tanh(self.conv1(x)), 2) out = F.max_pool3d(torch.tanh(self.conv2(out)), 2) out = out.view(-1, self.num_flat_features(out)) out = torch.tanh(self.fc1(out)) out = self.fc2(out) return out
def forward(self, X): h = F.relu(self.conv1_1(X), inplace=True) h = F.relu(self.conv1_2(h), inplace=True) # relu1_2 = h h = F.max_pool3d(h, kernel_size=2, stride=2) h = F.relu(self.conv2_1(h), inplace=True) h = F.relu(self.conv2_2(h), inplace=True) # relu2_2 = h h = F.max_pool3d(h, kernel_size=2, stride=2) h = F.relu(self.conv3_1(h), inplace=True) h = F.relu(self.conv3_2(h), inplace=True) h = F.relu(self.conv3_3(h), inplace=True) # relu3_3 = h h = F.max_pool3d(h, kernel_size=2, stride=2) h = F.relu(self.conv4_1(h), inplace=True) h = F.relu(self.conv4_2(h), inplace=True) h = F.relu(self.conv4_3(h), inplace=True) # relu4_3 = h h = F.relu(self.conv5_1(h), inplace=True) h = F.relu(self.conv5_2(h), inplace=True) h = F.relu(self.conv5_3(h), inplace=True) relu5_3 = h return relu5_3
def forward(self, input, fin_feature=None): fms_pre = [input] for l in range(self.num_blocks): fms = [] for fmi in range(len(fms_pre)): fms.append(crop(fms_pre[fmi]).contiguous()) convkey = 'l' + str(l) + '_conv' fm = torch.cat(fms_pre, dim=1).contiguous() fm = F.conv3d(fm, self.params[convkey + '_w'], self.params[convkey + '_b'], padding=1) fm = F.max_pool3d(fm, 2, 2) fm = F.dropout(fm, p=self.drop_rate, training=self.training) fm = F.relu(fm) fms.append(fm) fms_pre = fms convkey = 'l' + str(self.num_blocks) + '_conv' fm = torch.cat(fms_pre, dim=1).contiguous() fm = F.conv3d(fm, self.params[convkey + '_w'], self.params[convkey + '_b'], padding=1) fm = F.max_pool3d(fm, 2, 2) fmfinal = F.dropout(fm, p=self.drop_rate, training=self.training) return fmfinal
def forward(self, x): x = relu(self.conv1(x)) x1 = relu(self.conv2(x)) x = max_pool3d(x1, (2, 2, 2), stride=(2, 2, 2)) x = relu(self.conv3(x)) x2 = relu(self.conv4(x)) x = max_pool3d(x2, (2, 2, 2), stride=(2, 2, 2)) x = relu(self.conv5(x)) x = relu(self.conv6(x)) x = self.up7(x) x = torch.cat((x, x2), dim=1) x = relu(self.conv8(x)) x = relu(self.conv9(x)) x = self.up10(x) x = torch.cat((x, x1), dim=1) x = relu(self.conv11(x)) x = relu(self.conv12(x)) x = self.conv13(x) if self.task == 'segmentation': x = torch.sigmoid(x) return x
def forward(self, x): # Max pooling over a (2, 2) window x = F.max_pool3d(x, stride=2, kernel_size=2) x = self.conv1(x) x = F.relu(x) x = self.bn1(x) x = F.max_pool3d(x, stride=2, kernel_size=2) x = self.conv2(x) x = F.relu(x) x = self.bn2(x) x = F.max_pool3d(x, stride=2, kernel_size=2) x = self.conv3(x) x = F.relu(x) x = self.bn3(x) # flatten x = x.view(-1, self.num_flat_features(x)) x = self.dropout(x) x = self.fc1(x) # output x = self.output(x) return x
def apply(self, X): self._send_weights_to_device(X) n_examples, *_ = X.shape output = [] if self.filters_of_constant_shape: # This is more efficient, but can't be done if filters are of different filter_shape output = F.conv2d(X, self.weights) # output.shape -> (n_examples, n_filters*n_transforms, conv_height, conv_width) if self.maxpool_shape: self._compute_maxpool_shape(output) output = F.max_pool3d(output, self.maxpool_shape, ceil_mode=True) else: for weights in self.weights: # weights.shape -> (n_transforms, n_channels, height, width) output_ = torch.unsqueeze(F.conv2d(X, weights), dim=1) # output_.shape -> (n_examples, 1, n_transforms, conv_height, conv_width) if self.maxpool_shape: self._compute_maxpool_shape(output_) output_ = F.max_pool3d(output_, self.maxpool_shape, ceil_mode=True) output.append(output_.reshape((n_examples, -1))) output = torch.cat(output, dim=1) random_features = self.activation(output) random_features = random_features.cpu().reshape((n_examples, -1)) return random_features
def forward(self, t): tm = time.time() t = self.conv1(t) t = F.relu(t) t = F.max_pool3d(t, kernel_size=2, stride=2) t = self.conv2(t) t = F.relu(t) t = F.max_pool3d(t, kernel_size=2, stride=2) t = self.resnet(t) if t.shape[0] != 1: #input is a batch all_t = torch.unbind(t) t = torch.stack( [self.tcn(torch.reshape(t0, [15, 3, 512])) for t0 in all_t]) else: t = self.tcn(torch.reshape(t, [15, 3, 512])) t = torch.unsqueeze(t, 0) t = torch.flatten(t, start_dim=1) t = self.lin1(t) t = t.reshape(-1, MAX_WORD_COUNT, VOCAB) # t = torch.reshape(t,[-1,15,45*3]) # t = self.lstm(t) return t
def sample_outer_surface_in_voxel(volume): # surface = F.max_pool3d(volume[None, None].float(), kernel_size=3, stride=1, padding=1)[0, 0] - volume.float() # outer surface # surface = F.max_pool3d(-volume[None, None].float(), kernel_size=3, stride=1, padding=1)[0, 0] + volume.float() # inner surface # inner surface # a = F.max_pool3d(-volume[None,None].float(), kernel_size=(3,1,1), stride=1, padding=(1, 0, 0))[0] # b = F.max_pool3d(-volume[None,None].float(), kernel_size=(1,3, 1), stride=1, padding=(0, 1, 0))[0] # c = F.max_pool3d(-volume[None,None].float(), kernel_size=(1,1,3), stride=1, padding=(0, 0, 1))[0] # border, _ = torch.max(torch.cat([a,b,c],dim=0),dim=0) # surface = border + volume.float() # outer surface a = F.max_pool3d(volume[None, None].float(), kernel_size=(3, 1, 1), stride=1, padding=(1, 0, 0))[0] b = F.max_pool3d(volume[None, None].float(), kernel_size=(1, 3, 1), stride=1, padding=(0, 1, 0))[0] c = F.max_pool3d(volume[None, None].float(), kernel_size=(1, 1, 3), stride=1, padding=(0, 0, 1))[0] border, _ = torch.max(torch.cat([a, b, c], dim=0), dim=0) surface = border - volume.float() return surface.long()
def forward(self, x): x = F.max_pool3d(F.relu(self.conv3d1(x)), kernel_size=(3,3,3), stride=2, padding=0) x = F.max_pool3d(F.relu(self.conv3d2(x)), kernel_size=(2,2,2), stride=2, padding=1) x = x.view(-1, self.num_flat_features(x)) # x = self.dropout(F.relu(self.fc1(x))) x = F.relu(self.fc1(x)) x = self.fc2(x) return x
def forward(self, x): x = F.relu(F.max_pool3d(self.conv1(x), 2)) x = F.relu(F.max_pool3d(self.conv2(x), 2)) x = x.view(-1, x.size(1)*x.size(2)*x.size(3)*x.size(4)) x = F.relu(self.fc1(x)) # x = F.dropout(x, training=self.training) x = self.fc2(x) return F.log_softmax(x)
def forward(self, x): N, C, D, H, W = x.shape #x_pooled = F.max_pool3d(x, kernel_size=(1,2,2), stride=(1,2,2)) # max pooling in spatial domain x_theta = self.theta(x).view(N, C/2, D*H*W) x_phi = F.max_pool3d(self.phi(x), kernel_size=(1,2,2), stride=(1,2,2)).view(N, C/2, D*H*W/4) x_g = F.max_pool3d(self.g(x), kernel_size=(1,2,2), stride=(1,2,2)).view(N, C/2, D*H*W/4) x_f = F.softmax(torch.matmul(x_phi.transpose(1,2), x_theta), dim=1) # [N, D*H*W/4, D*H*W] return self.h(torch.matmul(x_g, x_f).view(N, C/2, D, H, W)) + x
def forward(self, x): x = F.max_pool3d(F.leaky_relu((self.conv1(x))), kernel_size=4) x = F.max_pool3d(F.leaky_relu((self.conv5(x))), kernel_size=4) x = F.max_pool3d(F.leaky_relu(self.conv10((x))), kernel_size=2) x = x.view(-1, self.num_flat_features(x)) x = torch.sigmoid(self.fc13(x)) return x
def forward(self, x): x = self.conv1(x) x = self.bn1(x) x = F.relu(x, inplace = True) x = F.max_pool3d(x, kernel_size = 3, stride = 2, padding = 1) x = self.conv2(x) x = self.bn2(x) x = F.relu(x, inplace = True) x = F.max_pool3d(x, kernel_size = 3, stride = 2, padding = 1) return x
def forward(self, x): x = F.max_pool3d(F.relu(self.conv1(x)), 2) x = F.max_pool3d(F.relu(self.conv2(x)), 2) x = x.view(x.size(0), -1) x = F.relu(self.fc1(x)) x = F.relu(self.fc2(x)) x = F.relu(self.fc22(x)) x = self.fc3(x).squeeze() return x
def forward(self, x): under_x = F.relu(self.local_conv3(x)) x = self.local_conv1(x) x = F.max_pool3d(F.relu(x), (4, 4, 1), stride = 1) x = self.local_conv2(x) x = F.max_pool3d(F.relu(x), (2, 2, 1), stride = 1) x = torch.cat((x, under_x), 1) x = self.total_conv(x) x = x.view(-1,3) return x
def soft_erode(img): if len(img.shape) == 4: p1 = -F.max_pool2d(-img, (3, 1), (1, 1), (1, 0)) p2 = -F.max_pool2d(-img, (1, 3), (1, 1), (0, 1)) return torch.min(p1, p2) elif len(img.shape) == 5: p1 = -F.max_pool3d(-img, (3, 1, 1), (1, 1, 1), (1, 0, 0)) p2 = -F.max_pool3d(-img, (1, 3, 1), (1, 1, 1), (0, 1, 0)) p3 = -F.max_pool3d(-img, (1, 1, 3), (1, 1, 1), (0, 0, 1)) return torch.min(torch.min(p1, p2), p3)
def forward(self, x): mask = self.conv1(x) mask = f.relu(mask) mask = f.max_pool3d(mask, 2, stride=2) mask = self.conv2(mask) mask = f.relu(mask) mask = f.upsample(mask, scale_factor=2) x = (1 + mask) * x mask = f.max_pool3d(mask, (2, 1, 1), stride=(2, 1, 1)) return x, mask
def _forward(self, x): # N x 3 x 299 x 299 x = self.Conv2d_1a_3x3(x) # N x 32 x 149 x 149 x = self.Conv2d_2a_3x3(x) # N x 32 x 147 x 147 x = self.Conv2d_2b_3x3(x) # N x 64 x 147 x 147 x = F.max_pool3d(x, kernel_size=3, stride=2) # N x 64 x 73 x 73 x = self.Conv2d_3b_1x1(x) # N x 80 x 73 x 73 x = self.Conv2d_4a_3x3(x) # N x 192 x 71 x 71 x = F.max_pool3d(x, kernel_size=3, stride=2) # N x 192 x 35 x 35 x = self.Mixed_5b(x) # N x 256 x 35 x 35 x = self.Mixed_5c(x) # N x 288 x 35 x 35 x = self.Mixed_5d(x) # N x 288 x 35 x 35 x = self.Mixed_6a(x) # N x 768 x 17 x 17 x = self.Mixed_6b(x) # N x 768 x 17 x 17 x = self.Mixed_6c(x) # N x 768 x 17 x 17 x = self.Mixed_6d(x) # N x 768 x 17 x 17 x = self.Mixed_6e(x) # N x 768 x 17 x 17 aux_defined = self.training and self.aux_logits if aux_defined: aux = self.AuxLogits(x) else: aux = None # N x 768 x 17 x 17 x = self.Mixed_7a(x) # N x 1280 x 8 x 8 x = self.Mixed_7b(x) # N x 2048 x 8 x 8 x = self.Mixed_7c(x) # N x 2048 x 8 x 8 # Adaptive average pooling x = F.adaptive_avg_pool3d(x, (1, 1, 1)) embedding = x # N x 2048 x 1 x 1 x = F.dropout(x, training=self.training) # N x 2048 x 1 x 1 x = torch.flatten(x, 1) # N x 2048 x = self.fc(x) # N x 1000 (num_classes) return x, aux, embedding
def forward(self, x): x = F.relu(x) p1 = F.max_pool3d(x, 3, stride=1, padding=1) p1 = self.conv1(p1) p2 = F.max_pool3d(x, 3, stride=1, padding=1) p2 = self.conv2(p2) ''' p3 = F.max_pool3d(x, 3, stride=1, padding=1) p3 = self.conv3(p3) ''' return x+p1+p2
def forward(self, x): x = F.relu(F.max_pool3d(self.conv1(x), (1, 2, 2))) x = F.relu(F.max_pool3d(self.conv2(x), 2)) x = F.relu(F.max_pool3d(self.conv3(x), 2)) x = F.relu(F.max_pool3d(self.conv4(x), 2)) x = F.relu(F.max_pool3d(self.conv5(x), 2)) x = x.view(-1, 2048) x = F.relu(self.fc1(x)) x = F.dropout(x, training=True) x = F.relu(self.fc2(x)) return x
def forward(self, input): x0_0 = self.conv0_0(input) x1_0 = self.conv1_0(F.max_pool3d(x0_0, 2)) x0_1 = self.conv0_1(torch.cat([x0_0, self.up(x1_0)], 1)) x2_0 = self.conv2_0(F.max_pool3d(x1_0, 2)) x1_1 = self.conv1_1(torch.cat([x1_0, self.up(x2_0)], 1)) x0_2 = self.conv0_2(torch.cat([x0_0, x0_1, self.up(x1_1)], 1)) x3_0 = self.conv3_0(F.max_pool3d(x2_0, 2)) x2_1 = self.conv2_1(torch.cat([x2_0, self.up(x3_0)], 1)) x1_2 = self.conv1_2(torch.cat([x1_0, x1_1, self.up(x2_1)], 1)) x0_3 = self.conv0_3(torch.cat([x0_0, x0_1, x0_2, self.up(x1_2)], 1)) x4_0 = self.conv4_0(F.max_pool3d(x3_0, 2)) x3_1 = self.conv3_1(torch.cat([x3_0, self.up(x4_0)], 1)) x2_2 = self.conv2_2(torch.cat([x2_0, x2_1, self.up(x3_1)], 1)) x1_3 = self.conv1_3(torch.cat([x1_0, x1_1, x1_2, self.up(x2_2)], 1)) x0_4 = self.conv0_4(torch.cat([x0_0, x0_1, x0_2, x0_3, self.up(x1_3)], 1)) # x0_0 = self.conv0_0(input) # x1_0 = self.conv1_0(self.pool(x0_0)) # x0_1 = self.conv0_1(torch.cat([x0_0, self.up(x1_0)], 1)) # x2_0 = self.conv2_0(self.pool(x1_0)) # x1_1 = self.conv1_1(torch.cat([x1_0, self.up(x2_0)], 1)) # x0_2 = self.conv0_2(torch.cat([x0_0, x0_1, self.up(x1_1)], 1)) # x3_0 = self.conv3_0(self.pool(x2_0)) # x2_1 = self.conv2_1(torch.cat([x2_0, self.up(x3_0)], 1)) # x1_2 = self.conv1_2(torch.cat([x1_0, x1_1, self.up(x2_1)], 1)) # x0_3 = self.conv0_3(torch.cat([x0_0, x0_1, x0_2, self.up(x1_2)], 1)) # x4_0 = self.conv4_0(self.pool(x3_0)) # x3_1 = self.conv3_1(torch.cat([x3_0, self.up(x4_0)], 1)) # x2_2 = self.conv2_2(torch.cat([x2_0, x2_1, self.up(x3_1)], 1)) # x1_3 = self.conv1_3(torch.cat([x1_0, x1_1, x1_2, self.up(x2_2)], 1)) # x0_4 = self.conv0_4(torch.cat([x0_0, x0_1, x0_2, x0_3, self.up(x1_3)], 1)) if self.deep_supervision: output1 = self.final1(x0_1) output2 = self.final2(x0_2) output3 = self.final3(x0_3) output4 = self.final4(x0_4) return [output1, output2, output3, output4] else: output = self.final(x0_4) return output
def forward(self, x): ###We make the size of the smallest output map in each mask branch 7*7 to be consistent #with the smallest trunk output map size. ###Thus 3,2,1 max-pooling layers are used in mask branch with input size 56 * 56, 28 * 28, 14 * 14 respectively. x = self.pre(x) input_size = (x.size(2), x.size(3), x.size(4)) x_t = self.trunk(x) #first downsample out 28 x_s = F.max_pool3d(x, kernel_size=3, stride=2, padding=1) x_s = self.soft_resdown1(x_s) #28 shortcut shape1 = (x_s.size(2), x_s.size(3), x_s.size(4)) shortcut_long = self.shortcut_long(x_s) #seccond downsample out 14 x_s = F.max_pool3d(x, kernel_size=3, stride=2, padding=1) x_s = self.soft_resdown2(x_s) #14 shortcut shape2 = (x_s.size(2), x_s.size(3), x_s.size(4)) shortcut_short = self.soft_resdown3(x_s) #third downsample out 7 x_s = F.max_pool3d(x, kernel_size=3, stride=2, padding=1) x_s = self.soft_resdown3(x_s) #mid ??? NOT IN THE PAPER x_s = self.soft_resdown4(x_s) x_s = self.soft_resup1(x_s) #first upsample out 14 x_s = self.soft_resup2(x_s) x_s = F.interpolate(x_s, size=shape2) x_s += shortcut_short #second upsample out 28 x_s = self.soft_resup3(x_s) x_s = F.interpolate(x_s, size=shape1) x_s += shortcut_long #thrid upsample out 54 x_s = self.soft_resup4(x_s) x_s = F.interpolate(x_s, size=input_size) x_s = self.sigmoid(x_s) x = (1 + x_s) * x_t x = self.last(x) return x
def encode(self, x): x = F.relu(self.conv1(x)) #shape after conv: (8, 61, 73, 61) x = F.max_pool3d(x, kernel_size=2) #shape after pooling: (8, 30, 36, 30) x = F.relu(self.conv2(x)) #shape after conv: (16, 30, 36, 30) x = F.max_pool3d(x, kernel_size=2) #shape after pooling: (16, 15, 18, 15) x = F.relu(self.conv3(x)) #shape after conv: (32, 15, 18, 15) x = F.max_pool3d(x, kernel_size=2) #shape after pooling: (32, 7, 9, 7) x = x.view(-1, 7 * 9 * 7 * 32) return self.fc1(x), self.fc2(x)
def forward(self, input): x0_0 = self.conv0_0(input) x1_0 = self.conv1_0(F.max_pool3d(x0_0, 2)) x2_0 = self.conv2_0(F.max_pool3d(x1_0, 2)) x3_0 = self.conv3_0(F.max_pool3d(x2_0, 2)) x4_0 = self.conv4_0(F.max_pool3d(x3_0, 2)) x3_1 = self.conv3_1(torch.cat([x3_0, self.up(x4_0)], 1)) x2_2 = self.conv2_2(torch.cat([x2_0, self.up(x3_1)], 1)) x1_3 = self.conv1_3(torch.cat([x1_0, self.up(x2_2)], 1)) x0_4 = self.conv0_4(torch.cat([x0_0, self.up(x1_3)], 1)) output = self.final(x0_4) return output
def forward(self, x): out = F.relu(F.max_pool3d(self.encoder1(x), 2, 2)) t1 = out out = F.relu(F.max_pool3d(self.encoder2(out), 2, 2)) t2 = out out = F.relu(F.max_pool3d(self.encoder3(out), 2, 2)) t3 = out out = F.relu(F.max_pool3d(self.encoder4(out), 2, 2)) t4 = out out = F.relu(F.max_pool3d(self.encoder5(out), 2, 2)) # t2 = out out = F.relu( F.interpolate(self.decoder1(out), scale_factor=(2, 2, 2), mode='trilinear')) # print(out.shape,t4.shape) out = torch.add(F.pad(out, [0, 0, 0, 0, 0, 1]), t4) output1 = self.map1(out) out = F.relu( F.interpolate(self.decoder2(out), scale_factor=(2, 2, 2), mode='trilinear')) # out = torch.add(out,t3) output2 = self.map2(out) out = F.relu( F.interpolate(self.decoder3(out), scale_factor=(2, 2, 2), mode='trilinear')) # out = torch.add(out,t2) output3 = self.map3(out) out = F.relu( F.interpolate(self.decoder4(out), scale_factor=(2, 2, 2), mode='trilinear')) # out = torch.add(out,t1) out = F.relu( F.interpolate(self.decoder5(out), scale_factor=(2, 2, 2), mode='trilinear')) output4 = self.map4(out) # print(out.shape) # print(output1.shape,output2.shape,output3.shape,output4.shape) if self.training is True: return output1, output2, output3, output4 else: return output4
def forward(self, x): x = F.max_pool3d(F.relu(self.conv2(F.relu(self.conv1(x)))), kernel_size=2, stride=2) x = F.max_pool3d(F.relu(self.conv4(F.relu(self.conv3(x)))), kernel_size=2, stride=2) x = F.max_pool3d(F.relu(self.conv6(F.relu(self.conv5(x)))), kernel_size=2, stride=2) x_feat = x.view(-1, self.num_flat_features(x)) x = self.fc13( self.d(F.relu(self.fc12(self.d(F.relu(self.fc11(x_feat))))))) return x_feat, x
def forward_RoI_Loc(self, x,y): y= F.max_pool3d(y,kernel_size=(2,4,4),stride=(2,4,4)) x1 = self.inc(x) x2 = self.down1(x1) x3 = self.down2(x2) #x4 = self.down3(x3) LocOut=self.LocTop(x3) LocOut=F.softmax(LocOut) return [LocOut,y]