-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from Tensor46/develop
+ added anatomy net for segmentation
- Loading branch information
Showing
6 changed files
with
397 additions
and
185 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,40 +1,58 @@ | ||
""" TensorMONK's :: NeuralArchitectures """ | ||
import torch.nn as nn | ||
from core.NeuralLayers import Convolution | ||
# =========================================================================== # | ||
|
||
""" TensorMONK's :: NeuralArchitectures """ | ||
|
||
import torch | ||
import torch.nn as nn | ||
import numpy as np | ||
from ..NeuralLayers import * | ||
#==============================================================================# | ||
class PointNet(nn.Module): | ||
r""" | ||
Implemented from paper: Learning Discriminative and Transformation | ||
Covariant Local Feature Detectors | ||
Args: | ||
tensor_size: shape of tensor in BCHW | ||
(None/any integer >0, channels, height, width) | ||
out_channels: depth of output feature channels. | ||
activation: None/relu/relu6/lklu/elu/prelu/tanh/sigm/maxo/rmxo/swish | ||
normalization: None/batch/group/instance/layer/pixelwise | ||
""" | ||
Implemented http://openaccess.thecvf.com/content_cvpr_2017/papers/Zhang_Learning_Discriminative_and_CVPR_2017_paper.pdf | ||
""" | ||
def __init__(self, tensor_size=(1, 1, 32, 32), out_channels=2, *args, **kwargs): | ||
def __init__(self, tensor_size=(1, 1, 32, 32), out_channels=2, | ||
*args, **kwargs): | ||
super(PointNet, self).__init__() | ||
normalization = "batch" | ||
self.PointNET = nn.Sequential() | ||
self.PointNET.add_module("CONV1", Convolution(tensor_size, 5, 32, 1, False, "relu", 0., None)) | ||
activation = "relu" | ||
self.PointNET = nn.Sequential() | ||
self.PointNET.add_module("CONV1", | ||
Convolution(tensor_size, 5, 32, 1, False, | ||
activation, 0., None)) | ||
self.PointNET.add_module("POOL1", nn.MaxPool2d(2)) | ||
_tensor_size = self.PointNET[-2].tensor_size | ||
_tensor_size = (_tensor_size[0], _tensor_size[1], _tensor_size[2]//2, _tensor_size[3]//2) | ||
#print(_tensor_size) | ||
self.PointNET.add_module("CONV2", Convolution(_tensor_size, 3, 128,1, False, "relu", 0.,normalization)) | ||
_tensor_size = (_tensor_size[0], _tensor_size[1], | ||
_tensor_size[2]//2, _tensor_size[3]//2) | ||
self.PointNET.add_module("CONV2", | ||
Convolution(_tensor_size, 3, 128, 1, False, | ||
activation, 0., normalization)) | ||
self.PointNET.add_module("POOL2", nn.MaxPool2d(2)) | ||
_tensor_size = self.PointNET[-2].tensor_size | ||
_tensor_size = (_tensor_size[0], _tensor_size[1], _tensor_size[2]//2, _tensor_size[3]//2) | ||
#print(_tensor_size) | ||
self.PointNET.add_module("CONV3", Convolution(_tensor_size, 3, 128, 1, False, "relu", 0.,normalization)) | ||
#print(self.PointNET[-1].tensor_size) | ||
self.PointNET.add_module("CONV4", Convolution(self.PointNET[-1].tensor_size, 3, 256, 1, False, "relu", 0.,normalization)) | ||
#print(self.PointNET[-1].tensor_size) | ||
self.PointNET.add_module("CONV5", Convolution(self.PointNET[-1].tensor_size, 2, out_channels, 1, False, "relu", 0.,None)) | ||
print(self.PointNET[-1].tensor_size) | ||
_tensor_size = (_tensor_size[0], _tensor_size[1], | ||
_tensor_size[2]//2, _tensor_size[3]//2) | ||
self.PointNET.add_module("CONV3", | ||
Convolution(_tensor_size, 3, 128, 1, False, | ||
activation, 0., normalization)) | ||
self.PointNET.add_module("CONV4", | ||
Convolution(self.PointNET[-1].tensor_size, 3, | ||
256, 1, False, activation, 0., | ||
normalization)) | ||
self.PointNET.add_module("CONV5", | ||
Convolution(self.PointNET[-1].tensor_size, 2, | ||
out_channels, 1, False, | ||
activation, 0., None)) | ||
self.tensor_size = self.PointNET[-1].tensor_size | ||
|
||
def forward(self, tensor): | ||
return self.PointNET(tensor).squeeze(2).squeeze(2) | ||
|
||
# from core.NeuralLayers import * | ||
|
||
# import torch | ||
# tensor_size = (1, 1, 32,32) | ||
# test = PointNet(tensor_size) | ||
# test(torch.rand(1,1,32,32)) |
Oops, something went wrong.