當前位置: 首頁>>代碼示例>>Python>>正文


Python caffe_pb2.SolverParameter方法代碼示例

本文整理匯總了Python中caffe.proto.caffe_pb2.SolverParameter方法的典型用法代碼示例。如果您正苦於以下問題:Python caffe_pb2.SolverParameter方法的具體用法?Python caffe_pb2.SolverParameter怎麽用?Python caffe_pb2.SolverParameter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在caffe.proto.caffe_pb2的用法示例。


在下文中一共展示了caffe_pb2.SolverParameter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import SolverParameter [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) 
開發者ID:luhaofang,項目名稱:tripletloss,代碼行數:18,代碼來源:train.py

示例2: __init__

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import SolverParameter [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) 
開發者ID:ppengtang,項目名稱:dpl,代碼行數:19,代碼來源:train.py

示例3: make_solver

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import SolverParameter [as 別名]
def make_solver(options):
    solver = caffe_pb2.SolverParameter()

    solver.train_net = options.train_net
    if options.test_net is not None:
        solver.test_net.append(options.test_net)
        solver.test_iter.append(50)
    solver.test_interval = 100
    solver.base_lr = options.lr
    solver.lr_policy = "step"
    solver.gamma = 0.1
    solver.stepsize = 100000
    solver.display = 5
    solver.max_iter = 400000
    solver.momentum = options.momentum
    solver.weight_decay = 0.0005
    solver.regularization_type = 'L2'
    solver.snapshot = 2000
    solver.solver_mode = solver.GPU
    solver.iter_size = options.iter_size
    solver.snapshot_format = solver.BINARYPROTO
    solver.type = 'SGD'
    solver.snapshot_prefix = options.snapshot_prefix

    return solver 
開發者ID:fyu,項目名稱:dilation,代碼行數:27,代碼來源:train.py

示例4: Get_caffe_solver_instance

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import SolverParameter [as 別名]
def Get_caffe_solver_instance(cls, solver_parameter_dict, net):
        """Get a caffe solver object."""
        # now we actually create a instance of the solver
        solver_message = _caffe_pb2.SolverParameter(**solver_parameter_dict)
        messagestr = _gprototext.MessageToString(solver_message)
        with _NamedTemporaryFile(mode='w+b', suffix='.prototxt') as tmpfile:
            tmpfile.write(bytes(messagestr.encode('utf-8')))
            tmpfile.flush()
            try:
                # Newer version of caffe with full solver init support.
                return cls.Get_caffe_solver_class(
                    solver_parameter_dict['solver_type'])._caffe_solver_class(
                        tmpfile.name, net, _caffe._caffe.NetVec(), True)
            except TypeError:
                # Fallback for older, patched versions.
                return cls.Get_caffe_solver_class(
                    solver_parameter_dict['solver_type'])._caffe_solver_class(
                        tmpfile.name, net)
        raise Exception('could not initialize solver class') 
開發者ID:classner,項目名稱:barrista,代碼行數:21,代碼來源:solver.py

示例5: __init__

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import SolverParameter [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) 
開發者ID:tanshen,項目名稱:SubCNN,代碼行數:25,代碼來源:train.py

示例6: __init__

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import SolverParameter [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) 
開發者ID:kyu-sz,項目名稱:WPAL-network,代碼行數:26,代碼來源:train.py

示例7: __init__

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import SolverParameter [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) 
開發者ID:hizhangp,項目名稱:triplet,代碼行數:19,代碼來源:train.py

示例8: generate_solver_proto

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import SolverParameter [as 別名]
def generate_solver_proto(**kwargs):
    sp = caffe_pb2.SolverParameter()
    for k,v in kwargs.iteritems():
        if not hasattr(sp, k):
            raise ValueError('The argument \'%s\' is not part of the Caffe solver parameters!')
        elif v is not None:
            elem = getattr(sp, k)
            if type(elem) == RepeatedScalarFieldContainer:
                elem.append(v)
            elif k == 'solver_mode':
                setattr(sp, k, sp.SolverMode.DESCRIPTOR.values_by_name[v].number)
            else:
                setattr(sp, k, v)
    return sp 
開發者ID:ssudholt,項目名稱:phocnet,代碼行數:16,代碼來源:solver_proto_generator.py

