diff --git a/src/pytti/ImageGuide.py b/src/pytti/ImageGuide.py index 7bd10d1..5aff2b9 100644 --- a/src/pytti/ImageGuide.py +++ b/src/pytti/ImageGuide.py @@ -366,8 +366,11 @@ def report_out( if model.dataframe: rec = model.dataframe[0].iloc[-1] logger.debug(rec) - for k, v in rec.iteritems(): - writer.add_scalar(tag=f"losses/{k}", scalar_value=v, global_step=i) + if writer is not None: + for k, v in rec.iteritems(): + writer.add_scalar( + tag=f"losses/{k}", scalar_value=v, global_step=i + ) # does this VRAM stuff even do anything? if approximate_vram_usage: @@ -420,13 +423,14 @@ def save_out( im.save(filename) im_np = np.array(im) - writer.add_image( - tag="pytti output", - # img_tensor=filename, # thought this would work? - img_tensor=im_np, - global_step=i, - dataformats="HWC", # this was the key - ) + if writer is not None: + writer.add_image( + tag="pytti output", + # img_tensor=filename, # thought this would work? + img_tensor=im_np, + global_step=i, + dataformats="HWC", # this was the key + ) if backups > 0: filename = f"backup/{file_namespace}/{base_name}_{n}.bak" diff --git a/src/pytti/Transforms.py b/src/pytti/Transforms.py index 2bf6bd3..e1d336d 100644 --- a/src/pytti/Transforms.py +++ b/src/pytti/Transforms.py @@ -9,11 +9,12 @@ # from pytti.Image.PixelImage import PixelImage from adabins.infer import InferenceHelper # Not used here -TB_LOGDIR = "logs" # to do: make this more easily configurable +# TB_LOGDIR = "logs" # to do: make this more easily configurable from loguru import logger -from torch.utils.tensorboard import SummaryWriter -writer = SummaryWriter(TB_LOGDIR) +# from torch.utils.tensorboard import SummaryWriter + +# writer = SummaryWriter(TB_LOGDIR) PADDING_MODES = { "mirror": "reflection", @@ -339,8 +340,8 @@ def animate_2d( infill_mode, sampling_mode, img, - writer, - i, + writer=None, + i=0, t=-1, ): tx, ty = parametric_eval(translate_x), parametric_eval(translate_y) @@ -355,16 +356,17 @@ def animate_2d( sampling_mode=sampling_mode, ) ################ - for k, v in { - "tx": tx, - "ty": ty, - "theta": theta, - "zx": zx, - "zy": zy, - "t": t, - }.items(): - - writer.add_scalar(tag=f"translation_2d/{k}", scalar_value=v, global_step=i) + if writer is not None: + for k, v in { + "tx": tx, + "ty": ty, + "theta": theta, + "zx": zx, + "zy": zy, + "t": t, + }.items(): + writer.add_scalar(tag=f"translation_2d/{k}", scalar_value=v, global_step=i) + return next_step_pil diff --git a/src/pytti/assets/default.yaml b/src/pytti/assets/default.yaml index 7193648..ebd19ad 100644 --- a/src/pytti/assets/default.yaml +++ b/src/pytti/assets/default.yaml @@ -138,6 +138,7 @@ save_every: 50 backups: 0 show_graphs: false approximate_vram_usage: false +use_tensorboard: false ##################################### diff --git a/src/pytti/config/structured_config.py b/src/pytti/config/structured_config.py index d3db9d4..71bcd60 100644 --- a/src/pytti/config/structured_config.py +++ b/src/pytti/config/structured_config.py @@ -33,6 +33,7 @@ class ConfigSchema: image_model: str = "VQGAN" vqgan_model: str = "sflckr" animation_mode: str = field(default="off") + @animation_mode.validator def check(self, attribute, value): check_input_against_list( @@ -55,6 +56,7 @@ def check(self, attribute, value): cut_pow: int = 2 cutout_border: float = 0.25 border_mode: str = field(default="clamp") + @border_mode.validator def check(self, attribute, value): check_input_against_list( @@ -80,14 +82,13 @@ def check(self, attribute, value): translate_x: str = "0" translate_y: str = "0" translate_z_3d: str = "0" - rotate_3d: str = ( - "[1, 0, 0, 0]" - ) + rotate_3d: str = "[1, 0, 0, 0]" rotate_2d: str = "0" zoom_x_2d: str = "0" zoom_y_2d: str = "0" sampling_mode: str = field(default="bicubic") + @sampling_mode.validator def check(self, attribute, value): check_input_against_list( @@ -95,6 +96,7 @@ def check(self, attribute, value): ) infill_mode: str = field(default="wrap") + @infill_mode.validator def check(self, attribute, value): check_input_against_list( @@ -170,6 +172,7 @@ def check(self, attribute, value): backups: int = 0 show_graphs: bool = False approximate_vram_usage: bool = False + use_tensorboard: bool = False ##################################### diff --git a/src/pytti/warmup.py b/src/pytti/warmup.py index 9ffcc7b..990a95e 100644 --- a/src/pytti/warmup.py +++ b/src/pytti/warmup.py @@ -25,7 +25,7 @@ dest_fpath_demo = Path(full_local) / demo_fname logger.debug(__path__) -install_dir = Path(__path__) # uh... I hope this is correct? +install_dir = Path(__path__) shipped_fpath = install_dir / "assets" src_fpath_default = Path(shipped_fpath) / default_fname diff --git a/src/pytti/workhorse.py b/src/pytti/workhorse.py index 90cde8e..0b7df90 100644 --- a/src/pytti/workhorse.py +++ b/src/pytti/workhorse.py @@ -77,7 +77,7 @@ TB_LOGDIR = "logs" # to do: make this more easily configurable -writer = SummaryWriter(TB_LOGDIR) +# writer = SummaryWriter(TB_LOGDIR) OUTPATH = f"{os.getcwd()}/images_out/" # To do: ove remaining gunk into this... @@ -188,6 +188,10 @@ def _main(cfg: DictConfig): logger.debug(OmegaConf.to_container(cfg, resolve=True)) latest = -1 + writer = None + if params.use_tensorboard: + writer = SummaryWriter(TB_LOGDIR) + batch_mode = False # @param{type:"boolean"} ### Move these into default.yaml @@ -551,7 +555,8 @@ def do_run(): if fig: del fig, axs ############################# DMARX - writer.close() + if writer is not None: + writer.close() ############################# ## Work on getting rid of this batch mode garbage. Hydra's got this. diff --git a/tests/config/default.yaml b/tests/config/default.yaml index fcfdbf6..79f9e4d 100644 --- a/tests/config/default.yaml +++ b/tests/config/default.yaml @@ -134,6 +134,7 @@ save_every: 50 backups: 5 show_graphs: false approximate_vram_usage: false +use_tensorboard: false ##################################### diff --git a/tests/test_animation_broken.py b/tests/test_animation_broken.py index 349227e..0bfbbec 100644 --- a/tests/test_animation_broken.py +++ b/tests/test_animation_broken.py @@ -87,6 +87,9 @@ "gradient_accumulation_steps": 1, "border_mode": "clamp", "models_parent_dir": ".", + ########################## + # adding new config items for backwards compatibility + "use_tensorboard": True, # This should actually default to False. Prior to April2022, tb was non-optional }