def load_config(self): """Loads the config file of the ironcar Tests if all the necessary fields are present: - 'commands' - 'dir_pin' - 'gas_pin' - 'left' - 'straight' - 'right' - 'stop' - 'neutral' - 'drive' - 'drive_max' - invert_dir' - 'fps' - 'datasets_path' - 'stream_path' - 'models_path' """ if not os.path.isfile(CONFIG): raise ConfigException('The config file `{}` does not exist'.format(CONFIG)) with open(CONFIG) as json_file: config = json.load(json_file) # Verify that the config file has the good fields error_message = '{} is not present in the config file' for field in ['commands', 'fps', 'datasets_path', 'stream_path', 'models_path']: if field not in config: raise ConfigException(error_message.format(field)) for field in ["dir_pin", "gas_pin", "left", "straight", "right", "stop", "neutral", "drive", "drive_max", "invert_dir"]: if field not in config['commands']: raise ConfigException(error_message.format('[commands][{}]'.format(field))) self.commands = config['commands'] self.fps = config['fps'] # Folder to save the stream in training to create a dataset # Only used in training mode from datetime import datetime select_classification(self,) ct = datetime.now().strftime('%Y_%m_%d_%H_%M') self.save_folder = os.path.join(config['datasets_path'], self.classification) #classification string whose value is the direction from the socket CLASSIFICATION if not os.path.exists(self.save_folder): os.makedirs(self.save_folder) # Folder used to save the stream when the stream is on self.stream_path = config['stream_path'] if not os.path.exists(self.stream_path): os.makedirs(self.stream_path) return config
def load_config(self): """ Load the config file of the ironcar """ if not os.path.isfile(CONFIG): raise ConfigException( 'The config file `{}` does not exist'.format(CONFIG)) with open(CONFIG) as json_file: config = json.load(json_file) # Verify that the config file has the good fields error_message = '{} is not present in the config file' for field in [ 'commands', 'fps', 'datasets_path', 'stream_path', 'models_path' ]: if field not in config: raise ConfigException(error_message.format('commands')) for field in [ "dir_pin", "gas_pin", "left", "straight", "right", "stop", "neutral", "drive", "drive_max", "invert_dir" ]: if field not in config['commands']: raise ConfigException( error_message.format('[commands][{}]'.format(field))) self.commands = config['commands'] self.fps = config['fps'] # Folder to save the stream in training to create a dataset # Only used in training mode from datetime import datetime ct = datetime.now().strftime('%Y_%m_%d_%H_%M') self.save_folder = os.path.join(config['datasets_path'], str(ct)) if not os.path.exists(self.save_folder): os.makedirs(self.save_folder) # Folder used to save the stream when the stream is on self.stream_path = config['stream_path'] if not os.path.exists(self.stream_path): os.makedirs(self.stream_path) return config