本文整理匯總了Python中caffe.NetSpec方法的典型用法代碼示例。如果您正苦於以下問題:Python caffe.NetSpec方法的具體用法?Python caffe.NetSpec怎麽用?Python caffe.NetSpec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類caffe
的用法示例。
在下文中一共展示了caffe.NetSpec方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: fcn
# 需要導入模塊: import caffe [as 別名]
# 或者: from caffe import NetSpec [as 別名]
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()
示例2: make_frontend_vgg
# 需要導入模塊: import caffe [as 別名]
# 或者: from caffe import NetSpec [as 別名]
def make_frontend_vgg(options, is_training):
batch_size = options.train_batch if is_training else options.test_batch
image_path = options.train_image if is_training else options.test_image
label_path = options.train_label if is_training else options.test_label
net = caffe.NetSpec()
net.data, net.label = network.make_image_label_data(
image_path, label_path, batch_size,
is_training, options.crop_size, options.mean)
last = network.build_frontend_vgg(
net, net.data, options.classes)[0]
if options.up:
net.upsample = network.make_upsample(last, options.classes)
last = net.upsample
net.loss = network.make_softmax_loss(last, net.label)
if not is_training:
net.accuracy = network.make_accuracy(last, net.label)
return net.to_proto()
示例3: make_context
# 需要導入模塊: import caffe [as 別名]
# 或者: from caffe import NetSpec [as 別名]
def make_context(options, is_training):
batch_size = options.train_batch if is_training else options.test_batch
image_path = options.train_image if is_training else options.test_image
label_path = options.train_label if is_training else options.test_label
net = caffe.NetSpec()
net.data, net.label = network.make_bin_label_data(
image_path, label_path, batch_size,
options.label_shape, options.label_stride)
last = network.build_context(
net, net.data, options.classes, options.layers)[0]
if options.up:
net.upsample = network.make_upsample(last, options.classes)
last = net.upsample
net.loss = network.make_softmax_loss(last, net.label)
if not is_training:
net.accuracy = network.make_accuracy(last, net.label)
return net.to_proto()
示例4: lenet
# 需要導入模塊: import caffe [as 別名]
# 或者: from caffe import NetSpec [as 別名]
def lenet(batch_size):
n = caffe.NetSpec()
n.data, n.label = L.DummyData(shape=[dict(dim=[batch_size, 1, 28, 28]),
dict(dim=[batch_size, 1, 1, 1])],
transform_param=dict(scale=1./255), ntop=2)
n.conv1 = L.Convolution(n.data, kernel_size=5, num_output=20,
weight_filler=dict(type='xavier'))
n.pool1 = L.Pooling(n.conv1, kernel_size=2, stride=2, pool=P.Pooling.MAX)
n.conv2 = L.Convolution(n.pool1, kernel_size=5, num_output=50,
weight_filler=dict(type='xavier'))
n.pool2 = L.Pooling(n.conv2, kernel_size=2, stride=2, pool=P.Pooling.MAX)
n.ip1 = L.InnerProduct(n.pool2, num_output=500,
weight_filler=dict(type='xavier'))
n.relu1 = L.ReLU(n.ip1, in_place=True)
n.ip2 = L.InnerProduct(n.relu1, num_output=10,
weight_filler=dict(type='xavier'))
n.loss = L.SoftmaxWithLoss(n.ip2, n.label)
return n.to_proto()
示例5: coord_net_spec
# 需要導入模塊: import caffe [as 別名]
# 或者: from caffe import NetSpec [as 別名]
def coord_net_spec(ks=3, stride=1, pad=0, pool=2, dstride=2, dpad=0):
"""
Define net spec for simple conv-pool-deconv pattern common to all
coordinate mapping tests.
"""
n = caffe.NetSpec()
n.data = L.Input(shape=dict(dim=[2, 1, 100, 100]))
n.aux = L.Input(shape=dict(dim=[2, 1, 20, 20]))
n.conv = L.Convolution(
n.data, num_output=10, kernel_size=ks, stride=stride, pad=pad)
n.pool = L.Pooling(
n.conv, pool=P.Pooling.MAX, kernel_size=pool, stride=pool, pad=0)
# for upsampling kernel size is 2x stride
try:
deconv_ks = [s*2 for s in dstride]
except:
deconv_ks = dstride*2
n.deconv = L.Deconvolution(
n.pool, num_output=10, kernel_size=deconv_ks, stride=dstride, pad=dpad)
return n
開發者ID:QinganZhao,項目名稱:Deep-Learning-Based-Structural-Damage-Detection,代碼行數:22,代碼來源:test_coord_map.py
示例6: test_nd_conv
# 需要導入模塊: import caffe [as 別名]
# 或者: from caffe import NetSpec [as 別名]
def test_nd_conv(self):
"""
ND conv maps the same way in more dimensions.
"""
n = caffe.NetSpec()
# define data with 3 spatial dimensions, otherwise the same net
n.data = L.Input(shape=dict(dim=[2, 3, 100, 100, 100]))
n.conv = L.Convolution(
n.data, num_output=10, kernel_size=[3, 3, 3], stride=[1, 1, 1],
pad=[0, 1, 2])
n.pool = L.Pooling(
n.conv, pool=P.Pooling.MAX, kernel_size=2, stride=2, pad=0)
n.deconv = L.Deconvolution(
n.pool, num_output=10, kernel_size=4, stride=2, pad=0)
ax, a, b = coord_map_from_to(n.deconv, n.data)
self.assertEquals(ax, 1)
self.assertTrue(len(a) == len(b))
self.assertTrue(np.all(a == 1))
self.assertEquals(b[0] - 1, b[1])
self.assertEquals(b[1] - 1, b[2])
開發者ID:QinganZhao,項目名稱:Deep-Learning-Based-Structural-Damage-Detection,代碼行數:22,代碼來源:test_coord_map.py
示例7: gen_net
# 需要導入模塊: import caffe [as 別名]
# 或者: from caffe import NetSpec [as 別名]
def gen_net(batch_size=512, use_bn=True):
n=NetSpec();
n.data = L.DummyData(shape={"dim":[batch_size,3,96,96]})
n.select1 = L.DummyData(shape={"dim":[2]})
n.select2 = L.DummyData(shape={"dim":[2]})
n.label = L.DummyData(shape={"dim":[2]})
caffenet_stack(n.data, n, use_bn)
n.first = L.BatchReindex(n.relu6, n.select1)
n.second = L.BatchReindex(n.relu6, n.select2)
n.fc6_concat=L.Concat(n.first, n.second);
fc_relu(n, n.fc6_concat, '7', 4096, batchnorm=use_bn);
fc_relu(n, n.relu7, '8', 4096);
n.fc9 = L.InnerProduct(n.relu8, num_output=8,
weight_filler=dict(type='xavier'));
n.loss = L.SoftmaxWithLoss(n.fc9, n.label, loss_param=dict(normalization=P.Loss.NONE));
prot=n.to_proto()
prot.debug_info=True
return prot;
# image preprocessing. Note that the input image will modified.
示例8: get_phocnet
# 需要導入模塊: import caffe [as 別名]
# 或者: from caffe import NetSpec [as 別名]
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()
示例9: get_tpp_phocnet
# 需要導入模塊: import caffe [as 別名]
# 或者: from caffe import NetSpec [as 別名]
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()
示例10: approx_bilinear_net
# 需要導入模塊: import caffe [as 別名]
# 或者: from caffe import NetSpec [as 別名]
def approx_bilinear_net(input_shapes, hdf5_txt_fname='', batch_size=1, net_name='ApproxBilinearNet', phase=None):
assert len(input_shapes) == 2
image_shape, vel_shape = input_shapes
assert len(image_shape) == 3
assert len(vel_shape) == 1
_, height, width = image_shape
y_dim = height * width
fc_kwargs = dict(param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=0, decay_mult=0)],
num_output=y_dim,
weight_filler=dict(type='gaussian', std=0.001),
bias_filler=dict(type='constant', value=0))
n = caffe.NetSpec()
data_kwargs = dict(name='data', ntop=3, batch_size=batch_size, source=hdf5_txt_fname)
if phase is not None:
data_kwargs.update(dict(include=dict(phase=phase)))
n.image_curr, n.image_diff, n.vel = L.HDF5Data(**data_kwargs)
u = n.vel
n.y = L.Flatten(n.image_curr, name='flatten1')
n.y_diff = L.Flatten(n.image_diff, name='flatten2')
n.fc1_y = L.InnerProduct(n.y, name='fc1', **fc_kwargs)
n.fc2_u = L.InnerProduct(u, name='fc2', **fc_kwargs)
n.fc3_u = L.InnerProduct(u, name='fc3', **fc_kwargs)
n.prod_y_u = L.Eltwise(n.fc1_y, n.fc2_u, name='prod', operation=P.Eltwise.PROD)
n.y_diff_pred = L.Eltwise(n.prod_y_u, n.fc3_u, name='sum', operation=P.Eltwise.SUM)
n.loss = L.EuclideanLoss(n.y_diff_pred, n.y_diff, name='loss')
net = n.to_proto()
net.name = net_name
return net, None
示例11: bilinear_net
# 需要導入模塊: import caffe [as 別名]
# 或者: from caffe import NetSpec [as 別名]
def bilinear_net(input_shapes, hdf5_txt_fname='', batch_size=1, net_name='BilinearNet', phase=None, **kwargs):
assert len(input_shapes) == 2
image_shape, vel_shape = input_shapes
assert len(image_shape) == 3
assert len(vel_shape) == 1
y_dim = np.prod(image_shape)
u_dim, = vel_shape
fc_kwargs = dict(param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=0, decay_mult=0)],
weight_filler=dict(type='gaussian', std=0.001),
bias_filler=dict(type='constant', value=0))
n = caffe.NetSpec()
data_kwargs = dict(name='data', ntop=3, batch_size=batch_size, source=hdf5_txt_fname)
if phase is not None:
data_kwargs.update(dict(include=dict(phase=phase)))
n.image_curr, n.image_diff, n.vel = L.HDF5Data(**data_kwargs)
u = n.vel
n.y = L.Flatten(n.image_curr)
n.y_diff_pred = Bilinear(n, n.y, u, y_dim, u_dim, **fc_kwargs)
n.y_diff = L.Flatten(n.image_diff)
n.loss = L.EuclideanLoss(n.y_diff_pred, n.y_diff, name='loss')
n.image_diff_pred = L.Reshape(n.y_diff_pred, shape=dict(dim=[batch_size] + list(image_shape)))
n.image_next_pred = L.Eltwise(n.image_curr, n.image_diff_pred, operation=P.Eltwise.SUM)
net = n.to_proto()
net.name = net_name
return net, None
示例12: bilinear_constrained_net
# 需要導入模塊: import caffe [as 別名]
# 或者: from caffe import NetSpec [as 別名]
def bilinear_constrained_net(input_shapes, hdf5_txt_fname='', batch_size=1, net_name='BilinearConstrainedNet', phase=None, **kwargs):
assert len(input_shapes) == 2
image_shape, vel_shape = input_shapes
assert len(image_shape) == 3
assert len(vel_shape) == 1
_, height, width = image_shape
y_dim = height * width
u_dim = vel_shape[0]
fc_kwargs = dict(param=[dict(lr_mult=1, decay_mult=1), dict(lr_mult=0, decay_mult=0)],
weight_filler=dict(type='gaussian', std=0.001),
bias_filler=dict(type='constant', value=0))
n = caffe.NetSpec()
data_kwargs = dict(name='data', ntop=3, batch_size=batch_size, source=hdf5_txt_fname)
if phase is not None:
data_kwargs.update(dict(include=dict(phase=phase)))
n.image_curr, n.image_diff, n.vel = L.HDF5Data(**data_kwargs)
u = n.vel
n.y = L.Flatten(n.image_curr)
n.y_diff_pred = Bilinear(n, n.y, u, y_dim, u_dim, **fc_kwargs)
n.image_diff_pred = L.Reshape(n.y_diff_pred, shape=dict(dim=[batch_size] + list(image_shape)))
n.image_next_pred_unconstrained = L.Eltwise(n.image_curr, n.image_diff_pred, operation=P.Eltwise.SUM)
n.image_next_pred = L.TanH(n.image_next_pred_unconstrained)
n.image_next = L.Eltwise(n.image_curr, n.image_diff, operation=P.Eltwise.SUM)
n.loss = L.EuclideanLoss(n.image_next, n.image_next_pred, name='loss')
net = n.to_proto()
net.name = net_name
return net, None
示例13: convert_to_caffe
# 需要導入模塊: import caffe [as 別名]
# 或者: from caffe import NetSpec [as 別名]
def convert_to_caffe(self, name):
caffe_net = caffe.NetSpec()
layer = L.Input(shape=dict(dim=[1, 3, args.image_hw, args.image_hw]))
caffe_net.tops['data'] = layer
slim.generate_caffe_prototxt(self, caffe_net, layer)
print(caffe_net.to_proto())
with open(name + '.prototxt', 'wb') as f:
f.write(str(caffe_net.to_proto()).encode())
caffe_net = caffe.Net(name + '.prototxt', caffe.TEST)
slim.convert_pytorch_to_caffe(self, caffe_net)
caffe_net.save(name + '.caffemodel')
示例14: convert_to_caffe
# 需要導入模塊: import caffe [as 別名]
# 或者: from caffe import NetSpec [as 別名]
def convert_to_caffe(self, name):
caffe_net = caffe.NetSpec()
layer = L.Input(shape=dict(dim=[1, 3, 224, 224]))
caffe_net.tops['data'] = layer
generate_caffe_prototxt(self, caffe_net, layer)
print(caffe_net.to_proto())
with open(name + '.prototxt', 'wb') as f:
f.write(str(caffe_net.to_proto()))
caffe_net = caffe.Net(name + '.prototxt', caffe.TEST)
convert_pytorch_to_caffe(self, caffe_net)
caffe_net.save(name + '.caffemodel')
示例15: header_code
# 需要導入模塊: import caffe [as 別名]
# 或者: from caffe import NetSpec [as 別名]
def header_code(self):
return """from __future__ import print_function
import numpy as np
import sys, argparse
import caffe
from caffe import layers as L
from caffe import params as P
from caffe import to_proto
from six import text_type as _text_type
__weights_dict = dict()
def load_weights(weight_file):
if weight_file == None:
return
try:
weights_dict = np.load(weight_file, allow_pickle=True).item()
except:
weights_dict = np.load(weight_file, allow_pickle=True, encoding='bytes').item()
return weights_dict
def KitModel(weight_file = None):
n = caffe.NetSpec()
"""