Esempio n. 1
0
def mknet():
    return df.Sequential(  # 48x70  (HxW)
        df.SpatialConvolution(3, 24, (3, 3)),  # 46x68
        df.BatchNormalization(24),
        df.ReLU(),
        df.SpatialConvolution(24, 24, (3, 3)),  # 44x66
        df.BatchNormalization(24),
        df.SpatialMaxPooling((2, 3)),  # 22x22
        df.ReLU(),
        df.SpatialConvolution(24, 48, (3, 3)),  # 20x20
        df.BatchNormalization(48),
        df.ReLU(),
        df.SpatialConvolution(48, 48, (3, 3)),  # 18x18
        df.BatchNormalization(48),
        df.SpatialMaxPooling((2, 2)),  # 9x9
        df.ReLU(),
        df.SpatialConvolution(48, 64, (3, 3)),  # 7x7
        df.BatchNormalization(64),
        df.ReLU(),
        df.SpatialConvolution(64, 64, (3, 3)),  # 5x5
        df.BatchNormalization(64),
        df.ReLU(),
        df.Dropout(0.2),
        Flatten(),
        df.Linear(64 * 5 * 5, 512),
        df.ReLU(),
        df.Dropout(0.5),
        df.Linear(512, 2, init=df.init.normal(0.01)),
        Biternion())
Esempio n. 2
0
def mknet_gpu(*outlayers):
    return df.Sequential(  #     3@46
        df.SpatialConvolutionCUDNN(3, 24, 3, 3),  # -> 24@44
        df.BatchNormalization(24),
        df.ReLU(),
        df.SpatialConvolutionCUDNN(24, 24, 3, 3),  # -> 24@42
        df.BatchNormalization(24),
        df.SpatialMaxPoolingCUDNN(2, 2),  # -> 24@21
        df.ReLU(),
        df.SpatialConvolutionCUDNN(24, 48, 3, 3),  # -> 48@19
        df.BatchNormalization(48),
        df.ReLU(),
        df.SpatialConvolutionCUDNN(48, 48, 3, 3),  # -> 48@17
        df.BatchNormalization(48),
        df.SpatialMaxPooling(2, 2),  # -> 48@9
        df.ReLU(),
        df.SpatialConvolutionCUDNN(48, 64, 3, 3),  # -> 48@7
        df.BatchNormalization(64),
        df.ReLU(),
        df.SpatialConvolutionCUDNN(64, 64, 3, 3),  # -> 48@5
        df.BatchNormalization(64),
        df.ReLU(),
        df.Dropout(0.2),
        Flatten(),
        df.Linear(64 * 5 * 5, 512),
        df.ReLU(),
        df.Dropout(0.5),
        *outlayers)
Esempio n. 3
0
    def __init__(self, weightsname, *unused, **unused_kw):
        self._net = df.Sequential(  # 48x70  (HxW)
            df.SpatialConvolution(3, 24, (3, 3)),  # 46x68
            df.BatchNormalization(24),
            df.ReLU(),
            df.SpatialConvolution(24, 24, (3, 3)),  # 44x66
            df.BatchNormalization(24),
            df.SpatialMaxPooling((2, 3)),  # 22x22
            df.ReLU(),
            df.SpatialConvolution(24, 48, (3, 3)),  # 20x20
            df.BatchNormalization(48),
            df.ReLU(),
            df.SpatialConvolution(48, 48, (3, 3)),  # 18x18
            df.BatchNormalization(48),
            df.SpatialMaxPooling((2, 2)),  # 9x9
            df.ReLU(),
            df.SpatialConvolution(48, 64, (3, 3)),  # 7x7
            df.BatchNormalization(64),
            df.ReLU(),
            df.SpatialConvolution(64, 64, (3, 3)),  # 5x5
            df.BatchNormalization(64),
            df.ReLU(),
            df.Dropout(0.2),
            Flatten(),
            df.Linear(64 * 5 * 5, 512),
            df.ReLU(),
            df.Dropout(0.5),
            df.Linear(512, 2, init=df.init.normal(0.01)),
            Biternion())

        self._net.__setstate__(np.load(weightsname))
        self._net.evaluate()

        self._aug = AugmentationPipeline(None, None, Cropper((48, 70)))
