Skip to content

Commit

Permalink
style: 🎨 run black
Browse files Browse the repository at this point in the history
  • Loading branch information
neptunes5thmoon committed Aug 22, 2024
1 parent cdbbfa4 commit 48b4afc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 7 additions & 3 deletions local.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ def show_one_image(image_path):
image = imageio.imread(image_path)
plt.imshow(image)


def unnormalize(tensor):
return (tensor+1)/2.
return (tensor + 1) / 2.0


class NucleiDataset(Dataset):
"""A PyTorch dataset to load cell images and nuclei masks"""
Expand Down Expand Up @@ -89,6 +91,7 @@ def show_random_dataset_image(dataset):
print("Image size is %s" % {img[0].shape})
plt.show()


def pad_to_size(small_tensor, target_size):
if small_tensor.size() > target_size:
msg = f"Can't pad tensor of size {small_tensor.size()} to tensor of size {target_size}."
Expand All @@ -97,10 +100,11 @@ def pad_to_size(small_tensor, target_size):
return small_tensor
pad_twoside = []
for small_size, large_size in zip(small_tensor.shape, target_size):
pad_twoside.append(math.floor((large_size - small_size)/2))
pad_twoside.append(math.ceil((large_size-small_size)/2))
pad_twoside.append(math.floor((large_size - small_size) / 2))
pad_twoside.append(math.ceil((large_size - small_size) / 2))
return torch.nn.functional.pad(small_tensor, pad_twoside[::-1])


def apply_and_show_random_image(f, ds):
# pick random raw image from dataset
img_tensor = ds[np.random.randint(len(ds))][0]
Expand Down
7 changes: 4 additions & 3 deletions solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
plot_receptive_field,
show_random_dataset_image,
pad_to_size,
unnormalize
unnormalize,
)

# %% tags=[]
Expand Down Expand Up @@ -1113,9 +1113,10 @@ def train(
global_step=step,
)
combined_image = torch.cat(
[x, pad_to_size(y, x.size()), pad_to_size(prediction, x.size())], dim=3
[x, pad_to_size(y, x.size()), pad_to_size(prediction, x.size())],
dim=3,
)

tb_logger.add_images(
tag="input_target_prediction",
img_tensor=combined_image,
Expand Down

0 comments on commit 48b4afc

Please sign in to comment.