def caffenet_multilabel(data_layer_params, datalayer):
# setup the python data layer
n = caffe.NetSpec()
n.data, n.label = L.Python(module = 'pascal_multilabel_datalayers', layer = datalayer,
ntop = 2, param_str=str(data_layer_params))
# the net itself
n.conv1, n.relu1 = conv_relu(n.data, 11, 96, stride=4)
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)
n.fc6, n.relu6 = fc_relu(n.pool5, 4096)
n.drop6 = L.Dropout(n.relu6, in_place=True)
n.fc7, n.relu7 = fc_relu(n.drop6, 4096)
n.drop7 = L.Dropout(n.relu7, in_place=True)
n.score = L.InnerProduct(n.drop7, num_output=20)
n.loss = L.SigmoidCrossEntropyLoss(n.score, n.label)
return str(n.to_proto())
# crete net and solver prototxts.
python类NetSpec()的实例源码
def logreg(hdf5, batch_size):
# logistic regression: data, matrix multiplication, and 2-class softmax loss
n=caffe.NetSpec()
n.data,n.label = L.HDF5Data(batch_size=batch_size,source=hdf5,ntop=2)
n.ip1 = L.InnerProduct(n.data,num_output=2,weight_filler=dict(type='xavier'))
n.accuracy = L.Accuracy(n.ip1,n.label)
n.loss = L.SoftmaxWithLoss(n.ip1,n.label)
return n.to_proto()
def SketchTriplet_anchor(out_dim):
n = caffe.NetSpec()
n.data_a = L.Input(name='data',
shape=dict(dim=[1,1,225,225]))
n.conv1_a, n.relu1_a = conv_relu_triplet_dep(n.data_a, 15, 64, stride = 3)
n.pool1_a = pooling(n.relu1_a, 3, stride=2)
n.conv2_a, n.relu2_a = conv_relu_triplet_dep(n.pool1_a, 5, 128)
n.pool2_a = pooling(n.relu2_a, 3, stride=2)
n.conv3_a, n.relu3_a = conv_relu_triplet_dep(n.pool2_a, 3, 256)
n.conv4_a, n.relu4_a = conv_relu_triplet_dep(n.relu3_a, 3, 256)
n.conv5_a, n.relu5_a = conv_relu_triplet_dep(n.relu4_a, 3, 256)
n.pool5_a = pooling(n.relu5_a, 3, stride=2)
n.fc6_a, n.relu6_a = fc_relu_triplet_dep(n.pool5_a, 512)
n.fc7_a, n.relu7_a = fc_relu_triplet_dep(n.relu6_a, 512)
#n.fc8_a, n.feat_a = fc_norm_triplet_dep(n.relu7_a, out_dim)
n.feat_a = fc_triplet_dep(n.relu7_a, out_dim)
proto = n.to_proto()
proto.name = 'SketchTriplet'
return proto
def SketchTriplet_pos(out_dim):
n = caffe.NetSpec()
n.data_p = L.Input(name='data',
shape=dict(dim=[1,1,225,225]))
n.conv1_p, n.relu1_p = conv_relu_triplet_dep(n.data_p, 15, 64, stride = 3)
n.pool1_p = pooling(n.relu1_p, 3, stride=2)
n.conv2_p, n.relu2_p = conv_relu_triplet_dep(n.pool1_p, 5, 128)
n.pool2_p = pooling(n.relu2_p, 3, stride=2)
n.conv3_p, n.relu3_p = conv_relu_triplet_dep(n.pool2_p, 3, 256)
n.conv4_p, n.relu4_p = conv_relu_triplet_dep(n.relu3_p, 3, 256)
n.conv5_p, n.relu5_p = conv_relu_triplet_dep(n.relu4_p, 3, 256)
n.pool5_p = pooling(n.relu5_p, 3, stride=2)
n.fc6_p, n.relu6_p = fc_relu_triplet_dep(n.pool5_p, 512)
n.fc7_p, n.relu7_p = fc_relu_triplet_dep(n.relu6_p, 512)
#n.fc8_p, n.feat_p = fc_norm_triplet_dep(n.relu7_p, out_dim)
n.feat_p = fc_triplet_dep(n.relu7_p, out_dim)
proto = n.to_proto()
proto.name = 'SketchTriplet'
return proto
def SketchTriplet_anchor(out_dim):
n = caffe.NetSpec()
n.data_a = L.Input(name='data',
shape=dict(dim=[1,1,225,225]))
n.conv1_a, n.relu1_a = conv_relu_triplet_dep(n.data_a, 15, 64, stride = 3)
n.pool1_a = pooling(n.relu1_a, 3, stride=2)
n.conv2_a, n.relu2_a = conv_relu_triplet_dep(n.pool1_a, 5, 128)
n.pool2_a = pooling(n.relu2_a, 3, stride=2)
n.conv3_a, n.relu3_a = conv_relu_triplet_dep(n.pool2_a, 3, 256)
n.conv4_a, n.relu4_a = conv_relu_triplet_dep(n.relu3_a, 3, 256)
n.conv5_a, n.relu5_a = conv_relu_triplet_dep(n.relu4_a, 3, 256)
n.pool5_a = pooling(n.relu5_a, 3, stride=2)
n.fc6_a, n.relu6_a = fc_relu_triplet_dep(n.pool5_a, 512)
n.fc7_a, n.relu7_a = fc_relu_triplet_dep(n.relu6_a, 512)
#n.fc8_a, n.feat_a = fc_norm_triplet_dep(n.relu7_a, out_dim)
n.feat_a = fc_triplet_dep(n.relu7_a, out_dim)
proto = n.to_proto()
proto.name = 'SketchTriplet'
return proto
def SketchTriplet_pos(out_dim):
n = caffe.NetSpec()
n.data_p = L.Input(name='data',
shape=dict(dim=[1,1,225,225]))
n.conv1_p, n.relu1_p = conv_relu_triplet_dep(n.data_p, 15, 64, stride = 3)
n.pool1_p = pooling(n.relu1_p, 3, stride=2)
n.conv2_p, n.relu2_p = conv_relu_triplet_dep(n.pool1_p, 5, 128)
n.pool2_p = pooling(n.relu2_p, 3, stride=2)
n.conv3_p, n.relu3_p = conv_relu_triplet_dep(n.pool2_p, 3, 256)
n.conv4_p, n.relu4_p = conv_relu_triplet_dep(n.relu3_p, 3, 256)
n.conv5_p, n.relu5_p = conv_relu_triplet_dep(n.relu4_p, 3, 256)
n.pool5_p = pooling(n.relu5_p, 3, stride=2)
n.fc6_p, n.relu6_p = fc_relu_triplet_dep(n.pool5_p, 512)
n.fc7_p, n.relu7_p = fc_relu_triplet_dep(n.relu6_p, 512)
#n.fc8_p, n.feat_p = fc_norm_triplet_dep(n.relu7_p, out_dim)
n.feat_p = fc_triplet_dep(n.relu7_p, out_dim)
proto = n.to_proto()
proto.name = 'SketchTriplet'
return proto
def SketchTriplet_anchor(out_dim):
n = caffe.NetSpec()
n.data_a = L.Input(name='data',
shape=dict(dim=[1,1,225,225]))
n.conv1_a, n.relu1_a = conv_relu_triplet_dep(n.data_a, 15, 64, stride = 3)
n.pool1_a = pooling(n.relu1_a, 3, stride=2)
n.conv2_a, n.relu2_a = conv_relu_triplet_dep(n.pool1_a, 5, 128)
n.pool2_a = pooling(n.relu2_a, 3, stride=2)
n.conv3_a, n.relu3_a = conv_relu_triplet_dep(n.pool2_a, 3, 256)
n.conv4_a, n.relu4_a = conv_relu_triplet_dep(n.relu3_a, 3, 256)
n.conv5_a, n.relu5_a = conv_relu_triplet_dep(n.relu4_a, 3, 256)
n.pool5_a = pooling(n.relu5_a, 3, stride=2)
n.fc6_a, n.relu6_a = fc_relu_triplet_dep(n.pool5_a, 512)
n.fc7_a, n.relu7_a = fc_relu_triplet_dep(n.relu6_a, 512)
#n.fc8_a, n.feat_a = fc_norm_triplet_dep(n.relu7_a, out_dim)
n.feat_a = fc_triplet_dep(n.relu7_a, out_dim)
n.norm_a = L.Normalize(n.feat_a,in_place=True)
proto = n.to_proto()
proto.name = 'SketchTriplet'
return proto
def siamese_anchor(out_dim=100):
n = caffe.NetSpec()
n.data_a = L.Input(name='data',
shape=dict(dim=[1,1,225,225]))
n.conv1_a, n.relu1_a = conv_relu_triplet_dep(n.data_a, 15, 64, stride = 3)
n.pool1_a = pooling(n.relu1_a, 3, stride=2)
n.conv2_a, n.relu2_a = conv_relu_triplet_dep(n.pool1_a, 5, 128)
n.pool2_a = pooling(n.relu2_a, 3, stride=2)
n.conv3_a, n.relu3_a = conv_relu_triplet_dep(n.pool2_a, 3, 256)
n.conv4_a, n.relu4_a = conv_relu_triplet_dep(n.relu3_a, 3, 256)
n.conv5_a, n.relu5_a = conv_relu_triplet_dep(n.relu4_a, 3, 256)
n.pool5_a = pooling(n.relu5_a, 3, stride=2)
n.fc6_a, n.relu6_a = fc_relu_triplet_dep(n.pool5_a, 512)
n.fc7_a, n.relu7_a = fc_relu_triplet_dep(n.relu6_a, 512)
#n.fc8_a, n.feat_a = fc_norm_triplet_dep(n.relu7_a, out_dim)
n.feat_a = fc_triplet_dep(n.relu7_a, out_dim)
#n.norm_a = L.Normalize(n.feat_a,in_place=True)
proto = n.to_proto()
proto.name = 'SketchTriplet'
return proto
def siamese_pos(out_dim=100):
n = caffe.NetSpec()
n.data_p = L.Input(name='data',
shape=dict(dim=[1,1,225,225]))
n.conv1_p, n.relu1_p = conv_relu_triplet_dep(n.data_p, 15, 64, stride = 3)
n.pool1_p = pooling(n.relu1_p, 3, stride=2)
n.conv2_p, n.relu2_p = conv_relu_triplet_dep(n.pool1_p, 5, 128)
n.pool2_p = pooling(n.relu2_p, 3, stride=2)
n.conv3_p, n.relu3_p = conv_relu_triplet_dep(n.pool2_p, 3, 256)
n.conv4_p, n.relu4_p = conv_relu_triplet_dep(n.relu3_p, 3, 256)
n.conv5_p, n.relu5_p = conv_relu_triplet_dep(n.relu4_p, 3, 256)
n.pool5_p = pooling(n.relu5_p, 3, stride=2)
n.fc6_p, n.relu6_p = fc_relu_triplet_dep(n.pool5_p, 512)
n.fc7_p, n.relu7_p = fc_relu_triplet_dep(n.relu6_p, 512)
#n.fc8_p, n.feat_p = fc_norm_triplet_dep(n.relu7_p, out_dim)
n.feat_p = fc_triplet_dep(n.relu7_p, out_dim)
#n.norm_p = L.Normalize(n.feat_p,in_place=True)
proto = n.to_proto()
proto.name = 'SketchTriplet'
return proto
def get_phocnet(self, word_image_lmdb_path, phoc_lmdb_path,
phoc_size=604, generate_deploy=False):
'''
Returns a NetSpec definition of the PHOCNet. The definition can then be transformed
into a protobuffer message by casting it into a str.
'''
n = NetSpec()
# Data
self.set_phocnet_data(n=n, generate_deploy=generate_deploy,
word_image_lmdb_path=word_image_lmdb_path,
phoc_lmdb_path=phoc_lmdb_path)
# Conv Part
self.set_phocnet_conv_body(n=n, relu_in_place=True)
# FC Part
n.spp5 = L.SPP(n.relu4_3, spp_param=dict(pool=P.SPP.MAX, pyramid_height=3, engine=self.spp_engine))
n.fc6, n.relu6, n.drop6 = self.fc_relu(bottom=n.spp5, layer_size=4096,
dropout_ratio=0.5, relu_in_place=True)
n.fc7, n.relu7, n.drop7 = self.fc_relu(bottom=n.drop6, layer_size=4096,
dropout_ratio=0.5, relu_in_place=True)
n.fc8 = L.InnerProduct(n.drop7, num_output=phoc_size,
weight_filler=dict(type=self.initialization),
bias_filler=dict(type='constant'))
n.sigmoid = L.Sigmoid(n.fc8, include=dict(phase=self.phase_test))
# output part
if not generate_deploy:
n.silence = L.Silence(n.sigmoid, ntop=0, include=dict(phase=self.phase_test))
n.loss = L.SigmoidCrossEntropyLoss(n.fc8, n.phocs)
return n.to_proto()
def get_tpp_phocnet(self, word_image_lmdb_path, phoc_lmdb_path, phoc_size, tpp_levels=5,
generate_deploy=False):
'''
Returns a NetSpec definition of the TPP-PHOCNet. The definition can then be transformed
into a protobuffer message by casting it into a str.
'''
n = NetSpec()
# Data
self.set_phocnet_data(n=n, generate_deploy=generate_deploy,
word_image_lmdb_path=word_image_lmdb_path,
phoc_lmdb_path=phoc_lmdb_path)
# Conv Part
self.set_phocnet_conv_body(n=n, relu_in_place=True)
# FC Part
n.tpp5 = L.TPP(n.relu4_3, tpp_param=dict(pool=P.TPP.MAX, pyramid_layer=range(1, tpp_levels + 1), engine=self.spp_engine))
n.fc6, n.relu6, n.drop6 = self.fc_relu(bottom=n.tpp5, layer_size=4096,
dropout_ratio=0.5, relu_in_place=True)
n.fc7, n.relu7, n.drop7 = self.fc_relu(bottom=n.drop6, layer_size=4096,
dropout_ratio=0.5, relu_in_place=True)
n.fc8 = L.InnerProduct(n.drop7, num_output=phoc_size,
weight_filler=dict(type=self.initialization),
bias_filler=dict(type='constant'))
n.sigmoid = L.Sigmoid(n.fc8, include=dict(phase=self.phase_test))
# output part
if not generate_deploy:
n.silence = L.Silence(n.sigmoid, ntop=0, include=dict(phase=self.phase_test))
n.loss = L.SigmoidCrossEntropyLoss(n.fc8, n.phocs)
return n.to_proto()
def lenethdf5(hdf5 , batch_size):
# Net: a series of linear and simple nonlinear transformations
n = caffe.NetSpec()
n.data, n.label = L.HDF5Data(batch_size=batch_size, source=hdf5,ntop=2)
# the base net
n.conv1, n.relu1 = conv_relu(n.data, 32)
n.pool1 = max_pool(n.relu1)
n.conv2, n.relu2 = conv_relu(n.pool1, 64)
n.pool2 = max_pool(n.relu2)
n.conv3, n.relu3 = conv_relu(n.pool2, 128)
n.pool3 = max_pool(n.relu3)
# fully convolutional
n.fc1, n.rlfc1 = conv_relu(n.pool3, 512, ks=3, pad=1)
n.decov5 = deconv(n.rlfc1, 128, pad=1)
n.relu5, n.conv5 = relu_conv(n.decov5, 128, pad=0)
n.decov6 = deconv(n.conv5, 64, pad=1)
n.relu6, n.conv6 = relu_conv(n.decov6, 64, pad=0)
n.decov7 = deconv(n.conv6, 32, pad=1)
n.relu7, n.conv7 = relu_conv(n.decov7, 32, pad=0)
n.relu8, n.conv8 = relu_conv(n.conv7, 2, pad=0)
n.accuracy= L.Accuracy(n.conv8, n.label)
n.loss = L.SoftmaxWithLoss(n.conv8, n.label)
return n.to_proto()
# create file prototxt for training and validation
def lenethdf5d():
# our version of LeNet: a series of linear and simple nonlinear transformations
n = caffe.NetSpec()
#cambiano il primo e gli ultimi 2 strati
n.data = L.Input(input_param=dict(shape=dict(dim=[1,1,128,128])))
# the base net
n.conv1, n.relu1 = conv_relu(n.data, 32)
n.pool1 = max_pool(n.relu1)
#n.norm1 = L.LRN(n.pool1, local_size=5, alpha=1e-4, beta=0.75)
n.conv2, n.relu2 = conv_relu(n.pool1, 64)
n.pool2 = max_pool(n.relu2)
n.conv3, n.relu3 = conv_relu(n.pool2, 128)
n.pool3 = max_pool(n.relu3)
# fully convolutional
n.fc1, n.rlfc1 = conv_relu(n.pool3, 512, ks=3, pad=1)
n.decov5 = deconv(n.rlfc1, 128, pad=1)
n.relu5, n.conv5 = relu_conv(n.decov5, 128, pad=0)
n.decov6 = deconv(n.conv5, 64, pad=1)
n.relu6, n.conv6 = relu_conv(n.decov6, 64, pad=0)
n.decov7 = deconv(n.conv6, 32, pad=1)
n.relu7, n.conv7 = relu_conv(n.decov7, 32, pad=0)
n.relu8, n.conv8 = relu_conv(n.conv7, 2, pad=0)
n.prob = L.Softmax(n.conv8)
return n.to_proto()
# create file prototxt for deployment
def construc_net(widening_factor, num_block_per_stage):
net = caffe.NetSpec()
net.data = L.Input(input_param = dict(shape = dict(dim = [1,3,32,32])))
net.conv1 = L.Convolution(net.data, num_output = 16,
kernel_size = 3, stride = 1, pad = 1,
bias_term = False)
# stage 1
num_out = widening_factor * 16
block_pre = _block('2_1', net, net.conv1, num_out, has_branch1=True, increasing_dims=False)
for idx in xrange(2,num_block_per_stage+1,1):
flag = '2_{}'.format(idx)
block_pre = _block(flag, net, block_pre, num_out)
# stage 2
num_out = widening_factor * 32
block_pre = _block('3_1', net, block_pre, num_out, has_branch1=True)
for idx in xrange(2,num_block_per_stage+1,1):
flag = '3_{}'.format(idx)
block_pre = _block(flag, net, block_pre, num_out)
# stage 3
num_out = widening_factor * 64
block_pre = _block('4_1', net, block_pre, num_out, has_branch1=True)
for idx in xrange(2,num_block_per_stage+1,1):
flag = '4_{}'.format(idx)
block_pre = _block(flag, net, block_pre, num_out)
net.bn5 = L.BatchNorm(block_pre)
net.scale5 = L.Scale(net.bn5, bias_term = True, in_place=True)
net.relu5 = L.ReLU(net.scale5, in_place = True)
net.pool5 = L.Pooling(net.relu5, pool = P.Pooling.AVE, global_pooling=True)
net.fc6 = L.InnerProduct(net.pool5, num_output = 10)
net.prob = L.Softmax(net.fc6)
return net.to_proto()
def construc_net():
net = caffe.NetSpec()
net.data = L.Input(input_param = dict(shape = dict(dim = [1,3,224,224])))
block1 = _block_first(net, net.data)
net.pool1 = L.Pooling(block1, pool = P.Pooling.MAX, kernel_size = 3, stride = 2)
branch_2a = _branch('2a', net, net.pool1, 64, has_branch1 = True, is_branch_2a = True)
branch_2b = _branch('2b', net, branch_2a, 64)
branch_2c = _branch('2c', net, branch_2b, 64)
branch_3a = _branch('3a', net, branch_2c, 128, has_branch1 = True)
branch_3b = _branch('3b', net, branch_3a, 128)
branch_3c = _branch('3c', net, branch_3b, 128)
branch_3d = _branch('3d', net, branch_3c, 128)
branch_4a = _branch('4a', net, branch_3d, 256, has_branch1 = True)
branch_pre = branch_4a
for idx in xrange(1,23,1): # conv4_x total 1+22=23
flag = '4b{}'.format(idx)
branch_pre = _branch(flag, net, branch_pre, 256)
branch_5a = _branch('5a', net, branch_pre, 512, has_branch1 = True)
branch_5b = _branch('5b', net, branch_5a, 512)
branch_5c = _branch('5c', net, branch_5b, 512)
net.pool5 = L.Pooling(branch_5c, pool = P.Pooling.AVE, kernel_size = 7, stride = 1)
net.fc6 = L.InnerProduct(net.pool5, num_output = 1000)
net.prob = L.Softmax(net.fc6)
return net.to_proto()
def construc_net():
net = caffe.NetSpec()
net.data = L.Input(input_param = dict(shape = dict(dim = [1,1,224,224])))
block1 = _block_first(net, net.data)
net.pool1 = L.Pooling(block1, pool = P.Pooling.MAX, kernel_size = 3, stride = 2)
branch_2a = _branch('2a', net, net.pool1, 64, has_branch1 = True, is_branch_2a = True)
branch_2b = _branch('2b', net, branch_2a, 64)
branch_2c = _branch('2c', net, branch_2b, 64)
branch_3a = _branch('3a', net, branch_2c, 128, has_branch1 = True)
branch_3b = _branch('3b', net, branch_3a, 128)
branch_3c = _branch('3c', net, branch_3b, 128)
branch_3d = _branch('3d', net, branch_3c, 128)
branch_4a = _branch('4a', net, branch_3d, 256, has_branch1 = True)
branch_4b = _branch('4b', net, branch_4a, 256)
branch_4c = _branch('4c', net, branch_4b, 256)
branch_4d = _branch('4d', net, branch_4c, 256)
branch_4e = _branch('4e', net, branch_4d, 256)
branch_4f = _branch('4f', net, branch_4e, 256)
branch_5a = _branch('5a', net, branch_4f, 512, has_branch1 = True)
branch_5b = _branch('5b', net, branch_5a, 512)
branch_5c = _branch('5c', net, branch_5b, 512)
net.pool5 = L.Pooling(branch_5c, pool = P.Pooling.AVE, kernel_size = 7, stride = 1)
net.fc6 = L.InnerProduct(net.pool5, num_output = 1000)
net.prob = L.Softmax(net.fc6)
return net.to_proto()
def construc_net():
net = caffe.NetSpec()
net.data = L.Input(input_param = dict(shape = dict(dim = [1,3,224,224])))
block1 = _block_first(net, net.data)
net.pool1 = L.Pooling(block1, pool = P.Pooling.MAX, kernel_size = 3, stride = 2)
branch_2a = _branch('2a', net, net.pool1, 64, has_branch1 = True, is_branch_2a = True)
branch_2b = _branch('2b', net, branch_2a, 64)
branch_2c = _branch('2c', net, branch_2b, 64)
branch_3a = _branch('3a', net, branch_2c, 128, has_branch1 = True)
branch_pre = branch_3a
for idx in xrange(1,8,1): # conv3_x total 1+7=8
flag = '3b{}'.format(idx)
branch_pre = _branch(flag, net, branch_pre, 128)
branch_4a = _branch('4a', net, branch_pre, 256, has_branch1 = True)
branch_pre = branch_4a
for idx in xrange(1,36,1): # conv4_x total 1+35=36
flag = '4b{}'.format(idx)
branch_pre = _branch(flag, net, branch_pre, 256)
branch_5a = _branch('5a', net, branch_pre, 512, has_branch1 = True)
branch_5b = _branch('5b', net, branch_5a, 512)
branch_5c = _branch('5c', net, branch_5b, 512)
net.pool5 = L.Pooling(branch_5c, pool = P.Pooling.AVE, kernel_size = 7, stride = 1)
net.fc6 = L.InnerProduct(net.pool5, num_output = 1000)
net.prob = L.Softmax(net.fc6)
return net.to_proto()
def construc_net():
net = caffe.NetSpec()
net.data = L.Input(shape = dict(dim = [10,3,224,224]))
block_cr_1 = _block_cr('conv1', '7x7_s2', net, net.data, 64, 3, 7, 2)
pool_layer_1 = 'pool1/3x3_s2'
net[pool_layer_1] = L.Pooling(block_cr_1, pool = P.Pooling.MAX,
kernel_size = 3, stride = 2)
##LRN
block_cr_2_reduce = _block_cr('conv2', '3x3_reduce', net, net[pool_layer_1], 64, 0, 1, 1)
block_cr_2 = _block_cr('conv2', '3x3', net, block_cr_2_reduce, 192, 1, 3, 1)
##LRN
pool_layer_2 = 'pool2/3x3_s2'
net[pool_layer_2] = L.Pooling(block_cr_2, pool = P.Pooling.MAX,
kernel_size = 3, stride = 2)
inception_3a = _inception_v1('inception_3a', net, net[pool_layer_2], [64,96,128,16,32,32])
inception_3b = _inception_v1('inception_3b', net, inception_3a, [128,128,192,32,96,64])
pool_layer_3 = 'pool3/3x3_s2'
net[pool_layer_3] = L.Pooling(inception_3b, pool = P.Pooling.MAX,
kernel_size = 3, stride = 2)
inception_4a = _inception_v1('inception_4a', net, net[pool_layer_3], [192,96,208,16,48,64])
inception_4b = _inception_v1('inception_4b', net, inception_4a, [160,112,224,24,64,64])
inception_4c = _inception_v1('inception_4c', net, inception_4b, [128,128,256,24,64,64])
inception_4d = _inception_v1('inception_4d', net, inception_4c, [112,144,288,32,64,64])
inception_4e = _inception_v1('inception_4e', net, inception_4d, [256,160,320,32,128,128])
pool_layer_4 = 'pool4/3x3_s2'
net[pool_layer_4] = L.Pooling(inception_4e, pool = P.Pooling.MAX,
kernel_size = 3, stride = 2)
inception_5a = _inception_v1('inception_5a', net, net[pool_layer_4], [256,160,320,32,128,128])
inception_5b = _inception_v1('inception_5b', net, inception_5a, [384,192,384,48,128,128])
pool_layer_5 = 'pool5/7x7_s1'
net[pool_layer_5] = L.Pooling(inception_5b, pool = P.Pooling.AVE,
kernel_size = 7, stride = 1)
pool_layer_5_drop = 'pool5/drop_7x7_s1'
net[pool_layer_5_drop] = L.Dropout(net[pool_layer_5], dropout_ratio = 0.4, in_place = True)
fc_layer = 'loos3/classifier'
net[fc_layer] = L.InnerProduct(net[pool_layer_5_drop], num_output = 1000)
net.prob = L.Softmax(net[fc_layer])
return net.to_proto()
def construc_net():
net = caffe.NetSpec()
net.data = L.Input(input_param = dict(shape = dict(dim = [1,3,224,224])))
block1 = _block_first(net, net.data)
net.pool1 = L.Pooling(block1, pool = P.Pooling.MAX, kernel_size = 3, stride = 2)
branch_2a = _branch('2a', net, net.pool1, 128, has_branch1 = True, is_branch_2a = True)
branch_2b = _branch('2b', net, branch_2a, 128)
branch_2c = _branch('2c', net, branch_2b, 128)
branch_3a = _branch('3a', net, branch_2c, 256, has_branch1 = True)
branch_3b = _branch('3b', net, branch_3a, 256)
branch_3c = _branch('3c', net, branch_3b, 256)
branch_3d = _branch('3d', net, branch_3c, 256)
branch_4a = _branch('4a', net, branch_3d, 512, has_branch1 = True)
branch_pre = branch_4a
for idx in xrange(1,23,1): # conv4_x total 1+22=23
flag = '4b{}'.format(idx)
branch_pre = _branch(flag, net, branch_pre, 512)
branch_5a = _branch('5a', net, branch_pre, 1024, has_branch1 = True)
branch_5b = _branch('5b', net, branch_5a, 1024)
branch_5c = _branch('5c', net, branch_5b, 1024)
net.pool5 = L.Pooling(branch_5c, pool = P.Pooling.AVE, kernel_size = 7, stride = 1)
net.fc6 = L.InnerProduct(net.pool5, num_output = 1000)
net.prob = L.Softmax(net.fc6)
return net.to_proto()
def construc_net():
net = caffe.NetSpec()
net.data = L.Input(input_param = dict(shape = dict(dim = [1,3,224,224])))
block1 = _block_first(net, net.data)
net.pool1 = L.Pooling(block1, pool = P.Pooling.MAX, kernel_size = 3, stride = 2)
branch_2a = _branch('2a', net, net.pool1, 128, has_branch1 = True, is_branch_2a = True)
branch_2b = _branch('2b', net, branch_2a, 128)
branch_2c = _branch('2c', net, branch_2b, 128)
branch_3a = _branch('3a', net, branch_2c, 256, has_branch1 = True)
branch_3b = _branch('3b', net, branch_3a, 256)
branch_3c = _branch('3c', net, branch_3b, 256)
branch_3d = _branch('3d', net, branch_3c, 256)
branch_4a = _branch('4a', net, branch_3d, 512, has_branch1 = True)
branch_4b = _branch('4b', net, branch_4a, 512)
branch_4c = _branch('4c', net, branch_4b, 512)
branch_4d = _branch('4d', net, branch_4c, 512)
branch_4e = _branch('4e', net, branch_4d, 512)
branch_4f = _branch('4f', net, branch_4e, 512)
branch_5a = _branch('5a', net, branch_4f, 1024, has_branch1 = True)
branch_5b = _branch('5b', net, branch_5a, 1024)
branch_5c = _branch('5c', net, branch_5b, 1024)
net.pool5 = L.Pooling(branch_5c, pool = P.Pooling.AVE, kernel_size = 7, stride = 1)
net.fc6 = L.InnerProduct(net.pool5, num_output = 1000)
net.prob = L.Softmax(net.fc6)
return net.to_proto()