def _construct_and_fill_model(self): self.device_ids = sly.remap_gpu_devices(self.config['gpu_devices']) src_train_cfg_path = join(self.helper.paths.model_dir, 'model.cfg') with open(src_train_cfg_path) as f: src_config = f.readlines() def repl_batch(row): if 'batch=' in row: return 'batch=1\n' if 'subdivisions=' in row: return 'subdivisions=1\n' return row changed_config = [repl_batch(x) for x in src_config] inf_cfg_path = join(self.helper.paths.model_dir, 'inf_model.cfg') if not os.path.exists(inf_cfg_path): with open(inf_cfg_path, 'w') as f: f.writelines(changed_config) self.net = load_net( inf_cfg_path.encode('utf-8'), join(self.helper.paths.model_dir, 'model.weights').encode('utf-8'), 0) # self.meta = load_meta(join(self.helper.paths.model_dir, 'model.names').encode('utf-8')) logger.info('Weights are loaded.')
def _construct_and_fill_model(self): model_dir = sly.TaskPaths(determine_in_project=False).model_dir self.device_ids = sly.remap_gpu_devices([self.source_gpu_device]) src_train_cfg_path = join(model_dir, 'model.cfg') with open(src_train_cfg_path) as f: src_config = f.readlines() def repl_batch(row): if 'batch=' in row: return 'batch=1\n' if 'subdivisions=' in row: return 'subdivisions=1\n' return row changed_config = [repl_batch(x) for x in src_config] inf_cfg_path = join(model_dir, 'inf_model.cfg') if not os.path.exists(inf_cfg_path): with open(inf_cfg_path, 'w') as f: f.writelines(changed_config) self.net = load_net(inf_cfg_path.encode('utf-8'), join(model_dir, 'model.weights').encode('utf-8'), 0) logger.info('Weights are loaded.')
def _construct_and_fill_model(self): super()._construct_and_fill_model() self.device_ids = sly.env.remap_gpu_devices([self._config[GPU_DEVICE]]) yolo_config = read_config( os.path.join(sly.TaskPaths.MODEL_DIR, MODEL_CFG)) [net_config] = [ section for section in yolo_config if section.name == NET_SECTION ] net_overrides = {'batch': 1, 'subdivisions': 1} replace_config_section_values(net_config, net_overrides) effective_model_cfg_path = os.path.join('/tmp', MODEL_CFG) write_config(yolo_config, effective_model_cfg_path) self.model = load_net( effective_model_cfg_path.encode('utf-8'), os.path.join(sly.TaskPaths.MODEL_DIR, 'model.weights').encode('utf-8'), 0) sly.logger.info('Weights are loaded.')