Esempio n. 4
0
def mknet():
    return df.Sequential(  #     3@46
        df.SpatialConvolution(3, 24, (3, 3)),  # -> 24@44
        df.BatchNormalization(24),
        df.ReLU(),
        df.SpatialConvolution(24, 24, (3, 3)),  # -> 24@42
        df.BatchNormalization(24),
        df.SpatialMaxPooling((2, 2), ignore_border=False),  # -> 24@21
        df.ReLU(),
        df.SpatialConvolution(24, 48, (3, 3)),  # -> 48@19
        df.BatchNormalization(48),
        df.ReLU(),
        df.SpatialConvolution(48, 48, (3, 3)),  # -> 48@17
        df.BatchNormalization(48),
        df.SpatialMaxPooling((2, 2), ignore_border=False),  # -> 48@9
        df.ReLU(),
        df.SpatialConvolution(48, 64, (3, 3)),  # -> 64@7
        df.BatchNormalization(64),
        df.ReLU(),
        df.SpatialConvolution(64, 64, (3, 3)),  # -> 64@5
        df.BatchNormalization(64),
        df.ReLU(),
        df.Dropout(0.2),
        Flatten(),
        df.Linear(64 * 5 * 5, 512),
        df.ReLU(),
        df.Dropout(0.5),
        df.Linear(512, 2, init=df.init.normal(0.01)),
        Biternion())
Esempio n. 5
0
def mknet():
    return df.Sequential(  # 184x76
        df.SpatialConvolution(3, 24, (3, 3)),  # 182x74
        df.BatchNormalization(24),
        df.ReLU(),
        df.SpatialConvolution(24, 24, (3, 3)),  # 180x72
        df.SpatialMaxPooling((3, 3)),  #  60x24
        df.BatchNormalization(24),
        df.ReLU(),
        df.SpatialConvolution(24, 48, (3, 3)),  #  58x22
        df.BatchNormalization(48),
        df.ReLU(),
        df.SpatialConvolution(48, 48, (3, 3)),  #  56x20
        df.SpatialMaxPooling((2, 2)),  #  28x10
        df.BatchNormalization(48),
        df.ReLU(),
        df.SpatialConvolution(48, 64, (3, 3)),  #  26x8
        df.BatchNormalization(64),
        df.ReLU(),
        df.SpatialConvolution(64, 64, (3, 3)),  #  24x6
        df.SpatialMaxPooling((2, 2)),  #  12x3
        df.BatchNormalization(64),
        df.ReLU(),
        df.SpatialConvolution(64, 64, (3, 2)),  #  10x2
        df.BatchNormalization(64),
        df.ReLU(),
        df.Dropout(0.2),
        Flatten(),
        df.Linear(64 * 10 * 2, 512),
        df.ReLU(),
        df.Dropout(0.5),
        df.Linear(512, 2, init=df.init.normal(0.01)),
        Biternion())
Esempio n. 6
0
    def __init__(self, weightsname, *unused, **unused_kw):
        self._net = df.Sequential(                  #     3@46
            df.SpatialConvolution( 3, 24, (3, 3)),  # -> 24@44
            df.BatchNormalization(24),
            df.ReLU(),
            df.SpatialConvolution(24, 24, (3, 3)),  # -> 24@42
            df.BatchNormalization(24),
            df.SpatialMaxPooling((2, 2), ignore_border=False),  # -> 24@21
            df.ReLU(),
            df.SpatialConvolution(24, 48, (3, 3)),  # -> 48@19
            df.BatchNormalization(48),
            df.ReLU(),
            df.SpatialConvolution(48, 48, (3, 3)),  # -> 48@17
            df.BatchNormalization(48),
            df.SpatialMaxPooling((2, 2), ignore_border=False),  # -> 48@9
            df.ReLU(),
            df.SpatialConvolution(48, 64, (3, 3)),  # -> 64@7
            df.BatchNormalization(64),
            df.ReLU(),
            df.SpatialConvolution(64, 64, (3, 3)),  # -> 64@5
            df.BatchNormalization(64),
            df.ReLU(),
            df.Dropout(0.2),
            Flatten(),
            df.Linear(64*5*5, 512),
            df.ReLU(),
            df.Dropout(0.5),
            df.Linear(512, 2, init=df.init.normal(0.01)),
            Biternion()
        )

        self._net.__setstate__(np.load(weightsname))
        self._net.evaluate()

        self._aug = AugmentationPipeline(None, None, Cropper((46, 46)))
Esempio n. 7
0
def net():
    model = df.Sequential()
    model.add(df.Linear(28 * 28, 100))
    model.add(df.ReLU())

    model.add(df.Linear(100, 100))
    model.add(df.ReLU())

    model.add(df.Linear(100, 100))
    model.add(df.ReLU())

    model.add(df.Linear(100, 10))
    model.add(df.SoftMax())
    return model
