Skip to content

Commit

Permalink
added use_tensorboard config option (PR #100)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarx authored Apr 1, 2022
2 parents 6ba4250 + 9442fbe commit f4eb385
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 30 deletions.
22 changes: 13 additions & 9 deletions src/pytti/ImageGuide.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
32 changes: 17 additions & 15 deletions src/pytti/Transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -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


Expand Down
1 change: 1 addition & 0 deletions src/pytti/assets/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ save_every: 50
backups: 0
show_graphs: false
approximate_vram_usage: false
use_tensorboard: false

#####################################

Expand Down
9 changes: 6 additions & 3 deletions src/pytti/config/structured_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -80,21 +82,21 @@ 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(
attribute, value, valid_values=["nearest", "bilinear", "bicubic"]
)

infill_mode: str = field(default="wrap")

@infill_mode.validator
def check(self, attribute, value):
check_input_against_list(
Expand Down Expand Up @@ -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

#####################################

Expand Down
2 changes: 1 addition & 1 deletion src/pytti/warmup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/pytti/workhorse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions tests/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ save_every: 50
backups: 5
show_graphs: false
approximate_vram_usage: false
use_tensorboard: false

#####################################

Expand Down
3 changes: 3 additions & 0 deletions tests/test_animation_broken.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand Down

0 comments on commit f4eb385

Please sign in to comment.