![]() ![]() BatchNorm2d ( out_channels ) if relu : modules = nn. cat (( x, out ), 1 ) def _make_grouped_conv1x1 ( self, in_channels, out_channels, groups, batch_norm = True, relu = False ): modules = OrderedDict () conv = conv1x1 ( in_channels, out_channels, groups = groups ) modules = conv if batch_norm : modules = nn. groups, batch_norm = True, relu = False ) def _add ( x, out ): # residual connection return x + out def _concat ( x, out ): # concatenate along channel axis return torch. bottleneck_channels ) # Use 1x1 grouped convolution to expand from # bottleneck_channels to out_channels self. first_1x1_groups, batch_norm = True, relu = True ) # 3x3 depthwise convolution followed by batch normalization self. # NOTE: Do not use group convolution for the first conv1x1 in Stage 2. combine )) # Use a 1x1 grouped or non-grouped convolution to reduce input channels # to bottleneck channels, as in a ResNet bottleneck module. ![]() in_channels else : raise ValueError ( "Cannot combine tensors with \" \" " \ _concat # ensure output of concat has the same channels as # original output channels. combine = 'concat' : # ShuffleUnit Figure 2c self. combine = 'add' : # ShuffleUnit Figure 2b self. out_channels // 4 # define the type of ShuffleUnit if self. ![]() Module ): def _init_ ( self, in_channels, out_channels, groups = 3, grouped_conv = True, combine = 'add' ): super ( ShuffleUnitOld, self ). view ( batchsize, - 1, height, width ) return x class ShuffleUnitOld ( nn. view ( batchsize, groups, channels_per_group, height, width ) # transpose # - contiguous() required if transpose() is used before view(). size () channels_per_group = num_channels // groups # reshape x = x. Sparse ( bool, optional) – See module initialization documentation.From collections import OrderedDict def channel_shuffle ( x, groups ): batchsize, num_channels, height, width = x. Scale_grad_by_freq ( bool, optional) – See module initialization documentation. Norm_type ( float, optional) – See module initialization documentation. Max_norm ( float, optional) – See module initialization documentation. Parameters :Įmbeddings ( Tensor) – FloatTensor containing weights for the Embedding.įirst dimension is being passed to Embedding as num_embeddings, second as embedding_dim.įreeze ( bool, optional) – If True, the tensor does not get updated in the learning process.Įquivalent to _grad = False. weight Parameter containing: tensor(,, ], requires_grad=True) classmethod from_pretrained ( embeddings, freeze = True, padding_idx = None, max_norm = None, norm_type = 2.0, scale_grad_by_freq = False, sparse = False ) ¶Ĭreates Embedding instance from given 2-dimensional FloatTensor. weight Parameter containing: tensor(,, ], requires_grad=True) > with torch. Embedding ( 3, 3, padding_idx = padding_idx ) > embedding. LongTensor (]) > embedding ( input ) tensor(,, , ]]) > # example of changing `pad` vector > padding_idx = 0 > embedding = nn. Embedding ( 10, 3, padding_idx = 0 ) > input = torch. LongTensor (, ]) > embedding ( input ) tensor(,, , ],, ,, ]]) > # example with padding_idx > embedding = nn. Embedding ( 10, 3 ) > # a batch of 2 samples of 4 indices each > input = torch. > # an Embedding module containing 10 tensors of size 3 > embedding = nn. Initialized from N ( 0, 1 ) \mathcal H = embedding_dim Weight ( Tensor) – the learnable weights of the module of shape (num_embeddings, embedding_dim) See Notes for more details regarding sparse gradients. Sparse ( bool, optional) – If True, gradient w.r.t. Scale_grad_by_freq ( bool, optional) – If given, this will scale gradients by the inverse of frequency of Norm_type ( float, optional) – The p of the p-norm to compute for the max_norm option. Max_norm ( float, optional) – If given, each embedding vector with norm larger than max_norm The embedding vector at padding_idx will default to all zeros,īut can be updated to another value to be used as the padding vector. Therefore, the embedding vector at padding_idx is not updated during training, Padding_idx ( int, optional) – If specified, the entries at padding_idx do not contribute to the gradient Num_embeddings ( int) – size of the dictionary of embeddingsĮmbedding_dim ( int) – the size of each embedding vector The input to the module is a list of indices, and the output is the corresponding This module is often used to store word embeddings and retrieve them using indices. Embedding ( num_embeddings, embedding_dim, padding_idx = None, max_norm = None, norm_type = 2.0, scale_grad_by_freq = False, sparse = False, _weight = None, _freeze = False, device = None, dtype = None ) ¶Ī simple lookup table that stores embeddings of a fixed dictionary and size.
2 Comments
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |