示例#1
0
 def __init__(self,
              name_scope='PointNet2_MSG_Seg_',
              num_classes=16,
              num_parts=50,
              normal_channel=False):
     super(PointNet2_MSG_Seg, self).__init__()
     if normal_channel:
         additional_channel = 3
     else:
         additional_channel = 0
     self.num_classes = num_classes
     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_parts, 1)
示例#2
0
 def __init__(self, num_classes=10, max_points=1024):
     super(PointNet_Basic_Clas, self).__init__()
     self.mlp_1 = nn.Sequential(
         nn.Conv1D(3, 64, 1),
         nn.BatchNorm(64),
         nn.ReLU(),
         nn.Conv1D(64, 64, 1),
         nn.BatchNorm(64),
         nn.ReLU(),
     )
     self.mlp_2 = nn.Sequential(
         nn.Conv1D(64, 64, 1),
         nn.BatchNorm(64),
         nn.ReLU(),
         nn.Conv1D(64, 128, 1),
         nn.BatchNorm(128),
         nn.ReLU(),
         nn.Conv1D(128, max_points, 1),
         nn.BatchNorm(max_points),
         nn.ReLU(),
     )
     self.fc = self.fc = nn.Sequential(nn.Linear(1024, 512), nn.ReLU(),
                                       nn.Linear(512, 256), nn.ReLU(),
                                       nn.Dropout(p=0.7),
                                       nn.Linear(256, num_classes))
示例#3
0
    def __init__(self,
                 num_attention_heads,
                 attention_probs_dropout_prob,
                 cin,
                 q_groups=1,
                 k_groups=1,
                 v_groups=1):
        super().__init__()
        if cin % num_attention_heads != 0:
            raise ValueError(
                f"cin ({cin}) is not a multiple of the number of attention heads ({num_attention_heads})"
            )
        self.num_attention_heads = num_attention_heads
        self.attention_head_size = int(cin / num_attention_heads)
        self.all_head_size = self.num_attention_heads * self.attention_head_size

        self.query = nn.Conv1D(in_channels=cin,
                               out_channels=cin,
                               kernel_size=1,
                               groups=q_groups)
        self.key = nn.Conv1D(in_channels=cin,
                             out_channels=cin,
                             kernel_size=1,
                             groups=k_groups)
        self.value = nn.Conv1D(in_channels=cin,
                               out_channels=cin,
                               kernel_size=1,
                               groups=v_groups)

        self.dropout = nn.Dropout(attention_probs_dropout_prob)
        self.softmax = nn.Softmax(axis=-1)

        self.matmul_qk = MatMulWrapper()
        self.matmul_qkv = MatMulWrapper()
示例#4
0
    def __init__(self,
                 block,
                 layers,
                 num_filters,
                 feature_dim,
                 encoder_type='SAP',
                 n_mels=40,
                 log_input=True,
                 **kwargs):
        super(ResNetSE, self).__init__()

        print('Embedding size is %d, encoder %s.' %
              (feature_dim, encoder_type))

        self.inplanes = num_filters[0]
        self.encoder_type = encoder_type
        self.n_mels = n_mels
        self.log_input = log_input

        self.conv1 = nn.Conv2D(1,
                               num_filters[0],
                               kernel_size=3,
                               stride=1,
                               padding=1)
        self.relu = nn.ReLU()
        self.bn1 = nn.BatchNorm2D(num_filters[0])

        self.layer1 = self._make_layer(block, num_filters[0], layers[0])
        self.layer2 = self._make_layer(block,
                                       num_filters[1],
                                       layers[1],
                                       stride=(2, 2))
        self.layer3 = self._make_layer(block,
                                       num_filters[2],
                                       layers[2],
                                       stride=(2, 2))
        self.layer4 = self._make_layer(block,
                                       num_filters[3],
                                       layers[3],
                                       stride=(2, 2))

        outmap_size = int(self.n_mels / 8)

        self.attention = nn.Sequential(
            nn.Conv1D(num_filters[3] * outmap_size, 128, kernel_size=1),
            nn.ReLU(),
            nn.BatchNorm1D(128),
            nn.Conv1D(128, num_filters[3] * outmap_size, kernel_size=1),
            nn.Softmax(axis=2),
        )

        if self.encoder_type == "SAP":
            out_dim = num_filters[3] * outmap_size
        elif self.encoder_type == "ASP":
            out_dim = num_filters[3] * outmap_size * 2
        else:
            raise ValueError('Undefined encoder')

        self.fc = nn.Linear(out_dim, feature_dim)
示例#5
0
 def __init__(self, num_state, num_node, bias=False):
     super(GCN, self).__init__()
     self.conv1 = nn.Conv1D(num_node, num_node, kernel_size=1)
     self.relu = nn.ReLU()
     self.conv2 = nn.Conv1D(num_state,
                            num_state,
                            kernel_size=1,
                            bias_attr=bias)
示例#6
0
 def __init__(self, feature_channels=256, num_classes=50, max_points=1024):
     super(VFE_Seg, self).__init__()
     self.max_points = max_points
     self.vfe = VFE(feature_channels, max_points)
     self.seg_net = nn.Sequential(
         nn.Conv1D(max_points + feature_channels * 2, 512, 1),
         nn.BatchNorm(512), nn.ReLU(), nn.Conv1D(512, 256, 1),
         nn.BatchNorm(256), nn.ReLU(), nn.Conv1D(256, 128, 1),
         nn.BatchNorm(128), nn.ReLU(), nn.Conv1D(128, 128, 1),
         nn.BatchNorm(128), nn.ReLU(), nn.Conv1D(128, num_classes, 1))
示例#7
0
    def __init__(self,
                 vocab_size,
                 emb_dim=256,
                 hidden_size=512,
                 kernel_size=9,
                 n_layers=32,
                 padding_idx=0,
                 dropout_rate=0.1,
                 epsilon=1e-6):
        super(ResnetEncoderModel, self).__init__()

        self.hidden_size = hidden_size
        self.n_layers = n_layers

        self.token_embedding = nn.Embedding(vocab_size,
                                            emb_dim,
                                            padding_idx=padding_idx)
        max_pos_len = 3000
        self.pos_embedding = nn.Embedding(max_pos_len,
                                          emb_dim,
                                          padding_idx=padding_idx)

        self.padded_conv = nn.Sequential(
            nn.BatchNorm1D(emb_dim, data_format="NLC"),
            nn.ReLU(),
            nn.Conv1D(in_channels=emb_dim, out_channels=hidden_size, kernel_size=kernel_size, padding="same", \
                      data_format="NLC", weight_attr=nn.initializer.KaimingNormal()),
            nn.Dropout(p=dropout_rate)
        )

        self.residual_block_1 = nn.Sequential(
            nn.BatchNorm1D(hidden_size, data_format="NLC"),
            nn.ReLU(),
            nn.Conv1D(in_channels=hidden_size, out_channels=hidden_size, kernel_size=kernel_size, padding="same", \
                      data_format="NLC", weight_attr=nn.initializer.KaimingNormal()),
            nn.Dropout(p=dropout_rate),
            nn.BatchNorm1D(hidden_size, data_format="NLC"),
            nn.ReLU(),
            nn.Conv1D(in_channels=hidden_size, out_channels=hidden_size, kernel_size=kernel_size, padding="same", \
                      data_format="NLC", weight_attr=nn.initializer.KaimingNormal()),
            nn.Dropout(p=dropout_rate)
        )

        self.residual_block_n = nn.Sequential(
            nn.BatchNorm1D(hidden_size, data_format="NLC"),
            nn.ReLU(),
            nn.Conv1D(in_channels=hidden_size, out_channels=hidden_size, kernel_size=kernel_size, dilation=2, \
                      padding="same", data_format="NLC", weight_attr=nn.initializer.KaimingNormal()),
            nn.Dropout(p=dropout_rate),
            nn.BatchNorm1D(hidden_size, data_format="NLC"),
            nn.ReLU(),
            nn.Conv1D(in_channels=hidden_size, out_channels=hidden_size, kernel_size=kernel_size, dilation=2, \
                      padding="same", data_format="NLC", weight_attr=nn.initializer.KaimingNormal()),
            nn.Dropout(p=dropout_rate)
        )
