type_specific_network.py
def forward(self, x, c = None):
        """ x: input image data
            c: type specific embedding to compute for the images, returns all embeddings
               when None including the general embedding concatenated onto the end
        """
        embedded_x = self.embeddingnet(x)
        if c is None:
            # used during testing, wants all type specific embeddings returned for an image
            if self.fc_masks:
                masked_embedding = []
                for mask in self.masks:
                    masked_embedding.append(mask(embedded_x).unsqueeze(1))

                masked_embedding = torch.cat(masked_embedding, 1)
                embedded_x = embedded_x.unsqueeze(1)
            else:
                masks = Variable(self.masks.weight.data)
                masks = masks.unsqueeze(0).repeat(embedded_x.size(0), 1, 1)
                embedded_x = embedded_x.unsqueeze(1)
                masked_embedding = embedded_x.expand_as(masks) * masks

            if self.l2_norm:
                norm = torch.norm(masked_embedding, p=2, dim=2) + 1e-10
                masked_embedding = masked_embedding / norm.expand_as(masked_embedding)

            return torch.cat((masked_embedding, embedded_x), 1)
            
        if self.fc_masks:
            mask_norm = 0.
            masked_embedding = []
            for embed, condition in zip(embedded_x, c):
                 mask = self.masks[condition]
                 masked_embedding.append(mask(embed.unsqueeze(0)))
                 mask_norm += mask.weight.norm(1)

            masked_embedding = torch.cat(masked_embedding)
        else:
            self.mask = self.masks(c)
            if self.learnedmask:
                self.mask = torch.nn.functional.relu(self.mask)

            masked_embedding = embedded_x * self.mask
            mask_norm = self.mask.norm(1)

        embed_norm = embedded_x.norm(2)
        if self.l2_norm:
            norm = torch.norm(masked_embedding, p=2, dim=1) + 1e-10
            masked_embedding = masked_embedding / norm.expand_as(masked_embedding)

        return masked_embedding, mask_norm, embed_norm, embedded_x
 x: input image data
            c: type specific embedding to compute for the images, returns all embeddings
               when None including the general embedding concatenated onto the end
        
input image data
c: type specific embedding to compute for the images, returns all embeddings
when None including the general embedding concatenated onto the end
input image data c : type specific embedding to compute for the images returns all embeddings when None including the general embedding concatenated onto the end
def forward(self, x, c = None):
        embedded_x = self.embeddingnet(x)
        if c is None:
            if self.fc_masks:
                masked_embedding = []
                for mask in self.masks:
                    masked_embedding.append(mask(embedded_x).unsqueeze(1))
                masked_embedding = torch.cat(masked_embedding, 1)
                embedded_x = embedded_x.unsqueeze(1)
            else:
                masks = Variable(self.masks.weight.data)
                masks = masks.unsqueeze(0).repeat(embedded_x.size(0), 1, 1)
                embedded_x = embedded_x.unsqueeze(1)
                masked_embedding = embedded_x.expand_as(masks) * masks
            if self.l2_norm:
                norm = torch.norm(masked_embedding, p=2, dim=2) + 1e-10
                masked_embedding = masked_embedding / norm.expand_as(masked_embedding)
            return torch.cat((masked_embedding, embedded_x), 1)
        if self.fc_masks:
            mask_norm = 0.
            masked_embedding = []
            for embed, condition in zip(embedded_x, c):
                 mask = self.masks[condition]
                 masked_embedding.append(mask(embed.unsqueeze(0)))
                 mask_norm += mask.weight.norm(1)
            masked_embedding = torch.cat(masked_embedding)
        else:
            self.mask = self.masks(c)
            if self.learnedmask:
                self.mask = torch.nn.functional.relu(self.mask)
            masked_embedding = embedded_x * self.mask
            mask_norm = self.mask.norm(1)
        embed_norm = embedded_x.norm(2)
        if self.l2_norm:
            norm = torch.norm(masked_embedding, p=2, dim=1) + 1e-10
            masked_embedding = masked_embedding / norm.expand_as(masked_embedding)
        return masked_embedding, mask_norm, embed_norm, embedded_x
def forward ( self , x , c = None ) : embedded_x = self . embeddingnet ( x ) if c is None : if self . fc_masks : masked_embedding = [ ] for mask in self . masks : masked_embedding . append ( mask ( embedded_x ) . unsqueeze ( 1 ) ) masked_embedding = torch . cat ( masked_embedding , 1 ) embedded_x = embedded_x . unsqueeze ( 1 ) else : masks = Variable ( self . masks . weight . data ) masks = masks . unsqueeze ( 0 ) . repeat ( embedded_x . size ( 0 ) , 1 , 1 ) embedded_x = embedded_x . unsqueeze ( 1 ) masked_embedding = embedded_x . expand_as ( masks ) * masks if self . l2_norm : norm = torch . norm ( masked_embedding , p = 2 , dim = 2 ) + 1e-10 masked_embedding = masked_embedding / norm . expand_as ( masked_embedding ) return torch . cat ( ( masked_embedding , embedded_x ) , 1 ) if self . fc_masks : mask_norm = 0. masked_embedding = [ ] for embed , condition in zip ( embedded_x , c ) : mask = self . masks [ condition ] masked_embedding . append ( mask ( embed . unsqueeze ( 0 ) ) ) mask_norm += mask . weight . norm ( 1 ) masked_embedding = torch . cat ( masked_embedding ) else : self . mask = self . masks ( c ) if self . learnedmask : self . mask = torch . nn . functional . relu ( self . mask ) masked_embedding = embedded_x * self . mask mask_norm = self . mask . norm ( 1 ) embed_norm = embedded_x . norm ( 2 ) if self . l2_norm : norm = torch . norm ( masked_embedding , p = 2 , dim = 1 ) + 1e-10 masked_embedding = masked_embedding / norm . expand_as ( masked_embedding ) return masked_embedding , mask_norm , embed_norm , embedded_x
x: input image data
c: type specific embedding to compute for the images, returns all embeddings
when None including the general embedding concatenated onto the end
x : input image data c : type specific embedding to compute for the images returns all embeddings when None including the general embedding concatenated onto the end
""" x: input image data
            c: type specific embedding to compute for the images, returns all embeddings
               when None including the general embedding concatenated onto the end
        """ # used during testing, wants all type specific embeddings returned for an image
self
x
c