ravens/agents/regression.py
def act(self, obs, info):
        """Run inference and return best action given visual observations."""
        self.pick_regression_model.set_batch_size(1)
        self.place_regression_model.set_batch_size(1)
        act = {'camera_config': self.camera_config, 'primitive': None}
        if not obs:
            return act

        # Get heightmap from RGB-D images.
        colormap, heightmap = self.get_heightmap(obs, self.camera_config)

        # Concatenate color with depth images.
        # input_image = np.concatenate((colormap,
        #                               heightmap[..., None],
        #                               heightmap[..., None],
        #                               heightmap[..., None]), axis=2)

        input_image = colormap[None, ...]

        # Regression pick model
        p0_yxtheta = self.pick_regression_model.forward(input_image)[0] # unbatch
        p0_pixel = [int(p0_yxtheta[0]), int(p0_yxtheta[1])]
        p0_theta = p0_yxtheta[2]

        # Regression place model
        p1_yxtheta = self.place_regression_model.forward(input_image)[0] # unbatch
        p1_pixel = [int(p1_yxtheta[0]), int(p1_yxtheta[1])]
        p1_theta = p1_yxtheta[2]

        # make sure safe:
        if p1_pixel[0] < 0:
            p1_pixel[0] = 0
        if p1_pixel[0] > 319:
            p1_pixel[0] = 319

        if p1_pixel[1] < 0:
            p1_pixel[1] = 0
        if p1_pixel[1] > 159:
            p1_pixel[1] = 159

        # Pixels to end effector poses.
        p0_position = utils.pixel_to_position(p0_pixel, heightmap, self.bounds, self.pixel_size)
        p1_position = utils.pixel_to_position(p1_pixel, heightmap, self.bounds, self.pixel_size)

        p0_rotation = p.getQuaternionFromEuler((0, 0, -p0_theta))
        p1_rotation = p.getQuaternionFromEuler((0, 0, -p1_theta))

        act['primitive'] = 'pick_place'
        if self.task == 'sweeping':
            act['primitive'] = 'sweep'
        elif self.task == 'pushing':
            act['primitive'] = 'push'
        params = {'pose0': (p0_position, p0_rotation),
                  'pose1': (p1_position, p1_rotation)}
        act['params'] = params
        self.pick_regression_model.set_batch_size(self.batch_size)
        self.place_regression_model.set_batch_size(self.batch_size)
        return act
Run inference and return best action given visual observations.
Run inference and return best action given visual observations.
Run inference and return best action given visual observations .
def act(self, obs, info):
        self.pick_regression_model.set_batch_size(1)
        self.place_regression_model.set_batch_size(1)
        act = {'camera_config': self.camera_config, 'primitive': None}
        if not obs:
            return act
        colormap, heightmap = self.get_heightmap(obs, self.camera_config)
        input_image = colormap[None, ...]
        p0_yxtheta = self.pick_regression_model.forward(input_image)[0] 
        p0_pixel = [int(p0_yxtheta[0]), int(p0_yxtheta[1])]
        p0_theta = p0_yxtheta[2]
        p1_yxtheta = self.place_regression_model.forward(input_image)[0] 
        p1_pixel = [int(p1_yxtheta[0]), int(p1_yxtheta[1])]
        p1_theta = p1_yxtheta[2]
        if p1_pixel[0] < 0:
            p1_pixel[0] = 0
        if p1_pixel[0] > 319:
            p1_pixel[0] = 319
        if p1_pixel[1] < 0:
            p1_pixel[1] = 0
        if p1_pixel[1] > 159:
            p1_pixel[1] = 159
        p0_position = utils.pixel_to_position(p0_pixel, heightmap, self.bounds, self.pixel_size)
        p1_position = utils.pixel_to_position(p1_pixel, heightmap, self.bounds, self.pixel_size)
        p0_rotation = p.getQuaternionFromEuler((0, 0, -p0_theta))
        p1_rotation = p.getQuaternionFromEuler((0, 0, -p1_theta))
        act['primitive'] = 'pick_place'
        if self.task == 'sweeping':
            act['primitive'] = 'sweep'
        elif self.task == 'pushing':
            act['primitive'] = 'push'
        params = {'pose0': (p0_position, p0_rotation),
                  'pose1': (p1_position, p1_rotation)}
        act['params'] = params
        self.pick_regression_model.set_batch_size(self.batch_size)
        self.place_regression_model.set_batch_size(self.batch_size)
        return act
def act ( self , obs , info ) : self . pick_regression_model . set_batch_size ( 1 ) self . place_regression_model . set_batch_size ( 1 ) act = { 'camera_config' : self . camera_config , 'primitive' : None } if not obs : return act colormap , heightmap = self . get_heightmap ( obs , self . camera_config ) input_image = colormap [ None , ... ] p0_yxtheta = self . pick_regression_model . forward ( input_image ) [ 0 ] p0_pixel = [ int ( p0_yxtheta [ 0 ] ) , int ( p0_yxtheta [ 1 ] ) ] p0_theta = p0_yxtheta [ 2 ] p1_yxtheta = self . place_regression_model . forward ( input_image ) [ 0 ] p1_pixel = [ int ( p1_yxtheta [ 0 ] ) , int ( p1_yxtheta [ 1 ] ) ] p1_theta = p1_yxtheta [ 2 ] if p1_pixel [ 0 ] < 0 : p1_pixel [ 0 ] = 0 if p1_pixel [ 0 ] > 319 : p1_pixel [ 0 ] = 319 if p1_pixel [ 1 ] < 0 : p1_pixel [ 1 ] = 0 if p1_pixel [ 1 ] > 159 : p1_pixel [ 1 ] = 159 p0_position = utils . pixel_to_position ( p0_pixel , heightmap , self . bounds , self . pixel_size ) p1_position = utils . pixel_to_position ( p1_pixel , heightmap , self . bounds , self . pixel_size ) p0_rotation = p . getQuaternionFromEuler ( ( 0 , 0 , - p0_theta ) ) p1_rotation = p . getQuaternionFromEuler ( ( 0 , 0 , - p1_theta ) ) act [ 'primitive' ] = 'pick_place' if self . task == 'sweeping' : act [ 'primitive' ] = 'sweep' elif self . task == 'pushing' : act [ 'primitive' ] = 'push' params = { 'pose0' : ( p0_position , p0_rotation ) , 'pose1' : ( p1_position , p1_rotation ) } act [ 'params' ] = params self . pick_regression_model . set_batch_size ( self . batch_size ) self . place_regression_model . set_batch_size ( self . batch_size ) return act
Run inference and return best action given visual observations.
Run inference and return best action given visual observations .
"""Run inference and return best action given visual observations.""" # Get heightmap from RGB-D images. # Concatenate color with depth images. # input_image = np.concatenate((colormap, #                               heightmap[..., None], #                               heightmap[..., None], #                               heightmap[..., None]), axis=2) # Regression pick model # unbatch # Regression place model # unbatch # make sure safe: # Pixels to end effector poses.
self
obs
info