當前位置: 首頁>>代碼示例>>Python>>正文


Python nn.Conv1d方法代碼示例

本文整理匯總了Python中torch.nn.Conv1d方法的典型用法代碼示例。如果您正苦於以下問題:Python nn.Conv1d方法的具體用法?Python nn.Conv1d怎麽用?Python nn.Conv1d使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在torch.nn的用法示例。


在下文中一共展示了nn.Conv1d方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Conv1d [as 別名]
def __init__(self, vocab_size, word_dim, embed_size, use_abs=False, glove_path='data/glove.pkl'):
        super(EncoderTextCNN, self).__init__()
        self.use_abs = use_abs
        self.embed_size = embed_size

        # word embedding
        self.embed = nn.Embedding(vocab_size, word_dim-300, padding_idx=0)  # 0 for <pad>
        _, embed_weight = pickle.load(open(glove_path, 'rb'))
        self.glove = Variable(torch.cuda.FloatTensor(embed_weight), requires_grad=False)

        channel_num = embed_size // 4
        self.conv2 = nn.Conv1d(word_dim, channel_num, 2)
        self.conv3 = nn.Conv1d(word_dim, channel_num, 3)
        self.conv4 = nn.Conv1d(word_dim, channel_num, 4)
        self.conv5 = nn.Conv1d(word_dim, channel_num, 5)
        self.drop = nn.Dropout(p=0.5)
        self.relu = nn.ReLU()

#        self.mlp = nn.Linear(embed_size, embed_size)

        self.init_weights() 
開發者ID:ExplorerFreda,項目名稱:VSE-C,代碼行數:23,代碼來源:model.py

示例2: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Conv1d [as 別名]
def __init__(self,
                 n_res_block: int = 10,
                 n_freq: int = 128,
                 n_hidden: int = 128,
                 n_output: int = 128,
                 kernel_size: int = 5) -> None:
        super().__init__()

        ResBlocks = [_ResBlock(n_hidden) for _ in range(n_res_block)]

        self.melresnet_model = nn.Sequential(
            nn.Conv1d(in_channels=n_freq, out_channels=n_hidden, kernel_size=kernel_size, bias=False),
            nn.BatchNorm1d(n_hidden),
            nn.ReLU(inplace=True),
            *ResBlocks,
            nn.Conv1d(in_channels=n_hidden, out_channels=n_output, kernel_size=1)
        ) 
開發者ID:pytorch,項目名稱:audio,代碼行數:19,代碼來源:_wavernn.py

