Beispiel #1
0
    def sample(self, data):
        if self._cur_sample_count >= self.max_sample_count:
            return
        self._cur_frequency += 1
        if self._cur_frequency < self.sampling_frequency:
            return

        pickle_filename_format = 'sample_{}.pkl'
        pickle_filename = pickle_filename_format.format(self._cur_sample_count)
        try:
            with open(pickle_filename, 'wb') as out_f:
                pickle.dump(data, out_f, protocol=2)
        except Exception as ex:
            raise GenericTrainerException(
                'Failed to dump the sample data: {}'.format(ex))

        try:
            self.s3_client.upload_file(
                os.path.normpath("%s/samples/%s" %
                                 (self.s3_prefix, pickle_filename)),
                pickle_filename)
        except Exception as ex:
            raise GenericTrainerException(
                'Failed to upload the sample pickle file to S3: {}'.format(ex))
        self._cur_frequency = 0
        self._cur_sample_count += 1
Beispiel #2
0
    def __init__(self,
                 s3_client,
                 s3_prefix,
                 max_sample_count=None,
                 sampling_frequency=None):
        self.max_sample_count = max_sample_count or 0
        self.sampling_frequency = sampling_frequency or 1
        if self.sampling_frequency < 1:
            err_msg = "sampling_frequency must be larger or equal to 1. (Given: {})".format(
                self.sampling_frequency)
            raise GenericTrainerException(err_msg)
        self.s3_client = s3_client
        self.s3_prefix = s3_prefix

        self._cur_sample_count = 0
        self._cur_frequency = 0
Beispiel #3
0
 def create_sensor(sensor_type, config_dict):
     '''Factory method for creating sensors
         type - String containing the desired sensor type
         kwargs - Meta data, usually containing the topics to subscribe to, the
                  concrete sensor classes are responsible for checking the topics.
     '''
     if sensor_type == Input.CAMERA.value:
         return Camera()
     elif sensor_type == Input.LEFT_CAMERA.value:
         return LeftCamera()
     elif sensor_type == Input.STEREO.value:
         return DualCamera()
     elif sensor_type == Input.LIDAR.value:
         return Lidar()
     elif sensor_type == Input.OBSERVATION.value:
         return Observation()
     else:
         raise GenericTrainerException("Unknown sensor")
Beispiel #4
0
 def get_input_embedders(self, network_type):
     try:
         return get_left_camera_embedders(network_type)
     except Exception as ex:
         raise GenericTrainerException('{}'.format(ex))
Beispiel #5
0
 def get_observation_space(self):
     try:
         return get_observation_space(Input.LEFT_CAMERA.value)
     except Exception as ex:
         raise GenericTrainerException('{}'.format(ex))
Beispiel #6
0
 def get_input_embedders(self, network_type):
     try:
         return get_observation_embedder()
     except Exception as ex:
         raise GenericTrainerException('{}'.format(ex))
Beispiel #7
0
 def get_observation_space(self):
     try:
         return get_observation_space(Input.OBSERVATION.value)
     except Exception as ex:
         raise GenericTrainerException('{}'.format(ex))