本文整理汇总了Python中caffe.SGDSolver方法的典型用法代码示例。如果您正苦于以下问题:Python caffe.SGDSolver方法的具体用法?Python caffe.SGDSolver怎么用?Python caffe.SGDSolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类caffe
的用法示例。
在下文中一共展示了caffe.SGDSolver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import SGDSolver [as 别名]
def __init__(self, solver_prototxt, output_dir,
pretrained_model=None):
"""Initialize the SolverWrapper."""
self.output_dir = output_dir
caffe.set_mode_gpu()
caffe.set_device(0)
self.solver = caffe.SGDSolver(solver_prototxt)
if pretrained_model is not None:
print ('Loading pretrained model '
'weights from {:s}').format(pretrained_model)
self.solver.net.copy_from(pretrained_model)
self.solver_param = caffe_pb2.SolverParameter()
with open(solver_prototxt, 'rt') as f:
pb2.text_format.Merge(f.read(), self.solver_param)
示例2: __init__
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import SGDSolver [as 别名]
def __init__(self, solver_prototxt, roidb, output_dir,
pretrained_model=None):
"""Initialize the SolverWrapper."""
self.output_dir = output_dir
print 'done'
self.solver = caffe.SGDSolver(solver_prototxt)
if pretrained_model is not None:
print ('Loading pretrained model '
'weights from {:s}').format(pretrained_model)
self.solver.net.copy_from(pretrained_model)
self.solver_param = caffe_pb2.SolverParameter()
with open(solver_prototxt, 'rt') as f:
pb2.text_format.Merge(f.read(), self.solver_param)
self.solver.net.layers[0].set_roidb(roidb)
示例3: load_nets
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import SGDSolver [as 别名]
def load_nets(args, cur_gpu):
# initialize solver and feature net,
# RNN should be initialized before CNN, because CNN cudnn conv layers
# may assume using all available memory
caffe.set_mode_gpu()
caffe.set_device(cur_gpu)
solver = caffe.SGDSolver(args.solver)
if args.snapshot:
print "Restoring history from {}".format(args.snapshot)
solver.restore(args.snapshot)
rnn = solver.net
if args.weights:
rnn.copy_from(args.weights)
feature_net = caffe.Net(args.feature_net, args.feature_param, caffe.TEST)
# apply bbox regression normalization on the net weights
with open(args.bbox_mean, 'rb') as f:
bbox_means = cPickle.load(f)
with open(args.bbox_std, 'rb') as f:
bbox_stds = cPickle.load(f)
feature_net.params['bbox_pred_vid'][0].data[...] = \
feature_net.params['bbox_pred_vid'][0].data * bbox_stds[:, np.newaxis]
feature_net.params['bbox_pred_vid'][1].data[...] = \
feature_net.params['bbox_pred_vid'][1].data * bbox_stds + bbox_means
return solver, feature_net, rnn, bbox_means, bbox_stds
示例4: load_nets
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import SGDSolver [as 别名]
def load_nets(args, cur_gpu):
# initialize solver and feature net,
# RNN should be initialized before CNN, because CNN cudnn conv layers
# may assume using all available memory
caffe.set_mode_gpu()
caffe.set_device(cur_gpu)
solver = caffe.SGDSolver(args.solver)
if args.snapshot:
print "Restoring history from {}".format(args.snapshot)
solver.restore(args.snapshot)
net = solver.net
if args.weights:
print "Copying weights from {}".format(args.weights)
net.copy_from(args.weights)
return solver, net
示例5: solve
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import SGDSolver [as 别名]
def solve(proto, snapshot, gpus, timing, uid, rank):
caffe.set_mode_gpu()
caffe.set_device(gpus[rank])
caffe.set_solver_count(len(gpus))
caffe.set_solver_rank(rank)
caffe.set_multiprocess(True)
solver = caffe.SGDSolver(proto)
if snapshot and len(snapshot) != 0:
solver.restore(snapshot)
nccl = caffe.NCCL(solver, uid)
nccl.bcast()
if timing and rank == 0:
time(solver, nccl)
else:
solver.add_callback(nccl)
if solver.param.layer_wise_reduce:
solver.net.after_backward(nccl)
solver.step(solver.param.max_iter)
示例6: setUp
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import SGDSolver [as 别名]
def setUp(self):
self.num_output = 13
net_f = simple_net_file(self.num_output)
f = tempfile.NamedTemporaryFile(delete=False)
f.write("""net: '""" + net_f + """'
test_iter: 10 test_interval: 10 base_lr: 0.01 momentum: 0.9
weight_decay: 0.0005 lr_policy: 'inv' gamma: 0.0001 power: 0.75
display: 100 max_iter: 100 snapshot_after_train: false""")
f.close()
self.solver = caffe.SGDSolver(f.name)
# also make sure get_solver runs
caffe.get_solver(f.name)
caffe.set_mode_cpu()
# fill in valid labels
self.solver.net.blobs['label'].data[...] = \
np.random.randint(self.num_output,
size=self.solver.net.blobs['label'].data.shape)
self.solver.test_nets[0].blobs['label'].data[...] = \
np.random.randint(self.num_output,
size=self.solver.test_nets[0].blobs['label'].data.shape)
os.remove(f.name)
os.remove(net_f)
示例7: __init__
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import SGDSolver [as 别名]
def __init__(self, solver_prototxt, roidb, output_dir, pretrained_model=None):
"""Initialize the SolverWrapper."""
self.output_dir = output_dir
print 'Computing bounding-box regression targets...'
if cfg.TRAIN.BBOX_REG:
if cfg.IS_RPN:
self.bbox_means, self.bbox_stds = gdl_roidb.add_bbox_regression_targets(roidb)
else:
self.bbox_means, self.bbox_stds = rdl_roidb.add_bbox_regression_targets(roidb)
print 'done'
self.solver = caffe.SGDSolver(solver_prototxt)
if pretrained_model is not None:
print ('Loading pretrained model '
'weights from {:s}').format(pretrained_model)
self.solver.net.copy_from(pretrained_model)
self.solver_param = caffe_pb2.SolverParameter()
with open(solver_prototxt, 'rt') as f:
pb2.text_format.Merge(f.read(), self.solver_param)
self.solver.net.layers[0].set_roidb(roidb)
示例8: setUp
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import SGDSolver [as 别名]
def setUp(self):
self.num_output = 13
net_f = simple_net_file(self.num_output)
f = tempfile.NamedTemporaryFile(mode='w+', delete=False)
f.write("""net: '""" + net_f + """'
test_iter: 10 test_interval: 10 base_lr: 0.01 momentum: 0.9
weight_decay: 0.0005 lr_policy: 'inv' gamma: 0.0001 power: 0.75
display: 100 max_iter: 100 snapshot_after_train: false
snapshot_prefix: "model" """)
f.close()
self.solver = caffe.SGDSolver(f.name)
# also make sure get_solver runs
caffe.get_solver(f.name)
caffe.set_mode_cpu()
# fill in valid labels
self.solver.net.blobs['label'].data[...] = \
np.random.randint(self.num_output,
size=self.solver.net.blobs['label'].data.shape)
self.solver.test_nets[0].blobs['label'].data[...] = \
np.random.randint(self.num_output,
size=self.solver.test_nets[0].blobs['label'].data.shape)
os.remove(f.name)
os.remove(net_f)
示例9: __init__
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import SGDSolver [as 别名]
def __init__(self, solver_prototxt, db, output_dir, do_flip,
snapshot_path=None):
"""Initialize the SolverWrapper."""
self._output_dir = output_dir
self._solver = caffe.SGDSolver(solver_prototxt)
self._solver_param = caffe_pb2.SolverParameter()
with open(solver_prototxt, 'rt') as f:
pb2.text_format.Merge(f.read(), self._solver_param)
infix = ('_' + cfg.TRAIN.SNAPSHOT_INFIX
if cfg.TRAIN.SNAPSHOT_INFIX != '' else '')
self._snapshot_prefix = self._solver_param.snapshot_prefix + infix + '_iter_'
if snapshot_path is not None:
print ('Loading snapshot weights from {:s}').format(snapshot_path)
self._solver.net.copy_from(snapshot_path)
snapshot_path = snapshot_path.split('/')[-1]
if snapshot_path.startswith(self._snapshot_prefix):
print 'Warning! Existing snapshots may be overriden by new snapshots!'
self._db = db
self._solver.net.layers[0].set_db(self._db, do_flip)
示例10: solve
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import SGDSolver [as 别名]
def solve(proto, gpus, uid, rank, max_iter):
caffe.set_mode_gpu()
caffe.set_device(gpus[rank])
caffe.set_solver_count(len(gpus))
caffe.set_solver_rank(rank)
caffe.set_multiprocess(True)
solver = caffe.SGDSolver(proto)
if rank == 0:
# solver.restore(_snapshot)
solver.net.copy_from(_weights)
solver.net.layers[0].get_gpu_id(gpus[rank])
nccl = caffe.NCCL(solver, uid)
nccl.bcast()
solver.add_callback(nccl)
if solver.param.layer_wise_reduce:
solver.net.after_backward(nccl)
for _ in range(max_iter):
solver.step(1)
示例11: __init__
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import SGDSolver [as 别名]
def __init__(self, solver, output_dir, pretrained_model=None, gpu_id=0, data=None):
"""Initialize the SolverWrapper."""
self.output_dir = output_dir
caffe.set_mode_gpu()
caffe.set_device(gpu_id)
self.solver = caffe.SGDSolver(solver)
if pretrained_model is not None:
print(('Loading pretrained model '
'weights from {:s}').format(pretrained_model))
self.solver.net.copy_from(pretrained_model)
self.solver_param = caffe_pb2.SolverParameter()
with open(solver, 'rt') as f:
pb2.text_format.Merge(f.read(), self.solver_param)
self.solver.net.layers[0].set_data(data)
示例12: __get_solver
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import SGDSolver [as 别名]
def __get_solver(self, solver_proto_path):
'''
Returns a caffe.SGDSolver for the given protofile path,
ignoring Caffe command line chatter if debug mode is not set
to True.
'''
if not self.debug_mode:
# disable Caffe init chatter when not in debug
with Suppressor():
return caffe.SGDSolver(solver_proto_path)
else:
return caffe.SGDSolver(solver_proto_path)
示例13: init_trainer
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import SGDSolver [as 别名]
def init_trainer(self, model, X =None, y = None):
f = tempfile.NamedTemporaryFile(delete=False)
f.write(model)
f.close()
self.X=X
self.y =y
self.params = pb2.SolverParameter()
self.params.net = f.name
set(self.params.test_iter, 10)
self.params.test_interval = 10
self.params.base_lr = 0.01
self.params.momentum = 0.9
self.params.weight_decay = 0.0005
self.params.lr_policy = 'inv'
self.params.gamma = 0.0001
self.params.power = 0.75
self.params.display = 10
self.params.max_iter = 100
self.params.snapshot_after_train = False
f2 = tempfile.NamedTemporaryFile(delete=False)
f2.write(self.params.__str__())
f2.close()
self.solver = caffe.SGDSolver(f2.name)
f2.delete = True
if (X is not None) and (y is not None):
self.create_batches()
# self.solver.set_train_data = types.MethodType(set_train_data, self.solver)
# self.solver.set_test_data = types.MethodType(set_test_data, self.solver)
return self.solver
示例14: __init__
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import SGDSolver [as 别名]
def __init__(self, solver_prototxt, roidb, output_dir,
pretrained_model=None):
"""Initialize the SolverWrapper."""
self.output_dir = output_dir
if (cfg.TRAIN.HAS_RPN and cfg.TRAIN.BBOX_REG and
cfg.TRAIN.BBOX_NORMALIZE_TARGETS):
# RPN can only use precomputed normalization because there are no
# fixed statistics to compute a priori
assert cfg.TRAIN.BBOX_NORMALIZE_TARGETS_PRECOMPUTED
if cfg.TRAIN.BBOX_REG:
print 'Computing bounding-box regression targets...'
self.bbox_means, self.bbox_stds = \
rdl_roidb.add_bbox_regression_targets(roidb)
print 'done'
self.solver = caffe.SGDSolver(solver_prototxt)
if pretrained_model is not None:
print ('Loading pretrained model '
'weights from {:s}').format(pretrained_model)
self.solver.net.copy_from(pretrained_model)
self.solver_param = caffe_pb2.SolverParameter()
with open(solver_prototxt, 'rt') as f:
pb2.text_format.Merge(f.read(), self.solver_param)
self.solver.net.layers[0].set_roidb(roidb)
示例15: text_save
# 需要导入模块: import caffe [as 别名]
# 或者: from caffe import SGDSolver [as 别名]
def text_save(content,filename,mode='a'):
# Try to save a list variable in txt file.
file = open(filename,mode)
for i in range(len(content)):
file.write(str(content[i])+' ')
file.write('\n')
file.close()
# savefile = 'frame_feat_flow.txt'
# if os.path.isfile(savefile):
# os.remove(savefile)
#
# solver = caffe.SGDSolver(relative_path + '/deeptemporal/models/ucf101/flow_feat_solver.prototxt')
# solver.net.copy_from(relative_path + "/ucf101_split_1_rgb_flow_models/ucf101_split_1_tsn_flow_reference_bn_inception.caffemodel")