replaced remaining print statements with log.*()

This commit is contained in:
Lincoln Stein
2023-04-18 20:49:00 -04:00
parent 0b0e6fe448
commit b164330e3c
13 changed files with 82 additions and 73 deletions

View File

@ -20,6 +20,7 @@ import npyscreen
from npyscreen import widget
from omegaconf import OmegaConf
import invokeai.backend.util.logging as log
from invokeai.backend.globals import Globals, global_set_root
from ...backend.training import do_textual_inversion_training, parse_args
@ -368,14 +369,14 @@ def copy_to_embeddings_folder(args: dict):
dest_dir_name = args["placeholder_token"].strip("<>")
destination = Path(Globals.root, "embeddings", dest_dir_name)
os.makedirs(destination, exist_ok=True)
print(f">> Training completed. Copying learned_embeds.bin into {str(destination)}")
log.info(f"Training completed. Copying learned_embeds.bin into {str(destination)}")
shutil.copy(source, destination)
if (
input("Delete training logs and intermediate checkpoints? [y] ") or "y"
).startswith(("y", "Y")):
shutil.rmtree(Path(args["output_dir"]))
else:
print(f'>> Keeping {args["output_dir"]}')
log.info(f'Keeping {args["output_dir"]}')
def save_args(args: dict):
@ -422,10 +423,10 @@ def do_front_end(args: Namespace):
do_textual_inversion_training(**args)
copy_to_embeddings_folder(args)
except Exception as e:
print("** An exception occurred during training. The exception was:")
print(str(e))
print("** DETAILS:")
print(traceback.format_exc())
log.error("An exception occurred during training. The exception was:")
log.error(str(e))
log.error("DETAILS:")
log.error(traceback.format_exc())
def main():
@ -437,21 +438,21 @@ def main():
else:
do_textual_inversion_training(**vars(args))
except AssertionError as e:
print(str(e))
log.error(e)
sys.exit(-1)
except KeyboardInterrupt:
pass
except (widget.NotEnoughSpaceForWidget, Exception) as e:
if str(e).startswith("Height of 1 allocated"):
print(
"** You need to have at least one diffusers models defined in models.yaml in order to train"
log.error(
"You need to have at least one diffusers models defined in models.yaml in order to train"
)
elif str(e).startswith("addwstr"):
print(
"** Not enough window space for the interface. Please make your window larger and try again."
log.error(
"Not enough window space for the interface. Please make your window larger and try again."
)
else:
print(f"** An error has occurred: {str(e)}")
log.error(e)
sys.exit(-1)