Skip to content
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

adds missing piece in utils code #13

Merged
merged 1 commit into from
Apr 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/sood/util/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import imp
import random
import warnings

import numpy as np
import torch
from torchvision.utils import save_image as tv_save_image
import os
from pathlib import Path


def get_vanilla_image_gradient(model, inpt, err_fn, abs=False):
Expand Down Expand Up @@ -204,14 +206,15 @@ def save_image_grid(tensor, name, save_dir, n_iter=None, prefix=False, iter_form
elif not name.endswith(".png"):
name += ".png"

img_file = os.path.join(save_dir, name)
img_file = save_dir / Path(name)

if image_args is None:
image_args = {}

os.makedirs(os.path.dirname(img_file), exist_ok=True)

tv_save_image(tensor, img_file, **image_args)
return str(img_file)


def name_and_iter_to_filename(name, n_iter, ending, iter_format="{:05d}", prefix=False):
Expand Down