示例9: add_default_parameters

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import SolverParameter [as 別名]
def add_default_parameters(self, solver_param, val_net=True):
        if not solver_param.train_net:
            train_val_fname = self.get_model_fname('train_val')
            solver_param.train_net = train_val_fname
        if val_net:
            if not solver_param.test_net:
                train_val_fname = self.get_model_fname('train_val')
                solver_param.test_net.append(train_val_fname)
            if not solver_param.test_iter:
                solver_param.test_iter.append(10)
        else:
            del solver_param.test_net[:]
            del solver_param.test_iter[:]
        if not solver_param.solver_type:   solver_param.solver_type = pb2.SolverParameter.SGD
        if not solver_param.test_interval: solver_param.test_interval = 1000
        if not solver_param.base_lr:       solver_param.base_lr = 0.05
        if not solver_param.lr_policy:     solver_param.lr_policy = "step"
        if not solver_param.gamma:         solver_param.gamma = 0.9
        if not solver_param.stepsize:      solver_param.stepsize = 1000
        if not solver_param.display:       solver_param.display = 20
        if not solver_param.max_iter:      solver_param.max_iter = 10000
        if not solver_param.momentum:      solver_param.momentum = 0.9
        if not solver_param.momentum2:      solver_param.momentum2 = 0.999
        if not solver_param.weight_decay:  solver_param.weight_decay = 0.0005
        if not solver_param.snapshot:      solver_param.snapshot = 1000
        if not solver_param.snapshot_prefix:
            snapshot_prefix = self.get_snapshot_prefix()
            solver_param.snapshot_prefix = snapshot_prefix
        # don't change solver_param.solver_mode 
開發者ID:alexlee-gk,項目名稱:visual_dynamics,代碼行數:31,代碼來源:predictor_caffe.py

示例10: __init__

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import SolverParameter [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) 
開發者ID:playerkk,項目名稱:face-py-faster-rcnn,代碼行數:30,代碼來源:train.py

示例11: get_snapshot_prefix

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import SolverParameter [as 別名]
def get_snapshot_prefix(solver_path):
    solver_param = caffe_pb2.SolverParameter()

    with open(solver_path, 'rt') as f:
        text_format.Merge(f.read(), solver_param)

    return solver_param.snapshot_prefix 
開發者ID:po0ya,項目名稱:face-magnet,代碼行數:9,代碼來源:config.py

示例12: __init__

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import SolverParameter [as 別名]
def __init__(self, solver_prototxt, roidb, output_dir,
                 pretrained_model=None):
        """Initialize the SolverWrapper."""
        self.output_dir = output_dir

        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:
            text_format.Merge(f.read(), self.solver_param)

        self.solver.net.layers[0].set_roidb(roidb) 
開發者ID:ppengtang,項目名稱:oicr,代碼行數:17,代碼來源:train.py

示例13: train_solver

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import SolverParameter [as 別名]
def train_solver(conf):
    s = caffe_pb2.SolverParameter()

    # Set a seed for reproducible experiments:
    # this controls for randomization in training.
    #s.random_seed = 0xCAFFE

    # Specify locations of the train and (maybe) test networks.
    s.train_net = conf.train_net_file
    s.test_net.append(conf.test_net_file)
    s.test_interval = 10000  # Test after every 500 training iterations.
    s.test_iter.append(1)  # Test on 100 batches each time we test.
    s.max_iter = conf.max_iter  # no. of times to update the net (training iterations)
    # s.max_iter = 50000  # no. of times to update the net (training iterations)
    s.type = "AdaGrad"
    s.gamma = 0.1
    s.base_lr = 0.01
    s.weight_decay = 5e-4
    s.lr_policy = 'multistep'
    s.display = 10000
    s.snapshot = 10000
    s.snapshot_prefix = conf.snapshot_prefix
    #s.stepvalue.append(1000000)
    #s.stepvalue.append(300000)
    s.solver_mode = caffe_pb2.SolverParameter.GPU
    s.device_id = 1 # will use the second GPU card
    s.snapshot_format = 0 # 0 is HDF5, 1 is binary
    return s 
開發者ID:MeiShaohui,項目名稱:Sensor-Specific-Hyperspectral-Image-Feature-Learning,代碼行數:30,代碼來源:proto_file.py

