-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use logging #129
Use logging #129
Changes from all commits
9d7277a
11bfe36
65f7aed
76be371
cb9beb1
7d12bf6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
from typing import Optional | ||
from pathlib import Path | ||
import argparse | ||
import json | ||
import logging | ||
import os | ||
import shutil | ||
import sys | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def save_example_scripts(path_save_dir: str) -> None: | ||
"""Save example training and prediction scripts. | ||
|
||
|
@@ -24,10 +29,10 @@ def save_example_scripts(path_save_dir: str) -> None: | |
path_src = os.path.join(path_examples_dir, fname) | ||
path_dst = os.path.join(path_save_dir, fname) | ||
if os.path.exists(path_dst): | ||
print('Example script already exists:', path_dst) | ||
logger.info(f'Example script already exists: {path_dst}') | ||
continue | ||
shutil.copy(path_src, path_dst) | ||
print('Saved:', path_dst) | ||
logger.info(f'Saved: {path_dst}') | ||
|
||
|
||
def save_default_train_options(path_save: str) -> None: | ||
|
@@ -39,12 +44,11 @@ def save_default_train_options(path_save: str) -> None: | |
Save path for default training options json. | ||
|
||
""" | ||
if os.path.exists(path_save): | ||
print('Training options file already exists:', path_save) | ||
path_save = Path(path_save) | ||
if path_save.exists(): | ||
logger.info(f'Training options file already exists: {path_save}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd probably throw a custom exception here personally. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An exception would imply that something went "wrong" though. The idea is to simply exit if the intended action had already been completed in the past. That way the user does not have to manually check the file system. |
||
return | ||
dirname = os.path.dirname(path_save) | ||
if not os.path.exists(dirname): | ||
os.makedirs(dirname) | ||
path_save.parent.mkdir(parents=True, exist_ok=True) | ||
train_options = { | ||
'batch_size': 28, | ||
'bpds_kwargs': { | ||
|
@@ -69,12 +73,12 @@ def save_default_train_options(path_save: str) -> None: | |
'interval_save': 1000, | ||
'iter_checkpoint': [], | ||
'n_iter': 250000, | ||
'path_save_dir': dirname, | ||
'path_save_dir': str(path_save.parent), | ||
'seed': None, | ||
} | ||
with open(path_save, 'w') as fo: | ||
with path_save.open('w') as fo: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
json.dump(train_options, fo, indent=4, sort_keys=True) | ||
print('Saved:', path_save) | ||
logger.info(f'Saved: {path_save}') | ||
|
||
|
||
def add_parser_arguments(parser: argparse.ArgumentParser) -> None: | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to make this
Path(path_save).expanduser().resolve()
. It will make it so people can put relative paths and also include their home directory like~/Desktop/trained_fnet_model/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! I'll look to add this type of functionality when I address #128.