def __init__(self, config_path, args, working_dir, temp_dir, should_perform_clean_up=True, avoid_rendering=False): """ Inits the pipeline, by calling the constructors of all modules mentioned in the config. :param config_path: path to the config :param args: arguments which were provided to the run.py and are specified in the config file :param working_dir: the current working dir usually the place where the run.py sits :param working_dir: the directory where to put temporary files during the execution :param should_perform_clean_up: if the generated temp file should be deleted at the end :param avoid_rendering: if this is true all renderes are not executed (except the RgbRenderer, \ where only the rendering call to blender is avoided) with this it is possible to debug \ properly """ Utility.working_dir = working_dir # Clean up example scene or scene created by last run when debugging pipeline inside blender if should_perform_clean_up: self._cleanup() config_parser = ConfigParser(silent=True) config = config_parser.parse(Utility.resolve_path(config_path), args) if avoid_rendering: GlobalStorage.add_to_config_before_init("avoid_rendering", True) Utility.temp_dir = Utility.resolve_path(temp_dir) os.makedirs(Utility.temp_dir, exist_ok=True) self.modules = Utility.initialize_modules(config["modules"])
def __init__(self, config_path, args, working_dir, temp_dir, avoid_output=False): """ Inits the pipeline, by calling the constructors of all modules mentioned in the config. :param config_path: path to the config :param args: arguments which were provided to the run.py and are specified in the config file :param working_dir: the current working dir usually the place where the run.py sits :param working_dir: the directory where to put temporary files during the execution :param avoid_output: if this is true, all modules (renderers and writers) skip producing output. With this it is possible to debug \ properly. """ Utility.working_dir = working_dir config_parser = ConfigParser(silent=True) config = config_parser.parse(Utility.resolve_path(config_path), args) # Setup pip packages specified in config SetupUtility.setup_pip(config["setup"]["pip"] if "pip" in config["setup"] else []) if avoid_output: GlobalStorage.add_to_config_before_init("avoid_output", True) Utility.temp_dir = Utility.resolve_path(temp_dir) os.makedirs(Utility.temp_dir, exist_ok=True) self.modules = Utility.initialize_modules(config["modules"])
def __init__(self, config_path, args, working_dir, should_perform_clean_up=True, avoid_rendering=False): Utility.working_dir = working_dir # Clean up example scene or scene created by last run when debugging pipeline inside blender if should_perform_clean_up: self._cleanup() config_parser = ConfigParser(silent=True) config = config_parser.parse(Utility.resolve_path(config_path), args) config_object = Config(config) if not config_object.get_bool("avoid_rendering", False) and avoid_rendering: # avoid rendering is not already on, but should be: if "all" in config["global"].keys(): config["global"]["all"] = {} config["global"]["all"]["avoid_rendering"] = True self._do_clean_up_temp_dir = config_object.get_bool( "delete_temporary_files_afterwards", True) self._temp_dir = Utility.get_temporary_directory(config_object) os.makedirs(self._temp_dir, exist_ok=True) self.modules = Utility.initialize_modules(config["modules"], config["global"])
def __init__(self, config_path, args, working_dir, should_perform_clean_up=True): Utility.working_dir = working_dir # Clean up example scene or scene created by last run when debugging pipeline inside blender if should_perform_clean_up: self._cleanup() config_parser = ConfigParser(silent=True) config = config_parser.parse(Utility.resolve_path(config_path), args) self.modules = Utility.initialize_modules(config["modules"], config["global"])
# Delete all loaded models inside src/, as they are cached inside blender for module in list(sys.modules.keys()): if module.startswith("src"): del sys.modules[module] from src.utility.ConfigParser import ConfigParser from src.utility.Utility import Utility from src.main.Pipeline import Pipeline config_path = "examples/bop/config.yaml" argv = ['/volume/pekdat/datasets/public/bop/original/tless', '/tmp/output_bop'] Utility.working_dir = working_dir config_parser = ConfigParser() config = config_parser.parse(Utility.resolve_path(config_path), argv) # Don't parse placeholder args in batch mode. setup_config = config["setup"] if "bop_toolkit_path" in setup_config: sys.path.append(setup_config["bop_toolkit_path"]) else: print('ERROR: Please download the bop_toolkit package and set bop_toolkit_path in config:') print('https://github.com/thodan/bop_toolkit') # Focus the 3D View, this is necessary to make undo work (otherwise undo will focus on the scripting area) for window in bpy.context.window_manager.windows: screen = window.screen for area in screen.areas:
'--keep-temp-dir', dest='keep_temp_dir', action='store_true', help="If set, the temporary directory is not removed in the end.") parser.add_argument('-h', '--help', dest='help', action='store_true', help='Show this help message and exit.') args = parser.parse_args() if args.config is None: print(parser.format_help()) exit(0) config_parser = ConfigParser() config = config_parser.parse( args.config, args.args, args.help, skip_arg_placeholders=(args.batch_process != None )) # Don't parse placeholder args in batch mode. setup_config = config["setup"] # If blender should be downloaded automatically if "custom_blender_path" not in setup_config: # Determine path where blender should be installed if "blender_install_path" in setup_config: blender_install_path = os.path.expanduser( setup_config["blender_install_path"]) if blender_install_path.startswith(
# Read args argv = sys.argv batch_index_file = None if "--batch-process" in argv: batch_index_file = argv[argv.index("--batch-process") + 1] argv = argv[argv.index("--") + 1:] working_dir = os.path.dirname(os.path.abspath(__file__)) from src.main.Pipeline import Pipeline config_path = argv[0] config_parser = ConfigParser() config = config_parser.parse( config_path, argv[1:]) # Don't parse placeholder args in batch mode. setup_config = config["setup"] if "bop_toolkit_path" in setup_config: sys.path.append(setup_config["bop_toolkit_path"]) else: print( 'ERROR: Please download the bop_toolkit package and set bop_toolkit_path in config:' ) print('https://github.com/thodan/bop_toolkit') if batch_index_file == None: pipeline = Pipeline(config_path, argv[1:], working_dir) pipeline.run()