-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
108 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,33 @@ | ||
import torch | ||
import numpy as np | ||
import PIL.Image as Image | ||
import torch | ||
|
||
|
||
def pil2tensor(image): | ||
return torch.from_numpy(np.array(image).astype(np.float32) / 255.0).unsqueeze(0) | ||
|
||
|
||
def tensor2pil(image): | ||
return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8)) | ||
return Image.fromarray( | ||
np.clip(255.0 * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8) | ||
) | ||
|
||
|
||
def conv_nd(dims, *args, **kwargs): | ||
""" | ||
Create a 1D, 2D, or 3D convolution module. | ||
""" | ||
if dims == 1: | ||
return torch.nn.Conv1d(*args, **kwargs) | ||
elif dims == 2: | ||
return torch.nn.Conv2d(*args, **kwargs) | ||
elif dims == 3: | ||
return torch.nn.Conv3d(*args, **kwargs) | ||
|
||
|
||
def linear(*args, **kwargs): | ||
return torch.nn.Linear(*args, **kwargs) | ||
|
||
|
||
def normalization(channels): | ||
return torch.nn.GroupNorm(32, channels) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters