Translocations_Detector/models/detr.py
def forward(self, inputs):
        """ The forward expects samples, which is a tensor and consists of:

               - samples: batched signal windows, of shape [batch_size x 1 x W]

            It returns a dict with the following elements:

               - "pred_logits":   the classification logits (including no-translocation) for all queries.
                                  Shape= [batch_size x num_queries x (num_classes + 1)]

               - "pred_segments": The normalized segments coordinates for all queries, represented as
                                  (center_x, width). These values are normalized in [0, 1],
                                  relative to the size of each individual window
        """
        # propagate inputs through the convolutional backbone
        x = self.backbone(inputs)   # x [batch_size, backbone number of channels * channel_dim]
                                    # where the backbone number of channels is 512 if backbone feature_predictor is resnet10,resnet18 or resnet34
                                    # and it is 2048 if feature_predictor is resnet50 or resnet101 or resnet152

        # Addapt the backbone output so it satisfies the required format
        x = x[:,0:-1]
        x = x.view(inputs.shape[0], self.backbone.num_channels, -1)    # x [batch_size, procesed_window_size, channel_dim]

        # convert from backbone number of channels to hidden_dim feature vectors for the transformer
        h = self.input_proj(x)      # h [batch_size, hidden_dim, channel_dim]

        # construct positional encodings (W stands for window Width)
        W = h.shape[-1]
        pos = self.pos_embed[:W].unsqueeze(1).repeat(1, h.shape[0], 1)  # pos [channel_dim, batch_size, hidden_dim]

        # propagate through the transformer
        # h [num_queries, batch_size, hidden_dim]
        hs = self.transformer(h, self.query_embed.weight, pos.permute(1, 2, 0))[0]
        
        # finally project transformer outputs to class labels and bounding boxes
        outputs_class = self.class_embed(hs)
        outputs_coord = self.bsegment_embed(hs).sigmoid()
        out = {'pred_logits': outputs_class[-1],        # [batch_size, num_queries, num_classes]
               'pred_segments': outputs_coord[-1]}      # [batch_size, num_queries, 2]

        # outputs_class shape is [num_decoder_layers, batch_size, num_queries, num_classes]
        # so outputs_class[-1] is the output from the last transformer decoder layer
        # outputs_coord shape is [num_decoder_layers, batch_size, num_queries, 2]
        # so outputs_coord[-1] is the output from the last transformer decoder layer
        return out
 The forward expects samples, which is a tensor and consists of:

               - samples: batched signal windows, of shape [batch_size x 1 x W]

            It returns a dict with the following elements:

               - "pred_logits":   the classification logits (including no-translocation) for all queries.
                                  Shape= [batch_size x num_queries x (num_classes + 1)]

               - "pred_segments": The normalized segments coordinates for all queries, represented as
                                  (center_x, width). These values are normalized in [0, 1],
                                  relative to the size of each individual window
        
The forward expects samples, which is a tensor and consists of:
samples: batched signal windows, of shape [batch_size x 1 x W]

It returns a dict with the following elements.

"pred_logits":   the classification logits (including no-translocation) for all queries.

"pred_segments": The normalized segments coordinates for all queries, represented as
(center_x, width). These values are normalized in [0, 1],
relative to the size of each individual window
The forward expects samples which is a tensor and consists of : samples : batched signal windows of shape [ batch_size x 1 x W ] It returns a dict with the following elements . " pred_logits " : the classification logits ( including no - translocation ) for all queries . " pred_segments " : The normalized segments coordinates for all queries represented as ( center_x width ) . These values are normalized in [ 0 1 ] relative to the size of each individual window
def forward(self, inputs):
        x = self.backbone(inputs)   
        x = x[:,0:-1]
        x = x.view(inputs.shape[0], self.backbone.num_channels, -1)    
        h = self.input_proj(x)      
        W = h.shape[-1]
        pos = self.pos_embed[:W].unsqueeze(1).repeat(1, h.shape[0], 1)  
        hs = self.transformer(h, self.query_embed.weight, pos.permute(1, 2, 0))[0]
        outputs_class = self.class_embed(hs)
        outputs_coord = self.bsegment_embed(hs).sigmoid()
        out = {'pred_logits': outputs_class[-1],        
               'pred_segments': outputs_coord[-1]}      
        return out
def forward ( self , inputs ) : x = self . backbone ( inputs ) x = x [ : , 0 : - 1 ] x = x . view ( inputs . shape [ 0 ] , self . backbone . num_channels , - 1 ) h = self . input_proj ( x ) W = h . shape [ - 1 ] pos = self . pos_embed [ : W ] . unsqueeze ( 1 ) . repeat ( 1 , h . shape [ 0 ] , 1 ) hs = self . transformer ( h , self . query_embed . weight , pos . permute ( 1 , 2 , 0 ) ) [ 0 ] outputs_class = self . class_embed ( hs ) outputs_coord = self . bsegment_embed ( hs ) . sigmoid ( ) out = { 'pred_logits' : outputs_class [ - 1 ] , 'pred_segments' : outputs_coord [ - 1 ] } return out
The forward expects samples, which is a tensor and consists of:
 samples: batched signal windows, of shape [batch_size x 1 x W]
The forward expects samples which is a tensor and consists of : samples : batched signal windows of shape [ batch_size x 1 x W ]
""" The forward expects samples, which is a tensor and consists of:

               - samples: batched signal windows, of shape [batch_size x 1 x W]

            It returns a dict with the following elements:

               - "pred_logits":   the classification logits (including no-translocation) for all queries.
                                  Shape= [batch_size x num_queries x (num_classes + 1)]

               - "pred_segments": The normalized segments coordinates for all queries, represented as
                                  (center_x, width). These values are normalized in [0, 1],
                                  relative to the size of each individual window
        """ # propagate inputs through the convolutional backbone # x [batch_size, backbone number of channels * channel_dim] # where the backbone number of channels is 512 if backbone feature_predictor is resnet10,resnet18 or resnet34 # and it is 2048 if feature_predictor is resnet50 or resnet101 or resnet152 # Addapt the backbone output so it satisfies the required format # x [batch_size, procesed_window_size, channel_dim] # convert from backbone number of channels to hidden_dim feature vectors for the transformer # h [batch_size, hidden_dim, channel_dim] # construct positional encodings (W stands for window Width) # pos [channel_dim, batch_size, hidden_dim] # propagate through the transformer # h [num_queries, batch_size, hidden_dim] # finally project transformer outputs to class labels and bounding boxes # [batch_size, num_queries, num_classes] # [batch_size, num_queries, 2] # outputs_class shape is [num_decoder_layers, batch_size, num_queries, num_classes] # so outputs_class[-1] is the output from the last transformer decoder layer # outputs_coord shape is [num_decoder_layers, batch_size, num_queries, 2] # so outputs_coord[-1] is the output from the last transformer decoder layer
self
inputs