示例#8
0
 def __init__(self, num_classes=50, max_points=1024):
     super(PointNet_Basic_Seg, self).__init__()
     self.max_points = max_points
     self.pointnet_bacic = PointNet_Basic(max_points)
     self.seg_net = nn.Sequential(nn.Conv1D(max_points + 64, 512, 1),
                                  nn.BatchNorm(512), nn.ReLU(),
                                  nn.Conv1D(512, 256, 1), nn.BatchNorm(256),
                                  nn.ReLU(), nn.Conv1D(256, 128, 1),
                                  nn.BatchNorm(128), nn.ReLU(),
                                  nn.Conv1D(128, 128, 1), nn.BatchNorm(128),
                                  nn.ReLU(), nn.Conv1D(128, num_classes, 1))
示例#9
0
 def __init__(self, name_scope='KDNet_', num_classes=10):
     super(KDNet, self).__init__()
     self.conv1 = nn.Conv1D(3, 32 * 3, 1, 1)
     self.conv2 = nn.Conv1D(32, 64 * 3, 1, 1)
     self.conv3 = nn.Conv1D(64, 64 * 3, 1, 1)
     self.conv4 = nn.Conv1D(64, 128 * 3, 1, 1)
     self.conv5 = nn.Conv1D(128, 128 * 3, 1, 1)
     self.conv6 = nn.Conv1D(128, 256 * 3, 1, 1)
     self.conv7 = nn.Conv1D(256, 256 * 3, 1, 1)
     self.conv8 = nn.Conv1D(256, 512 * 3, 1, 1)
     self.conv9 = nn.Conv1D(512, 512 * 3, 1, 1)
     self.conv10 = nn.Conv1D(512, 128 * 3, 1, 1)
     self.fc = nn.Linear(128, num_classes)