示例3: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Conv1d [as 別名]
def __init__(self, in_ch, out_ch, k, dim=1, relu=True):
        """
        :param in_ch: input hidden dimension size
        :param out_ch: output hidden dimension size
        :param k: kernel size
        :param dim: default 1. 1D conv or 2D conv
        """
        super(DepthwiseSeparableConv, self).__init__()
        self.relu = relu
        if dim == 1:
            self.depthwise_conv = nn.Conv1d(in_channels=in_ch, out_channels=in_ch,
                                            kernel_size=k, groups=in_ch, padding=k//2)
            self.pointwise_conv = nn.Conv1d(in_channels=in_ch, out_channels=out_ch,
                                            kernel_size=1, padding=0)
        elif dim == 2:
            self.depthwise_conv = nn.Conv2d(in_channels=in_ch, out_channels=in_ch,
                                            kernel_size=k, groups=in_ch, padding=k//2)
            self.pointwise_conv = nn.Conv2d(in_channels=in_ch, out_channels=out_ch,
                                            kernel_size=1, padding=0)
        else:
            raise Exception("Incorrect dimension!") 
開發者ID:jayleicn,項目名稱:TVQAplus,代碼行數:23,代碼來源:cnn.py

示例4: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Conv1d [as 別名]
def __init__(self, dataset, gconv=GCNConv, latent_dim=[32, 32, 32, 1], k=30, 
                 regression=False, adj_dropout=0.2, force_undirected=False):
        super(DGCNN, self).__init__(
            dataset, gconv, latent_dim, regression, adj_dropout, force_undirected
        )
        if k < 1:  # transform percentile to number
            node_nums = sorted([g.num_nodes for g in dataset])
            k = node_nums[int(math.ceil(k * len(node_nums)))-1]
            k = max(10, k)  # no smaller than 10
        self.k = int(k)
        print('k used in sortpooling is:', self.k)
        conv1d_channels = [16, 32]
        conv1d_activation = nn.ReLU()
        self.total_latent_dim = sum(latent_dim)
        conv1d_kws = [self.total_latent_dim, 5]
        self.conv1d_params1 = Conv1d(1, conv1d_channels[0], conv1d_kws[0], conv1d_kws[0])
        self.maxpool1d = nn.MaxPool1d(2, 2)
        self.conv1d_params2 = Conv1d(conv1d_channels[0], conv1d_channels[1], conv1d_kws[1], 1)
        dense_dim = int((k - 2) / 2 + 1)
        self.dense_dim = (dense_dim - conv1d_kws[1] + 1) * conv1d_channels[1]
        self.lin1 = Linear(self.dense_dim, 128) 
開發者ID:muhanzhang,項目名稱:IGMC,代碼行數:23,代碼來源:models.py

示例5: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Conv1d [as 別名]
def __init__(self, inChannels, outChannels, kernelSize = 1, stride = 1, padding = 0):
		super(NewConvBnRelu3D, self).__init__()
		self.inChannels = inChannels
		self.outChannels = outChannels
		self.kernelSize = kernelSize
		self.stride = stride
		self.padding = padding
		self.relu = nn.LeakyReLU()
		self.bn = nn.BatchNorm3d(self.inChannels)
		if (kernelSize == 1):
			self.conv = nn.Conv1d(self.inChannels, self.outChannels, self.kernelSize, self.stride, self.padding)
		elif (isinstance(kernelSize, int)):
			self.conv = nn.Conv3d(self.inChannels, self.outChannels, self.kernelSize, self.stride, self.padding)	
		elif (kernelSize[0] == 1):
			self.conv = nn.Conv2d(self.inChannels, self.outChannels, self.kernelSize[1:], self.stride, self.padding)
		else :
			self.conv = nn.Conv3d(self.inChannels, self.outChannels, self.kernelSize, self.stride, self.padding) 
開發者ID:Naman-ntc,項目名稱:3D-HourGlass-Network,代碼行數:19,代碼來源:newLayers3D.py

示例6: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Conv1d [as 別名]
def __init__(self, channels, kernel_size=7):
        super(Decoder, self).__init__()

        model = []
        pad = (kernel_size - 1) // 2
        acti = nn.LeakyReLU(0.2)

        for i in range(len(channels) - 1):
            model.append(nn.Upsample(scale_factor=2, mode='nearest'))
            model.append(nn.ReflectionPad1d(pad))
            model.append(nn.Conv1d(channels[i], channels[i + 1],
                                            kernel_size=kernel_size, stride=1))
            if i == 0 or i == 1:
                model.append(nn.Dropout(p=0.2))
            if not i == len(channels) - 2:
                model.append(acti)          # whether to add tanh a last?
                #model.append(nn.Dropout(p=0.2))

        self.model = nn.Sequential(*model) 
開發者ID:ChrisWu1997,項目名稱:2D-Motion-Retargeting,代碼行數:21,代碼來源:networks.py

示例7: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Conv1d [as 別名]
def __init__(self, input_channel, channels, output_channel):
        super(VoiceEmbedNet, self).__init__()
        self.model = nn.Sequential(
            nn.Conv1d(input_channel, channels[0], 3, 2, 1, bias=False),
            nn.BatchNorm1d(channels[0], affine=True),
            nn.ReLU(inplace=True),
            nn.Conv1d(channels[0], channels[1], 3, 2, 1, bias=False),
            nn.BatchNorm1d(channels[1], affine=True),
            nn.ReLU(inplace=True),
            nn.Conv1d(channels[1], channels[2], 3, 2, 1, bias=False),
            nn.BatchNorm1d(channels[2], affine=True),
            nn.ReLU(inplace=True),
            nn.Conv1d(channels[2], channels[3], 3, 2, 1, bias=False),
            nn.BatchNorm1d(channels[3], affine=True),
            nn.ReLU(inplace=True),
            nn.Conv1d(channels[3], output_channel, 3, 2, 1, bias=True),
        ) 
開發者ID:cmu-mlsp,項目名稱:reconstructing_faces_from_voices,代碼行數:19,代碼來源:network.py

示例8: net_init

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Conv1d [as 別名]
def net_init(net):
    for m in net.modules():
        if isinstance(m, nn.Linear):
            m.weight.data = fanin_init(m.weight.data.size())
        elif isinstance(m, nn.Conv3d):
            n = m.kernel_size[0] * m.kernel_size[1] * m.kernel_size[2] * m.out_channels
            m.weight.data.normal_(0, np.sqrt(2.0 / n))
        elif isinstance(m, nn.Conv2d):
            n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
            m.weight.data.normal_(0, np.sqrt(2.0 / n))
        elif isinstance(m, nn.Conv1d):
            n = m.kernel_size[0] * m.out_channels
            m.weight.data.normal_(0, np.sqrt(2.0 / n))
        elif isinstance(m, nn.BatchNorm3d):
            m.weight.data.fill_(1)
            m.bias.data.zero_()
        elif isinstance(m, nn.BatchNorm2d):
            m.weight.data.fill_(1)
            m.bias.data.zero_()
        elif isinstance(m, nn.BatchNorm1d):
            m.weight.data.fill_(1)
            m.bias.data.zero_()

# corr1d 
開發者ID:wyf2017,項目名稱:DSMnet,代碼行數:26,代碼來源:util_conv.py

示例9: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Conv1d [as 別名]
def __init__(self, input_shape, kernel_size, dilation, name):
        super(DepthwiseConv1DLayer, self).__init__()

        assert len(input_shape) == 5

        self.kernel_size = kernel_size
        self.dilation = dilation
        self._name = name

        n_channels = input_shape[1]
        n_timesteps = input_shape[2]

        # TODO: support using different dilation rates.
        padding = pytorch_utils.calc_padding_1d(n_timesteps, kernel_size)
        self.depthwise_conv1d = Conv1d(n_channels, n_channels, kernel_size, dilation=dilation, groups=n_channels, padding=padding)
        self.depthwise_conv1d._name = name 
開發者ID:CMU-CREATE-Lab,項目名稱:deep-smoke-machine,代碼行數:18,代碼來源:layers_pytorch.py

示例10: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Conv1d [as 別名]
def __init__(self, input_dim, hidden_dim, leaf_transformation, trans_hidden_dim, dropout_prob):
        super().__init__()
        self.leaf_transformation = leaf_transformation
        if leaf_transformation == BinaryTreeBasedModule.no_transformation:
            self.linear = nn.Linear(in_features=input_dim, out_features=2 * hidden_dim)
        elif leaf_transformation == BinaryTreeBasedModule.lstm_transformation:
            self.lstm = LstmRnn(input_dim, trans_hidden_dim)
            self.linear = nn.Linear(in_features=trans_hidden_dim, out_features=2 * hidden_dim)
        elif leaf_transformation == BinaryTreeBasedModule.bi_lstm_transformation:
            self.lstm_f = LstmRnn(input_dim, trans_hidden_dim)
            self.lstm_b = LstmRnn(input_dim, trans_hidden_dim)
            self.linear = nn.Linear(in_features=2 * trans_hidden_dim, out_features=2 * hidden_dim)
        elif leaf_transformation == BinaryTreeBasedModule.conv_transformation:
            self.conv1 = nn.Conv1d(input_dim, trans_hidden_dim, kernel_size=5, padding=2)
            self.conv2 = nn.Conv1d(trans_hidden_dim, trans_hidden_dim, kernel_size=3, padding=1)
            self.linear = nn.Linear(in_features=trans_hidden_dim, out_features=2 * hidden_dim)
        else:
            raise ValueError(f'"{leaf_transformation}" is not in the list of possible transformations!')
        self.tree_lstm_cell = BinaryTreeLstmCell(hidden_dim, dropout_prob)
        # TODO(serhii): I am not sure whether this is necessary to keep this.
        # It is not `self` because there can be an issue when overriding reset_parameters method in inherited classes.
        # When the inherited class calls super().__init__ self is an instance of the inherited class and thus base
        # reset_parameters method is not going to be called.
        BinaryTreeBasedModule.reset_parameters(self) 
開發者ID:facebookresearch,項目名稱:latent-treelstm,代碼行數:26,代碼來源:BinaryTreeBasedModule.py

示例11: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Conv1d [as 別名]
def __init__(self, num_classes, normal_channel=False):
        super(get_model, self).__init__()
        if normal_channel:
            additional_channel = 3
        else:
            additional_channel = 0
        self.normal_channel = normal_channel
        self.sa1 = PointNetSetAbstraction(npoint=512, radius=0.2, nsample=32, in_channel=6+additional_channel, mlp=[64, 64, 128], group_all=False)
        self.sa2 = PointNetSetAbstraction(npoint=128, radius=0.4, nsample=64, in_channel=128 + 3, mlp=[128, 128, 256], group_all=False)
        self.sa3 = PointNetSetAbstraction(npoint=None, radius=None, nsample=None, in_channel=256 + 3, mlp=[256, 512, 1024], group_all=True)
        self.fp3 = PointNetFeaturePropagation(in_channel=1280, mlp=[256, 256])
        self.fp2 = PointNetFeaturePropagation(in_channel=384, mlp=[256, 128])
        self.fp1 = PointNetFeaturePropagation(in_channel=128+16+6+additional_channel, mlp=[128, 128, 128])
        self.conv1 = nn.Conv1d(128, 128, 1)
        self.bn1 = nn.BatchNorm1d(128)
        self.drop1 = nn.Dropout(0.5)
        self.conv2 = nn.Conv1d(128, num_classes, 1) 
開發者ID:yanx27,項目名稱:Pointnet_Pointnet2_pytorch,代碼行數:19,代碼來源:pointnet2_part_seg_ssg.py

示例12: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Conv1d [as 別名]
def __init__(self, num_classes, normal_channel=False):
        super(get_model, self).__init__()
        if normal_channel:
            additional_channel = 3
        else:
            additional_channel = 0
        self.normal_channel = normal_channel
        self.sa1 = PointNetSetAbstractionMsg(512, [0.1, 0.2, 0.4], [32, 64, 128], 3+additional_channel, [[32, 32, 64], [64, 64, 128], [64, 96, 128]])
        self.sa2 = PointNetSetAbstractionMsg(128, [0.4,0.8], [64, 128], 128+128+64, [[128, 128, 256], [128, 196, 256]])
        self.sa3 = PointNetSetAbstraction(npoint=None, radius=None, nsample=None, in_channel=512 + 3, mlp=[256, 512, 1024], group_all=True)
        self.fp3 = PointNetFeaturePropagation(in_channel=1536, mlp=[256, 256])
        self.fp2 = PointNetFeaturePropagation(in_channel=576, mlp=[256, 128])
        self.fp1 = PointNetFeaturePropagation(in_channel=150+additional_channel, mlp=[128, 128])
        self.conv1 = nn.Conv1d(128, 128, 1)
        self.bn1 = nn.BatchNorm1d(128)
        self.drop1 = nn.Dropout(0.5)
        self.conv2 = nn.Conv1d(128, num_classes, 1) 
開發者ID:yanx27,項目名稱:Pointnet_Pointnet2_pytorch,代碼行數:19,代碼來源:pointnet2_part_seg_msg.py

示例13: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Conv1d [as 別名]
def __init__(self, ft_size=1024, hop_size=384):
        super(Analysis, self).__init__()

        # Parameters
        self.batch_size = None
        self.time_domain_samples = None
        self.sz = ft_size
        self.hop = hop_size
        self.half_N = int(self.sz/2. + 1)

        # Analysis 1D CNN
        self.conv_analysis_real = nn.Conv1d(1, self.sz, self.sz,
                                            padding=self.sz, stride=self.hop, bias=False)
        self.conv_analysis_imag = nn.Conv1d(1, self.sz, self.sz,
                                            padding=self.sz, stride=self.hop, bias=False)

        # Custom Initialization with Fourier matrix
        self.initialize() 
開發者ID:drscotthawley,項目名稱:signaltrain,代碼行數:20,代碼來源:cls_fe_dft.py

示例14: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Conv1d [as 別名]
def __init__(self, ft_size=1024, w_size=2048, hop_size=1024, shrink=False):
        super(Analysis, self).__init__()

        # Parameters
        self.batch_size = None
        self.time_domain_samples = None
        self.sz = ft_size
        self.wsz = w_size
        self.hop = hop_size

        # Analysis 1D CNN
        self.conv_analysis = nn.Conv1d(1, self.sz, self.wsz,
                                       padding=self.sz, stride=self.hop, bias=True)

        # Custom Initialization with Fourier matrix
        self.initialize() 
開發者ID:drscotthawley,項目名稱:signaltrain,代碼行數:18,代碼來源:cls_fe_dct_bases.py

示例15: __init__

# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Conv1d [as 別名]
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) 
開發者ID:santi-pdp,項目名稱:pase,代碼行數:25,代碼來源:modules.py


注:本文中的torch.nn.Conv1d方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。