Python torch.nn.AvgPool1d() Examples
The following are 30
code examples of torch.nn.AvgPool1d().
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: networks.py From MeshCNN with MIT License | 6 votes |
def __init__(self, norm_layer, nf0, conv_res, nclasses, input_res, pool_res, fc_n, nresblocks=3): super(MeshConvNet, self).__init__() self.k = [nf0] + conv_res self.res = [input_res] + pool_res norm_args = get_norm_args(norm_layer, self.k[1:]) for i, ki in enumerate(self.k[:-1]): setattr(self, 'conv{}'.format(i), MResConv(ki, self.k[i + 1], nresblocks)) setattr(self, 'norm{}'.format(i), norm_layer(**norm_args[i])) setattr(self, 'pool{}'.format(i), MeshPool(self.res[i + 1])) self.gp = torch.nn.AvgPool1d(self.res[-1]) # self.gp = torch.nn.MaxPool1d(self.res[-1]) self.fc1 = nn.Linear(self.k[-1], fc_n) self.fc2 = nn.Linear(fc_n, nclasses)
Example #2
Source File: bc.py From ban-vqa with MIT License | 6 votes |
def __init__(self, v_dim, q_dim, h_dim, h_out, act='ReLU', dropout=[.2,.5], k=3): super(BCNet, self).__init__() self.c = 32 self.k = k self.v_dim = v_dim; self.q_dim = q_dim self.h_dim = h_dim; self.h_out = h_out self.v_net = FCNet([v_dim, h_dim * self.k], act=act, dropout=dropout[0]) self.q_net = FCNet([q_dim, h_dim * self.k], act=act, dropout=dropout[0]) self.dropout = nn.Dropout(dropout[1]) # attention if 1 < k: self.p_net = nn.AvgPool1d(self.k, stride=self.k) if None == h_out: pass elif h_out <= self.c: self.h_mat = nn.Parameter(torch.Tensor(1, h_out, 1, h_dim * self.k).normal_()) self.h_bias = nn.Parameter(torch.Tensor(1, h_out, 1, 1).normal_()) else: self.h_net = weight_norm(nn.Linear(h_dim * self.k, h_out), dim=None)
Example #3
Source File: modules.py From pase with MIT License | 6 votes |
def __init__(self, ninp, fmaps, din=0, dout=0, context=1, tie_context_weights=False, name='MLPBlock', ratio_fixed=None, range_fixed=None, dropin_mode='std', drop_channels=False, emb_size=100): super().__init__(name=name) self.ninp = ninp self.fmaps = fmaps self.tie_context_weights = tie_context_weights assert context % 2 != 0, context if tie_context_weights: self.W = nn.Conv1d(ninp, fmaps, 1) self.pool = nn.AvgPool1d(kernel_size=context, stride=1, padding=context//2, count_include_pad=False) else: self.W = nn.Conv1d(ninp, fmaps, context, padding=context//2) self.din = PatternedDropout(emb_size=emb_size, p=din, dropout_mode=dropin_mode, range_fixed=range_fixed, ratio_fixed=ratio_fixed, drop_whole_channels=drop_channels) self.act = nn.PReLU(fmaps) self.dout = nn.Dropout(dout)
Example #4
Source File: nn_with_sep_pooling.py From attacut with MIT License | 6 votes |
def __init__(self, no_vocabs, embedding_dim=16, window_size=1): super(Model, self).__init__() self.input_size = 2*window_size+1 self.embeddings = nn.ModuleList([ nn.Embedding( no_vocabs, embedding_dim, padding_idx=0 ) for i in range(self.input_size) ]) self.pooling = nn.AvgPool1d(embedding_dim) self.linear1 = nn.Linear(embedding_dim, 8) self.linear2 = nn.Linear(8, 1)
Example #5
Source File: ban.py From openvqa with Apache License 2.0 | 6 votes |
def __init__(self, __C, atten=False): super(BC, self).__init__() self.__C = __C self.v_net = MLP([__C.IMG_FEAT_SIZE, __C.BA_HIDDEN_SIZE], dropout_r=__C.DROPOUT_R) self.q_net = MLP([__C.HIDDEN_SIZE, __C.BA_HIDDEN_SIZE], dropout_r=__C.DROPOUT_R) if not atten: self.p_net = nn.AvgPool1d(__C.K_TIMES, stride=__C.K_TIMES) else: self.dropout = nn.Dropout(__C.CLASSIFER_DROPOUT_R) # attention self.h_mat = nn.Parameter(torch.Tensor( 1, __C.GLIMPSE, 1, __C.BA_HIDDEN_SIZE).normal_()) self.h_bias = nn.Parameter( torch.Tensor(1, __C.GLIMPSE, 1, 1).normal_())
Example #6
Source File: multiscale.py From melgan with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self): super(MultiScaleDiscriminator, self).__init__() self.discriminators = nn.ModuleList( [Discriminator() for _ in range(3)] ) self.pooling = nn.ModuleList( [Identity()] + [nn.AvgPool1d(kernel_size=4, stride=2, padding=1, count_include_pad=False) for _ in range(1, 3)] )
Example #7
Source File: avg_pool.py From REDN with MIT License | 5 votes |
def __init__(self, kernel_size, segment_num=None): """ Args: input_size: dimention of input embedding kernel_size: kernel_size for CNN padding: padding for CNN hidden_size: hidden size """ super().__init__() self.segment_num = segment_num if self.segment_num != None: self.mask_embedding = nn.Embedding(segment_num + 1, segment_num) self.mask_embedding.weight.data.copy_(torch.FloatTensor(np.concatenate([np.zeros(segment_num), np.identity(segment_num)], axis = 0))) self.mask_embedding.weight.requires_grad = False self.pool = nn.AvgPool1d(kernel_size)
Example #8
Source File: DFL.py From DFL-CNN with MIT License | 5 votes |
def __init__(self, k = 10, nclass = 200): super(DFL_VGG16, self).__init__() self.k = k self.nclass = nclass # k channels for one class, nclass is total classes, therefore k * nclass for conv6 vgg16featuremap = torchvision.models.vgg16_bn(pretrained=True).features conv1_conv4 = torch.nn.Sequential(*list(vgg16featuremap.children())[:-11]) conv5 = torch.nn.Sequential(*list(vgg16featuremap.children())[-11:]) conv6 = torch.nn.Conv2d(512, k * nclass, kernel_size = 1, stride = 1, padding = 0) pool6 = torch.nn.MaxPool2d((56, 56), stride = (56, 56), return_indices = True) # Feature extraction root self.conv1_conv4 = conv1_conv4 # G-Stream self.conv5 = conv5 self.cls5 = nn.Sequential( nn.Conv2d(512, 200, kernel_size=1, stride = 1, padding = 0), nn.BatchNorm2d(200), nn.ReLU(True), nn.AdaptiveAvgPool2d((1,1)), ) # P-Stream self.conv6 = conv6 self.pool6 = pool6 self.cls6 = nn.Sequential( nn.Conv2d(k * nclass, nclass, kernel_size = 1, stride = 1, padding = 0), nn.AdaptiveAvgPool2d((1,1)), ) # Side-branch self.cross_channel_pool = nn.AvgPool1d(kernel_size = k, stride = k, padding = 0)
Example #9
Source File: modules.py From melgan-neurips with MIT License | 5 votes |
def __init__(self, num_D, ndf, n_layers, downsampling_factor): super().__init__() self.model = nn.ModuleDict() for i in range(num_D): self.model[f"disc_{i}"] = NLayerDiscriminator( ndf, n_layers, downsampling_factor ) self.downsample = nn.AvgPool1d(4, stride=2, padding=1, count_include_pad=False) self.apply(weights_init)
Example #10
Source File: imdb.py From pytorch-dp with Apache License 2.0 | 5 votes |
def __init__(self, vocab_size: int): super().__init__() # Embedding dimension: vocab_size + <unk>, <pad>, <eos>, <sos> self.emb = nn.Embedding(vocab_size + 4, 16) self.pool = nn.AvgPool1d(256) self.fc1 = nn.Linear(16, 16) self.fc2 = nn.Linear(16, 2)
Example #11
Source File: convolution.py From biva-pytorch with MIT License | 5 votes |
def __init__(self, input_shape, output_shape, residual=True): """ args: input_shape (tuple): input module shape x output_shape (tuple): output module shape y=f(x) residual (bool): apply residual conenction y' = y+x = f(x)+x """ super().__init__() self.residual = residual self.input_shape = input_shape self.output_shape = output_shape is_text = len(input_shape) == 3 # residual: features if residual and self.output_shape[1] < self.input_shape[1]: pad = int(self.output_shape[1]) - int(self.input_shape[1]) self.redidual_padding = [0, 0, 0, pad] if is_text else [0, 0, 0, 0, 0, pad] elif residual and self.output_shape[1] > self.input_shape[1]: pad = int(self.output_shape[1]) - int(self.input_shape[1]) self.redidual_padding = [0, 0, 0, pad] if is_text else [0, 0, 0, 0, 0, pad] warnings.warn("The input has more feature maps than the output. There will be no residual connection for this layer.") self.residual = False else: self.redidual_padding = None # residual: dimension if residual and list(output_shape)[2:] < list(input_shape)[2:]: pool_obj = nn.AvgPool1d if len(output_shape[2:]) == 1 else nn.AvgPool2d stride = tuple((np.asarray(input_shape)[2:] // np.asarray(output_shape)[2:]).tolist()) self.residual_op = PaddedConv(input_shape, pool_obj(3, stride=stride)) elif residual and list(output_shape)[2:] > list(input_shape)[2:]: warnings.warn( "The height and width of the output are larger than the input. There will be no residual connection for this layer.") # self.residual_op = nn.UpsamplingBilinear2d(size=self.output_shape[2:]) self.residual = False else: self.residual_op = None
Example #12
Source File: co_pacrr.py From transformer-kernel-ranking with Apache License 2.0 | 5 votes |
def __init__(self, unified_query_length:int, unified_document_length:int, max_conv_kernel_size: int, # 2 to n conv_output_size: int, # conv output channels kmax_pooling_size: int): # per query k-max pooling super(CO_PACRR,self).__init__() self.cosine_module = CosineMatrixAttention() self.unified_query_length = unified_query_length self.unified_document_length = unified_document_length self.convolutions = [] for i in range(2, max_conv_kernel_size + 1): self.convolutions.append( nn.Sequential( nn.ConstantPad2d((0,i - 1,0, i - 1), 0), # this outputs [batch,1,unified_query_length + i - 1 ,unified_document_length + i - 1] nn.Conv2d(kernel_size=i, in_channels=1, out_channels=conv_output_size), # this outputs [batch,32,unified_query_length,unified_document_length] nn.MaxPool3d(kernel_size=(conv_output_size,1,1)) # this outputs [batch,1,unified_query_length,unified_document_length] )) self.convolutions = nn.ModuleList(self.convolutions) # register conv as part of the model context_pool_size = 6 self.doc_context_pool = nn.Sequential( nn.ConstantPad1d((0,context_pool_size - 1),0), nn.AvgPool1d(kernel_size=context_pool_size,stride=1)) self.masked_softmax = MaskedSoftmax() self.kmax_pooling_size = kmax_pooling_size kmax_pooling_view_percent = [0.25,0.5,0.75,1] self.kmax_pooling_views = [int(unified_document_length * x) for x in kmax_pooling_view_percent] self.dense = nn.Linear(len(self.kmax_pooling_views) * 2 * kmax_pooling_size * unified_query_length * max_conv_kernel_size, out_features=100, bias=True) self.dense2 = nn.Linear(100, out_features=10, bias=True) self.dense3 = nn.Linear(10, out_features=1, bias=False)
Example #13
Source File: model.py From AI-writer_Data2Doc with Apache License 2.0 | 5 votes |
def __init__(self, hidden_size, embedding_layer, level='local'): super(EncoderLIN, self).__init__() self.level = level self.hidden_size = hidden_size if self.level == 'local': self.embedding = embedding_layer self.avgpool = nn.AvgPool1d(3, stride=2, padding=1)
Example #14
Source File: jasper.py From NeMo with Apache License 2.0 | 5 votes |
def __init__( self, channels: int, reduction_ratio: int, context_window: int = -1, interpolation_mode: str = 'nearest', activation: Optional[Callable] = None, ): """ Squeeze-and-Excitation sub-module. Args: channels: Input number of channels. reduction_ratio: Reduction ratio for "squeeze" layer. context_window: Integer number of timesteps that the context should be computed over, using stride 1 average pooling. If value < 1, then global context is computed. interpolation_mode: Interpolation mode of timestep dimension. Used only if context window is > 1. The modes available for resizing are: `nearest`, `linear` (3D-only), `bilinear`, `area` activation: Intermediate activation function used. Must be a callable activation function. """ super(SqueezeExcite, self).__init__() self.context_window = int(context_window) self.interpolation_mode = interpolation_mode if self.context_window <= 0: self.pool = nn.AdaptiveAvgPool1d(1) # context window = T else: self.pool = nn.AvgPool1d(self.context_window, stride=1) if activation is None: activation = nn.ReLU(inplace=True) self.fc = nn.Sequential( nn.Linear(channels, channels // reduction_ratio, bias=False), activation, nn.Linear(channels // reduction_ratio, channels, bias=False), )
Example #15
Source File: NeuralStyleTransfer.py From Neural-Style-Transfer-Audio with MIT License | 5 votes |
def __init__(self): super(CNNModel, self).__init__() self.cnn1 = nn.Conv1d(in_channels=1025, out_channels=4096, kernel_size=3, stride=1, padding=1) #self.nl1 = nn.ReLU() #self.pool1 = nn.AvgPool1d(kernel_size=5) #self.fc1 = nn.Linear(4096*2500,2**5) #self.nl3 = nn.ReLU() #self.fc2 = nn.Linear(2**10,2**5)
Example #16
Source File: avg_pool.py From OpenNRE with MIT License | 5 votes |
def __init__(self, kernel_size, segment_num=None): """ Args: input_size: dimention of input embedding kernel_size: kernel_size for CNN padding: padding for CNN hidden_size: hidden size """ super().__init__() self.segment_num = segment_num if self.segment_num != None: self.mask_embedding = nn.Embedding(segment_num + 1, segment_num) self.mask_embedding.weight.data.copy_(torch.FloatTensor(np.concatenate([np.zeros(segment_num), np.identity(segment_num)], axis = 0))) self.mask_embedding.weight.requires_grad = False self.pool = nn.AvgPool1d(kernel_size)
Example #17
Source File: Pooling1D.py From NeuronBlocks with MIT License | 5 votes |
def __init__(self, layer_conf): super(Pooling1D, self).__init__(layer_conf) self.pool = None if layer_conf.pool_type == "max": self.pool = nn.MaxPool1d(kernel_size=layer_conf.window_size, stride=layer_conf.stride, padding=layer_conf.padding) elif layer_conf.pool_type == "mean": self.pool = nn.AvgPool1d(kernel_size=layer_conf.window_size, stride=layer_conf.stride, padding=layer_conf.padding)
Example #18
Source File: ops.py From nni with MIT License | 5 votes |
def __init__(self, kernal_size, pre_mask, post_mask): super(AvgPool, self).__init__() self.avg_pool = nn.AvgPool1d(kernal_size, 1, padding=(kernal_size - 1) // 2) self.pre_mask = pre_mask self.post_mask = post_mask self.mask_opt = Mask()
Example #19
Source File: bc.py From VQA_ReGAT with MIT License | 5 votes |
def __init__(self, v_dim, q_dim, h_dim, h_out, act='ReLU', dropout=[.2, .5], k=3): super(BCNet, self).__init__() self.c = 32 self.k = k self.v_dim = v_dim self.q_dim = q_dim self.h_dim = h_dim self.h_out = h_out self.v_net = FCNet([v_dim, h_dim * self.k], act=act, dropout=dropout[0]) self.q_net = FCNet([q_dim, h_dim * self.k], act=act, dropout=dropout[0]) self.dropout = nn.Dropout(dropout[1]) # attention if 1 < k: self.p_net = nn.AvgPool1d(self.k, stride=self.k) if h_out is None: pass elif h_out <= self.c: self.h_mat = nn.Parameter( torch.Tensor(1, h_out, 1, h_dim * self.k).normal_()) self.h_bias = nn.Parameter( torch.Tensor(1, h_out, 1, 1).normal_()) else: self.h_net = weight_norm( nn.Linear(h_dim * self.k, h_out), dim=None)
Example #20
Source File: model.py From Multilevel_Wavelet_Decomposition_Network_Pytorch with Apache License 2.0 | 5 votes |
def __init__(self,seq_len, hidden_size,output_size): super(Wavelet_LSTM,self).__init__() self.seq_len = seq_len self.hidden_size = hidden_size self.output_size = output_size self.mWDN1_H = nn.Linear(seq_len,seq_len) self.mWDN1_L = nn.Linear(seq_len,seq_len) self.mWDN2_H = nn.Linear(int(seq_len/2),int(seq_len/2)) self.mWDN2_L = nn.Linear(int(seq_len/2),int(seq_len/2)) self.a_to_x = nn.AvgPool1d(2) self.sigmoid = nn.Sigmoid() self.lstm_xh1 = nn.LSTM(1,hidden_size,batch_first=True) self.lstm_xh2 = nn.LSTM(1,hidden_size,batch_first=True) self.lstm_xl2 = nn.LSTM(1,hidden_size,batch_first=True) self.output = nn.Linear(hidden_size,output_size) self.l_filter = [-0.0106,0.0329,0.0308,-0.187,-0.028,0.6309,0.7148,0.2304] self.h_filter = [-0.2304,0.7148,-0.6309,-0.028,0.187,0.0308,-0.0329,-0.0106] self.cmp_mWDN1_H = ToVariable(self.create_W(seq_len,False,is_comp=True)) self.cmp_mWDN1_L = ToVariable(self.create_W(seq_len,True,is_comp=True)) self.cmp_mWDN2_H = ToVariable(self.create_W(int(seq_len/2),False,is_comp=True)) self.cmp_mWDN2_L = ToVariable(self.create_W(int(seq_len/2),True,is_comp=True)) self.mWDN1_H.weight = torch.nn.Parameter(ToVariable(self.create_W(seq_len,False))) self.mWDN1_L.weight = torch.nn.Parameter(ToVariable(self.create_W(seq_len,True))) self.mWDN2_H.weight = torch.nn.Parameter(ToVariable(self.create_W(int(seq_len/2),False))) self.mWDN2_L.weight = torch.nn.Parameter(ToVariable(self.create_W(int(seq_len/2),True)))
Example #21
Source File: test_numerical.py From coremltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_avg_pool1d(self, input_shape, kernel_size, stride, pad, include_pad): if pad > kernel_size / 2: # Because this test is xfail, we have to fail rather than # just return here, otherwise these test cases unexpectedly pass. # This can be changed to `return` once the above radar # is fixed and the test is no longer xfail. raise ValueError("pad must be less than half the kernel size") model = nn.AvgPool1d(kernel_size, stride, pad, False, include_pad) run_numerical_test(input_shape, model)
Example #22
Source File: factories.py From MONAI with Apache License 2.0 | 5 votes |
def avgpooling_factory(dim): types = [nn.AvgPool1d, nn.AvgPool2d, nn.AvgPool3d] return types[dim - 1]
Example #23
Source File: pooling.py From fastNLP with Apache License 2.0 | 5 votes |
def forward(self, x): r""" :param torch.Tensor x: [N, C, L] 初始tensor :return: torch.Tensor x: [N, C] avg pool后的结果 """ # [N,C,L] -> [N,C] kernel_size = x.size(2) pooling = nn.AvgPool1d( kernel_size=kernel_size, stride=self.stride, padding=self.padding) x = pooling(x) return x.squeeze(dim=-1)
Example #24
Source File: mfb.py From openvqa with Apache License 2.0 | 5 votes |
def __init__(self, __C, img_feat_size, ques_feat_size, is_first): super(MFB, self).__init__() self.__C = __C self.is_first = is_first self.proj_i = nn.Linear(img_feat_size, __C.MFB_K * __C.MFB_O) self.proj_q = nn.Linear(ques_feat_size, __C.MFB_K * __C.MFB_O) self.dropout = nn.Dropout(__C.DROPOUT_R) self.pool = nn.AvgPool1d(__C.MFB_K, stride=__C.MFB_K)
Example #25
Source File: networks.py From MeshCNN with MIT License | 5 votes |
def __init__(self, pools, convs, fcs=None, blocks=0, global_pool=None): super(MeshEncoder, self).__init__() self.fcs = None self.convs = [] for i in range(len(convs) - 1): if i + 1 < len(pools): pool = pools[i + 1] else: pool = 0 self.convs.append(DownConv(convs[i], convs[i + 1], blocks=blocks, pool=pool)) self.global_pool = None if fcs is not None: self.fcs = [] self.fcs_bn = [] last_length = convs[-1] if global_pool is not None: if global_pool == 'max': self.global_pool = nn.MaxPool1d(pools[-1]) elif global_pool == 'avg': self.global_pool = nn.AvgPool1d(pools[-1]) else: assert False, 'global_pool %s is not defined' % global_pool else: last_length *= pools[-1] if fcs[0] == last_length: fcs = fcs[1:] for length in fcs: self.fcs.append(nn.Linear(last_length, length)) self.fcs_bn.append(nn.InstanceNorm1d(length)) last_length = length self.fcs = nn.ModuleList(self.fcs) self.fcs_bn = nn.ModuleList(self.fcs_bn) self.convs = nn.ModuleList(self.convs) reset_params(self)
Example #26
Source File: networks.py From 2D-Motion-Retargeting with MIT License | 5 votes |
def __init__(self, mot_en_channels, body_en_channels, view_en_channels, de_channels): super(AutoEncoder3x, self).__init__() assert mot_en_channels[0] == de_channels[-1] and \ mot_en_channels[-1] + body_en_channels[-1] + view_en_channels[-1] == de_channels[0] self.mot_encoder = Encoder(mot_en_channels) self.body_encoder = Encoder(body_en_channels, kernel_size=7, global_pool=F.max_pool1d, convpool=nn.MaxPool1d, compress=True) self.view_encoder = Encoder(view_en_channels, kernel_size=7, global_pool=F.avg_pool1d, convpool=nn.AvgPool1d, compress=True) self.decoder = Decoder(de_channels)
Example #27
Source File: multi_scale_ori.py From Multi-Scale-1D-ResNet with MIT License | 4 votes |
def __init__(self, input_channel, layers=[1, 1, 1, 1], num_classes=10): self.inplanes3 = 64 self.inplanes5 = 64 self.inplanes7 = 64 super(MSResNet, self).__init__() self.conv1 = nn.Conv1d(input_channel, 64, kernel_size=7, stride=2, padding=3, bias=False) self.bn1 = nn.BatchNorm1d(64) self.relu = nn.ReLU(inplace=True) self.maxpool = nn.MaxPool1d(kernel_size=3, stride=2, padding=1) self.layer3x3_1 = self._make_layer3(BasicBlock3x3, 64, layers[0], stride=2) self.layer3x3_2 = self._make_layer3(BasicBlock3x3, 128, layers[1], stride=2) self.layer3x3_3 = self._make_layer3(BasicBlock3x3, 256, layers[2], stride=2) # self.layer3x3_4 = self._make_layer3(BasicBlock3x3, 512, layers[3], stride=2) # maxplooing kernel size: 16, 11, 6 self.maxpool3 = nn.AvgPool1d(kernel_size=16, stride=1, padding=0) self.layer5x5_1 = self._make_layer5(BasicBlock5x5, 64, layers[0], stride=2) self.layer5x5_2 = self._make_layer5(BasicBlock5x5, 128, layers[1], stride=2) self.layer5x5_3 = self._make_layer5(BasicBlock5x5, 256, layers[2], stride=2) # self.layer5x5_4 = self._make_layer5(BasicBlock5x5, 512, layers[3], stride=2) self.maxpool5 = nn.AvgPool1d(kernel_size=11, stride=1, padding=0) self.layer7x7_1 = self._make_layer7(BasicBlock7x7, 64, layers[0], stride=2) self.layer7x7_2 = self._make_layer7(BasicBlock7x7, 128, layers[1], stride=2) self.layer7x7_3 = self._make_layer7(BasicBlock7x7, 256, layers[2], stride=2) # self.layer7x7_4 = self._make_layer7(BasicBlock7x7, 512, layers[3], stride=2) self.maxpool7 = nn.AvgPool1d(kernel_size=6, stride=1, padding=0) # self.drop = nn.Dropout(p=0.2) self.fc = nn.Linear(256*3, num_classes) # todo: modify the initialization # for m in self.modules(): # if isinstance(m, nn.Conv1d): # n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels # m.weight.data.normal_(0, math.sqrt(2. / n)) # elif isinstance(m, nn.BatchNorm1d): # m.weight.data.fill_(1) # m.bias.data.zero_()
Example #28
Source File: multi_scale_one3x3.py From Multi-Scale-1D-ResNet with MIT License | 4 votes |
def __init__(self, input_channel, layers=[1, 1, 1, 1], num_classes=10): self.inplanes3_1 = 64 self.inplanes3_2 = 64 self.inplanes3_3 = 64 super(MSResNet, self).__init__() self.conv1 = nn.Conv1d(input_channel, 64, kernel_size=7, stride=2, padding=3, bias=False) self.bn1 = nn.BatchNorm1d(64) self.relu = nn.ReLU(inplace=True) self.maxpool = nn.MaxPool1d(kernel_size=3, stride=2, padding=1) self.layer3x3_11 = self._make_layer3_1(BasicBlock3x3_1, 64, layers[0], stride=2) self.layer3x3_12 = self._make_layer3_1(BasicBlock3x3_1, 128, layers[1], stride=2) self.layer3x3_13 = self._make_layer3_1(BasicBlock3x3_1, 256, layers[2], stride=2) # self.layer3x3_4 = self._make_layer3(BasicBlock3x3, 512, layers[3], stride=2) # maxplooing kernel size: 16, 11, 6 self.maxpool3_1 = nn.AvgPool1d(kernel_size=16, stride=1, padding=0) self.layer3x3_21 = self._make_layer3_2(BasicBlock3x3_2, 64, layers[0], stride=2) self.layer3x3_22 = self._make_layer3_2(BasicBlock3x3_2, 128, layers[1], stride=2) self.layer3x3_23 = self._make_layer3_2(BasicBlock3x3_2, 256, layers[2], stride=2) # self.layer3x3_4 = self._make_layer3(BasicBlock3x3, 512, layers[3], stride=2) # maxplooing kernel size: 16, 11, 6 self.maxpool3_2 = nn.AvgPool1d(kernel_size=16, stride=1, padding=0) self.layer3x3_31 = self._make_layer3_3(BasicBlock3x3_3, 64, layers[0], stride=2) self.layer3x3_32 = self._make_layer3_3(BasicBlock3x3_3, 128, layers[1], stride=2) self.layer3x3_33 = self._make_layer3_3(BasicBlock3x3_3, 256, layers[2], stride=2) # self.layer3x3_4 = self._make_layer3(BasicBlock3x3, 512, layers[3], stride=2) # maxplooing kernel size: 16, 11, 6 self.maxpool3_3 = nn.AvgPool1d(kernel_size=16, stride=1, padding=0) # self.drop = nn.Dropout(p=0.2) self.fc = nn.Linear(256*3, num_classes) # todo: modify the initialization # for m in self.modules(): # if isinstance(m, nn.Conv1d): # n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels # m.weight.data.normal_(0, math.sqrt(2. / n)) # elif isinstance(m, nn.BatchNorm1d): # m.weight.data.fill_(1) # m.bias.data.zero_()
Example #29
Source File: multi_scale_ori.py From Multi-Scale-1D-ResNet with MIT License | 4 votes |
def __init__(self, input_channel, layers=[1, 1, 1, 1], num_classes=10): self.inplanes3 = 64 self.inplanes5 = 64 self.inplanes7 = 64 super(MSResNet, self).__init__() self.conv1 = nn.Conv1d(input_channel, 64, kernel_size=7, stride=2, padding=3, bias=False) self.bn1 = nn.BatchNorm1d(64) self.relu = nn.ReLU(inplace=True) self.maxpool = nn.MaxPool1d(kernel_size=3, stride=2, padding=1) self.layer3x3_1 = self._make_layer3(BasicBlock3x3, 64, layers[0], stride=2) self.layer3x3_2 = self._make_layer3(BasicBlock3x3, 128, layers[1], stride=2) self.layer3x3_3 = self._make_layer3(BasicBlock3x3, 256, layers[2], stride=2) # self.layer3x3_4 = self._make_layer3(BasicBlock3x3, 512, layers[3], stride=2) # maxplooing kernel size: 16, 11, 6 self.maxpool3 = nn.AvgPool1d(kernel_size=16, stride=1, padding=0) self.layer5x5_1 = self._make_layer5(BasicBlock5x5, 64, layers[0], stride=2) self.layer5x5_2 = self._make_layer5(BasicBlock5x5, 128, layers[1], stride=2) self.layer5x5_3 = self._make_layer5(BasicBlock5x5, 256, layers[2], stride=2) # self.layer5x5_4 = self._make_layer5(BasicBlock5x5, 512, layers[3], stride=2) self.maxpool5 = nn.AvgPool1d(kernel_size=11, stride=1, padding=0) self.layer7x7_1 = self._make_layer7(BasicBlock7x7, 64, layers[0], stride=2) self.layer7x7_2 = self._make_layer7(BasicBlock7x7, 128, layers[1], stride=2) self.layer7x7_3 = self._make_layer7(BasicBlock7x7, 256, layers[2], stride=2) # self.layer7x7_4 = self._make_layer7(BasicBlock7x7, 512, layers[3], stride=2) self.maxpool7 = nn.AvgPool1d(kernel_size=6, stride=1, padding=0) # self.drop = nn.Dropout(p=0.2) self.fc = nn.Linear(256*3, num_classes) # todo: modify the initialization # for m in self.modules(): # if isinstance(m, nn.Conv1d): # n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels # m.weight.data.normal_(0, math.sqrt(2. / n)) # elif isinstance(m, nn.BatchNorm1d): # m.weight.data.fill_(1) # m.bias.data.zero_()
Example #30
Source File: multi_scale_one5x5.py From Multi-Scale-1D-ResNet with MIT License | 4 votes |
def __init__(self, input_channel, layers=[1, 1, 1, 1], num_classes=10): self.inplanes5_1 = 64 self.inplanes5_2 = 64 self.inplanes5_3 = 64 super(MSResNet, self).__init__() self.conv1 = nn.Conv1d(input_channel, 64, kernel_size=7, stride=2, padding=3, bias=False) self.bn1 = nn.BatchNorm1d(64) self.relu = nn.ReLU(inplace=True) self.maxpool = nn.MaxPool1d(kernel_size=3, stride=2, padding=1) self.layer5x5_11 = self._make_layer5_1(BasicBlock5x5_1, 64, layers[0], stride=2) self.layer5x5_12 = self._make_layer5_1(BasicBlock5x5_1, 128, layers[1], stride=2) self.layer5x5_13 = self._make_layer5_1(BasicBlock5x5_1, 256, layers[2], stride=2) # self.layer3x3_4 = self._make_layer3(BasicBlock3x3, 512, layers[3], stride=2) # maxplooing kernel size: 16, 11, 6 self.maxpool5_1 = nn.AvgPool1d(kernel_size=11, stride=1, padding=0) self.layer5x5_21 = self._make_layer5_2(BasicBlock5x5_2, 64, layers[0], stride=2) self.layer5x5_22 = self._make_layer5_2(BasicBlock5x5_2, 128, layers[1], stride=2) self.layer5x5_23 = self._make_layer5_2(BasicBlock5x5_2, 256, layers[2], stride=2) # self.layer3x3_4 = self._make_layer3(BasicBlock3x3, 512, layers[3], stride=2) # maxplooing kernel size: 16, 11, 6 self.maxpool5_2 = nn.AvgPool1d(kernel_size=11, stride=1, padding=0) self.layer5x5_31 = self._make_layer5_3(BasicBlock5x5_3, 64, layers[0], stride=2) self.layer5x5_32 = self._make_layer5_3(BasicBlock5x5_3, 128, layers[1], stride=2) self.layer5x5_33 = self._make_layer5_3(BasicBlock5x5_3, 256, layers[2], stride=2) # self.layer3x3_4 = self._make_layer3(BasicBlock3x3, 512, layers[3], stride=2) # maxplooing kernel size: 16, 11, 6 self.maxpool5_3 = nn.AvgPool1d(kernel_size=11, stride=1, padding=0) # self.drop = nn.Dropout(p=0.2) self.fc = nn.Linear(256*3, num_classes) # todo: modify the initialization # for m in self.modules(): # if isinstance(m, nn.Conv1d): # n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels # m.weight.data.normal_(0, math.sqrt(2. / n)) # elif isinstance(m, nn.BatchNorm1d): # m.weight.data.fill_(1) # m.bias.data.zero_()