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

Unet #95

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open

Unet #95

Changes from 1 commit
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
Prev Previous commit
Next Next commit
add tests for U-net
  • Loading branch information
jacob-rosenthal committed Feb 18, 2021
commit d40889cd59a313e79106f30f47648b12d67f3c7c
35 changes: 35 additions & 0 deletions tests/ml_tests/test_unet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pytest
import torch

from pathml.ml.unet import UNet


@pytest.mark.parametrize("keepdim", [True, False])
@pytest.mark.parametrize("out_c", [1, 3])
def test_unet_shapes(out_c, keepdim):
batch_size = 1
channels_in = 3
im_size_in = 572

x = torch.randn(batch_size, channels_in, im_size_in, im_size_in)

net = UNet(out_channels = out_c, keep_dim = keepdim)
out = net(x)

if keepdim:
assert out.shape == (batch_size, out_c, im_size_in, im_size_in)
else:

# compute output size, if keep_dim is false
nlayers = 4
im_size_out = im_size_in
# at each layer in encoder, two conv layers without padding loses 4px total, followed by a downsample by 2
for _ in range(nlayers):
im_size_out = (im_size_out - 4) / 2
# two more conv layers at the bottom layer
im_size_out = im_size_out - 4
# at each layer in decoder, upsample by 2 followed by two conv layers without padding for a loss of 4
for _ in range(nlayers):
im_size_out = (im_size_out * 2) - 4

assert out.shape == (batch_size, out_c, im_size_out, im_size_out)