Python torch.nn.Dropout3d() Examples
The following are 30
code examples of torch.nn.Dropout3d().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
torch.nn
, or try the search function
.
Example #1
Source File: nnUNetTrainerV2_ReLU.py From nnUNet with Apache License 2.0 | 6 votes |
def initialize_network(self): if self.threeD: conv_op = nn.Conv3d dropout_op = nn.Dropout3d norm_op = nn.InstanceNorm3d else: conv_op = nn.Conv2d dropout_op = nn.Dropout2d norm_op = nn.InstanceNorm2d norm_op_kwargs = {'eps': 1e-5, 'affine': True} dropout_op_kwargs = {'p': 0, 'inplace': True} net_nonlin = nn.ReLU net_nonlin_kwargs = {'inplace': True} self.network = Generic_UNet(self.num_input_channels, self.base_num_features, self.num_classes, len(self.net_num_pool_op_kernel_sizes), self.conv_per_stage, 2, conv_op, norm_op, norm_op_kwargs, dropout_op, dropout_op_kwargs, net_nonlin, net_nonlin_kwargs, True, False, lambda x: x, InitWeights_He(0), self.net_num_pool_op_kernel_sizes, self.net_conv_kernel_sizes, False, True, True) if torch.cuda.is_available(): self.network.cuda() self.network.inference_apply_nonlin = softmax_helper
Example #2
Source File: nnUNetTrainerV2_ReLU_biasInSegOutput.py From nnUNet with Apache License 2.0 | 6 votes |
def initialize_network(self): if self.threeD: conv_op = nn.Conv3d dropout_op = nn.Dropout3d norm_op = nn.InstanceNorm3d else: conv_op = nn.Conv2d dropout_op = nn.Dropout2d norm_op = nn.InstanceNorm2d norm_op_kwargs = {'eps': 1e-5, 'affine': True} dropout_op_kwargs = {'p': 0, 'inplace': True} net_nonlin = nn.ReLU net_nonlin_kwargs = {'inplace': True} self.network = Generic_UNet(self.num_input_channels, self.base_num_features, self.num_classes, len(self.net_num_pool_op_kernel_sizes), self.conv_per_stage, 2, conv_op, norm_op, norm_op_kwargs, dropout_op, dropout_op_kwargs, net_nonlin, net_nonlin_kwargs, True, False, lambda x: x, InitWeights_He(0), self.net_num_pool_op_kernel_sizes, self.net_conv_kernel_sizes, False, True, True, seg_output_use_bias=True) self.network.cuda() self.network.inference_apply_nonlin = softmax_helper
Example #3
Source File: nnUNetTrainerV2_LReLU_slope_2en1.py From nnUNet with Apache License 2.0 | 6 votes |
def initialize_network(self): if self.threeD: conv_op = nn.Conv3d dropout_op = nn.Dropout3d norm_op = nn.InstanceNorm3d else: conv_op = nn.Conv2d dropout_op = nn.Dropout2d norm_op = nn.InstanceNorm2d norm_op_kwargs = {'eps': 1e-5, 'affine': True} dropout_op_kwargs = {'p': 0, 'inplace': True} net_nonlin = nn.LeakyReLU net_nonlin_kwargs = {'inplace': True, 'negative_slope': 2e-1} self.network = Generic_UNet(self.num_input_channels, self.base_num_features, self.num_classes, len(self.net_num_pool_op_kernel_sizes), self.conv_per_stage, 2, conv_op, norm_op, norm_op_kwargs, dropout_op, dropout_op_kwargs, net_nonlin, net_nonlin_kwargs, True, False, lambda x: x, InitWeights_He(0), self.net_num_pool_op_kernel_sizes, self.net_conv_kernel_sizes, False, True, True) if torch.cuda.is_available(): self.network.cuda() self.network.inference_apply_nonlin = softmax_helper
Example #4
Source File: nnUNetTrainerV2_3ConvPerStage_samefilters.py From nnUNet with Apache License 2.0 | 6 votes |
def initialize_network(self): if self.threeD: conv_op = nn.Conv3d dropout_op = nn.Dropout3d norm_op = nn.InstanceNorm3d else: conv_op = nn.Conv2d dropout_op = nn.Dropout2d norm_op = nn.InstanceNorm2d norm_op_kwargs = {'eps': 1e-5, 'affine': True} dropout_op_kwargs = {'p': 0, 'inplace': True} net_nonlin = nn.LeakyReLU net_nonlin_kwargs = {'negative_slope': 1e-2, 'inplace': True} self.network = Generic_UNet(self.num_input_channels, self.base_num_features, self.num_classes, len(self.net_num_pool_op_kernel_sizes), 3, 2, conv_op, norm_op, norm_op_kwargs, dropout_op, dropout_op_kwargs, net_nonlin, net_nonlin_kwargs, True, False, lambda x: x, InitWeights_He(1e-2), self.net_num_pool_op_kernel_sizes, self.net_conv_kernel_sizes, False, True, True) if torch.cuda.is_available(): self.network.cuda() self.network.inference_apply_nonlin = softmax_helper
Example #5
Source File: nnUNetTrainerV2_ReLU_convReLUIN.py From nnUNet with Apache License 2.0 | 6 votes |
def initialize_network(self): if self.threeD: conv_op = nn.Conv3d dropout_op = nn.Dropout3d norm_op = nn.InstanceNorm3d else: conv_op = nn.Conv2d dropout_op = nn.Dropout2d norm_op = nn.InstanceNorm2d norm_op_kwargs = {'eps': 1e-5, 'affine': True} dropout_op_kwargs = {'p': 0, 'inplace': True} net_nonlin = nn.ReLU net_nonlin_kwargs = {'inplace': True} self.network = Generic_UNet(self.num_input_channels, self.base_num_features, self.num_classes, len(self.net_num_pool_op_kernel_sizes), self.conv_per_stage, 2, conv_op, norm_op, norm_op_kwargs, dropout_op, dropout_op_kwargs, net_nonlin, net_nonlin_kwargs, True, False, lambda x: x, InitWeights_He(0), self.net_num_pool_op_kernel_sizes, self.net_conv_kernel_sizes, False, True, True, basic_block=ConvDropoutNonlinNorm) if torch.cuda.is_available(): self.network.cuda() self.network.inference_apply_nonlin = softmax_helper
Example #6
Source File: ResUnet3d_pytorch.py From medSynthesisV1 with MIT License | 6 votes |
def __init__(self, in_channel=1, n_classes=4, dp_prob=0): super(ResUNet_LRes, self).__init__() # self.imsize = imsize self.activation = F.relu self.pool1 = nn.MaxPool3d(2) self.pool2 = nn.MaxPool3d(2) self.pool3 = nn.MaxPool3d(2) # self.pool4 = nn.MaxPool3d(2) self.conv_block1_64 = UNetConvBlock(in_channel, 32) self.conv_block64_128 = residualUnit(32, 64) self.conv_block128_256 = residualUnit(64, 128) self.conv_block256_512 = residualUnit(128, 256) # self.conv_block512_1024 = residualUnit(512, 1024) # this kind of symmetric design is awesome, it automatically solves the number of channels during upsamping # self.up_block1024_512 = UNetUpResBlock(1024, 512) self.up_block512_256 = UNetUpResBlock(256, 128) self.up_block256_128 = UNetUpResBlock(128, 64) self.up_block128_64 = UNetUpResBlock(64, 32) self.Dropout = nn.Dropout3d(p=dp_prob) self.last = nn.Conv3d(32, n_classes, 1, stride=1)
Example #7
Source File: nnUNetTrainerV2_3ConvPerStage.py From nnUNet with Apache License 2.0 | 6 votes |
def initialize_network(self): self.base_num_features = 24 # otherwise we run out of VRAM if self.threeD: conv_op = nn.Conv3d dropout_op = nn.Dropout3d norm_op = nn.InstanceNorm3d else: conv_op = nn.Conv2d dropout_op = nn.Dropout2d norm_op = nn.InstanceNorm2d norm_op_kwargs = {'eps': 1e-5, 'affine': True} dropout_op_kwargs = {'p': 0, 'inplace': True} net_nonlin = nn.LeakyReLU net_nonlin_kwargs = {'negative_slope': 1e-2, 'inplace': True} self.network = Generic_UNet(self.num_input_channels, self.base_num_features, self.num_classes, len(self.net_num_pool_op_kernel_sizes), 3, 2, conv_op, norm_op, norm_op_kwargs, dropout_op, dropout_op_kwargs, net_nonlin, net_nonlin_kwargs, True, False, lambda x: x, InitWeights_He(1e-2), self.net_num_pool_op_kernel_sizes, self.net_conv_kernel_sizes, False, True, True) if torch.cuda.is_available(): self.network.cuda() self.network.inference_apply_nonlin = softmax_helper
Example #8
Source File: S3DG_Pytorch.py From s3d.pytorch with MIT License | 6 votes |
def __init__(self, num_classes=400, dropout_keep_prob = 1, input_channel = 3, spatial_squeeze=True): super(S3DG, self).__init__() self.features = nn.Sequential( STConv3d(input_channel, 64, kernel_size=7, stride=2, padding=3), # (64, 32, 112, 112) nn.MaxPool3d(kernel_size=(1,3,3), stride=(1,2,2), padding=(0,1,1)), # (64, 32, 56, 56) BasicConv3d(64, 64, kernel_size=1, stride=1), # (64, 32, 56, 56) STConv3d(64, 192, kernel_size=3, stride=1, padding=1), # (192, 32, 56, 56) nn.MaxPool3d(kernel_size=(1,3,3), stride=(1,2,2), padding=(0,1,1)), # (192, 32, 28, 28) Mixed_3b(), # (256, 32, 28, 28) Mixed_3c(), # (480, 32, 28, 28) nn.MaxPool3d(kernel_size=(3, 3, 3), stride=(2, 2, 2), padding=(1, 1, 1)), # (480, 16, 14, 14) Mixed_4b(),# (512, 16, 14, 14) Mixed_4c(),# (512, 16, 14, 14) Mixed_4d(),# (512, 16, 14, 14) Mixed_4e(),# (528, 16, 14, 14) Mixed_4f(),# (832, 16, 14, 14) nn.MaxPool3d(kernel_size=(2, 2, 2), stride=(2, 2, 2), padding=(0, 0, 0)), # (832, 8, 7, 7) Mixed_5b(), # (832, 8, 7, 7) Mixed_5c(), # (1024, 8, 7, 7) nn.AvgPool3d(kernel_size=(2, 7, 7), stride=1),# (1024, 8, 1, 1) nn.Dropout3d(dropout_keep_prob), nn.Conv3d(1024, num_classes, kernel_size=1, stride=1, bias=True),# (400, 8, 1, 1) ) self.spatial_squeeze = spatial_squeeze self.softmax = nn.Softmax()
Example #9
Source File: noNewReversible.py From PartiallyReversibleUnet with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self): super(NoNewReversible, self).__init__() depth = 1 self.levels = 5 self.firstConv = nn.Conv3d(4, CHANNELS[0], 3, padding=1, bias=False) #self.dropout = nn.Dropout3d(0.2, True) self.lastConv = nn.Conv3d(CHANNELS[0], 3, 1, bias=True) #create encoder levels encoderModules = [] for i in range(self.levels): encoderModules.append(EncoderModule(getChannelsAtIndex(i - 1), getChannelsAtIndex(i), depth, i != 0)) self.encoders = nn.ModuleList(encoderModules) #create decoder levels decoderModules = [] for i in range(self.levels): decoderModules.append(DecoderModule(getChannelsAtIndex(self.levels - i - 1), getChannelsAtIndex(self.levels - i - 2), depth, i != (self.levels -1))) self.decoders = nn.ModuleList(decoderModules)
Example #10
Source File: nnUNetTrainerV2_Mish.py From nnUNet with Apache License 2.0 | 6 votes |
def initialize_network(self): if self.threeD: conv_op = nn.Conv3d dropout_op = nn.Dropout3d norm_op = nn.InstanceNorm3d else: conv_op = nn.Conv2d dropout_op = nn.Dropout2d norm_op = nn.InstanceNorm2d norm_op_kwargs = {'eps': 1e-5, 'affine': True} dropout_op_kwargs = {'p': 0, 'inplace': True} net_nonlin = Mish net_nonlin_kwargs = {} self.network = Generic_UNet(self.num_input_channels, self.base_num_features, self.num_classes, len(self.net_num_pool_op_kernel_sizes), self.conv_per_stage, 2, conv_op, norm_op, norm_op_kwargs, dropout_op, dropout_op_kwargs, net_nonlin, net_nonlin_kwargs, True, False, lambda x: x, InitWeights_He(0), self.net_num_pool_op_kernel_sizes, self.net_conv_kernel_sizes, False, True, True) if torch.cuda.is_available(): self.network.cuda() self.network.inference_apply_nonlin = softmax_helper
Example #11
Source File: noNewReversibleFat.py From PartiallyReversibleUnet with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self): super(NoNewReversible, self).__init__() encoderDepth = encDepth decoderDepth = 1 self.levels = 5 self.firstConv = nn.Conv3d(4, CHANNELS[0], 3, padding=1, bias=False) #self.dropout = nn.Dropout3d(0.2, True) self.lastConv = nn.Conv3d(CHANNELS[0], 3, 1, bias=True) #create encoder levels encoderModules = [] for i in range(self.levels): encoderModules.append(EncoderModule(getChannelsAtIndex(i - 1), getChannelsAtIndex(i), encoderDepth, i != 0)) self.encoders = nn.ModuleList(encoderModules) #create decoder levels decoderModules = [] for i in range(self.levels): decoderModules.append(DecoderModule(getChannelsAtIndex(self.levels - i - 1), getChannelsAtIndex(self.levels - i - 2), decoderDepth, i != (self.levels -1))) self.decoders = nn.ModuleList(decoderModules)
Example #12
Source File: nnUNetTrainerV2_lReLU_convlReLUIN.py From nnUNet with Apache License 2.0 | 6 votes |
def initialize_network(self): if self.threeD: conv_op = nn.Conv3d dropout_op = nn.Dropout3d norm_op = nn.InstanceNorm3d else: conv_op = nn.Conv2d dropout_op = nn.Dropout2d norm_op = nn.InstanceNorm2d norm_op_kwargs = {'eps': 1e-5, 'affine': True} dropout_op_kwargs = {'p': 0, 'inplace': True} net_nonlin = nn.LeakyReLU net_nonlin_kwargs = {'inplace': True, 'negative_slope': 1e-2} self.network = Generic_UNet(self.num_input_channels, self.base_num_features, self.num_classes, len(self.net_num_pool_op_kernel_sizes), self.conv_per_stage, 2, conv_op, norm_op, norm_op_kwargs, dropout_op, dropout_op_kwargs, net_nonlin, net_nonlin_kwargs, True, False, lambda x: x, InitWeights_He(1e-2), self.net_num_pool_op_kernel_sizes, self.net_conv_kernel_sizes, False, True, True, basic_block=ConvDropoutNonlinNorm) self.network.cuda() self.network.inference_apply_nonlin = softmax_helper
Example #13
Source File: blocks.py From pytorch-UNet with MIT License | 6 votes |
def __init__(self, in_channels, middle_channels, out_channels, deconv_channels, dropout=False): super(Decoder3D, self).__init__() layers = [ nn.Conv3d(in_channels, middle_channels, kernel_size=3, padding=1), nn.BatchNorm3d(middle_channels), nn.ReLU(inplace=True), nn.Conv3d(middle_channels, out_channels, kernel_size=3, padding=1), nn.BatchNorm3d(out_channels), nn.ReLU(inplace=True), nn.ConvTranspose3d(out_channels, deconv_channels, kernel_size=2, stride=2) ] if dropout: assert 0 <= dropout <= 1, 'dropout must be between 0 and 1' layers.append(nn.Dropout3d(p=dropout)) self.decoder = nn.Sequential(*layers)
Example #14
Source File: blocks.py From pytorch-UNet with MIT License | 6 votes |
def __init__(self, in_channels, middle_channels, out_channels, deconv_channels, dropout=False): super(Center3D, self).__init__() layers = [ nn.MaxPool3d(kernel_size=2), nn.Conv3d(in_channels, middle_channels, kernel_size=3, padding=1), nn.BatchNorm3d(middle_channels), nn.ReLU(inplace=True), nn.Conv3d(middle_channels, out_channels, kernel_size=3, padding=1), nn.BatchNorm3d(out_channels), nn.ReLU(inplace=True), nn.ConvTranspose3d(out_channels, deconv_channels, kernel_size=2, stride=2) ] if dropout: assert 0 <= dropout <= 1, 'dropout must be between 0 and 1' layers.append(nn.Dropout3d(p=dropout)) self.center = nn.Sequential(*layers)
Example #15
Source File: blocks.py From pytorch-UNet with MIT License | 6 votes |
def __init__( self, in_channels, middle_channels, out_channels, dropout=False, downsample_kernel=2 ): super(Encoder3D, self).__init__() layers = [ nn.MaxPool3d(kernel_size=downsample_kernel), nn.Conv3d(in_channels, middle_channels, kernel_size=3, padding=1), nn.BatchNorm3d(middle_channels), nn.ReLU(inplace=True), nn.Conv3d(middle_channels, out_channels, kernel_size=3, padding=1), nn.BatchNorm3d(out_channels), nn.ReLU(inplace=True) ] if dropout: assert 0 <= dropout <= 1, 'dropout must be between 0 and 1' layers.append(nn.Dropout3d(p=dropout)) self.encoder = nn.Sequential(*layers)
Example #16
Source File: blocks.py From pytorch-UNet with MIT License | 6 votes |
def __init__(self, in_channels, middle_channels, out_channels, dropout=False): super(First3D, self).__init__() layers = [ nn.Conv3d(in_channels, middle_channels, kernel_size=3, padding=1), nn.BatchNorm3d(middle_channels), nn.ReLU(inplace=True), nn.Conv3d(middle_channels, out_channels, kernel_size=3, padding=1), nn.BatchNorm3d(out_channels), nn.ReLU(inplace=True) ] if dropout: assert 0 <= dropout <= 1, 'dropout must be between 0 and 1' layers.append(nn.Dropout3d(p=dropout)) self.first = nn.Sequential(*layers)
Example #17
Source File: nnUNetTrainerV2_lReLU_biasInSegOutput.py From nnUNet with Apache License 2.0 | 6 votes |
def initialize_network(self): if self.threeD: conv_op = nn.Conv3d dropout_op = nn.Dropout3d norm_op = nn.InstanceNorm3d else: conv_op = nn.Conv2d dropout_op = nn.Dropout2d norm_op = nn.InstanceNorm2d norm_op_kwargs = {'eps': 1e-5, 'affine': True} dropout_op_kwargs = {'p': 0, 'inplace': True} net_nonlin = nn.LeakyReLU net_nonlin_kwargs = {'negative_slope': 1e-2, 'inplace': True} self.network = Generic_UNet(self.num_input_channels, self.base_num_features, self.num_classes, len(self.net_num_pool_op_kernel_sizes), self.conv_per_stage, 2, conv_op, norm_op, norm_op_kwargs, dropout_op, dropout_op_kwargs, net_nonlin, net_nonlin_kwargs, True, False, lambda x: x, InitWeights_He(0), self.net_num_pool_op_kernel_sizes, self.net_conv_kernel_sizes, False, True, True, seg_output_use_bias=True) if torch.cuda.is_available(): self.network.cuda() self.network.inference_apply_nonlin = softmax_helper
Example #18
Source File: drop_block.py From Magic-VNet with MIT License | 5 votes |
def __init__(self, drop_type): super(Drop, self).__init__() if drop_type is None: self.drop = keep_origin elif drop_type == 'alpha': self.drop = nn.AlphaDropout(p=0.5) elif drop_type == 'dropout': self.drop = nn.Dropout3d(p=0.5) elif drop_type == 'drop_block': self.drop = DropBlock3D(drop_prob=0.2, block_size=2) else: raise NotImplementedError('{} not implemented'.format(drop_type))
Example #19
Source File: vnet_new.py From pytorch_memonger with GNU General Public License v3.0 | 5 votes |
def __init__(self, inChans, outChans, nConvs, elu, dropout=False): super(UpTransition, self).__init__() self.up_conv = nn.ConvTranspose3d(inChans, outChans // 2, kernel_size=2, stride=2) self.bn1 = ContBatchNorm3d(outChans // 2) self.do1 = passthrough self.do2 = nn.Dropout3d() self.relu1 = ELUCons(elu, outChans // 2) self.relu2 = ELUCons(elu, outChans) if dropout: self.do1 = nn.Dropout3d() self.ops = _make_nConv(outChans, nConvs, elu)
Example #20
Source File: vnet_new.py From pytorch_memonger with GNU General Public License v3.0 | 5 votes |
def __init__(self, inChans, nConvs, elu, dropout=False): super(DownTransition, self).__init__() outChans = 2*inChans self.down_conv = nn.Conv3d(inChans, outChans, kernel_size=2, stride=2) self.bn1 = ContBatchNorm3d(outChans) self.do1 = passthrough self.relu1 = ELUCons(elu, outChans) self.relu2 = ELUCons(elu, outChans) if dropout: self.do1 = nn.Dropout3d() self.ops = _make_nConv(outChans, nConvs, elu)
Example #21
Source File: noNewNet.py From PartiallyReversibleUnet with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, inChannels, outChannels, maxpool=False, secondConv=True, hasDropout=False): super(EncoderModule, self).__init__() groups = min(outChannels, CHANNELS) self.maxpool = maxpool self.secondConv = secondConv self.hasDropout = hasDropout self.conv1 = nn.Conv3d(inChannels, outChannels, 3, padding=1, bias=False) self.gn1 = nn.GroupNorm(groups, outChannels) if secondConv: self.conv2 = nn.Conv3d(outChannels, outChannels, 3, padding=1, bias=False) self.gn2 = nn.GroupNorm(groups, outChannels) if hasDropout: self.dropout = nn.Dropout3d(0.2, True)
Example #22
Source File: HighResNet3D.py From MedicalZooPytorch with MIT License | 5 votes |
def __init__(self, in_channels=1, classes=4, shortcut_type="A", dropout_layer=True): super(HighResNet3D, self).__init__() self.in_channels = in_channels self.shortcut_type = shortcut_type self.classes = classes self.init_channels = 16 self.red_channels = 16 self.dil2_channels = 32 self.dil4_channels = 64 self.conv_out_channels = 80 if self.shortcut_type == "B": self.res_pad_1 = Conv1x1x1(self.red_channels, self.dil2_channels) self.res_pad_2 = Conv1x1x1(self.dil2_channels, self.dil4_channels) self.conv_init = ConvInit(in_channels) self.red_blocks1 = self.create_red(self.init_channels) self.red_blocks2 = self.create_red(self.red_channels) self.red_blocks3 = self.create_red(self.red_channels) self.dil2block1 = self.create_dil2(self.red_channels) self.dil2block2 = self.create_dil2(self.dil2_channels) self.dil2block3 = self.create_dil2(self.dil2_channels) self.dil4block1 = self.create_dil4(self.dil2_channels) self.dil4block2 = self.create_dil4(self.dil4_channels) self.dil4block3 = self.create_dil4(self.dil4_channels) if dropout_layer: conv_out = nn.Conv3d(self.dil4_channels, self.conv_out_channels, kernel_size=1) drop3d = nn.Dropout3d() conv1x1x1 = Conv1x1x1(self.conv_out_channels, self.classes) self.conv_out = nn.Sequential(conv_out, drop3d, conv1x1x1) else: self.conv_out = Conv1x1x1(self.dil4_channels, self.classes)
Example #23
Source File: Vnet.py From MedicalZooPytorch with MIT License | 5 votes |
def __init__(self, inChans, nConvs, elu, dropout=False): super(DownTransition, self).__init__() outChans = 2 * inChans self.down_conv = nn.Conv3d(inChans, outChans, kernel_size=2, stride=2) self.bn1 = torch.nn.BatchNorm3d(outChans) self.do1 = passthrough self.relu1 = ELUCons(elu, outChans) self.relu2 = ELUCons(elu, outChans) if dropout: self.do1 = nn.Dropout3d() self.ops = _make_nConv(outChans, nConvs, elu)
Example #24
Source File: Vnet.py From MedicalZooPytorch with MIT License | 5 votes |
def __init__(self, inChans, outChans, nConvs, elu, dropout=False): super(UpTransition, self).__init__() self.up_conv = nn.ConvTranspose3d(inChans, outChans // 2, kernel_size=2, stride=2) self.bn1 = torch.nn.BatchNorm3d(outChans // 2) self.do1 = passthrough self.do2 = nn.Dropout3d() self.relu1 = ELUCons(elu, outChans // 2) self.relu2 = ELUCons(elu, outChans) if dropout: self.do1 = nn.Dropout3d() self.ops = _make_nConv(outChans, nConvs, elu)
Example #25
Source File: ResNet3D_VAE.py From MedicalZooPytorch with MIT License | 5 votes |
def __init__(self, in_channels, start_channels=32): super(ResNetEncoder, self).__init__() self.start_channels = start_channels self.down_channels_1 = 2 * self.start_channels self.down_channels_2 = 2 * self.down_channels_1 self.down_channels_3 = 2 * self.down_channels_2 # print("self.down_channels_3", self.down_channels_3) self.blue_1 = BlueBlock(in_channels=in_channels, out_channels=self.start_channels) self.drop = nn.Dropout3d(0.2) self.green_1 = GreenBlock(in_channels=self.start_channels) self.down_1 = DownBlock(in_channels=self.start_channels, out_channels=self.down_channels_1) self.green_2_1 = GreenBlock(in_channels=self.down_channels_1) self.green_2_2 = GreenBlock(in_channels=self.down_channels_1) self.down_2 = DownBlock(in_channels=self.down_channels_1, out_channels=self.down_channels_2) self.green_3_1 = GreenBlock(in_channels=self.down_channels_2) self.green_3_2 = GreenBlock(in_channels=self.down_channels_2) self.down_3 = DownBlock(in_channels=self.down_channels_2, out_channels=self.down_channels_3) self.green_4_1 = GreenBlock(in_channels=self.down_channels_3) self.green_4_2 = GreenBlock(in_channels=self.down_channels_3) self.green_4_3 = GreenBlock(in_channels=self.down_channels_3) self.green_4_4 = GreenBlock(in_channels=self.down_channels_3)
Example #26
Source File: vnet.py From vnet.pytorch with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, inChans, outChans, nConvs, elu, dropout=False): super(UpTransition, self).__init__() self.up_conv = nn.ConvTranspose3d(inChans, outChans // 2, kernel_size=2, stride=2) self.bn1 = ContBatchNorm3d(outChans // 2) self.do1 = passthrough self.do2 = nn.Dropout3d() self.relu1 = ELUCons(elu, outChans // 2) self.relu2 = ELUCons(elu, outChans) if dropout: self.do1 = nn.Dropout3d() self.ops = _make_nConv(outChans, nConvs, elu)
Example #27
Source File: nnUNetTrainer.py From nnUNet with Apache License 2.0 | 5 votes |
def initialize_network(self): """ This is specific to the U-Net and must be adapted for other network architectures :return: """ # self.print_to_log_file(self.net_num_pool_op_kernel_sizes) # self.print_to_log_file(self.net_conv_kernel_sizes) net_numpool = len(self.net_num_pool_op_kernel_sizes) if self.threeD: conv_op = nn.Conv3d dropout_op = nn.Dropout3d norm_op = nn.InstanceNorm3d else: conv_op = nn.Conv2d dropout_op = nn.Dropout2d norm_op = nn.InstanceNorm2d norm_op_kwargs = {'eps': 1e-5, 'affine': True} dropout_op_kwargs = {'p': 0, 'inplace': True} net_nonlin = nn.LeakyReLU net_nonlin_kwargs = {'negative_slope': 1e-2, 'inplace': True} self.network = Generic_UNet(self.num_input_channels, self.base_num_features, self.num_classes, net_numpool, self.conv_per_stage, 2, conv_op, norm_op, norm_op_kwargs, dropout_op, dropout_op_kwargs, net_nonlin, net_nonlin_kwargs, False, False, lambda x: x, InitWeights_He(1e-2), self.net_num_pool_op_kernel_sizes, self.net_conv_kernel_sizes, False, True, True) self.network.inference_apply_nonlin = softmax_helper if torch.cuda.is_available(): self.network.cuda()
Example #28
Source File: nnUNetTrainerV2_DDP.py From nnUNet with Apache License 2.0 | 5 votes |
def initialize_network(self): """ This is specific to the U-Net and must be adapted for other network architectures :return: """ self.print_to_log_file(self.net_num_pool_op_kernel_sizes) self.print_to_log_file(self.net_conv_kernel_sizes) if self.threeD: conv_op = nn.Conv3d dropout_op = nn.Dropout3d norm_op = nn.InstanceNorm3d else: conv_op = nn.Conv2d dropout_op = nn.Dropout2d norm_op = nn.InstanceNorm2d norm_op_kwargs = {'eps': 1e-5, 'affine': True} dropout_op_kwargs = {'p': 0, 'inplace': True} net_nonlin = nn.LeakyReLU net_nonlin_kwargs = {'negative_slope': 1e-2, 'inplace': True} self.network = Generic_UNet(self.num_input_channels, self.base_num_features, self.num_classes, len(self.net_num_pool_op_kernel_sizes), self.conv_per_stage, 2, conv_op, norm_op, norm_op_kwargs, dropout_op, dropout_op_kwargs, net_nonlin, net_nonlin_kwargs, True, False, lambda x: x, InitWeights_He(1e-2), self.net_num_pool_op_kernel_sizes, self.net_conv_kernel_sizes, False, True, True) if torch.cuda.is_available(): self.network.cuda() self.network.inference_apply_nonlin = softmax_helper
Example #29
Source File: nnUNetTrainerV2_BN.py From nnUNet with Apache License 2.0 | 5 votes |
def initialize_network(self): """ changed deep supervision to False :return: """ if self.threeD: conv_op = nn.Conv3d dropout_op = nn.Dropout3d norm_op = nn.BatchNorm3d else: conv_op = nn.Conv2d dropout_op = nn.Dropout2d norm_op = nn.BatchNorm2d norm_op_kwargs = {'eps': 1e-5, 'affine': True} dropout_op_kwargs = {'p': 0, 'inplace': True} net_nonlin = nn.LeakyReLU net_nonlin_kwargs = {'negative_slope': 1e-2, 'inplace': True} self.network = Generic_UNet(self.num_input_channels, self.base_num_features, self.num_classes, len(self.net_num_pool_op_kernel_sizes), self.conv_per_stage, 2, conv_op, norm_op, norm_op_kwargs, dropout_op, dropout_op_kwargs, net_nonlin, net_nonlin_kwargs, True, False, lambda x: x, InitWeights_He(1e-2), self.net_num_pool_op_kernel_sizes, self.net_conv_kernel_sizes, False, True, True) if torch.cuda.is_available(): self.network.cuda() self.network.inference_apply_nonlin = softmax_helper
Example #30
Source File: nnUNetTrainerV2_GN.py From nnUNet with Apache License 2.0 | 5 votes |
def initialize_network(self): """ changed deep supervision to False :return: """ if self.threeD: conv_op = nn.Conv3d dropout_op = nn.Dropout3d norm_op = MyGroupNorm else: conv_op = nn.Conv2d dropout_op = nn.Dropout2d norm_op = MyGroupNorm norm_op_kwargs = {'eps': 1e-5, 'affine': True, 'num_groups': 8} dropout_op_kwargs = {'p': 0, 'inplace': True} net_nonlin = nn.LeakyReLU net_nonlin_kwargs = {'negative_slope': 1e-2, 'inplace': True} self.network = Generic_UNet(self.num_input_channels, self.base_num_features, self.num_classes, len(self.net_num_pool_op_kernel_sizes), self.conv_per_stage, 2, conv_op, norm_op, norm_op_kwargs, dropout_op, dropout_op_kwargs, net_nonlin, net_nonlin_kwargs, True, False, lambda x: x, InitWeights_He(1e-2), self.net_num_pool_op_kernel_sizes, self.net_conv_kernel_sizes, False, True, True) if torch.cuda.is_available(): self.network.cuda() self.network.inference_apply_nonlin = softmax_helper