Exemple #1
0
    def __init__(self,
                 nInputFeatures,
                 nClasses,
                 dropout_depth=False,
                 dropout_width=False,
                 dropout_p=0.5,
                 wide_model=False,
                 old_version=False):
        nn.Module.__init__(self)
        self.sparseModel = scn.Sequential().add(
            scn.ValidConvolution(3, nInputFeatures, 64, 3, False)).add(
            ResNetUNetDropout(3, 64, 2, 4, dropout_depth=dropout_depth, dropout_width=dropout_width, dropout_p=dropout_p) \
               if dropout_depth or dropout_width else scn.ResNetUNet(3, 64, 2, 4))

        self.use_wide_model = wide_model
        if wide_model:
            self.wide = nn.Linear(nInputFeatures, 1)
            #self.wide_and_deep = scn.JoinTable()
            self.linear = nn.Linear(65, nClasses)
            print "Using wide model"
        else:
            self.linear = nn.Linear(64, nClasses)

        self.act = nn.Softmax(dim=1)

        #Some older models still have this in, but it's not called
        if old_version:
            self.final = scn.ValidConvolution(3, 64, nClasses, 1, False)
            self.relu = scn.ReLU()
Exemple #2
0
 def __init__(self):
     nn.Module.__init__(self)
     self.stage1 = scn.Sequential().add(
         scn.ValidConvolution(3, 1, 16, 3, False))
     self.stage1.add(scn.MaxPooling(3, 2, 2))
     res(self.stage1, 3, 16, 64)
     self.stage1.add(scn.MaxPooling(3, 2, 2))
     self.stage2 = UNet6(3, nClasses)
     self.densePred = scn.SparseToDense(3, nClasses)
Exemple #3
0
 def __init__(self, sgc_config):
     nn.Module.__init__(self)
     self.stage1 = scn.Sequential().add(
        scn.ValidConvolution(3, 1, 16, 3, False))
     self.stage1_2 = scn.MaxPooling(3, 2, 2)
     self.stage2 = scn.Sequential()
     res(self.stage2, 3, 16, 64)
     self.stage2_2 = scn.MaxPooling(3, 2, 2)
     self.stage3 = UNet6(3, nClasses, sgc_config=sgc_config)
     self.densePred = scn.SparseToDense(3, nClasses)
     self.sgc_config = sgc_config
Exemple #4
0
 def __init__(self, num_classes=5):
     nn.Module.__init__(self)
     self.sparseModel = scn.Sequential().add(scn.DenseToSparse(2)).add(
         scn.ValidConvolution(2, 3, 8, 2, False)).add(
             scn.MaxPooling(2, 4, 2)).add(
                 scn.SparseResNet(2, 8, [['b', 8, 3, 1], [
                     'b', 16, 2, 2
                 ], ['b', 24, 2, 2], ['b', 32, 2, 2]])).add(
                     scn.Convolution(2, 32, 64, 4, 1,
                                     False)).add(scn.BatchNormReLU(64)).add(
                                         scn.SparseToDense(2, 64))
     self.linear = nn.Linear(6400, num_classes)
Exemple #5
0
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.

import torch
import sparseconvnet as scn

# Use the GPU if there is one, otherwise CPU
use_gpu = torch.cuda.is_available()

model = scn.Sequential().add(
    scn.SparseVggNet(2, 1,
		     [['C',  8], ['C',  8], ['MP', 3, 2],
		      ['C', 16], ['C', 16], ['MP', 3, 2],
		      ['C', 24], ['C', 24], ['MP', 3, 2]])
).add(
    scn.ValidConvolution(2, 24, 32, 3, False)
).add(
    scn.BatchNormReLU(32)
).add(
    scn.SparseToDense(2,32)
)
if use_gpu:
    model.cuda()

# output will be 10x10
inputSpatialSize = model.input_spatial_size(torch.LongTensor([10, 10]))
input = scn.InputBatch(2, inputSpatialSize)

msg = [
    " X   X  XXX  X    X    XX     X       X   XX   XXX   X    XXX   ",
    " X   X  X    X    X   X  X    X       X  X  X  X  X  X    X  X  ",
Exemple #6
0
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.

import torch
import sparseconvnet as scn

# Use the GPU if there is one, otherwise CPU
use_gpu = torch.cuda.is_available()

model = scn.Sequential().add(
    scn.SparseVggNet(2, 1,
                     [['C', 8], ['C', 8], ['MP', 3, 2], ['C', 16], ['C', 16],
                      ['MP', 3, 2], ['C', 24], ['C', 24], ['MP', 3, 2]
                      ])).add(scn.ValidConvolution(2, 24, 32, 3, False)).add(
                          scn.BatchNormReLU(32)).add(scn.SparseToDense(2, 32))
if use_gpu:
    model.cuda()

# output will be 10x10
inputSpatialSize = model.input_spatial_size(torch.LongTensor([10, 10]))
input = scn.InputBatch(2, inputSpatialSize)

msg = [
    " X   X  XXX  X    X    XX     X       X   XX   XXX   X    XXX   ",
    " X   X  X    X    X   X  X    X       X  X  X  X  X  X    X  X  ",
    " XXXXX  XX   X    X   X  X    X   X   X  X  X  XXX   X    X   X ",
    " X   X  X    X    X   X  X     X X X X   X  X  X  X  X    X  X  ",
    " X   X  XXX  XXX  XXX  XX       X   X     XX   X  X  XXX  XXX   "
]
Exemple #7
0
 def __init__(self):
     torch.nn.Module.__init__(self)
     self.sparseModel = scn.Sequential(
         scn.InputLayer(dimension=3, spatial_size=65536, mode=4),
         scn.ValidConvolution(3, 4, 16, 3, False),
         ShrinkScatterC22l(3, 16, 40, 1, 9), scn.OutputLayer(dimension=3))