in deepracer_navigation_pkg/deepracer_navigation_pkg/deepracer_navigation_node.py [0:0]
def set_action_space_cb(self, req, res):
"""Callback for the load_action_space service, should be called whenever a new
model is loaded.
Args:
req (LoadModelSrv.Request): Request object with the full artifact path to the
loaded model.
res (LoadModelSrv.Response): Response object with error(int) flag to indicate
if the service call was successful.
Returns:
LoadModelSrv.Response: Response object with error(int) flag to indicate
if the service call was successful.
"""
try:
model_dir = os.path.dirname(req.artifact_path)
model_metadata_file = "model_metadata.json"
with open(os.path.join(model_dir, model_metadata_file), 'r') as meta_file:
data = json.load(meta_file)
self.action_space = data['action_space']
self.get_logger().info(f"Action space loaded: {self.action_space}")
self.action_space_type = constants.ActionSpaceTypes(req.action_space_type)
self.validate_action_space()
except Exception as ex:
self.action_space = constants.DEFAULT_ACTION_SPACE
self.action_space_type = constants.ActionSpaceTypes.DISCRETE
self.get_logger().error(f"Failed to load action space and action space type due to: {ex}")
res.error = 1
return res
self.get_logger().info(f"Setting the action space: {self.action_space} and"
f" action space type: {self.action_space_type} ")
self.set_action_space_scales()
res.error = 0
return res