示例#10
0
 def __init__(self, in_dim):
     super().__init__()
     self.channle_in = in_dim
     self.query_conv = nn.Conv1D(
         in_channels=in_dim, out_channels=in_dim // 2, kernel_size=1)
     self.key_conv = nn.Conv1D(
         in_channels=in_dim, out_channels=in_dim // 2, kernel_size=1)
     self.value_conv_vis = nn.Conv1D(
         in_channels=in_dim, out_channels=in_dim, kernel_size=1)
     self.value_conv_word = nn.Conv1D(
         in_channels=in_dim, out_channels=in_dim, kernel_size=1)
     self.softmax_vis = nn.Softmax(axis=-1)
     self.softmax_word = nn.Softmax(axis=-2)
示例#11
0
    def __init__(self,
                 vocab_size,
                 num_class,
                 emb_dim=512,
                 hidden_size=512,
                 head_num=4,
                 layer_num=4,
                 padding_idx=0,
                 epsilon=1e-5,
                 dropout_rate=0.1):
        """Init model

        Args:
            vocab_size (int): vocab size.
            num_class (int): num classes.
            emb_dim (int, optional): embeding dimension. Defaults to 512.
            hidden_size (int, optional): hidden size. Defaults to 512.
            head_num (int, optional): head_num. Defaults to 4.
            layer_num (int, optional): layer num. Defaults to 4.
            padding_idx (int, optional): padding index. Defaults to 0.
            epsilon (float, optional): epsilon. Defaults to 1e-5.
            dropout_rate (float, optional): dropout rate. Defaults to 0.1.
        """
        super().__init__()
        self.padding_idx = padding_idx
        self.embedder = nn.Embedding(vocab_size,
                                     emb_dim,
                                     padding_idx=padding_idx)
        self.layer_norm = nn.LayerNorm(normalized_shape=emb_dim,
                                       epsilon=epsilon)
        self.dropout = nn.Dropout(p=dropout_rate)
        self.transformer_encoder = TransformerEncoder(
            d_model=emb_dim,
            nhead=head_num,
            num_encoder_layers=layer_num,
            dim_feedforward=hidden_size * 4,
            dropout=dropout_rate,
            attn_dropout=dropout_rate,
            act_dropout=dropout_rate,
        )

        in_channels = hidden_size
        self.conv_encoder = nn.Conv1D(in_channels=in_channels,
                                      out_channels=hidden_size,
                                      kernel_size=5,
                                      padding=2)
        self.output_layer = nn.Conv1D(in_channels=hidden_size,
                                      out_channels=num_class,
                                      kernel_size=3,
                                      padding=1)
示例#12
0
    def __init__(self, max_len, latent_dim):
        super(CNNEncoder, self).__init__()

        self.latent_dim = latent_dim
        self.max_len = max_len

        self.conv1 = nn.Conv1D(DECISION_DIM, 9, 9)
        self.conv2 = nn.Conv1D(9, 9, 9)
        self.conv3 = nn.Conv1D(9, 10, 11)

        self.last_conv_size = max_len - 9 + 1 - 9 + 1 - 11 + 1
        self.w1 = nn.Linear(self.last_conv_size * 10, 435)
        self.mean_w = nn.Linear(435, latent_dim)
        self.log_var_w = nn.Linear(435, latent_dim)

        weights_init(self)
示例#13
0
    def __init__(
        self,
        in_channels,
        out_channels,
        kernel_size,
        stride=1,
        padding="same",
        dilation=1,
        groups=1,
        bias=True,
        padding_mode="reflect",
    ):
        super(Conv1d, self).__init__()

        self.kernel_size = kernel_size
        self.stride = stride
        self.dilation = dilation
        self.padding = padding
        self.padding_mode = padding_mode

        self.conv = nn.Conv1D(
            in_channels,
            out_channels,
            self.kernel_size,
            stride=self.stride,
            padding=0,
            dilation=self.dilation,
            groups=groups,
            bias_attr=bias,
        )
示例#14
0
 def __init__(self, cin, cout, groups, act):
     super().__init__()
     self.conv1d = nn.Conv1D(in_channels=cin,
                             out_channels=cout,
                             kernel_size=1,
                             groups=groups)
     self.act = ACT2FN[act]
示例#15
0
    def __init__(self, config):
        super(ProteinSequenceModel, self).__init__()
        self.config = config
        self.output_dim = config['output_dim']
        self.embed_dim = config['embed_dim']
        self.max_protein_len = config['max_protein_len']
        self.vocab_size = len(ProteinTokenizer.vocab)

        self.num_filters = config.get('num_filters', 32)
        self.pool_type = config.get('pool_type', 'mean')
        self.initializer_range = config.get('initializer_range', 0.02)

        self.protein_embeddings = nn.Embedding(
            self.vocab_size,
            self.embed_dim,
            weight_attr=nn.initializer.TruncatedNormal(
                std=self.initializer_range))

        self.conv1d = nn.Conv1D(self.embed_dim,
                                self.num_filters,
                                kernel_size=8,
                                padding='SAME',
                                data_format='NLC')

        if self.max_protein_len < 0:
            self.fc = nn.Linear(self.num_filters, self.output_dim)
        else:
            self.fc = nn.Linear(self.num_filters * self.max_protein_len,
                                self.output_dim)
示例#16
0
 def __init__(self,
              in_channels,
              out_channels,
              kernel_size,
              padding=0,
              stride=1,
              conv_cfg='Conv1D',
              norm_cfg='None',
              **kwargs):
     super().__init__()
     if (conv_cfg == 'Conv1D'):
         self._conv = nn.Conv1D(in_channels,
                                out_channels,
                                kernel_size,
                                stride=stride,
                                padding=padding,
                                **kwargs)
     if (conv_cfg == 'Conv2D'):
         self._conv = nn.Conv2D(in_channels,
                                out_channels,
                                kernel_size,
                                stride=stride,
                                padding=padding,
                                **kwargs)
     if 'data_format' in kwargs:
         data_format = kwargs['data_format']
     else:
         data_format = 'NCHW'
     if (norm_cfg != 'None'):
         self._batch_norm = layers.SyncBatchNorm(out_channels,
                                                 data_format=data_format)
     else:
         self._batch_norm = None
示例#17
0
    def __init__(self, vocab_text_size, vocab_tag_size, emb_dim, hid_dim,
                 win_size, margin, neg_size, text_len):
        super(TagspaceLayer, self).__init__()
        self.vocab_text_size = vocab_text_size
        self.vocab_tag_size = vocab_tag_size
        self.emb_dim = emb_dim
        self.hid_dim = hid_dim
        self.win_size = win_size
        self.margin = margin
        self.neg_size = neg_size
        self.text_len = text_len

        self.text_embedding = paddle.nn.Embedding(
            self.vocab_text_size,
            self.emb_dim,
            padding_idx=75377,
            sparse=True,
            name="text_emb")
        self.tag_embedding = paddle.nn.Embedding(
            self.vocab_tag_size, self.emb_dim, sparse=True, name="tag_emb")

        self.conv = nn.Conv1D(
            in_channels=self.emb_dim,
            out_channels=self.hid_dim,
            kernel_size=self.win_size,
            data_format='NLC')

        self.hid_fc = paddle.nn.Linear(
            in_features=self.hid_dim,
            out_features=self.emb_dim,
            name="text_hid")
示例#18
0
    def __init__(self,
                 vocab_size,
                 num_class,
                 emb_dim=512,
                 hidden_size=512,
                 n_lstm_layer=3,
                 is_bidirectory=True,
                 padding_idx=0,
                 epsilon=1e-5,
                 dropout_rate=0.1):
        """Init model

        Args:
            vocab_size (int): vocab size.
            num_class (int): num of classes.
            emb_dim (int, optional): embedding dimmension. Defaults to 512.
            hidden_size (int, optional): hidden size. Defaults to 512.
            n_lstm_layer (int, optional): number of lstm layer. Defaults to 3.
            is_bidirectory (bool, optional): use bidirect lstm. Defaults to True.
            padding_idx (int, optional): padding index. Defaults to 0.
            epsilon (float, optional): epsilon. Defaults to 1e-5.
            dropout_rate (float, optional): dropout rate. Defaults to 0.1.
        """
        super().__init__()
        self.padding_idx = padding_idx
        self.embedder = nn.Embedding(vocab_size,
                                     emb_dim,
                                     padding_idx=padding_idx)
        self.layer_norm = nn.LayerNorm(normalized_shape=emb_dim,
                                       epsilon=epsilon)
        self.dropout = nn.Dropout(p=dropout_rate)
        direction = 'bidirectional' if is_bidirectory else 'forward'
        self.lstm_encoder = nn.LSTM(emb_dim,
                                    hidden_size,
                                    num_layers=n_lstm_layer,
                                    direction=direction)
        # kernel_size = (5, hidden_size * 2) if is_bidirectory else (5, hidden_size)

        in_channels = hidden_size * 2 if is_bidirectory else hidden_size
        self.conv_encoder = nn.Conv1D(in_channels=in_channels,
                                      out_channels=hidden_size,
                                      kernel_size=5,
                                      padding=2)
        self.output_layer = nn.Conv1D(in_channels=hidden_size,
                                      out_channels=num_class,
                                      kernel_size=3,
                                      padding=1)
 def __init__(self,
              inplanes=256,
              planes=256,
              kernel_size=9,
              dilation=1,
              dropout_rate=0.1):
     super(ResnetBasicBlock, self).__init__()
     self.conv1 = nn.Conv1D(in_channels=inplanes, out_channels=planes, kernel_size=kernel_size, dilation=dilation, \
                            padding="same", data_format="NLC", weight_attr=nn.initializer.KaimingNormal())
     self.bn1 = nn.BatchNorm1D(planes, data_format="NLC")
     self.gelu1 = nn.GELU()
     self.dropout1 = nn.Dropout(p=dropout_rate)
     self.conv2 = nn.Conv1D(in_channels=planes, out_channels=planes, kernel_size=kernel_size, dilation=dilation, \
                            padding="same", data_format="NLC", weight_attr=nn.initializer.KaimingNormal())
     self.bn2 = nn.BatchNorm1D(planes, data_format="NLC")
     self.gelu2 = nn.GELU()
     self.dropout2 = nn.Dropout(p=dropout_rate)
示例#20
0
    def __init__(self, cin, cout, groups, dropout_prob):
        super().__init__()

        self.conv1d = nn.Conv1D(in_channels=cin,
                                out_channels=cout,
                                kernel_size=1,
                                groups=groups)
        self.layernorm = SqueezeBertLayerNorm(cout)
        self.dropout = nn.Dropout(dropout_prob)
示例#21
0
def conv1d(ni: int,
           no: int,
           ks: int = 1,
           stride: int = 1,
           padding: int = 0,
           bias: bool = False):
    "Create and initialize a `nn.Conv1d` layer with spectral normalization."
    conv = nn.Conv1D(ni, no, ks, stride=stride, padding=padding, bias_attr=bias)
    return Spectralnorm(conv)
示例#22
0
 def __init__(self, in_channel, mlp):
     super(PointNetFeaturePropagation, self).__init__()
     self.mlp_convs = []
     self.mlp_bns = []
     last_channel = in_channel
     for out_channel in mlp:
         self.mlp_convs.append(nn.Conv1D(last_channel, out_channel, 1))
         self.mlp_bns.append(nn.BatchNorm1D(out_channel))
         last_channel = out_channel
示例#23
0
 def __init__(self, num_state=128, num_node=64, bias=False):
     super().__init__()
     self.conv1 = nn.Conv1D(
         num_node,
         num_node,
         kernel_size=1,
         padding=0,
         stride=1,
         groups=1,
     )
     self.relu = nn.ReLU()
     self.conv2 = nn.Conv1D(num_state,
                            num_state,
                            kernel_size=1,
                            padding=0,
                            stride=1,
                            groups=1,
                            bias_attr=bias)
示例#24
0
    def __init__(self,
                 n_inputs,
                 n_outputs,
                 kernel_size,
                 stride,
                 dilation,
                 padding,
                 dropout=0.2):

        super(TemporalBlock, self).__init__()
        self.conv1 = weight_norm(
            nn.Conv1D(
                n_inputs,
                n_outputs,
                kernel_size,
                stride=stride,
                padding=padding,
                dilation=dilation))
        # Chomp1d is used to make sure the network is causal.
        # We pad by (k-1)*d on the two sides of the input for convolution, 
        # and then use Chomp1d to remove the (k-1)*d output elements on the right.
        self.chomp1 = Chomp1d(padding)
        self.relu1 = nn.ReLU()
        self.dropout1 = nn.Dropout(dropout)

        self.conv2 = weight_norm(
            nn.Conv1D(
                n_outputs,
                n_outputs,
                kernel_size,
                stride=stride,
                padding=padding,
                dilation=dilation))
        self.chomp2 = Chomp1d(padding)
        self.relu2 = nn.ReLU()
        self.dropout2 = nn.Dropout(dropout)

        self.net = nn.Sequential(self.conv1, self.chomp1, self.relu1,
                                 self.dropout1, self.conv2, self.chomp2,
                                 self.relu2, self.dropout2)
        self.downsample = nn.Conv1D(n_inputs, n_outputs,
                                    1) if n_inputs != n_outputs else None
        self.relu = nn.ReLU()
        self.init_weights()
示例#25
0
 def __init__(self, in_channels=3, out_channels=3, kernel_size=3, *args):
     super(Block, self).__init__()
     self.nn = nn.Sequential(
         nn.Conv1D(in_channels=in_channels,
                   out_channels=out_channels,
                   kernel_size=kernel_size,
                   padding=0,
                   bias_attr=False),
         nn.BatchNorm1D(num_features=out_channels), nn.LeakyReLU(.2),
         nn.Dropout(p=.2))
示例#26
0
 def __init__(self, config):
     super().__init__()
     self.conv = nn.Conv1D(
         config.hidden_size,
         config.hidden_size,
         kernel_size=config.num_conv_pos_embeddings,
         padding=config.num_conv_pos_embeddings // 2,
         groups=config.num_conv_pos_embedding_groups,
     )
     # self.conv = nn.utils.weight_norm(self.conv, name="weight", axis=2)
     self.padding = Wav2Vec2SamePadLayer(config.num_conv_pos_embeddings)
     self.activation = ACT2FN[config.feat_extract_activation]
示例#27
0
 def __init__(self, max_points=1024):
     super(PointNet_Basic, self).__init__()
     self.mlp_1 = nn.Sequential(
         nn.Conv1D(3, 64, 1),
         nn.BatchNorm(64),
         nn.ReLU(),
         nn.Conv1D(64, 64, 1),
         nn.BatchNorm(64),
         nn.ReLU(),
     )
     self.mlp_2 = nn.Sequential(
         nn.Conv1D(64, 64, 1),
         nn.BatchNorm(64),
         nn.ReLU(),
         nn.Conv1D(64, 128, 1),
         nn.BatchNorm(128),
         nn.ReLU(),
         nn.Conv1D(128, max_points, 1),
         nn.BatchNorm(max_points),
         nn.ReLU(),
     )
示例#28
0
    def __init__(self,
                 n_fft: int = 2048,
                 hop_length: Optional[int] = None,
                 win_length: Optional[int] = None,
                 window: str = 'hann',
                 center: bool = True,
                 pad_mode: str = 'reflect',
                 one_sided: bool = True,
                 dtype: str = 'float64'):

        super(STFT, self).__init__()

        assert pad_mode in ['constant', 'reflect'
                            ], ('pad_mode must be choosen ' +
                                'between "constant" and "reflect", ' +
                                f'but received pad_mode={pad_mode} instead')

        self.n_fft = n_fft
        self.hop_length = hop_length
        self.win_length = win_length
        self.window = window
        self.center = center
        self.pad_mode = pad_mode
        # By default, use the entire frame.
        if self.win_length is None:
            self.win_length = n_fft
        # Set the default hop, if it's not already specified.
        if self.hop_length is None:
            self.hop_length = int(self.win_length // 4)
        fft_window = F.get_window(window,
                                  self.win_length,
                                  fftbins=True,
                                  dtype=dtype)
        fft_window = F.center_padding(fft_window, n_fft)
        # DFT & IDFT matrix.
        dft_mat = F.dft_matrix(n_fft, dtype=dtype)
        if one_sided:
            out_channels = n_fft // 2 + 1
        else:
            out_channels = n_fft
        self.conv = nn.Conv1D(1,
                              out_channels * 2,
                              n_fft,
                              stride=self.hop_length,
                              bias_attr=False)
        weight = fft_window.unsqueeze([1, 2]) * dft_mat[:, 0:out_channels, :]
        weight = weight.transpose([1, 2, 0])
        weight = weight.reshape([-1, weight.shape[-1]])
        self.conv.load_dict({'weight': weight.unsqueeze(1).astype('float32')})
        # by default, the STFT is not learnable
        for param in self.parameters():
            param.stop_gradient = True
示例#29
0
 def __init__(self,
              name_scope='PointNet2_SSG_Seg_',
              num_classes=16,
              num_parts=50,
              normal_channel=False):
     super(PointNet2_SSG_Seg, self).__init__()
     if normal_channel:
         additional_channel = 3
     else:
         additional_channel = 0
     self.num_classes = num_classes
     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_parts, 1)
示例#30
0
    def __init__(self, config, layer_id=0):
        super().__init__()
        self.in_conv_dim = config.conv_dim[layer_id] if layer_id > 0 else 1
        self.out_conv_dim = config.conv_dim[layer_id]

        self.conv = nn.Conv1D(
            self.in_conv_dim,
            self.out_conv_dim,
            kernel_size=config.conv_kernel[layer_id],
            stride=config.conv_stride[layer_id],
            bias_attr=config.conv_bias,
        )
        self.activation = ACT2FN[config.feat_extract_activation]