def __init__(self, data, label, class_n=21): self.net = caffe.NetSpec() self.createDataLayer(data, label) self.in_block = self.creatInitBlock() self.encoder1 = self.createEncoder("res2", self.in_block["top"], 64) self.encoder2 = self.createEncoder("res3", self.encoder1["top"], 128, stride=2) self.encoder3 = self.createEncoder("res4", self.encoder2["top"], 256, stride=2) self.encoder4 = self.createEncoder("res5", self.encoder3["top"], 512, stride=2) self.decoder4 = self.createDecoder("decoder4", self.encoder4["top"], 512, 256, 2, pad=0) d4_crop = crop(self.decoder4["top"], self.encoder3["top"]) d3_in = L.Eltwise(self.encoder3["top"], d4_crop, operation=P.Eltwise.SUM) self.decoder3 = self.createDecoder("decoder3", d3_in, 256, 128, 2, pad=0) d3_crop = crop(self.decoder3["top"], self.encoder2["top"]) d2_in = L.Eltwise(self.encoder2["top"], d3_crop, operation=P.Eltwise.SUM) self.decoder2 = self.createDecoder("decoder2", d2_in, 128, 64, 2, pad=0) d2_crop = crop(self.decoder2["top"], self.encoder1["top"]) d1_in = L.Eltwise(self.encoder1["top"], d2_crop, operation=P.Eltwise.SUM) self.decoder1 = self.createDecoder("decoder1", d1_in, 64, 64, 1, pad=0) d1_crop = crop(self.decoder1["top"], self.in_block["top"]) self.endblock = self.createEndBlock(d1_crop, 64, class_n) end_crop = crop(self.endblock["top"], data) n = self.net n.loss = L.SoftmaxWithLoss(end_crop, n.label, loss_param=dict(normalize=False, ignore_label=255))
def fcn(obj_cls, part, split): n = caffe.NetSpec() n.data, n.label = L.Python(module='pascalpart_layers', layer='PASCALPartSegDataLayer', ntop=2, param_str=str(dict(voc_dir='/home/cv/hdl/caffe/data/pascal/VOC', part_dir='/home/cv/hdl/caffe/data/pascal/pascal-part', obj_cls=obj_cls, part=part, split=split, seed=1337))) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution(n.drop7, num_output=11, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore2 = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=11, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) n.score_pool4 = L.Convolution(n.pool4, num_output=11, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool4c = crop(n.score_pool4, n.upscore2) n.fuse_pool4 = L.Eltwise(n.upscore2, n.score_pool4c, operation=P.Eltwise.SUM) n.upscore16 = L.Deconvolution(n.fuse_pool4, convolution_param=dict(num_output=11, kernel_size=32, stride=16, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore16, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def fcn(split): n = caffe.NetSpec() n.data, n.sem, n.geo = L.Python(module='siftflow_layers', layer='SIFTFlowSegDataLayer', ntop=3, param_str=str(dict(siftflow_dir='../data/sift-flow', split=split, seed=1337))) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr_sem = L.Convolution(n.drop7, num_output=33, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore_sem = L.Deconvolution(n.score_fr_sem, convolution_param=dict(num_output=33, kernel_size=64, stride=32, bias_term=False), param=[dict(lr_mult=0)]) n.score_sem = crop(n.upscore_sem, n.data) # losses to make score happy (o.w. loss_sem) n.loss = L.SoftmaxWithLoss(n.score_sem, n.sem, loss_param=dict(normalize=False, ignore_label=255)) n.score_fr_geo = L.Convolution(n.drop7, num_output=3, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore_geo = L.Deconvolution(n.score_fr_geo, convolution_param=dict(num_output=3, kernel_size=64, stride=32, bias_term=False), param=[dict(lr_mult=0)]) n.score_geo = crop(n.upscore_geo, n.data) n.loss_geo = L.SoftmaxWithLoss(n.score_geo, n.geo, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def fcn(split): n = caffe.NetSpec() n.data, n.sem, n.geo = L.Python(module='siftflow_layers', layer='SIFTFlowSegDataLayer', ntop=3, param_str=str(dict(siftflow_dir='../data/sift-flow', split=split, seed=1337))) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr_sem = L.Convolution(n.drop7, num_output=33, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore_sem = L.Deconvolution(n.score_fr_sem, convolution_param=dict(num_output=33, kernel_size=64, stride=32, bias_term=False), param=[dict(lr_mult=0)]) n.score_sem = crop(n.upscore_sem, n.data) # loss to make score happy (o.w. loss_sem) n.loss = L.SoftmaxWithLoss(n.score_sem, n.sem, loss_param=dict(normalize=False, ignore_label=255)) n.score_fr_geo = L.Convolution(n.drop7, num_output=3, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore_geo = L.Deconvolution(n.score_fr_geo, convolution_param=dict(num_output=3, kernel_size=64, stride=32, bias_term=False), param=[dict(lr_mult=0)]) n.score_geo = crop(n.upscore_geo, n.data) n.loss_geo = L.SoftmaxWithLoss(n.score_geo, n.geo, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def fcn(split, tops): n = caffe.NetSpec() n.data, n.label = L.Python(module='nyud_layers', layer='NYUDSegDataLayer', ntop=2, param_str=str(dict(nyud_dir='../data/nyud', split=split, tops=tops, seed=1337))) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution(n.drop7, num_output=40, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore2 = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=40, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) n.score_pool4 = L.Convolution(n.pool4, num_output=40, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool4c = crop(n.score_pool4, n.upscore2) n.fuse_pool4 = L.Eltwise(n.upscore2, n.score_pool4c, operation=P.Eltwise.SUM) n.upscore16 = L.Deconvolution(n.fuse_pool4, convolution_param=dict(num_output=40, kernel_size=32, stride=16, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore16, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def test_catch_scale_mismatch(self): """ Catch incompatible scales, such as when the top to be cropped is mapped to a differently strided reference top. """ n = coord_net_spec(pool=3, dstride=2) # pool 3x but deconv 2x with self.assertRaises(AssertionError): crop(n.deconv, n.data)
def test_catch_negative_crop(self): """ Catch impossible offsets, such as when the top to be cropped is mapped to a larger reference top. """ n = coord_net_spec(dpad=10) # make output smaller than input with self.assertRaises(AssertionError): crop(n.deconv, n.data)
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(104.00699, 116.66877, 122.67892), seed=1337) if split == 'train': pydata_params['sbdd_dir'] = '../data/sbdd/dataset' pylayer = 'SBDDSegDataLayer' else: pydata_params['voc_dir'] = '../data/pascal/VOC2011' pylayer = 'VOCSegDataLayer' n.data, n.label = L.Python(module='voc_layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1, n.relu1 = conv_relu(n.data,96,ks=11,stride=4,pad=100) n.pool1 = max_pool(n.relu1) n.lrn1 = lrn(n.pool1) n.conv2, n.relu2 = conv_relu(n.lrn1, 256, ks=5, stride=1, pad=2, group=2) n.pool2 = max_pool(n.relu2) n.lrn2 = lrn(n.pool2) n.conv3, n.relu3 = conv_relu(n.lrn2, 384, ks=3, stride = 1, pad=1) n.conv4, n.relu4 = conv_relu(n.relu3, 384, ks=3, stride = 1, pad=1, group=2) n.conv5, n.relu5 = conv_relu(n.relu4, 256, ks=3, stride = 1, pad=1, group=2) n.pool5 = max_pool(n.relu5) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=6, stride = 1, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, stride = 1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution(n.drop7, num_output=21, kernel_size=1, pad=0, stride = 1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore2 = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=21, kernel_size=5, stride=2, bias_term=False), param=[dict(lr_mult=0)]) n.score_pool2 = L.Convolution(n.lrn2, num_output=21, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool2c = crop(n.score_pool2, n.upscore2) n.fuse_pool2 = L.Eltwise(n.upscore2, n.score_pool2c, operation=P.Eltwise.SUM) n.upscore16 = L.Deconvolution(n.fuse_pool2, convolution_param=dict(num_output=21, kernel_size=31, stride=16, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore16, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=True, ignore_label=255)) return n.to_proto()
def fcn(split, num_classes=None): n = caffe.NetSpec() n.data = L.Input(shape=[dict(dim=[1, 3, 500, 500])]) # conv1 n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) # conv2 n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) # conv3 n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) # score n.score_fr = L.Convolution(n.pool3, num_output=num_classes, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) # deconv : 8x n.upscore = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=num_classes, kernel_size=16, stride=8, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore, n.data) return n.to_proto()
def fcn(split, tops): n = caffe.NetSpec() n.color, n.hha, n.label = L.Python(module='nyud_layers', layer='NYUDSegDataLayer', ntop=3, param_str=str( dict(nyud_dir='../data/nyud', split=split, tops=tops, seed=1337))) n = modality_fcn(n, 'color', 'color') n = modality_fcn(n, 'hha', 'hha') n.score_fused = L.Eltwise(n.score_frcolor, n.score_frhha, operation=P.Eltwise.SUM, coeff=[0.5, 0.5]) n.upscore = L.Deconvolution(n.score_fused, convolution_param=dict(num_output=40, kernel_size=64, stride=32, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore, n.color) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(104.00699, 116.66877, 122.67892), seed=1337) ''' if split == 'train': pydata_params['sbdd_dir'] = '../../data/sbdd/dataset' pylayer = 'SBDDSegDataLayer' else: # pydata_params['voc_dir'] = '../../data/pascal/VOC2011' pydata_params['voc_dir'] = '/home/joe/FCN/VOCtrainval_06-Nov-2007/VOCdevkit/VOC2007/ImageSets/Segmentation' pylayer = 'VOCSegDataLayer' ''' pydata_params['voc_dir'] = '/home/joe/FCN/VOCtrainval_06-Nov-2007/VOCdevkit/VOC2007' pylayer = 'VOCSegDataLayer' n.data, n.label = L.Python(module='layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution(n.drop7, num_output=21, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=21, kernel_size=64, stride=32, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def generate_net(): n = caffe.NetSpec() n.data = L.Data(source=TRAIN_LMDB_DATA_FILE, backend=P.Data.LMDB, batch_size=1, ntop=1, transform_param=dict(scale=1. / 255)) n.label = L.Data(source=TRAIN_LMDB_LABEL_FILE, backend=P.Data.LMDB, batch_size=1, ntop=1) # the base net n.conv1, n.relu1 = conv_relu(n.data, 11, 96, stride=4, pad=100) n.pool1 = max_pool(n.relu1, 3, stride=2) n.norm1 = L.LRN(n.pool1, local_size=5, alpha=1e-4, beta=0.75) n.conv2, n.relu2 = conv_relu(n.norm1, 5, 256, pad=2, group=2) n.pool2 = max_pool(n.relu2, 3, stride=2) n.norm2 = L.LRN(n.pool2, local_size=5, alpha=1e-4, beta=0.75) n.conv3, n.relu3 = conv_relu(n.norm2, 3, 384, pad=1) n.conv4, n.relu4 = conv_relu(n.relu3, 3, 384, pad=1, group=2) n.conv5, n.relu5 = conv_relu(n.relu4, 3, 256, pad=1, group=2) n.pool5 = max_pool(n.relu5, 3, stride=2) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 6, 4096) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 1, 4096) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) # weight_filler=dict(type='gaussian', std=0.0001), bias_filler=dict(type='constant') n.score_fr_ = L.Convolution( n.drop7, num_output=2, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore_ = L.Deconvolution(n.score_fr_, convolution_param=dict( num_output=2, kernel_size=63, stride=32, group=2, bias_term=False, weight_filler=dict(type='bilinear')), param=[dict(lr_mult=0)]) n.score = crop(n.upscore_, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_weight=1, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(104.00699, 116.66877, 122.67892), seed=1337) if split == 'train': pydata_params['sbdd_dir'] = '../data/sbdd/dataset' pylayer = 'BDDSegDataLayer' else: pydata_params['bdd_dir'] = '/dl/data/bdd100k/seg' pylayer = 'BDDSegDataLayer' n.data, n.label = L.Python(module='voc_layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1, n.relu1 = conv_relu(n.data, 11, 96, stride=4, pad=100) n.pool1 = max_pool(n.relu1, 3, stride=2) n.norm1 = L.LRN(n.pool1, local_size=5, alpha=1e-4, beta=0.75) n.conv2, n.relu2 = conv_relu(n.norm1, 5, 256, pad=2, group=2) n.pool2 = max_pool(n.relu2, 3, stride=2) n.norm2 = L.LRN(n.pool2, local_size=5, alpha=1e-4, beta=0.75) n.conv3, n.relu3 = conv_relu(n.norm2, 3, 384, pad=1) n.conv4, n.relu4 = conv_relu(n.relu3, 3, 384, pad=1, group=2) n.conv5, n.relu5 = conv_relu(n.relu4, 3, 256, pad=1, group=2) n.pool5 = max_pool(n.relu5, 3, stride=2) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 6, 4096) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 1, 4096) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution( n.drop7, num_output=21, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) # upscore n.upscore = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=21, kernel_size=63, stride=32, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=True, ignore_label=255)) return n.to_proto()
def vgg_fcn_32s(n, nclasses, learn = True): # first in put 'n', must have layer n.data n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, learn = learn, pad = 81) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64, learn = learn) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128, learn = learn) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128, learn = learn) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256, learn = learn) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256, learn = learn) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256, learn = learn) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512, learn = learn) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512, learn = learn) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512, learn = learn) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512, learn = learn) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512, learn = learn) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512, learn = learn) n.pool5 = max_pool(n.relu5_3) n.fc6_conv, n.relu6 = conv_relu(n.pool5, 4096, ks = 7, pad = 0, learn = learn) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7_conv, n.relu7 = conv_relu(n.relu6, 4096, ks = 1, pad = 0, learn = learn) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_small = L.Convolution(n.drop7, kernel_size=1, stride=1, num_output=nclasses, pad=0, param=[dict(lr_mult=5, decay_mult=1), dict(lr_mult=10, decay_mult=0)], weight_filler= dict(type="gaussian",std=0.005), bias_filler=dict(type="constant", value = 1)) n.score_upsample = L.Deconvolution(n.score_small, convolution_param = dict( bias_term=False, kernel_size=64, stride=32, group = nclasses, num_output= nclasses, weight_filler= dict( type='bilinear')), param= dict( lr_mult=0, decay_mult=1), ) n.score = coord_map.crop(n.score_upsample, n.data) return n
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(104.00699, 116.66877, 122.67892), seed=1337) if split == 'train': pydata_params['sbdd_dir'] = '../../data/sbdd/dataset' pylayer = 'SBDDSegDataLayer' else: pydata_params['voc_dir'] = '../../data/pascal/VOC2011' pylayer = 'VOCSegDataLayer' n.data, n.label = L.Python(module='layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution(n.drop7, num_output=21, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=21, kernel_size=64, stride=32, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(104.00699, 116.66877, 122.67892), seed=1337) pydata_params['data_path'] = './laneseg_train_10.h5' pylayer = 'VOCSegDataLayer' n.data, n.label = L.Python(module='voc_layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.ls_score_fr = L.Convolution(n.drop7, num_output=2, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)], weight_filler=dict(type='xavier'), ) n.ls_upscore = L.Deconvolution(n.ls_score_fr, convolution_param=dict(num_output=2, kernel_size=64, stride=32, bias_term=False), param=[dict(lr_mult=0)]) n.ls_upscore.fn.params['convolution_param']['weight_filler'] = dict(type='xavier') n.score = crop(n.ls_upscore, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def fcn(split, tops): n = caffe.NetSpec() n.color, n.depth, n.label = L.Python(module='nyud_layers', layer='NYUDSegDataLayer', ntop=3, param_str=str(dict(nyud_dir='../data/nyud', split=split, tops=tops, seed=1337))) n.data = L.Concat(n.color, n.depth) # the base net n.conv1_1_bgrd, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution(n.drop7, num_output=40, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=40, kernel_size=64, stride=32, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def fcn(split, tops): n = caffe.NetSpec() n.color, n.hha, n.label = L.Python(module='nyud_layers', layer='NYUDSegDataLayer', ntop=3, param_str=str(dict(nyud_dir='../data/nyud', split=split, tops=tops, seed=1337))) n = modality_fcn(n, 'color', 'color') n = modality_fcn(n, 'hha', 'hha') n.score_fused = L.Eltwise(n.score_frcolor, n.score_frhha, operation=P.Eltwise.SUM, coeff=[0.5, 0.5]) n.upscore = L.Deconvolution(n.score_fused, convolution_param=dict(num_output=40, kernel_size=64, stride=32, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore, n.color) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(104.00699, 116.66877, 122.67892), seed=1337) if split == 'train': pydata_params['sbdd_dir'] = '../data/sbdd/dataset' pylayer = 'SBDDSegDataLayer' else: pydata_params['voc_dir'] = '../data/pascal/VOC2011' pylayer = 'VOCSegDataLayer' n.data, n.label = L.Python(module='voc_layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1, n.relu1 = conv_relu(n.data, 11, 96, stride=4, pad=100) n.pool1 = max_pool(n.relu1, 3, stride=2) n.norm1 = L.LRN(n.pool1, local_size=5, alpha=1e-4, beta=0.75) n.conv2, n.relu2 = conv_relu(n.norm1, 5, 256, pad=2, group=2) n.pool2 = max_pool(n.relu2, 3, stride=2) n.norm2 = L.LRN(n.pool2, local_size=5, alpha=1e-4, beta=0.75) n.conv3, n.relu3 = conv_relu(n.norm2, 3, 384, pad=1) n.conv4, n.relu4 = conv_relu(n.relu3, 3, 384, pad=1, group=2) n.conv5, n.relu5 = conv_relu(n.relu4, 3, 256, pad=1, group=2) n.pool5 = max_pool(n.relu5, 3, stride=2) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 6, 4096) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 1, 4096) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution(n.drop7, num_output=21, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=21, kernel_size=63, stride=32, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=True, ignore_label=255)) return n.to_proto()
def __init__(self, data, label, class_n=21): self.net = caffe.NetSpec() n = self.net self.createDataLayer(data, label) self.in_block = self.creatInitBlock() self.encoder1 = self.createEncoder("res2", self.in_block["top"], 64) self.encoder2 = self.createEncoder("res3", self.encoder1["top"], 128, stride=2) self.encoder3 = self.createEncoder("res4", self.encoder2["top"], 256, stride=2) self.encoder4 = self.createEncoder("res5", self.encoder3["top"], 512, stride=2) # self.decoder4 = self.createDecoder("decoder4", self.encoder4["top"], 512, 256, 2, pad=0) # d4_crop = crop(self.decoder4["top"], self.encoder3["top"]) # d3_in = L.Eltwise(self.encoder3["top"], d4_crop, operation=P.Eltwise.SUM) # self.decoder3 = self.createDecoder("decoder3", d3_in, 256, 128, 2, pad=0) # d3_crop = crop(self.decoder3["top"], self.encoder2["top"]) # d2_in = L.Eltwise(self.encoder2["top"], d3_crop, operation=P.Eltwise.SUM) # self.decoder2 = self.createDecoder("decoder2", d2_in, 128, 64, 2, pad=0) # d2_crop = crop(self.decoder2["top"], self.encoder1["top"]) # d1_in = L.Eltwise(self.encoder1["top"], d2_crop, operation=P.Eltwise.SUM) # self.decoder1 = self.createDecoder("decoder1", d1_in, 64, 64, 1, pad=0) # d1_crop = crop(self.decoder1["top"], self.in_block["top"]) # self.endblock = self.createEndBlock(d1_crop, 64, class_n) # end_crop = crop(self.endblock["top"], data) n.score_fr = L.Convolution(self.encoder4["top"], num_output=21, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=21, kernel_size=64, stride=32, bias_term=False, weight_filler=dict(type="bilinear") ), param=[dict(lr_mult=0)]) n.score = crop(n.upscore, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255))
def define_structure(self, stage): n = caffe.NetSpec() if stage != NetStage.DEPLOY: source_params = dict(stage=stage) source_params['dataset_dir'] = self.DATASET_DIR source_params['patch_dir'] = self.PATCH_DIR source_params['average_image'] = self.AVERAGE_IMAGE source_params['training_patches'] = self.TRAINING_PATCHES source_params['validation_patches'] = self.VALIDATION_PATCHES source_params['random_training'] = self.RANDOM_TRAINING source_params['include_rotations'] = self.INCLUDE_ROTATIONS n.data, n.label = L.Python(module='DataLayer', layer='DataLayer', ntop=2, param_str=str(source_params)) else: n.data = L.Input(shape=dict(dim=[1, 3, self.WSIZE, self.WSIZE])) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 32, pad=85) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 32) n.pool1 = max_pool(n.conv1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 64) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 64) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 128) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 128) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 128) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 256) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 256) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 256) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 256) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 256) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 256) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 2048, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 2048, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution( n.drop7, num_output=self.NUM_LABELS, kernel_size=1, pad=0, param=[ dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0) ], weight_filler=dict(type='xavier'), bias_filler=dict( type='constant')) # must be 1 x num_classes x 1 x 1 n.upscore_a = L.Deconvolution(n.score_fr, convolution_param=dict( num_output=self.NUM_LABELS, kernel_size=4, stride=2, bias_term=False, weight_filler=dict(type='xavier'), bias_filler=dict(type='constant')), param=[dict(lr_mult=1, decay_mult=1)]) n.score_pool4 = L.Convolution(n.pool4, num_output=self.NUM_LABELS, kernel_size=1, pad=0, param=[ dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0) ], weight_filler=dict(type='xavier'), bias_filler=dict(type='constant')) n.score_pool4c = crop(n.score_pool4, n.upscore_a) n.fuse_pool4 = L.Eltwise(n.upscore_a, n.score_pool4c, operation=P.Eltwise.SUM) n.upscore_pool4 = L.Deconvolution( n.fuse_pool4, convolution_param=dict(num_output=self.NUM_LABELS, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=1, decay_mult=1)]) n.score_pool3 = L.Convolution(n.pool3, num_output=self.NUM_LABELS, kernel_size=1, pad=0, param=[ dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0) ], weight_filler=dict(type='xavier'), bias_filler=dict(type='constant')) n.score_pool3c = crop(n.score_pool3, n.upscore_pool4) n.fuse_pool3 = L.Eltwise(n.upscore_pool4, n.score_pool3c, operation=P.Eltwise.SUM) n.upscore8 = L.Deconvolution(n.fuse_pool3, convolution_param=dict( num_output=self.NUM_LABELS, kernel_size=16, stride=8, bias_term=False), param=[dict(lr_mult=1, decay_mult=1)]) n.score = crop(n.upscore8, n.data) if stage != NetStage.DEPLOY: n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False)) # @TODO: here we were investigating other losses. If required this is the place to plug the loss layer in # else: # n.output = L.Softmax(n.score) # n.loss = L.Python(n.score, n.label, module='LossLayer', layer='TopoLossLayer', loss_weight=1) return n.to_proto()
def fcn(split,fname_img_lmdb,fname_map_lmdb,learn_all=False): param = learned_param if learn_all else frozen_param n = caffe.NetSpec() # invoke LMDB data loader n.data = L.Data(batch_size=1, backend=P.Data.LMDB, source=fname_img_lmdb, ntop=1) n.label = L.Data(batch_size=1, backend=P.Data.LMDB, source=fname_map_lmdb, ntop=1) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100, param=param) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64, param=param) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128, param=param) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128, param=param) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256, param=param) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256, param=param) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256, param=param) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512, param=param) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512, param=param) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512, param=param) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512, param=param) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512, param=param) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512, param=param) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0, param=param) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0, param=param) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) # the following are parameters being learnt anyway # made layer named score_sal, upscore_sal to avoid copying new weights n.score_sal = L.Convolution(n.drop7, num_output=1, kernel_size=1, pad=0, param=learned_param) # <- learning weights for this layer # CHANGES DUE TO SKIP CONNECTION: # don't upscale all the way, only to the previous layer # replaced kernel_size=64, stride=32 with: n.upscore_sal2 = L.Deconvolution(n.score_sal, convolution_param=dict(num_output=1, kernel_size=4, stride=2, bias_term=False),param=[dict(lr_mult=0)]) # don't learn upscoring; fix it as bilinear n.score_pool4 = L.Convolution(n.pool4, num_output=1, kernel_size=1, pad=0, param=learned_param) # <- learning weights for this layer n.score_pool4c = crop(n.score_pool4, n.upscore_sal2) n.fuse_pool4 = L.Eltwise(n.upscore_sal2, n.score_pool4c, operation=P.Eltwise.SUM) n.upscore16 = L.Deconvolution(n.fuse_pool4, convolution_param=dict(num_output=1, kernel_size=32, stride=16, bias_term=False),param=[dict(lr_mult=0)]) # don't learn any of the upscaling (deconvolution) filters - just fix at bilinear # n.score = crop(n.upscore_sal, n.data) n.score = crop(n.upscore16, n.data) n.loss = L.SigmoidCrossEntropyLoss(n.score, n.label, loss_weight=1) return n.to_proto()
def fcn(train, mask, batch_size=8): n = caffe.NetSpec() # n.data, n.sem, n.geo = L.Python(module='siftflow_layers', # layer='SIFTFlowSegDataLayer', ntop=3, # param_str=str(dict(siftflow_dir='../data/sift-flow', # split=split, seed=1337))) n.data = L.Data(backend=P.Data.LMDB, batch_size=batch_size, source=train, transform_param=dict(scale=1. / 255), ntop=1) n.geo = L.Data(backend=P.Data.LMDB, batch_size=batch_size, source=mask, ntop=1) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv dropout = True Deconv_filters = 300 if dropout: n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr_geo = L.Convolution(n.drop7, num_output=Deconv_filters, kernel_size=1, pad=0, param=[ dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0) ]) else: n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.fc7, n.relu7 = conv_relu(n.relu6, 4096, ks=1, pad=0) # upsampling n.score_fr_geo = L.Convolution(n.relu7, num_output=Deconv_filters, kernel_size=1, pad=0, param=[ dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0) ]) n.upscore2_geo = L.Deconvolution( n.score_fr_geo, convolution_param=dict(num_output=Deconv_filters, kernel_size=4, stride=2, bias_term=False, weight_filler=dict(type="msra")), param=[dict(lr_mult=0)], ) n.score_pool4_geo = L.Convolution( n.pool4, num_output=Deconv_filters, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool4_geoc = crop(n.score_pool4_geo, n.upscore2_geo) n.fuse_pool4_geo = L.Eltwise(n.upscore2_geo, n.score_pool4_geoc, operation=P.Eltwise.SUM) n.upscore_pool4_geo = L.Deconvolution(n.fuse_pool4_geo, convolution_param=dict( num_output=Deconv_filters, kernel_size=4, stride=2, bias_term=False, weight_filler=dict(type="msra")), param=[dict(lr_mult=0)]) n.score_pool3_geo = L.Convolution( n.pool3, num_output=Deconv_filters, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool3_geoc = crop(n.score_pool3_geo, n.upscore_pool4_geo) n.fuse_pool3_geo = L.Eltwise(n.upscore_pool4_geo, n.score_pool3_geoc, operation=P.Eltwise.SUM) n.upscore8_geo = L.Deconvolution( n.fuse_pool3_geo, convolution_param=dict( num_output=Deconv_filters, kernel_size=16, stride=8, #ks 16 bias_term=False, weight_filler=dict(type="msra")), param=[dict(lr_mult=0)]) b = L.Convolution( n.upscore8_geo, kernel_size=3, stride=1, num_output=2, pad=1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)], weight_filler=dict(type='msra')) n.score_geo = max_pool(crop(b, n.data)) #n.score_geo = max_pool(crop(n.upscore8_geo, n.data)) n.loss_geo = L.SoftmaxWithLoss( n.score_geo, n.geo, loss_param=dict(normalize=False)) #, ignore_label=255)) return n.to_proto()
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(104.00699, 116.66877, 122.67892), seed=1337) if split.startswith('train'): pydata_params['sbdd_dir'] = '../data/sbdd/dataset' pylayer = 'SBDDSegDataLayer' else: pydata_params['voc_dir'] = '../data/pascal-obfuscated/VOC2011' pylayer = 'VOCSegDataLayer' n.data, n.label = L.Python(module='voc_layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution(n.drop7, num_output=16, kernel_size=1, pad=0, weight_filler=dict(type='xavier'), param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore2 = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=16, kernel_size=4, stride=2, weight_filler=dict(type='xavier'), bias_term=False), param=[dict(lr_mult=0)]) # scale pool4 skip for compatibility n.scale_pool4 = L.Scale(n.pool4, filler=dict(type='constant', value=0.01), param=[dict(lr_mult=0)]) n.score_pool4 = L.Convolution(n.scale_pool4, num_output=16, kernel_size=1, pad=0, weight_filler=dict(type='xavier'), param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool4c = crop(n.score_pool4, n.upscore2) n.fuse_pool4 = L.Eltwise(n.upscore2, n.score_pool4c, operation=P.Eltwise.SUM) n.upscore_pool4 = L.Deconvolution(n.fuse_pool4, convolution_param=dict(num_output=16, kernel_size=4, stride=2, weight_filler=dict(type='xavier'), bias_term=False), param=[dict(lr_mult=0)]) # scale pool3 skip for compatibility n.scale_pool3 = L.Scale(n.pool3, filler=dict(type='constant', value=0.0001), param=[dict(lr_mult=0)]) n.score_pool3 = L.Convolution(n.scale_pool3, num_output=16, kernel_size=1, pad=0, weight_filler=dict(type='xavier'), param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool3c = crop(n.score_pool3, n.upscore_pool4) n.fuse_pool3 = L.Eltwise(n.upscore_pool4, n.score_pool3c, operation=P.Eltwise.SUM) n.upscore8 = L.Deconvolution(n.fuse_pool3, convolution_param=dict(num_output=16, kernel_size=16, stride=8, weight_filler=dict(type='xavier'), bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore8, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def fcn(train,mask,batch_size=8): n = caffe.NetSpec() # n.data, n.sem, n.geo = L.Python(module='siftflow_layers', # layer='SIFTFlowSegDataLayer', ntop=3, # param_str=str(dict(siftflow_dir='../data/sift-flow', # split=split, seed=1337))) n.data =L.Data(backend=P.Data.LMDB,batch_size=batch_size, source=train, transform_param=dict(scale=1./255),ntop=1 ) n.geo = L.Data(backend=P.Data.LMDB, batch_size=batch_size, source=mask, ntop=1) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64,pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv dropout=True Deconv_filters=300 if dropout: n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr_geo = L.Convolution(n.drop7, num_output=Deconv_filters, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) else: n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.fc7, n.relu7 = conv_relu(n.relu6, 4096, ks=1, pad=0) # upsampling n.score_fr_geo = L.Convolution(n.relu7, num_output=Deconv_filters, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore2_geo = L.Deconvolution(n.score_fr_geo, convolution_param=dict(num_output=Deconv_filters, kernel_size=4, stride=2, bias_term=False, weight_filler=dict(type="msra") ), param=[dict(lr_mult=0)], ) n.score_pool4_geo = L.Convolution(n.pool4, num_output=Deconv_filters, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool4_geoc = crop(n.score_pool4_geo, n.upscore2_geo) n.fuse_pool4_geo = L.Eltwise(n.upscore2_geo, n.score_pool4_geoc, operation=P.Eltwise.SUM) n.upscore_pool4_geo = L.Deconvolution(n.fuse_pool4_geo, convolution_param=dict(num_output=Deconv_filters, kernel_size=4, stride=2, bias_term=False, weight_filler=dict(type="msra") ), param=[dict(lr_mult=0)]) n.score_pool3_geo = L.Convolution(n.pool3, num_output=Deconv_filters, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool3_geoc = crop(n.score_pool3_geo, n.upscore_pool4_geo) n.fuse_pool3_geo = L.Eltwise(n.upscore_pool4_geo, n.score_pool3_geoc, operation=P.Eltwise.SUM) n.upscore8_geo = L.Deconvolution(n.fuse_pool3_geo, convolution_param=dict(num_output=Deconv_filters, kernel_size=16, stride=8,#ks 16 bias_term=False, weight_filler=dict(type="msra") ), param=[dict(lr_mult=0)]) b=L.Convolution(n.upscore8_geo, kernel_size=3, stride=1, num_output=2, pad=1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)], weight_filler=dict(type='msra')) n.score_geo = max_pool(crop(b, n.data)) #n.score_geo = max_pool(crop(n.upscore8_geo, n.data)) n.loss_geo = L.SoftmaxWithLoss(n.score_geo, n.geo, loss_param=dict(normalize=False))#, ignore_label=255)) return n.to_proto()
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(106., 120., 114.), seed=1337) pydata_params['voc_dir'] = '../data/card' pylayer = 'VOCSegDataLayer' # if split == 'train': # pydata_params['sbdd_dir'] = '../data/sbdd/dataset' # pylayer = 'SBDDSegDataLayer' # else: # pydata_params['voc_dir'] = '../data/pascal/VOCdevkit/VOC2012' # pylayer = 'VOCSegDataLayer' n.data, n.label = L.Python(module='voc_layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6_conv, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7_conv, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr_new = L.Convolution(n.drop7, num_output=2, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore2_new = L.Deconvolution(n.score_fr_new, convolution_param=dict(num_output=2, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=1)]) n.score_pool4_new = L.Convolution(n.pool4, num_output=2, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool4c_new = crop(n.score_pool4_new, n.upscore2_new) n.fuse_pool4_new = L.Eltwise(n.upscore2_new, n.score_pool4c_new, operation=P.Eltwise.SUM) n.upscore_pool4_new = L.Deconvolution(n.fuse_pool4_new, convolution_param=dict(num_output=2, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=1)]) n.score_pool3_new = L.Convolution(n.pool3, num_output=2, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool3c_new = crop(n.score_pool3_new, n.upscore_pool4_new) n.fuse_pool3_new = L.Eltwise(n.upscore_pool4_new, n.score_pool3c_new, operation=P.Eltwise.SUM) n.upscore8_new = L.Deconvolution(n.fuse_pool3_new, convolution_param=dict(num_output=2, kernel_size=16, stride=8, bias_term=False), param=[dict(lr_mult=1)]) n.score_new = crop(n.upscore8_new, n.data) n.loss = L.SoftmaxWithLoss(n.score_new, n.label, # loss_param=dict(normalize=False, ignore_label=255)) loss_param=dict(normalize=True)) return n.to_proto()
def fcn(split, num_classes=None): n = caffe.NetSpec() n.data = L.Input(shape=[dict(dim=[1, 3, 500, 500])]) # conv 1 n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) # conv 2 n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) # conv 3 n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) # conv 4 n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) # conv 5 n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fc6 n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) # fc7 n.fc7, n.relu7 = conv_relu(n.relu6, 4096, ks=1, pad=0) # score n.score_fr = L.Convolution( n.relu7, num_output=num_classes, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) # deconv 1 : 2x n.upscore2 = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=num_classes, group=num_classes, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) n.score_pool4 = L.Convolution( n.pool4, num_output=num_classes, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) # fuse 1 n.score_pool4c = crop(n.score_pool4, n.upscore2) n.fuse_pool4 = L.Eltwise(n.upscore2, n.score_pool4c, operation=P.Eltwise.SUM) # deconv 2 : 2x n.upscore_pool4 = L.Deconvolution(n.fuse_pool4, convolution_param=dict( num_output=num_classes, group=num_classes, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) n.score_pool3 = L.Convolution( n.pool3, num_output=num_classes, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) # fuse 2 n.score_pool3c = crop(n.score_pool3, n.upscore_pool4) n.fuse_pool3 = L.Eltwise(n.upscore_pool4, n.score_pool3c, operation=P.Eltwise.SUM) # deconv 2 : 8x n.upscore8 = L.Deconvolution(n.fuse_pool3, convolution_param=dict(num_output=num_classes, group=num_classes, kernel_size=16, stride=8, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore8, n.data) return n.to_proto()
def fcn(split, tops): n = caffe.NetSpec() n.data, n.label = L.Python( module='nyud_layers', layer='NYUDSegDataLayer', ntop=2, param_str=str( dict(image_path='/media/ssd500/autocity_dataset/images/', image_list="/media/ssd500/autocity_dataset/image_train.txt", label_list="/media/ssd500/autocity_dataset/label_train.txt", label_path="/media/ssd500/autocity_dataset/labels/0/", split=split, tops=tops, seed=1337))) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution( n.drop7, num_output=2, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=2, kernel_size=64, stride=32, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore, n.data) n.loss = L.SoftmaxWithLoss( n.score, n.label, loss_param=dict(normalize=False)) #, ignore_label=255 return n.to_proto()
def net(split): n = caffe.NetSpec() if split == 'train': data_params = dict(mean=(104.00699, 116.66877, 122.67892)) data_params['root'] = 'data/HED-BSDS' data_params['source'] = "train_pair.lst" data_params['shuffle'] = True data_params['ignore_label'] = -1 # ignore label n.data, n.label = L.Python(module='pylayer', layer='ImageLabelmapDataLayer', ntop=2, \ param_str=str(data_params)) loss_param = dict(normalize=False) if data_params.has_key('ignore_label'): loss_param['ignore_label'] = data_params['ignore_label'] elif split == 'test': n.data = L.Input(name='data', input_param=dict(shape=dict(dim=[1, 3, 500, 500]))) else: raise Exception("Invalid phase") n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=1) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512, mult=[100, 1, 200, 0]) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512, mult=[100, 1, 200, 0]) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512, mult=[100, 1, 200, 0]) # DSN1 n.score_dsn1 = conv1x1(n.conv1_2, 'score-dsn1', lr=1) n.upscore_dsn1 = crop(n.score_dsn1, n.data) if split == 'train': n.loss1 = L.BalanceCrossEntropyLoss(n.upscore_dsn1, n.label, loss_param=loss_param) else: n.sigmoid_dsn1 = L.Sigmoid(n.upscore_dsn1) # DSN2 n.score_dsn2 = conv1x1(n.conv2_2, 'score-dsn2') n.score_dsn2_up = upsample(n.score_dsn2, stride=2) n.upscore_dsn2 = crop(n.score_dsn2_up, n.data) if split == 'train': n.loss2 = L.BalanceCrossEntropyLoss(n.upscore_dsn2, n.label, loss_param=loss_param) else: n.sigmoid_dsn2 = L.Sigmoid(n.upscore_dsn2) # DSN3 n.score_dsn3 = conv1x1(n.conv3_3, 'score-dsn3') n.score_dsn3_up = upsample(n.score_dsn3, stride=4) n.upscore_dsn3 = crop(n.score_dsn3_up, n.data) if split == 'train': n.loss3 = L.BalanceCrossEntropyLoss(n.upscore_dsn3, n.label, loss_param=loss_param) else: n.sigmoid_dsn3 = L.Sigmoid(n.upscore_dsn3) # DSN4 n.score_dsn4 = conv1x1(n.conv4_3, 'score-dsn4') n.score_dsn4_up = upsample(n.score_dsn4, stride=8) n.upscore_dsn4 = crop(n.score_dsn4_up, n.data) if split == 'train': n.loss4 = L.BalanceCrossEntropyLoss(n.upscore_dsn4, n.label, loss_param=loss_param) else: n.sigmoid_dsn4 = L.Sigmoid(n.upscore_dsn4) # DSN5 n.score_dsn5 = conv1x1(n.conv5_3, 'score-dsn5') n.score_dsn5_up = upsample(n.score_dsn5, stride=16) n.upscore_dsn5 = crop(n.score_dsn5_up, n.data) if split == 'train': n.loss5 = L.BalanceCrossEntropyLoss(n.upscore_dsn5, n.label, loss_param=loss_param) elif split == 'test': n.sigmoid_dsn5 = L.Sigmoid(n.upscore_dsn5) # concat and fuse n.concat_upscore = L.Concat(n.upscore_dsn1, n.upscore_dsn2, n.upscore_dsn3, n.upscore_dsn4, n.upscore_dsn5, name='concat', concat_param=dict({'concat_dim': 1})) n.upscore_fuse = L.Convolution(n.concat_upscore, name='new-score-weighting', num_output=1, kernel_size=1, param=[ dict(lr_mult=0.001, decay_mult=1), dict(lr_mult=0.002, decay_mult=0) ], weight_filler=dict(type='constant', value=0.2)) if split == 'test': n.sigmoid_fuse = L.Sigmoid(n.upscore_fuse) else: n.loss_fuse = L.BalanceCrossEntropyLoss(n.upscore_fuse, n.label, loss_param=loss_param) return n.to_proto()
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(104.00699, 116.66877, 122.67892), seed=1337) # pydata_params['icdar_dir'] = '../../../data/icdar-resized' # pylayer = 'ICDARDataLayer' pydata_params['coco_dir'] = '../../../data/coco-text' pylayer = 'COCODataLayer' # pydata_params['synthtext_dir'] = '../../../data/synthtext' # pylayer = 'SYNTHTEXTDataLayer' n.data, n.label = L.Python(module='layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6x, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7x, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution(n.drop7, num_output=2, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore2 = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=2, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) # scale pool4 skip for compatibility n.scale_pool4 = L.Scale(n.pool4, filler=dict(type='constant', value=0.01), param=[dict(lr_mult=0)]) n.score_pool4 = L.Convolution(n.scale_pool4, num_output=2, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool4c = crop(n.score_pool4, n.upscore2) n.fuse_pool4 = L.Eltwise(n.upscore2, n.score_pool4c, operation=P.Eltwise.SUM) n.upscore_pool4 = L.Deconvolution(n.fuse_pool4, convolution_param=dict(num_output=2, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) # scale pool3 skip for compatibility n.scale_pool3 = L.Scale(n.pool3, filler=dict(type='constant', value=0.0001), param=[dict(lr_mult=0)]) n.score_pool3 = L.Convolution(n.scale_pool3, num_output=2, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool3c = crop(n.score_pool3, n.upscore_pool4) n.fuse_pool3 = L.Eltwise(n.upscore_pool4, n.score_pool3c, operation=P.Eltwise.SUM) n.upscore8 = L.Deconvolution(n.fuse_pool3, convolution_param=dict(num_output=2, kernel_size=16, stride=8, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore8, n.data) n.loss_conv = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(104.00699, 116.66877, 122.67892), seed=1337) pydata_params['cocostuff_dir'] = 'cocostuff' pylayer = 'COCOSTUFFSegDataLayer' n.data, n.label = L.Python(module='cocostuff_layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution(n.drop7, num_output=182, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore2 = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=182, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) # scale pool4 skip for compatibility n.scale_pool4 = L.Scale(n.pool4, filler=dict(type='constant', value=0.01), param=[dict(lr_mult=0)]) n.score_pool4 = L.Convolution(n.scale_pool4, num_output=182, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool4c = crop(n.score_pool4, n.upscore2) n.fuse_pool4 = L.Eltwise(n.upscore2, n.score_pool4c, operation=P.Eltwise.SUM) n.upscore_pool4 = L.Deconvolution(n.fuse_pool4, convolution_param=dict(num_output=182, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) # scale pool3 skip for compatibility n.scale_pool3 = L.Scale(n.pool3, filler=dict(type='constant', value=0.0001), param=[dict(lr_mult=0)]) n.score_pool3 = L.Convolution(n.scale_pool3, num_output=182, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool3c = crop(n.score_pool3, n.upscore_pool4) n.fuse_pool3 = L.Eltwise(n.upscore_pool4, n.score_pool3c, operation=P.Eltwise.SUM) n.upscore8 = L.Deconvolution(n.fuse_pool3, convolution_param=dict(num_output=182, kernel_size=16, stride=8, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore8, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def net(split): n = caffe.NetSpec() loss_param = dict(normalization=P.Loss.VALID) # loss_param = dict(normalize=False) if split=='train': data_params = dict(mean=(104.00699, 116.66877, 122.67892)) #data_params['root'] = 'data/HED-BSDS_PASCAL' data_params['root'] = 'data/PASCAL-Context-Edge/' data_params['source'] = "train_pair.lst" data_params['shuffle'] = True #data_params['ignore_label'] = -1 n.data, n.label = L.Python(module='pylayer', layer='ImageLabelmapDataLayer', ntop=2, \ param_str=str(data_params)) if data_params.has_key('ignore_label'): loss_param['ignore_label'] = int(data_params['ignore_label']) elif split == 'test': n.data = L.Input(name = 'data', input_param=dict(shape=dict(dim=[1,3,200,200]))) else: raise Exception("Invalid phase") n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=1) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512, mult=[100,1,200,0]) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512, mult=[100,1,200,0]) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512, mult=[100,1,200,0]) ## w1 n.w1_1top = conv1x1(n.conv1_1, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w1_2top = conv1x1(n.conv1_2, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) ## w2 n.w2_1top = conv1x1(n.conv2_1, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w2_2top = conv1x1(n.conv2_2, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w2_1down = conv1x1(n.conv2_1, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w2_2down = conv1x1(n.conv2_2, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) ## w3 n.w3_1top = conv1x1(n.conv3_1, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w3_2top = conv1x1(n.conv3_2, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w3_3top = conv1x1(n.conv3_3, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w3_1down = conv1x1(n.conv3_1, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w3_2down = conv1x1(n.conv3_2, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w3_3down = conv1x1(n.conv3_3, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) ## w4 n.w4_1top = conv1x1(n.conv4_1, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w4_2top = conv1x1(n.conv4_2, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w4_3top = conv1x1(n.conv4_3, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w4_1down = conv1x1(n.conv4_1, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w4_2down = conv1x1(n.conv4_2, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w4_3down = conv1x1(n.conv4_3, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) ## w5 n.w5_1down = conv1x1(n.conv5_1, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w5_2down = conv1x1(n.conv5_2, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) n.w5_3down = conv1x1(n.conv5_3, nout=args.nfeat, lr=[0.1, 1, 0.2, 0], wf=dict(type='gaussian', std=0.001)) ## upsample wx_xdown n.w2_1down_up = upsample(n.w2_1down, nout=args.nfeat, stride=2, name='upsample2_1') n.w2_2down_up = upsample(n.w2_2down, nout=args.nfeat, stride=2, name='upsample2_2') n.w3_1down_up = upsample(n.w3_1down, nout=args.nfeat, stride=2, name='upsample3_1') n.w3_2down_up = upsample(n.w3_2down, nout=args.nfeat, stride=2, name='upsample3_2') n.w3_3down_up = upsample(n.w3_3down, nout=args.nfeat, stride=2, name='upsample3_3') n.w4_1down_up = upsample(n.w4_1down, nout=args.nfeat, stride=2, name='upsample4_1') n.w4_2down_up = upsample(n.w4_2down, nout=args.nfeat, stride=2, name='upsample4_2') n.w4_3down_up = upsample(n.w4_3down, nout=args.nfeat, stride=2, name='upsample4_3') n.w5_1down_up = upsample(n.w5_1down, nout=args.nfeat, stride=2, name='upsample5_1') n.w5_2down_up = upsample(n.w5_2down, nout=args.nfeat, stride=2, name='upsample5_2') n.w5_3down_up = upsample(n.w5_3down, nout=args.nfeat, stride=2, name='upsample5_3') ## crop wx_xdown_up n.w2_1down_up_crop = crop(n.w2_1down_up, n.w1_1top) n.w2_2down_up_crop = crop(n.w2_2down_up, n.w1_1top) n.w3_1down_up_crop = crop(n.w3_1down_up, n.w2_1top) n.w3_2down_up_crop = crop(n.w3_2down_up, n.w2_1top) n.w3_3down_up_crop = crop(n.w3_3down_up, n.w2_1top) n.w4_1down_up_crop = crop(n.w4_1down_up, n.w3_1top) n.w4_2down_up_crop = crop(n.w4_2down_up, n.w3_1top) n.w4_3down_up_crop = crop(n.w4_3down_up, n.w3_1top) n.w5_1down_up_crop = crop(n.w5_1down_up, n.w4_1top) n.w5_2down_up_crop = crop(n.w5_2down_up, n.w4_1top) n.w5_3down_up_crop = crop(n.w5_3down_up, n.w4_1top) ## fuse if args.cat: n.h1s1_2 = L.Concat(n.w1_1top, n.w1_2top, n.w2_1down_up_crop, n.w2_2down_up_crop) n.h1s2_3 = L.Concat(n.w2_1top, n.w2_2top, n.w3_1down_up_crop, n.w3_2down_up_crop, n.w3_3down_up_crop) n.h1s3_4 = L.Concat(n.w3_1top, n.w3_2top, n.w3_3top, \ n.w4_1down_up_crop, n.w4_2down_up_crop, n.w4_3down_up_crop) n.h1s4_5 = L.Concat(n.w4_1top, n.w4_2top, n.w4_3top, \ n.w5_1down_up_crop, n.w5_2down_up_crop, n.w5_3down_up_crop) # n.h1s1_2 = conv1x1(n.h1s1_2cat, lr=[0.01, 1, 0.02, 0], wf=dict(type='constant', value=1)) # n.h1s2_3 = conv1x1(n.h1s2_3cat, lr=[0.01, 1, 0.02, 0], wf=dict(type='constant', value=1)) # n.h1s3_4 = conv1x1(n.h1s3_4cat, lr=[0.01, 1, 0.02, 0], wf=dict(type='constant', value=1)) # n.h1s4_5 = conv1x1(n.h1s4_5cat, lr=[0.01, 1, 0.02, 0], wf=dict(type='constant', value=1)) else: n.h1s1_2 = L.Eltwise(n.w1_1top, n.w1_2top, n.w2_1down_up_crop, n.w2_2down_up_crop) n.h1s2_3 = L.Eltwise(n.w2_1top, n.w2_2top, n.w3_1down_up_crop, n.w3_2down_up_crop, n.w3_3down_up_crop) n.h1s3_4 = L.Eltwise(n.w3_1top, n.w3_2top, n.w3_3top, \ n.w4_1down_up_crop, n.w4_2down_up_crop, n.w4_3down_up_crop) n.h1s4_5 = L.Eltwise(n.w4_1top, n.w4_2top, n.w4_3top, \ n.w5_1down_up_crop, n.w5_2down_up_crop, n.w5_3down_up_crop) ## score h1sx_x n.score_h1s1_2 = conv1x1(n.h1s1_2, lr=[0.01, 1, 0.02, 0], wf=dict(type='gaussian', std=0.01)) n.score_h1s2_3 = conv1x1(n.h1s2_3, lr=[0.01, 1, 0.02, 0], wf=dict(type='gaussian', std=0.01)) n.score_h1s3_4 = conv1x1(n.h1s3_4, lr=[0.01, 1, 0.02, 0], wf=dict(type='gaussian', std=0.01)) n.score_h1s4_5 = conv1x1(n.h1s4_5, lr=[0.01, 1, 0.02, 0], wf=dict(type='gaussian', std=0.01)) ## upsample score n.upscore_h1s2_3 = upsample(n.score_h1s2_3, stride=2, name='upscore_h1s2_3') n.upscore_h1s3_4 = upsample(n.score_h1s3_4, stride=4, name='upscore_h1s3_4') n.upscore_h1s4_5 = upsample(n.score_h1s4_5, stride=8, name='upscore_h1s4_5') ## crop upscore_h1sx_x n.crop_h1s1_2 = crop(n.score_h1s1_2, n.data) n.crop_h1s2_3 = crop(n.upscore_h1s2_3, n.data) n.crop_h1s3_4 = crop(n.upscore_h1s3_4, n.data) n.crop_h1s4_5 = crop(n.upscore_h1s4_5, n.data) ## fuse n.h1_concat = L.Concat(n.crop_h1s1_2, n.crop_h1s2_3, n.crop_h1s3_4, n.crop_h1s4_5, concat_param=dict({'concat_dim':1})) n.h1_fuse = conv1x1(n.h1_concat, lr=[0.001, 1, 0.002, 0], wf=dict(type='constant', value=float(1)/4)) if split == 'train': n.loss_h1s1_2 = L.BalanceCrossEntropyLoss(n.crop_h1s1_2, n.label, loss_param=loss_param) n.loss_h1s2_3 = L.BalanceCrossEntropyLoss(n.crop_h1s2_3, n.label, loss_param=loss_param) n.loss_h1s3_4 = L.BalanceCrossEntropyLoss(n.crop_h1s3_4, n.label, loss_param=loss_param) n.loss_h1s4_5 = L.BalanceCrossEntropyLoss(n.crop_h1s4_5, n.label, loss_param=loss_param) n.loss_h1_fuse = L.BalanceCrossEntropyLoss(n.h1_fuse, n.label, loss_param=loss_param) else: n.sigmoid_h1s1_2 = L.Sigmoid(n.crop_h1s1_2) n.sigmoid_h1s2_3 = L.Sigmoid(n.crop_h1s2_3) n.sigmoid_h1s3_4 = L.Sigmoid(n.crop_h1s3_4) n.sigmoid_h1s4_5 = L.Sigmoid(n.crop_h1s4_5) n.sigmoid_h1_fuse = L.Sigmoid(n.h1_fuse) return n.to_proto()
def fcn(dataset): n = caffe.NetSpec() n.data, n.label = L.Python( module='satellite_layers', layer='SatelliteDataLayer', ntop=2, param_str=str( dict(input_dir='../data/mass_merged/' + dataset + '/sat', output_dir='../data/mass_merged/' + dataset + '/map', seed=1337, data_set=dataset))) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution( n.drop7, num_output=3, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore2 = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=3, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) # scale pool4 skip for compatibility n.scale_pool4 = L.Scale(n.pool4, filler=dict(type='constant', value=0.01), param=[dict(lr_mult=0)]) n.score_pool4 = L.Convolution( n.scale_pool4, num_output=3, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool4c = crop(n.score_pool4, n.upscore2) n.fuse_pool4 = L.Eltwise(n.upscore2, n.score_pool4c, operation=P.Eltwise.SUM) n.upscore_pool4 = L.Deconvolution(n.fuse_pool4, convolution_param=dict(num_output=3, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) # scale pool3 skip for compatibility n.scale_pool3 = L.Scale(n.pool3, filler=dict(type='constant', value=0.0001), param=[dict(lr_mult=0)]) n.score_pool3 = L.Convolution( n.scale_pool3, num_output=3, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool3c = crop(n.score_pool3, n.upscore_pool4) n.fuse_pool3 = L.Eltwise(n.upscore_pool4, n.score_pool3c, operation=P.Eltwise.SUM) n.upscore8 = L.Deconvolution(n.fuse_pool3, convolution_param=dict(num_output=3, kernel_size=16, stride=8, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore8, n.data) n.loss = L.InfogainLoss( n.score, n.label, loss_param=dict(normalization=False, ignore_label=255), infogain_loss_param=dict(source="infogainH.binaryproto")) return n.to_proto()
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(71.60167789, 82.09696889, 72.30608881), seed=1337) if split == 'train': pydata_params[ 'cityscapes_dir'] = '/export/home/sguist/fcn/fcn.berkeleyvision.org-master/data/cityscapes' pylayer = 'CityscapesSegDataLayer' else: pydata_params[ 'cityscapes_dir'] = '/export/home/sguist/fcn/fcn.berkeleyvision.org-master/data/cityscapes' pylayer = 'CityscapesSegDataLayer' n.data, n.label = L.Python(module='cityscapes_layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution( n.drop7, num_output=19, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=19, kernel_size=64, stride=32, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) # n.accuracy = L.Accuracy(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def define_structure(self, stage): n = caffe.NetSpec() if stage != NetStage.DEPLOY: source_params = dict(stage=stage) source_params['dataset_dir'] = self.DATASET_DIR source_params['patch_dir'] = self.PATCH_DIR source_params['average_image'] = self.AVERAGE_IMAGE source_params['training_patches'] = self.TRAINING_PATCHES source_params['validation_patches'] = self.VALIDATION_PATCHES source_params['random_training'] = self.RANDOM_TRAINING source_params['include_rotations'] = self.INCLUDE_ROTATIONS n.data, n.label = L.Python(module='DataLayer', layer='DataLayer', ntop=2, param_str=str(source_params)) else: n.data = L.Input(shape=dict(dim=[1, 3, self.WSIZE, self.WSIZE])) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 32, pad=7) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 32) n.pool1 = max_pool(n.conv1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 64) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 64) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 128) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 128) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 128) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 256) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 256) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 256) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 256) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 256) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 256) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 2048, ks=2, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 2048, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution( n.drop7, num_output=self.NUM_LABELS, kernel_size=1, pad=0, param=[ dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0) ], weight_filler=dict(type='xavier'), bias_filler=dict( type='constant')) # must be 1 x num_classes x 1 x 1 n.upscore_a = L.Deconvolution(n.score_fr, convolution_param=dict( num_output=self.NUM_LABELS, kernel_size=4, stride=8, bias_term=False, weight_filler=dict(type='xavier'), bias_filler=dict(type='constant')), param=[dict(lr_mult=1, decay_mult=1)]) n.score_pool2 = L.Convolution(n.pool2, num_output=self.NUM_LABELS, kernel_size=1, pad=0, param=[ dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0) ], weight_filler=dict(type='xavier'), bias_filler=dict(type='constant')) n.score_pool2c = crop(n.score_pool2, n.upscore_a) n.fuse_pool2 = L.Eltwise(n.upscore_a, n.score_pool2c, operation=P.Eltwise.SUM) n.upscore_b = L.Deconvolution(n.fuse_pool2, convolution_param=dict( num_output=self.NUM_LABELS, kernel_size=40, stride=4, bias_term=False), param=[dict(lr_mult=1, decay_mult=1)]) # THIS IS A BRUTE FORCE EXAMINATION FINDING A GOOD PARAMETER FOR THE CROP OPERATION # keep = True # ks = 40 # st = ks # while(keep): # try: # n.upscore_b = L.Deconvolution(n.fuse_pool2, # convolution_param=dict(num_output=CaffeLocations.NUM_LABELS, # kernel_size=ks, # stride=st, # bias_term=False), # param=[dict(lr_mult=0)]) # # n.score = crop(n.upscore_b, n.data) # break # except AssertionError as e: # st=st-1 # # print # print 'FOUND' # print ks, st n.score = crop(n.upscore_b, n.data) if stage != NetStage.DEPLOY: n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False)) # n.loss = L.Python(n.score, n.label, module='LossLayer', layer='TopoLossLayer', loss_weight=1) return n.to_proto()
def test_crop_helper(self): """ Define Crop layer by crop(). """ n = coord_net_spec() crop(n.deconv, n.data)
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(0, 0, 0), seed=1337) if split == 'train': pydata_params['sbdd_dir'] = '../trian/data' pylayer = 'SBDDSegDataLayer' else: pydata_params['voc_dir'] = '../trian/data' pylayer = 'VOCSegDataLayer' n.data, n.label = L.Python(module='layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution( n.drop7, num_output=2, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore2 = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=2, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) n.score_pool4 = L.Convolution( n.pool4, num_output=2, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool4c = crop(n.score_pool4, n.upscore2) n.fuse_pool4 = L.Eltwise(n.upscore2, n.score_pool4c, operation=P.Eltwise.SUM) n.upscore_pool4 = L.Deconvolution(n.fuse_pool4, convolution_param=dict(num_output=2, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) n.score_pool3 = L.Convolution( n.pool3, num_output=2, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool3c = crop(n.score_pool3, n.upscore_pool4) n.fuse_pool3 = L.Eltwise(n.upscore_pool4, n.score_pool3c, operation=P.Eltwise.SUM) n.upscore8 = L.Deconvolution(n.fuse_pool3, convolution_param=dict(num_output=2, kernel_size=16, stride=8, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore8, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=True, ignore_label=100)) return n.to_proto()
def fcn(split,learn_all=False): param = learned_param if learn_all else frozen_param n = caffe.NetSpec() pydata_params = dict(split=split, mean=(104.00699, 116.66877, 122.67892), seed=1337) if split == 'train': pydata_params['train_dir'] = '../data/' # <- # CHANGETHIS: provided you have the massvis data files here pylayer = 'MassvisTrainDataLayerBubble' pydata_params['binarize'] = tobinarize else: pydata_params['val_dir'] = '../data/' # <- # CHANGETHIS: provided you have the massvis data files here pylayer = 'MassvisDataLayerBubble' pydata_params['binarize'] = tobinarize # will invoke the custom python data loader in imp_layers_massvis.py n.data, n.label = L.Python(module='imp_layers_massvis', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100, param=param) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64, param=param) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128, param=param) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128, param=param) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256, param=param) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256, param=param) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256, param=param) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512, param=param) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512, param=param) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512, param=param) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512, param=param) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512, param=param) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512, param=param) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0, param=param) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0, param=param) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) # the following are parameters being learnt anyway # made layer named score_sal, upscore_sal to avoid copying new weights n.score_sal = L.Convolution(n.drop7, num_output=1, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore_sal = L.Deconvolution(n.score_sal, convolution_param=dict(num_output=1, kernel_size=64, stride=32, bias_term=False), param=[dict(lr_mult=0)]) # don't learn upscoring; fix it as bilinear n.score = crop(n.upscore_sal, n.data) n.loss = L.SigmoidCrossEntropyLoss(n.score, n.label, loss_weight=1) return n.to_proto()
def fcn(mode): net = caffe.NetSpec() data_params = dict(mode = mode, mean=(104.00699, 116.66877, 122.67892), seed = 1337) if mode == 'train': data_params['data_dir']='/jet/prs/workspace/VOCdevkit/VOC2012' ##TODO data_layer = 'TrainingDataLayer' elif mode == 'val': data_params['data_dir']='/jet/prs/workspace/VOCdevkit/VOC2012' ##TODO data_layer = 'ValidDataLayer' net.data, net.label = layers.Python(module='data_layer', layer = data_layer, ntop=2, param_str = str(data_params)) # layer1 , conv+relu -> conv+relu -> max_pooling net.conv1_1 = conv(net.data, 64, pad=100) net.relu1_1 = relu(net.conv1_1) net.conv1_2 = conv(net.relu1_1, 64) net.relu1_2 = relu(net.conv1_2) net.pool1 = max_pooling(net.relu1_2) # layer2, conv+relu -> conv+relu -> max_pooling net.conv2_1 = conv(net.pool1, 128) net.relu2_1 = relu(net.conv2_1) net.conv2_2 = conv(net.relu2_1, 128) net.relu2_2 = relu(net.conv2_2) net.pool2 = max_pooling(net.relu2_2) # layer3, conv+relu -> conv+relu -> max_pooling net.conv3_1 = conv(net.pool2, 256) net.relu3_1 = relu(net.conv3_1) net.conv3_2 = conv(net.relu3_1, 256) net.relu3_2 = relu(net.conv3_2) net.conv3_3 = conv(net.relu3_2, 256) net.relu3_3 = relu(net.conv3_3) net.pool3 = max_pooling(net.relu3_3) # layer4, conv+relu -> conv+relu -> max_pooling net.conv4_1 = conv(net.pool3, 512) net.relu4_1 = relu(net.conv4_1) net.conv4_2 = conv(net.relu4_1, 512) net.relu4_2 = relu(net.conv4_2) net.conv4_3 = conv(net.relu4_2, 512) net.relu4_3 = relu(net.conv4_3) net.pool4 = max_pooling(net.relu4_3) # layer5, conv+relu -> conv+relu -> max_pooling net.conv5_1 = conv(net.pool4, 512) net.relu5_1 = relu(net.conv5_1) net.conv5_2 = conv(net.relu5_1, 512) net.relu5_2 = relu(net.conv5_2) net.conv5_3 = conv(net.relu5_2, 512) net.relu5_3 = relu(net.conv5_3) net.pool5 = max_pooling(net.relu5_3) # layer6, conv + relu -> dropout net.fc6 = conv(net.pool5, 4096, ks=7, pad=0) net.relu6 = relu(net.fc6) net.drop6 = dropout(net.relu6) # layer7, conv + relu -> dropout net.fc7 = conv(net.drop6, 4096, ks=1, pad=0) net.relu7 = relu(net.fc7) net.drop7 = dropout(net.relu7) # layer8, forward score net.score_fr = conv(net.drop7, 21, ks=1, pad=0) net.upscore = deconv(net.score_fr, 21, ks=64, stride = 32) net.score = crop(net.upscore, net.data) net.loss = softmax(net.score, net.label) # layer9, skip with layer4: conv -> crop -> sum up -> deconv #net.score2_1 = conv(net.pool4, 21, ks=1, pad=0) #net.score2_1c = crop(net.score2_1, net.upscore1_1) #net.sum_score2_1 = sumup(net.upscore1_1, net.score2_1c) #net.upscore2_1 = deconv(net.sum_score2_1, 21) # layer10, skip with layer3: conv->crop->sum up->deconv #net.score3_1 = conv(net.pool3, 21, ks=1, pad=0) #net.score3_1c = crop(net.score3_1, net.upscore2_1) #net.sum_score3_1 = sumup(net.upscore2_1, net.score3_1c) #net.upscore3_1 = deconv(net.sum_score3_1, 21) #net.score = crop(net.upscore3_1, net.data) #net.loss = softmax(net.score, net.data) return net.to_proto()
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(104.00699, 116.66877, 122.67892), seed=1337) if split == 'train': pydata_params['sbdd_dir'] = '../data/pascal/VOC2011' pylayer = 'SBDDSegDataLayer' else: pydata_params['voc_dir'] = '../data/pascal/VOC2011' pylayer = 'VOCSegDataLayer' n.data, n.label = L.Python(module='voc_layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1_1 = L.Convolution( n.data, kernel_size=3, stride=1, num_output=64, pad=100, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.relu1_1 = L.ReLU(n.conv1_1, in_place=True) n.conv1_2 = L.Convolution( n.relu1_1, kernel_size=3, stride=1, num_output=64, pad=1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.relu1_2 = L.ReLU(n.conv1_2, in_place=True) n.pool1 = L.Pooling(n.relu1_2, pool=P.Pooling.MAX, kernel_size=2, stride=2) n.conv2_1 = L.Convolution( n.pool1, kernel_size=3, stride=1, num_output=128, pad=1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.relu2_1 = L.ReLU(n.conv2_1, in_place=True) n.conv2_2 = L.Convolution( n.relu2_1, kernel_size=3, stride=1, num_output=128, pad=1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.relu2_2 = L.ReLU(n.conv2_2, in_place=True) n.pool2 = L.Pooling(n.relu2_2, pool=P.Pooling.MAX, kernel_size=2, stride=2) n.conv3_1 = L.Convolution( n.pool2, kernel_size=3, stride=1, num_output=256, pad=1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.relu3_1 = L.ReLU(n.conv3_1, in_place=True) n.conv3_2 = L.Convolution( n.relu3_1, kernel_size=3, stride=1, num_output=256, pad=1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.relu3_2 = L.ReLU(n.conv3_2, in_place=True) n.conv3_3 = L.Convolution( n.relu3_2, kernel_size=3, stride=1, num_output=256, pad=1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.relu3_3 = L.ReLU(n.conv3_3, in_place=True) n.pool3 = L.Pooling(n.relu3_3, pool=P.Pooling.MAX, kernel_size=2, stride=2) n.conv4_1 = L.Convolution( n.pool3, kernel_size=3, stride=1, num_output=512, pad=1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.relu4_1 = L.ReLU(n.conv4_1, in_place=True) n.conv4_2 = L.Convolution( n.relu4_1, kernel_size=3, stride=1, num_output=512, pad=1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.relu4_2 = L.ReLU(n.conv4_2, in_place=True) n.conv4_3 = L.Convolution( n.relu4_2, kernel_size=3, stride=1, num_output=512, pad=1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.relu4_3 = L.ReLU(n.conv4_3, in_place=True) n.pool4 = L.Pooling(n.relu4_3, pool=P.Pooling.MAX, kernel_size=2, stride=2) n.conv5_1 = L.Convolution( n.pool4, kernel_size=3, stride=1, num_output=512, pad=1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.relu5_1 = L.ReLU(n.conv5_1, in_place=True) n.conv5_2 = L.Convolution( n.relu5_1, kernel_size=3, stride=1, num_output=512, pad=1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.relu5_2 = L.ReLU(n.conv5_2, in_place=True) n.conv5_3 = L.Convolution( n.relu5_2, kernel_size=3, stride=1, num_output=512, pad=1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.relu5_3 = L.ReLU(n.conv5_3, in_place=True) n.pool5 = L.Pooling(n.relu5_3, pool=P.Pooling.MAX, kernel_size=2, stride=2) # fully connected n.fc6 = L.Convolution( n.pool5, kernel_size=7, stride=1, num_output=4096, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.relu6 = L.ReLU(n.fc6, in_place=True) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7 = L.Convolution( n.drop6, kernel_size=1, stride=1, num_output=4096, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.relu7 = L.ReLU(n.fc7, in_place=True) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution( n.drop7, num_output=21, kernel_size=1, pad=0, stride=1, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore2 = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=21, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) n.score_pool4 = L.Convolution( n.pool4, num_output=21, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool4c = crop(n.score_pool4, n.upscore2) n.fuse_pool4 = L.Eltwise(n.upscore2, n.score_pool4c, operation=P.Eltwise.SUM) n.upscore_pool4 = L.Deconvolution(n.fuse_pool4, convolution_param=dict(num_output=21, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) n.score_pool3 = L.Convolution( n.pool3, num_output=21, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool3c = crop(n.score_pool3, n.upscore_pool4) n.fuse_pool3 = L.Eltwise(n.upscore_pool4, n.score_pool3c, operation=P.Eltwise.SUM) n.upscore8 = L.Deconvolution(n.fuse_pool3, convolution_param=dict(num_output=21, kernel_size=16, stride=8, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore8, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=True, ignore_label=255)) return n.to_proto()
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(104.00699, 116.66877, 122.67892), seed=1337) if split == 'train': pydata_params['sbdd_dir'] = '../data/sbdd/dataset' pylayer = 'SBDDSegDataLayer' else: pydata_params['voc_dir'] = '../data/pascal/VOC2012' pylayer = 'VOCSegDataLayer' n.data, n.label, n.flux, n.flux_weight = L.Python( module='voc_layers', layer=pylayer, ntop=4, param_str=str(pydata_params)) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) flux_hidden_channels = 256 # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution( n.drop7, num_output=21, kernel_size=1, pad=0, param=[dict(lr_mult=10, decay_mult=1), dict(lr_mult=20, decay_mult=0)]) n.upscore2 = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=21, kernel_size=4, stride=2, pad=1, bias_term=False), param=[dict(lr_mult=0)]) # fully flux conv n.fc6_flux, n.relu6_flux = conv_relu(n.relu5_3, 4096, ks=7, pad=0) n.drop6_flux = L.Dropout(n.relu6_flux, dropout_ratio=0.5, in_place=True) n.fc7_flux, n.relu7_flux = conv_relu(n.drop6_flux, 4096, ks=1, pad=0) n.drop7_flux = L.Dropout(n.relu7_flux, dropout_ratio=0.5, in_place=True) n.score_fr_flux = L.Convolution( n.drop7_flux, num_output=flux_hidden_channels, kernel_size=1, pad=0, weight_filler={"type": "xavier"}, bias_filler={"type": "constant"}, param=[dict(lr_mult=10, decay_mult=1), dict(lr_mult=20, decay_mult=0)]) n.upscore2_flux = L.Deconvolution(n.score_fr_flux, convolution_param=dict( num_output=flux_hidden_channels, kernel_size=4, stride=2, pad=1, bias_term=False), param=[dict(lr_mult=0)]) # scale pool4 skip for compatibility n.scale_pool4 = L.Scale(n.pool4, filler=dict(type='constant', value=0.01), param=[dict(lr_mult=0)]) n.score_pool4 = L.Convolution( n.scale_pool4, num_output=21, kernel_size=1, pad=0, param=[dict(lr_mult=10, decay_mult=1), dict(lr_mult=20, decay_mult=0)]) n.score_pool4c = crop(n.score_pool4, n.upscore2) n.fuse_pool4 = L.Eltwise(n.upscore2, n.score_pool4c, operation=P.Eltwise.SUM) n.upscore_pool4 = L.Deconvolution(n.fuse_pool4, convolution_param=dict(num_output=21, kernel_size=4, stride=2, pad=1, bias_term=False), param=[dict(lr_mult=0)]) # scale pool4 skip for compatibility flux n.scale_pool4_flux = L.Scale(n.relu4_3, filler=dict(type='constant', value=0.01), param=[dict(lr_mult=0)]) n.score_pool4_flux = L.Convolution( n.scale_pool4_flux, num_output=flux_hidden_channels, kernel_size=1, pad=0, weight_filler={"type": "xavier"}, bias_filler={"type": "constant"}, param=[dict(lr_mult=10, decay_mult=1), dict(lr_mult=20, decay_mult=0)]) n.score_pool4c_flux = crop(n.score_pool4_flux, n.upscore2_flux) n.fuse_pool4_flux = L.Eltwise(n.upscore2_flux, n.score_pool4c_flux, operation=P.Eltwise.SUM) n.upscore_pool4_flux = L.Deconvolution(n.fuse_pool4_flux, convolution_param=dict( num_output=flux_hidden_channels, kernel_size=4, stride=2, pad=1, bias_term=False), param=[dict(lr_mult=0)]) # scale pool3 skip for compatibility n.scale_pool3 = L.Scale(n.pool3, filler=dict(type='constant', value=0.0001), param=[dict(lr_mult=0)]) n.score_pool3 = L.Convolution( n.scale_pool3, num_output=21, kernel_size=1, pad=0, param=[dict(lr_mult=10, decay_mult=1), dict(lr_mult=20, decay_mult=0)]) n.score_pool3c = crop(n.score_pool3, n.upscore_pool4) n.fuse_pool3 = L.Eltwise(n.upscore_pool4, n.score_pool3c, operation=P.Eltwise.SUM) n.upscore8 = L.Deconvolution(n.fuse_pool3, convolution_param=dict(num_output=21, kernel_size=16, stride=8, pad=4, bias_term=False), param=[dict(lr_mult=0)]) # scale pool3 skip for compatibility flux n.scale_pool3_flux = L.Scale(n.relu3_3, filler=dict(type='constant', value=0.0001), param=[dict(lr_mult=0)]) n.score_pool3_flux = L.Convolution( n.scale_pool3_flux, num_output=flux_hidden_channels, kernel_size=1, pad=0, weight_filler={"type": "xavier"}, bias_filler={"type": "constant"}, param=[dict(lr_mult=10, decay_mult=1), dict(lr_mult=20, decay_mult=0)]) n.score_pool3c_flux = crop(n.score_pool3_flux, n.upscore_pool4_flux) n.fuse_pool3_flux = L.Eltwise(n.upscore_pool4_flux, n.score_pool3c_flux, operation=P.Eltwise.SUM) n.final_conv1, n.final_relu1 = conv_relu_10x(n.fuse_pool3_flux, 64) n.final_conv2, n.final_relu2 = conv_relu_10x(n.final_relu1, 64) n.final_conv3 = L.Convolution( n.final_relu2, num_output=2, kernel_size=3, stride=1, pad=1, weight_filler={"type": "xavier"}, bias_filler={"type": "constant"}, param=[dict(lr_mult=10, decay_mult=1), dict(lr_mult=20, decay_mult=0)]) n.upscore4_final_conv3 = L.Deconvolution(n.final_conv3, convolution_param=dict( num_output=2, kernel_size=8, stride=4, pad=2, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore8, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) n.flux_score = crop(n.upscore4_final_conv3, n.data) n.norm_loss = L.Python(n.flux_score, n.flux, n.flux_weight, module='utils', layer='WeightedEuclideanLossLayer', loss_weight=1) n.angle_loss = L.Python(n.flux_score, n.flux, n.flux_weight, module='utils', layer='WeightedAngleLossLayer', loss_weight=1) return n.to_proto()
def define_structure(self, stage): n = caffe.NetSpec() if stage != CaffeLocations.STAGE_DEPLOY: source_params = dict(stage=stage) source_params['data_dir'] = self.DATA_DIR source_params['split_dir'] = self.SPLIT_DIR n.data, n.label = L.Python(module='DataLayer', layer='DataLayer', ntop=2, param_str=str(source_params)) else: n.data = L.Input(shape=dict(dim=[1, 3, self.WSIZE, self.WSIZE])) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 32, pad=7) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 32) n.pool1 = max_pool(n.conv1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 64) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 64) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 128) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 128) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 128) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 256) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 256) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 256) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 256) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 256) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 256) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 2048, ks=2, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 2048, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution( n.drop7, num_output=CaffeLocations.NUM_LABELS, kernel_size=1, pad=0, param=[ dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0) ], weight_filler=dict(type='xavier'), bias_filler=dict( type='constant')) # must be 1 x num_classes x 1 x 1 n.upscore_a = L.Deconvolution(n.score_fr, convolution_param=dict( num_output=CaffeLocations.NUM_LABELS, kernel_size=4, stride=8, bias_term=False, weight_filler=dict(type='xavier'), bias_filler=dict(type='constant')), param=[dict(lr_mult=1, decay_mult=1)]) n.score_pool2 = L.Convolution(n.pool2, num_output=CaffeLocations.NUM_LABELS, kernel_size=1, pad=0, param=[ dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0) ], weight_filler=dict(type='xavier'), bias_filler=dict(type='constant')) n.score_pool2c = crop(n.score_pool2, n.upscore_a) n.fuse_pool2 = L.Eltwise(n.upscore_a, n.score_pool2c, operation=P.Eltwise.SUM) n.upscore_b = L.Deconvolution(n.fuse_pool2, convolution_param=dict( num_output=CaffeLocations.NUM_LABELS, kernel_size=40, stride=4, bias_term=False), param=[dict(lr_mult=1, decay_mult=1)]) # keep = True # ks = 40 # st = ks # while(keep): # try: # n.upscore_b = L.Deconvolution(n.fuse_pool2, # convolution_param=dict(num_output=CaffeLocations.NUM_LABELS, # kernel_size=ks, # stride=st, # bias_term=False), # param=[dict(lr_mult=0)]) # # n.score = crop(n.upscore_b, n.data) # break # except AssertionError as e: # st=st-1 # # print # print 'FOUND' # print ks, st n.score = crop(n.upscore_b, n.data) if stage != CaffeLocations.STAGE_DEPLOY: n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False)) # n.loss = L.Python(n.score, n.label, module='LossLayer', layer='TopoLossLayer', loss_weight=1) return n.to_proto()
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(104.00699, 116.66877, 122.67892), seed=1337) if split == 'train': pydata_params['sbdd_dir'] = '/data02/bioinf/treml/pascal/SBDD/dataset' pylayer = 'SBDDSegDataLayer' else: pydata_params['voc_dir'] = '/data02/bioinf/treml/pascal/VOC2011' pylayer = 'VOCSegDataLayer' n.data, n.label = L.Python(module='voc_layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_fr = L.Convolution(n.drop7, num_output=21, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore2 = L.Deconvolution(n.score_fr, convolution_param=dict(num_output=21, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) n.score_pool4 = L.Convolution(n.pool4, num_output=21, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool4c = crop(n.score_pool4, n.upscore2) n.fuse_pool4 = L.Eltwise(n.upscore2, n.score_pool4c, operation=P.Eltwise.SUM) n.upscore16 = L.Deconvolution(n.fuse_pool4, convolution_param=dict(num_output=21, kernel_size=32, stride=16, bias_term=False), param=[dict(lr_mult=0)]) n.score = crop(n.upscore16, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def fcn(split, nb_class): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(104.00699, 116.66877, 122.67892), seed=1337) pydata_params['prague_dir'] = '../data/prague_normal' pylayer = 'PRAGUESegDataLayer' n.data, n.label = L.Python(module='prague_layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) # fully conv n.fc6b, n.relu6 = conv_relu(n.pool4, 4096, ks=5, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7b, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) n.score_frb = L.Convolution( n.drop7, num_output=nb_class, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore1b = L.Deconvolution(n.score_frb, convolution_param=dict(num_output=nb_class, group=nb_class, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0, decay_mult=0)], weight_filler=dict(type='bilinear')) n.score_pool3b = L.Convolution( n.pool3, num_output=nb_class, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool3c = crop(n.score_pool3b, n.upscore1b) n.fuse_pool3 = L.Eltwise(n.upscore1b, n.score_pool3c, operation=P.Eltwise.SUM) n.upscore2b = L.Deconvolution(n.fuse_pool3, convolution_param=dict(num_output=nb_class, group=nb_class, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0, decay_mult=0)], weight_filler=dict(type='bilinear')) n.score_pool2b = L.Convolution( n.pool2, num_output=nb_class, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool2c = crop(n.score_pool2b, n.upscore2b) n.fuse_pool2 = L.Eltwise(n.upscore2b, n.score_pool2c, operation=P.Eltwise.SUM) n.upscore3b = L.Deconvolution(n.fuse_pool2, convolution_param=dict(num_output=nb_class, group=nb_class, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0, decay_mult=0)], weight_filler=dict(type='bilinear')) n.score_pool1b = L.Convolution( n.pool1, num_output=nb_class, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool1c = crop(n.score_pool1b, n.upscore3b) n.fuse_pool1 = L.Eltwise(n.upscore3b, n.score_pool1c, operation=P.Eltwise.SUM) n.upscore4b = L.Deconvolution(n.fuse_pool1, convolution_param=dict(num_output=nb_class, group=nb_class, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0, decay_mult=0)], weight_filler=dict(type='bilinear')) n.score = crop(n.upscore4b, n.data) n.loss = L.SoftmaxWithLoss(n.score, n.label, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()
def fcn(split): n = caffe.NetSpec() pydata_params = dict(split=split, mean=(104.00699, 116.66877, 122.67892), seed=1337) # if split == 'train': # pydata_params['sbdd_dir'] = '../../data/sbdd/dataset' # pylayer = 'SBDDSegDataLayer' # else: # pydata_params['voc_dir'] = '../../data/pascal/VOC2011' # pylayer = 'VOCSegDataLayer' # pydata_params['icdar_dir'] = '../../../data/icdar' # pylayer = 'ICDARDataLayer' pydata_params['coco_dir'] = '../../../data/coco-text' pylayer = 'COCODataLayer' n.data, n.label = L.Python(module='layers', layer=pylayer, ntop=2, param_str=str(pydata_params)) # the base net n.conv1_1, n.relu1_1 = conv_relu(n.data, 64, pad=100) n.conv1_2, n.relu1_2 = conv_relu(n.relu1_1, 64) n.pool1 = max_pool(n.relu1_2) n.conv2_1, n.relu2_1 = conv_relu(n.pool1, 128) n.conv2_2, n.relu2_2 = conv_relu(n.relu2_1, 128) n.pool2 = max_pool(n.relu2_2) n.conv3_1, n.relu3_1 = conv_relu(n.pool2, 256) n.conv3_2, n.relu3_2 = conv_relu(n.relu3_1, 256) n.conv3_3, n.relu3_3 = conv_relu(n.relu3_2, 256) n.pool3 = max_pool(n.relu3_3) n.conv4_1, n.relu4_1 = conv_relu(n.pool3, 512) n.conv4_2, n.relu4_2 = conv_relu(n.relu4_1, 512) n.conv4_3, n.relu4_3 = conv_relu(n.relu4_2, 512) n.pool4 = max_pool(n.relu4_3) n.conv5_1, n.relu5_1 = conv_relu(n.pool4, 512) n.conv5_2, n.relu5_2 = conv_relu(n.relu5_1, 512) n.conv5_3, n.relu5_3 = conv_relu(n.relu5_2, 512) n.pool5 = max_pool(n.relu5_3) # fully conv n.fc6, n.relu6 = conv_relu(n.pool5, 4096, ks=7, pad=0) n.drop6 = L.Dropout(n.relu6, dropout_ratio=0.5, in_place=True) n.fc7, n.relu7 = conv_relu(n.drop6, 4096, ks=1, pad=0) n.drop7 = L.Dropout(n.relu7, dropout_ratio=0.5, in_place=True) # n.score_fr = L.Convolution(n.drop7, num_output=21, kernel_size=1, pad=0, # param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) # n.upscore2 = L.Deconvolution(n.score_fr, # convolution_param=dict(num_output=21, kernel_size=4, stride=2, # bias_term=False), # param=[dict(lr_mult=0)]) # n.score_pool4 = L.Convolution(n.pool4, num_output=21, kernel_size=1, pad=0, # param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) # n.score_pool4c = crop(n.score_pool4, n.upscore2) # n.fuse_pool4 = L.Eltwise(n.upscore2, n.score_pool4c, # operation=P.Eltwise.SUM) # n.upscore16 = L.Deconvolution(n.fuse_pool4, # convolution_param=dict(num_output=21, kernel_size=32, stride=16, # bias_term=False), # param=[dict(lr_mult=0)]) n.score_fr_conv = L.Convolution(n.drop7, num_output=2, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) # n.score_fr_conv = L.Convolution(n.drop7, num_output=2, kernel_size=1, pad=0, weight_filler=dict(type='gaussian',std=0.01), bias_filler=dict(type='constant',value=0), # param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.upscore2_conv = L.Deconvolution(n.score_fr_conv , convolution_param=dict(num_output=2, kernel_size=4, stride=2, bias_term=False), param=[dict(lr_mult=0)]) # n.upscore2_conv = L.Deconvolution(n.score_fr_conv , # convolution_param=dict(num_output=2, kernel_size=4, stride=2, # bias_term=False, group=2,weight_filler=dict(type='constant',value=1)), # param=[dict(lr_mult=0)]) n.score_pool4_conv = L.Convolution(n.pool4, num_output=2, kernel_size=1, pad=0, param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) # n.score_pool4_conv = L.Convolution(n.pool4, num_output=2, kernel_size=1, pad=0, weight_filler=dict(type='gaussian',std=0.01), bias_filler=dict(type='constant',value=0), # param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=2, decay_mult=0)]) n.score_pool4c = crop(n.score_pool4_conv , n.upscore2_conv ) n.fuse_pool4 = L.Eltwise(n.upscore2_conv , n.score_pool4c , operation=P.Eltwise.SUM) n.upscore16_conv = L.Deconvolution(n.fuse_pool4 , convolution_param=dict(num_output=2, kernel_size=32, stride=16, bias_term=False), param=[dict(lr_mult=0)]) # n.upscore16_conv = L.Deconvolution(n.fuse_pool4 , # convolution_param=dict(num_output=2, kernel_size=32, stride=16, # bias_term=False,group=2,weight_filler=dict(type='constant',value=1)), # param=[dict(lr_mult=0)]) n.score = crop(n.upscore16_conv , n.data) n.loss = L.SoftmaxWithLoss(n.score , n.label, loss_param=dict(normalize=False, ignore_label=255)) return n.to_proto()