ravens/models/conv_mlp.py
def compute_spatial_soft_argmax(self, x):
        """
        Parameter-less, extract coordinates for each channel.

        ~H = size related to original image H size
        ~W = size related to original image W size
        C channels

        Args:
          x, shape: (batch_size, ~H, ~W, C)
        Returns:
          shape: (batch_size, C, 2)
        """

        
        
        # unfortunately can't easily dynamically compute these sizes
        # inside a @tf.function, so just hard-coding them
        H, W, C = 149, 69, 16
        B = self.batch_size

        # see: https://github.com/tensorflow/tensorflow/issues/6271
        x = tf.reshape(tf.transpose(x, [0, 3, 1, 2]), [B * C, H * W])
        softmax = tf.nn.softmax(x)
        softmax = tf.transpose(tf.reshape(softmax, [B, C, H, W]), [0, 2, 3, 1])
        
        posx, posy = tf.meshgrid(tf.linspace(-1., 1., num=H), 
                                 tf.linspace(-1., 1., num=W), 
                                 indexing='ij')

        image_coords = tf.stack((posx, posy), axis=2) # (H, W, 2)
        # Convert softmax to shape [B, H, W, C, 1]
        softmax = tf.expand_dims(softmax, -1)
        # Convert image coords to shape [H, W, 1, 2]
        image_coords = tf.expand_dims(image_coords, 2)
        # Multiply (with broadcasting) and reduce over image dimensions to get the result
        # of shape [B, C, 2]
        spatial_soft_argmax = tf.reduce_sum(softmax * image_coords, axis=[1, 2])
        return spatial_soft_argmax

        Parameter-less, extract coordinates for each channel.

        ~H = size related to original image H size
        ~W = size related to original image W size
        C channels

        Args:
          x, shape: (batch_size, ~H, ~W, C)
        Returns:
          shape: (batch_size, C, 2)
        
Parameter-less, extract coordinates for each channel.
~H = size related to original image H size
~W = size related to original image W size
C channels
Parameter - less extract coordinates for each channel . ~H = size related to original image H size ~W = size related to original image W size C channels
def compute_spatial_soft_argmax(self, x):
        H, W, C = 149, 69, 16
        B = self.batch_size
        x = tf.reshape(tf.transpose(x, [0, 3, 1, 2]), [B * C, H * W])
        softmax = tf.nn.softmax(x)
        softmax = tf.transpose(tf.reshape(softmax, [B, C, H, W]), [0, 2, 3, 1])
        posx, posy = tf.meshgrid(tf.linspace(-1., 1., num=H), 
                                 tf.linspace(-1., 1., num=W), 
                                 indexing='ij')
        image_coords = tf.stack((posx, posy), axis=2) 
        softmax = tf.expand_dims(softmax, -1)
        image_coords = tf.expand_dims(image_coords, 2)
        spatial_soft_argmax = tf.reduce_sum(softmax * image_coords, axis=[1, 2])
        return spatial_soft_argmax
def compute_spatial_soft_argmax ( self , x ) : H , W , C = 149 , 69 , 16 B = self . batch_size x = tf . reshape ( tf . transpose ( x , [ 0 , 3 , 1 , 2 ] ) , [ B * C , H * W ] ) softmax = tf . nn . softmax ( x ) softmax = tf . transpose ( tf . reshape ( softmax , [ B , C , H , W ] ) , [ 0 , 2 , 3 , 1 ] ) posx , posy = tf . meshgrid ( tf . linspace ( - 1. , 1. , num = H ) , tf . linspace ( - 1. , 1. , num = W ) , indexing = 'ij' ) image_coords = tf . stack ( ( posx , posy ) , axis = 2 ) softmax = tf . expand_dims ( softmax , - 1 ) image_coords = tf . expand_dims ( image_coords , 2 ) spatial_soft_argmax = tf . reduce_sum ( softmax * image_coords , axis = [ 1 , 2 ] ) return spatial_soft_argmax
Parameter-less, extract coordinates for each channel.
Parameter - less extract coordinates for each channel .
"""
        Parameter-less, extract coordinates for each channel.

        ~H = size related to original image H size
        ~W = size related to original image W size
        C channels

        Args:
          x, shape: (batch_size, ~H, ~W, C)
        Returns:
          shape: (batch_size, C, 2)
        """ # unfortunately can't easily dynamically compute these sizes # inside a @tf.function, so just hard-coding them # see: https://github.com/tensorflow/tensorflow/issues/6271 # (H, W, 2) # Convert softmax to shape [B, H, W, C, 1] # Convert image coords to shape [H, W, 1, 2] # Multiply (with broadcasting) and reduce over image dimensions to get the result # of shape [B, C, 2]
None
shape
self
x
x, shape
None