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())
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)
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)))
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())
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())
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)))
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)
def model_head(fully_conv=True): if fully_conv: return [ df.SpatialConvolutionCUDNN(512, 4096, 7, 7, border='valid'), df.ReLU(), df.Dropout(0.5), df.SpatialConvolutionCUDNN(4096, 4096, 1, 1, border='valid'), df.ReLU(), df.Dropout(0.5), df.SpatialConvolutionCUDNN(4096, 1000, 1, 1, border='valid'), df.SpatialSoftMaxCUDNN(), ] else: return [ df.Reshape(-1, 512 * 7 * 7), df.Linear(512 * 7 * 7, 4096), df.ReLU(), df.Dropout(0.5), df.Linear(4096, 4096), df.ReLU(), df.Dropout(0.5), df.Linear(4096, 1000), df.SoftMax() ]
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
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
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