Esempio n. 8
0
def model(fully_conv=True):
    conv3 = lambda nin, nout: df.SpatialConvolutionCUDNN(
        nin, nout, 3, 3, border='same')

    return df.Sequential(conv3(3, 64), df.ReLU(), conv3(64, 64), df.ReLU(),
                         df.SpatialMaxPoolingCUDNN(2, 2), conv3(64, 128),
                         df.ReLU(), conv3(128, 128), df.ReLU(),
                         df.SpatialMaxPoolingCUDNN(2, 2), conv3(128, 256),
                         df.ReLU(), conv3(256,
                                          256), df.ReLU(), conv3(256, 256),
                         df.ReLU(), df.SpatialMaxPoolingCUDNN(2, 2),
                         conv3(256, 512), df.ReLU(), conv3(512,
                                                           512), df.ReLU(),
                         conv3(512, 512), df.ReLU(),
                         df.SpatialMaxPoolingCUDNN(2, 2), conv3(512, 512),
                         df.ReLU(), conv3(512, 512), df.ReLU(),
                         conv3(512, 512), df.ReLU(),
                         df.SpatialMaxPoolingCUDNN(2, 2),
                         *_vgg.model_head(fully_conv))
Esempio n. 9
0
def lenet():
    model = df.Sequential()
    model.add(df.Reshape(-1, 1, 28, 28))
    model.add(df.SpatialConvolution(1, 32, 5, 5, 1, 1, with_bias=False))
    model.add(df.BatchNormalization(32))
    model.add(df.ReLU())
    model.add(df.SpatialMaxPooling(2, 2))

    model.add(df.SpatialConvolution(32, 64, 5, 5, 1, 1, with_bias=False))
    model.add(df.BatchNormalization(64))
    model.add(df.ReLU())
    model.add(df.SpatialMaxPooling(2, 2))
    model.add(df.Reshape(-1, 4 * 4 * 64))

    model.add(df.Linear(4 * 4 * 64, 100, with_bias=False))
    model.add(df.BatchNormalization(100))
    model.add(df.ReLU())
    model.add(df.Dropout(0.5))

    model.add(df.Linear(100, 10))
    model.add(df.SoftMax())
    return model
Esempio n. 10
0
def lenet_cudnn():
    model = df.Sequential()
    model.add(df.Reshape(-1, 1, 28, 28))
    model.add(
        df.SpatialConvolutionCUDNN(1,
                                   32,
                                   5,
                                   5,
                                   1,
                                   1,
                                   border='same',
                                   with_bias=False))
    model.add(df.BatchNormalization(32))
    model.add(df.ReLU())
    model.add(df.SpatialMaxPoolingCUDNN(2, 2))

    model.add(
        df.SpatialConvolutionCUDNN(32,
                                   64,
                                   5,
                                   5,
                                   1,
                                   1,
                                   border='same',
                                   with_bias=False))
    model.add(df.BatchNormalization(64))
    model.add(df.ReLU())
    model.add(df.SpatialMaxPoolingCUDNN(2, 2))
    model.add(df.Reshape(-1, 7 * 7 * 64))

    model.add(df.Linear(7 * 7 * 64, 100, with_bias=False))
    model.add(df.BatchNormalization(100))
    model.add(df.ReLU())
    model.add(df.Dropout(0.5))

    model.add(df.Linear(100, 10))
    model.add(df.SoftMax())
    return model
