def test_all(app_name: str, app_author: str): print("-- app dirs (with optional 'version')") dirs = AppPath(app_name, app_author, app_version="1.0", ensure_existence_on_access=False) for prop in props: print(f"{prop}: {getattr(dirs, prop)}") dirs.clean()
def clean_arg(): """""" parser = argparse.ArgumentParser(description="Apppath Clean Path") parser.add_argument("APP_NAME", metavar="Name", type=str, help="App name to clean AppPath for") parser.add_argument( "--DIR", "-d", type=str, default="cache", metavar="DIR", help="Which AppPath directory to clean (default: 'cache')", ) args = parser.parse_args() project_app_path = AppPath(args.APP_NAME) if args.DIR == "data": directory = project_app_path.user_data elif args.DIR == "config": directory = project_app_path.user_config elif args.DIR == "cache": directory = project_app_path.user_cache elif args.DIR == "logs": directory = project_app_path.user_log else: raise NotADirectoryError(args.DIR) print(f"Wiping {directory}") if directory.exists(): rmtree(directory) else: directory.mkdir()
def open_arg(): """""" parser = argparse.ArgumentParser(description="Apppath Open Path") parser.add_argument("APP_NAME", metavar="Name", type=str, help="App name to open AppPath for") parser.add_argument( "--SITE", "-s", type=bool, default=False, metavar="SITE", help="Open user or site dirs (default: User)", ) parser.add_argument( "--DIR", "-d", type=str, default="data", metavar="DIR", help="Which AppPath directory to open (default: 'data')", ) args = parser.parse_args() project_app_path = AppPath(args.APP_NAME) open_app_path(project_app_path, AppPathSubDirEnum(args.DIR), args.SITE)
def main(): """description""" apppath = AppPath("AppPath") print(apppath.user_config) print(apppath.user_log) print(apppath.user_data) print(apppath.user_cache)
def a(): """ """ _path_to_events_file = next( AppPath("Draugr", "Christian Heider Nielsen").user_log.rglob( "events.out.tfevents.*")) print(_path_to_events_file) tee = TensorboardEventExporter(_path_to_events_file.parent, save_to_disk=True) print(tee.tags_available) # tee.export_csv('train_loss') # tee.export_line_plot('train_loss') # pyplot.show() print(tee.export_histogram()) print(tee.available_scalars) print( tee.pr_curve_export_csv( *tee.tags_available["tensors"], out_dir=ensure_existence(Path.cwd() / "exclude"), )) print(list(iter(tee.TagTypeEnum)))
def dist_is_editable(dist: Any) -> bool: """ Return True if given Distribution is an editable install. """ for path_item in sys.path: egg_link = Path(path_item) / f"{dist.project_name}.egg-link" if egg_link.is_file(): return True return False PROJECT_NAME = __project__.lower().strip().replace(" ", "_") PROJECT_VERSION = __version__ PROJECT_AUTHOR = __author__.lower().strip().replace(" ", "_") PROJECT_APP_PATH = AppPath(app_name=PROJECT_NAME, app_author=PROJECT_AUTHOR) distributions = {v.key: v for v in pkg_resources.working_set} if PROJECT_NAME in distributions: distribution = distributions[PROJECT_NAME] IS_DEVELOP = dist_is_editable(distribution) else: IS_DEVELOP = True def get_version(append_time: Any = IS_DEVELOP) -> str: version = __version__ if not version: version = os.getenv("VERSION", "0.0.0") if append_time:
def extract_scalars_as_csv( train_path: Path = EXPORT_RESULTS_PATH / "csv" / "training", test_path: Path = EXPORT_RESULTS_PATH / "csv" / "testing", export_train: bool = True, export_test: bool = True, verbose: bool = False, only_extract_from_latest_event_file: bool = False, ) -> None: """ :param train_path: :param test_path: :param export_train: :param export_test: :param verbose: :param only_extract_from_latest_event_file: """ if only_extract_from_latest_event_file: max_load_time = max( list( AppPath( "Adversarial Speech", "Christian Heider Nielsen" ).user_log.iterdir() ), key=os.path.getctime, ) unique_event_files_parents = set( [ef.parent for ef in max_load_time.rglob("events.out.tfevents.*")] ) event_files = {max_load_time: unique_event_files_parents} else: event_files = { a: set([ef.parent for ef in a.rglob("events.out.tfevents.*")]) for a in list( AppPath( "Adversarial Speech", "Christian Heider Nielsen" ).user_log.iterdir() ) } for k, v in progress_bar(event_files.items()): for e in progress_bar(v): relative_path = e.relative_to(k) mapping_id, *rest = relative_path.parts mappind_id_test = f"{mapping_id}_Test_{relative_path.name}" # model_id = relative_path.parent.name can be include but is always the same relative_path = Path(*(mappind_id_test, *rest)) with TensorboardEventExporter(e, save_to_disk=True) as tee: if export_test: out_tags = [] for tag in progress_bar(TestingScalars): if tag.value in tee.available_scalars: out_tags.append(tag.value) if len(out_tags): tee.scalar_export_csv( *out_tags, out_dir=ensure_existence( test_path / k.name / relative_path, force_overwrite=True, verbose=verbose, ), ) print(e) else: if verbose: print( f"{e}, no requested tags found {TestingScalars.__members__.values()}, {tee.available_scalars}" ) if export_train: out_tags = [] for tag in progress_bar(TrainingScalars): if tag.value in tee.available_scalars: out_tags.append(tag.value) if len(out_tags): tee.scalar_export_csv( *out_tags, out_dir=ensure_existence( train_path / k.name / relative_path, force_overwrite=True, verbose=verbose, ), ) else: if verbose: print( f"{e}, no requested tags found {TrainingScalars.__members__.values()}, {tee.available_scalars}" )
# To add a new cell, type '# %%' # To add a new markdown cell, type '# %% [markdown]' # %% [markdown] # Christian Heider Nielsen # Created on 05/04/2020 # %% from apppath import AppPath # %% apppath = AppPath("AppPath") print(apppath.user_config) print(apppath.user_log) print(apppath.user_data) print(apppath.user_cache)
def test_no_author(app_name): print("\n-- app dirs (with disabled '_app_author')") dirs = AppPath(app_name, ensure_existence_on_access=False) for prop in props: print(f"{prop}: {getattr(dirs, prop)}") dirs.clean()
def test_no_ver(app_name, app_author): print("\n-- app dirs (without optional 'version')") dirs = AppPath(app_name, app_author, ensure_existence_on_access=False) for prop in props: print(f"{prop}: {getattr(dirs, prop)}") dirs.clean()