示例14: train

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import SolverParameter [as 別名]
def train(self, train_hdf5_fname, val_hdf5_fname=None, solverstate_fname=None, solver_param=None, batch_size=32, visualize_response_maps=False):
        hdf5_txt_fnames = []
        for hdf5_fname in [train_hdf5_fname, val_hdf5_fname]:
            if hdf5_fname is not None:
                head, tail = os.path.split(hdf5_fname)
                root, _ = os.path.splitext(tail)
                hdf5_txt_fname = os.path.join(head, '.' + root + '.txt')
                if not os.path.isfile(hdf5_txt_fname):
                    with open(hdf5_txt_fname, 'w') as f:
                        f.write(hdf5_fname + '\n')
                hdf5_txt_fnames.append(hdf5_txt_fname)
            else:
                hdf5_txt_fnames.append(None)
        train_hdf5_txt_fname, val_hdf5_txt_fname = hdf5_txt_fnames

        input_shapes = (self.x_shape, self.u_shape)
        train_net_param, weight_fillers = self.net_func(input_shapes, train_hdf5_txt_fname, batch_size, self.net_name, phase=caffe.TRAIN)
        if val_hdf5_fname is not None:
            val_net_param, _ = self.net_func(input_shapes, val_hdf5_txt_fname, batch_size, self.net_name, phase=caffe.TEST)

        self.train_val_net_param = train_net_param
        if val_hdf5_fname is not None:
            layers = [layer for layer in self.train_val_net_param.layer]
            # remove layers except for data layers
            for layer in layers:
                if 'Data' not in layer.type:
                    self.train_val_net_param.layer.remove(layer)
            # add data layers from validation net_caffe
            self.train_val_net_param.layer.extend([layer for layer in val_net_param.layer if 'Data' in layer.type])
            # add back the layers that are not data layers
            self.train_val_net_param.layer.extend([layer for layer in layers if 'Data' not in layer.type])
        self.train_val_net_param = net_caffe.train_val_net(self.train_val_net_param)
        train_val_fname = self.get_model_fname('train_val')
        with open(train_val_fname, 'w') as f:
            f.write(str(self.train_val_net_param))

        if solver_param is None:
            solver_param = pb2.SolverParameter()
        self.add_default_parameters(solver_param, val_net=val_hdf5_fname is not None)

        solver_fname = self.get_model_fname('solver')
        with open(solver_fname, 'w') as f:
            f.write(str(solver_param))

        solver = caffe.get_solver(solver_fname)
        self.set_weight_fillers(solver.net.params, weight_fillers)
        for param_name, param in self.params.items():
            for blob, solver_blob in zip(param, solver.net.params[param_name]):
                solver_blob.data[...] = blob.data
        if solverstate_fname is not None:
            if not solverstate_fname.endswith('.solverstate'):
                solverstate_fname = self.get_snapshot_prefix() + '_iter_' + solverstate_fname + '.solverstate'
            solver.restore(solverstate_fname)
        self.solve(solver, solver_param, visualize_response_maps=visualize_response_maps)
        for param_name, param in self.params.items():
            for blob, solver_blob in zip(param, solver.net.params[param_name]):
                blob.data[...] = solver_blob.data

        self.train_net = solver.net
        if val_hdf5_fname is not None:
            self.val_net = solver.test_nets[0] 
開發者ID:alexlee-gk,項目名稱:visual_dynamics,代碼行數:63,代碼來源:predictor_caffe.py

示例15: generate

# 需要導入模塊: from caffe.proto import caffe_pb2 [as 別名]
# 或者: from caffe.proto.caffe_pb2 import SolverParameter [as 別名]
def generate(self, net):
        if net == None:
            raise Exception("Net not provided!")

        self.setScenario(net.scenarios_dir, net.scenario)
        self.stage=net.stage
        self.net_type=net.network_type

        s = caffe_pb2.SolverParameter()

        # Specify locations of the train and (maybe) test networks.
        s.train_net = net.path()

        s.lr_policy=self.lr_policy

        # The number of iterations over which to average the gradient.
        # Effectively boosts the training batch size by the given factor, without
        # affecting memory utilization.
        s.iter_size = 1

        # Solve using the stochastic gradient descent (SGD) algorithm.
        # Other choices include 'Adam' and 'RMSProp'.
        s.type = self.solver_type

        # Set the initial learning rate for SGD.
        s.base_lr = self.base_lr

        # Set `lr_policy` to define how the learning rate changes during training.
        # Here, we 'step' the learning rate by multiplying it by a factor `gamma`
        # every `stepsize` iterations.
        s.gamma = self.gamma
        s.stepsize = self.step_size

        # Set other SGD hyperparameters. Setting a non-zero `momentum` takes a
        # weighted average of the current gradient and previous gradients to make
        # learning more stable. L2 weight decay regularizes learning, to help prevent
        # the model from overfitting.
        s.momentum = self.momentum
        s.weight_decay = self.weight_decay

        # Display the current training loss and accuracy every 1000 iterations.
        s.display = self.display

        # Snapshots are files used to store networks we've trained.  Here, we'll
        # snapshot every 10K iterations -- ten times during training.
        s.snapshot = 0

        # Train on the GPU.  Using the CPU to train large networks is very slow.
        s.solver_mode = caffe_pb2.SolverParameter.GPU

        s.snapshot_prefix=self.snapshot_prefix
        return self.save(s) 
開發者ID:djdam,項目名稱:faster-rcnn-scenarios,代碼行數:54,代碼來源:solver.py


注:本文中的caffe.proto.caffe_pb2.SolverParameter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。