Esempio n. 11
0
    def __init__(self, weightsname, *unused, **unused_kw):
        self._net = df.Sequential(  # 184x76
            df.SpatialConvolution(3, 24, (3, 3)),  # 182x74
            df.BatchNormalization(24),
            df.ReLU(),
            df.SpatialConvolution(24, 24, (3, 3)),  # 180x72
            df.SpatialMaxPooling((3, 3)),  #  60x24
            df.BatchNormalization(24),
            df.ReLU(),
            df.SpatialConvolution(24, 48, (3, 3)),  #  58x22
            df.BatchNormalization(48),
            df.ReLU(),
            df.SpatialConvolution(48, 48, (3, 3)),  #  56x20
            df.SpatialMaxPooling((2, 2)),  #  28x10
            df.BatchNormalization(48),
            df.ReLU(),
            df.SpatialConvolution(48, 64, (3, 3)),  #  26x8
            df.BatchNormalization(64),
            df.ReLU(),
            df.SpatialConvolution(64, 64, (3, 3)),  #  24x6
            df.SpatialMaxPooling((2, 2)),  #  12x3
            df.BatchNormalization(64),
            df.ReLU(),
            df.SpatialConvolution(64, 64, (3, 2)),  #  10x2
            df.BatchNormalization(64),
            df.ReLU(),
            df.Dropout(0.2),
            Flatten(),
            df.Linear(64 * 10 * 2, 512),
            df.ReLU(),
            df.Dropout(0.5),
            df.Linear(512, 2, init=df.init.normal(0.01)),
            Biternion())

        self._net.__setstate__(np.load(weightsname))
        self._net.evaluate()

        self._aug = AugmentationPipeline(None, None, Cropper((184, 76)))
 def mknet(self, *outlayers):
     return df.Sequential(
         #df.SpatialConvolutionCUDNN(3,24,(3,3)),
         df.SpatialConvolution(3, 24, (3, 3)),
         df.BatchNormalization(24),
         df.ReLU(),
         #df.SpatialConvolutionCUDNN(24,24,(3,3)),
         df.SpatialConvolution(24, 24, (3, 3)),
         df.BatchNormalization(24),
         #df.SpatialMaxPoolingCUDNN(2,2),
         df.SpatialMaxPooling((2, 2)),
         #df.MaxPooling(2,2),
         df.ReLU(),
         #df.SpatialConvolutionCUDNN(24,48,(3,3)),
         df.SpatialConvolution(24, 48, (3, 3)),
         df.BatchNormalization(48),
         df.ReLU(),
         # df.PoolingCUDNN()?
         df.SpatialMaxPoolingCUDNN(48, 48, 3, 3),
         #df.SpatialConvolution(48,48,(3,3)),
         df.BatchNormalization(48),
         df.SpatialMaxPooling((2, 2)),
         df.ReLU(),
         #df.SpatialConvolutionCUDNN(48,64,(3,3)),
         df.SpatialConvolution(48, 64, (3, 3)),
         df.BatchNormalization(64),
         df.ReLU(),
         #df.SpatialConvolutionCUDNN(64,64,(3,3)),
         df.SpatialConvolution(64, 64, (3, 3)),
         df.BatchNormalization(64),
         df.ReLU(),
         df.Dropout(0.2),
         Flatten(),
         df.Linear(64 * 5 * 5, 512),
         df.ReLU(),
         df.Dropout(0.5),
         *outlayers)
Esempio n. 13
0
def nnet():
    model = df.Sequential()
    model.add(df.AddConstant(1.0))
    model.add(df.Log())
    model.add(df.BatchNormalization(93))
    model.add(df.Dropout(0.1))
    model.add(df.Linear(93, 512))
    model.add(df.BatchNormalization(512))
    model.add(df.ReLU())
    model.add(df.Dropout(0.5))

    model.add(df.Linear(512, 512))
    model.add(df.BatchNormalization(512))
    model.add(df.ReLU())
    model.add(df.Dropout(0.5))

    model.add(df.Linear(512, 512))
    model.add(df.BatchNormalization(512))
    model.add(df.ReLU())
    model.add(df.Dropout(0.5))

    model.add(df.Linear(512, 9))
    model.add(df.SoftMax())
    return model
    (trainX, trainY, trainNum), (testX, testY, testNum) = split(data,
                                                                label,
                                                                Number,
                                                                split=0.9)
    #trainX,trainY = trainX.astype(df.floatX)/255,trainY.astype(df.floatX)
    trainX, trainY = trainX.astype(np.float32) / 255, trainY.astype(np.float32)
    #testX,testY = testX.astype(df.floatX)/255,testY.astype(df.floatX)
    testX, testY = testX.astype(np.float32) / 255, testY.astype(np.float32)
    pdb.set_trace()
    ################### Pure Linear Regression #######################

    aug = AugmentationPipeline(trainX, trainY, Cropper((46, 46)))

    #LinearTrain = [dotrain(net,df.MADCriterion(),aug,trainX,trainY[:,None]) for net in nets_shallow_linreg]
    nets_shallow_linreg = [
        df.Sequential(Flatten(),
                      df.Linear(3 * 46 * 46, 1, init=df.init.const(0)))
        for _ in range(10)
    ]

    LinearPred = [
        Flatten().dopred_deg(net, aug, testX) for net in nets_shallow_linreg
    ]
    Flatten().Error(LinearPred, testY[:, None])

    pdb.set_trace()
    #################### Deep Linear Regression ##################

    nets_linreg = [
        Flatten().mknet(df.Linear(512, 1, init=df.init.const(0)))
        for _ in range(5)
    ]