Python caffe.proto.caffe_pb2 模块,SolverParameter() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用caffe.proto.caffe_pb2.SolverParameter()

项目:tripletloss    作者:luhaofang    | 项目源码 | 文件源码
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)
项目:dpl    作者:ppengtang    | 项目源码 | 文件源码
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)
项目:fast-rcnn-distillation    作者:xiaolonw    | 项目源码 | 文件源码
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...'
        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)
项目:image-classifier    作者:gustavkkk    | 项目源码 | 文件源码
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)
项目:dilation    作者:fyu    | 项目源码 | 文件源码
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
项目:RON    作者:taokong    | 项目源码 | 文件源码
def __init__(self, solver_prototxt, roidb, output_dir,
                 model=None):
        """Initialize the SolverWrapper."""
        self.output_dir = output_dir

        self.solver = caffe.SGDSolver(solver_prototxt)

        if model is not None:
            print ('Loading pretrained model '
                   'weights from {:s}').format(model)
            self.solver.net.copy_from(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)
项目:vqa-mfb    作者:yuzcccc    | 项目源码 | 文件源码
def get_solver(folder):
    s = caffe_pb2.SolverParameter()
    s.train_net = './%s/proto_train.prototxt'%folder
    s.snapshot = 10000
    s.snapshot_prefix = './%s/'%folder
    s.max_iter = int(config.MAX_ITERATIONS)
    s.display = int(config.VALIDATE_INTERVAL)
    s.type = 'Adam'
    s.stepsize = int(config.MAX_ITERATIONS*0.2)
    s.gamma = 0.5
    s.lr_policy = "step"
    s.base_lr = 0.0007
    s.momentum = 0.9
    s.momentum2 = 0.999
    s.weight_decay = 0.000
    s.clip_gradients = 10
    return s
项目:vqa-mfb    作者:yuzcccc    | 项目源码 | 文件源码
def get_solver(folder):
    s = caffe_pb2.SolverParameter()
    s.train_net = './%s/proto_train.prototxt'%folder
    s.snapshot = int(config.VALIDATE_INTERVAL)
    s.snapshot_prefix = './%s/'%folder
    s.max_iter = int(config.MAX_ITERATIONS)
    s.display = int(config.VALIDATE_INTERVAL)
    s.type = 'Adam'
    s.stepsize = int(config.MAX_ITERATIONS*0.4)
    s.gamma = 0.5
    s.lr_policy = "step"
    s.base_lr = 0.0007
    s.momentum = 0.9
    s.momentum2 = 0.999
    s.weight_decay = 0.000
    s.clip_gradients = 10
    return s
项目:vqa-mfb    作者:yuzcccc    | 项目源码 | 文件源码
def get_solver(folder):
    s = caffe_pb2.SolverParameter()
    s.train_net = './%s/proto_train.prototxt'%folder
    s.snapshot = 10000
    s.snapshot_prefix = './%s/'%folder
    s.max_iter = int(config.MAX_ITERATIONS)
    s.display = int(config.VALIDATE_INTERVAL)
    s.type = 'Adam'
    s.stepsize = int(config.MAX_ITERATIONS*0.4)
    s.gamma = 0.25
    s.lr_policy = "step"
    s.base_lr = 0.0007
    s.momentum = 0.9
    s.momentum2 = 0.999
    s.weight_decay = 0.000
    s.clip_gradients = 10
    return s
项目:vqa-mfb    作者:yuzcccc    | 项目源码 | 文件源码
def get_solver(folder):
    s = caffe_pb2.SolverParameter()
    s.train_net = './%s/proto_train.prototxt'%folder
    s.snapshot = int(config.VALIDATE_INTERVAL)
    s.snapshot_prefix = './%s/'%folder
    s.max_iter = int(config.MAX_ITERATIONS)
    s.display = int(config.VALIDATE_INTERVAL)
    s.type = 'Adam'
    s.stepsize = int(config.MAX_ITERATIONS*0.4)
    s.gamma = 0.5
    s.lr_policy = "step"
    s.base_lr = 0.0007
    s.momentum = 0.9
    s.momentum2 = 0.999
    s.weight_decay = 0.000
    s.clip_gradients = 10
    return s
项目:CRAFT    作者:byangderek    | 项目源码 | 文件源码
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...'
        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)
项目:CRAFT    作者:byangderek    | 项目源码 | 文件源码
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...'
        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)
项目:CRAFT    作者:byangderek    | 项目源码 | 文件源码
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...'
        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)
项目:triplet    作者:hizhangp    | 项目源码 | 文件源码
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)
项目:Triplet_Loss_SBIR    作者:TuBui    | 项目源码 | 文件源码
def __init__(self, solver_path = '', debug=False):
    """
    Initialise solver params
    If a file is given, SolverConfig is initialised with params from that file
    """
    self.sp = caffe_pb2.SolverParameter()
    #critical:
    self.sp.base_lr = 0.01
    self.sp.momentum = 0.9

    if solver_path:
      self.read(solver_path)

    if debug:
      self.sp.max_iter = 12
      self.sp.display = 1

    self.sp.type = 'SGD'
项目:SubCNN    作者:tanshen    | 项目源码 | 文件源码
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)
项目:shuffle-tuple    作者:imisra    | 项目源码 | 文件源码
def parse_solver(self):
        solverPath = self.solverPath;
        self.expName = os.path.split(solverPath)[-1].split('_')[0];
        self.expDir = os.path.split(solverPath)[0];
        self.solver_param = caffe_pb2.SolverParameter();
        with open(self.solverPath, 'rt') as f:
            pb2.text_format.Merge(f.read(), self.solver_param)

        allLines = [x.strip() for x in open(solverPath,'r')];

        snapPath = self.solver_param.snapshot_prefix;
        snapExp = os.path.split(snapPath)[-1];
        snapPath = os.path.split(snapPath)[0];
        sg_utils.mkdir(snapPath);
        assert( os.path.isdir(snapPath) ), '%s does not exist'%(snapPath);
        self.snapPath = snapPath;
        assert( self.snapPath == os.path.split(self.solver_param.snapshot_prefix)[0] );
项目:WPAL-network    作者:kyu-sz    | 项目源码 | 文件源码
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)
项目:caffe-model-gallery    作者:Xiangyu-CAS    | 项目源码 | 文件源码
def make_solver():
    s = caffe_pb2.SolverParameter()
    s.random_seed = 0xCAFFE

    s.train_net = 'train_densenet.prototxt'
    s.test_net.append('test_densenet.prototxt')
    s.test_interval = 800
    s.test_iter.append(200)

    s.max_iter = 230000
    s.type = 'Nesterov'
    s.display = 1

    s.base_lr = 0.1
    s.momentum = 0.9
    s.weight_decay = 1e-4

    s.lr_policy='multistep'
    s.gamma = 0.1
    s.stepvalue.append(int(0.5 * s.max_iter))
    s.stepvalue.append(int(0.75 * s.max_iter))
    s.solver_mode = caffe_pb2.SolverParameter.GPU

    solver_path = 'solver.prototxt'
    with open(solver_path, 'w') as f:
        f.write(str(s))
项目:adversarial-frcnn    作者:xiaolonw    | 项目源码 | 文件源码
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)
项目:faster-rcnn-resnet    作者:Eniac-Xie    | 项目源码 | 文件源码
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)
项目:CoupleNet    作者:tshizys    | 项目源码 | 文件源码
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)
项目:py-faster-rcnn-tk1    作者:joeking11829    | 项目源码 | 文件源码
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)
项目:py-faster-rcnn-resnet-imagenet    作者:tianzhi0549    | 项目源码 | 文件源码
def __init__(self, solver_prototxt, roidb, output_dir, 
            nccl_uid, rank, bbox_means=None, bbox_stds=None, 
            pretrained_model=None):
        """Initialize the SolverWrapper."""
        self.output_dir = output_dir
        self.rank = rank
        if cfg.TRAIN.BBOX_REG:
            self.bbox_means, self.bbox_stds = bbox_means, bbox_stds
        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

        self.solver = caffe.SGDSolver(solver_prototxt)

        assert caffe.solver_count() * cfg.TRAIN.IMS_PER_BATCH * self.solver.param.iter_size == \
            cfg.TRAIN.REAL_BATCH_SIZE, "{} vs {}". \
            format(caffe.solver_count() * cfg.TRAIN.IMS_PER_BATCH * self.solver.param.iter_size, cfg.TRAIN.REAL_BATCH_SIZE)

        if pretrained_model is not None:
            print ('Loading pretrained model '
                   'weights from {:s}').format(pretrained_model)
            self.solver.net.copy_from(pretrained_model)

        nccl = caffe.NCCL(self.solver, nccl_uid)
        nccl.bcast()
        self.solver.add_callback(nccl)
        assert self.solver.param.layer_wise_reduce
        if self.solver.param.layer_wise_reduce:
            self.solver.net.after_backward(nccl)
        self.nccl = nccl # hold the reference to nccl

        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)
项目:Sensor-Specific-Hyperspectral-Image-Feature-Learning    作者:MeiShaohui    | 项目源码 | 文件源码
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
项目:material-seg    作者:paulu    | 项目源码 | 文件源码
def build_solver(solver_filename, **kwargs):
    solver = caffe_pb2.SolverParameter()
    for k, v in kwargs.iteritems():
        setattr(solver, v)
    with open(solver_filename, 'w') as f:
        f.write(text_format.MessageToString(solver))
项目:face-py-faster-rcnn    作者:playerkk    | 项目源码 | 文件源码
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)
项目:score-zeroshot    作者:pedro-morgado    | 项目源码 | 文件源码
def generate_solver_proto(solver_fn, model_fn, trainOpts):
        from caffe.proto import caffe_pb2
        solver = caffe_pb2.SolverParameter()
        solver.net = model_fn

        if trainOpts.num_lr_decays > 0:
            solver.lr_policy = 'step'
            solver.gamma = trainOpts.lr_decay_factor
            solver.stepsize = int(trainOpts.iters/(trainOpts.num_lr_decays+1))
        else:
            solver.lr_policy = 'fixed'
        solver.base_lr = trainOpts.init_lr
        solver.max_iter = trainOpts.iters
        solver.display = 20
        solver.momentum = 0.9
        solver.weight_decay = trainOpts.paramReg

        solver.test_state.add()
        solver.test_state.add()
        solver.test_state[0].stage.append('TestRecognition')
        solver.test_state[1].stage.append('TestZeroShot')
        solver.test_iter.extend([20, 20])
        solver.test_interval = 100

        solver.snapshot = 5000
        solver.snapshot_prefix = os.path.splitext(model_fn)[0]

        with open(solver_fn, 'w') as f:
            f.write(str(solver))
项目:deep-fashion    作者:zuowang    | 项目源码 | 文件源码
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)
项目:RPN    作者:hfut721    | 项目源码 | 文件源码
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)
项目:oicr    作者:ppengtang    | 项目源码 | 文件源码
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:
            pb2.text_format.Merge(f.read(), self.solver_param)

        self.solver.net.layers[0].set_roidb(roidb)
项目:Caffe-Python-Tutorial    作者:tostq    | 项目源码 | 文件源码
def solver_file(model_root, model_name):
    s = caffe_pb2.SolverParameter() # ??solver??
    s.train_net = model_root+'train.prototxt' # ??????????
    s.test_net.append(model_root+'test.prototxt') # ????????????????????
    # ?????test_interval????????
    s.test_interval = 500
    # ???????????????????
    s.test_iter.append(100)
    # ????????
    s.max_iter = 10000
    # ?????
    s.base_lr = 0.01
    # ???????
    s.momentum = 0.9
    # ??????????
    s.weight_decay = 5e-4
    # ?????????????fixed?step?exp?inv?multistep
    # fixed: ??base_lr???
    # step: ???????base_lr * gamma ^ (floor(iter / stepsize))???iter??????????
    # exp: ???????base_lr * gamma ^ iter?
    # inv: ???????power????????base_lr * (1 + gamma * iter) ^ (- power)?
    # multistep: ???????stepvalue??????step???step??????????multistep????stepvalue????
    #   stepvalue?????
    #       poly: ?????????????base_lr (1 - iter/max_iter) ^ (power)?
    #       sigmoid: ?????sigmod?????base_lr ( 1/(1 + exp(-gamma * (iter - stepsize))))?
    s.lr_policy = 'inv'
    s.gamma = 0.0001
    s.power = 0.75

    s.display = 100 # ???display?????
    s.snapshot = 5000 # ??????????
    s.snapshot_prefix = model_root+model_name+'shapshot' # ????????????model???
    s.type = 'SGD' # ???????????????????SGD?AdaDelta?AdaGrad?Adam?Nesterov?RMSProp
    s.solver_mode = caffe_pb2.SolverParameter.GPU # ????????GPU?CPU

    solver_file=model_root+'solver.prototxt' # ????solver???

    with open(solver_file, 'w') as f:
        f.write(str(s))
项目:deepwater-nae    作者:h2oai    | 项目源码 | 文件源码
def start(self, rank):
        self.rank = rank

        if len(self.gpus) > 0:
            self.device = self.gpus[rank]
            if debug:
                s = 'solver gpu %d' % self.gpus[self.rank] + \
                    ' pid %d' % os.getpid() + ' size %d' % self.size + \
                    ' rank %d' % self.rank
                print(s, file = sys.stderr)
            caffe.set_mode_gpu()
            caffe.set_device(self.device)
            caffe.set_solver_count(self.size)
            caffe.set_solver_rank(self.rank)
            caffe.set_multiprocess(True)
        else:
            print('solver cpu', file = sys.stderr)
            caffe.set_mode_cpu()

        if self.cmd.graph.endswith('.json'):
            with open(self.cmd.graph, mode = 'r') as f:
                graph = caffe_pb2.SolverParameter()
                text_format.Merge(f.read(), graph)
                self.graph = graph
        else:
            self.graph = self.solver_graph()

        import tempfile
        with tempfile.NamedTemporaryFile(mode = 'w+', delete = False) as f:
            text_format.PrintMessage(self.graph, f)
            tmp = f.name
        self.caffe = caffe.AdamSolver(tmp)

        if self.uid:
            self.nccl = caffe.NCCL(self.caffe, self.uid)
            self.nccl.bcast()
            self.caffe.add_callback(self.nccl)
            if self.caffe.param.layer_wise_reduce:
                self.caffe.net.after_backward(self.nccl)
项目:deepwater-nae    作者:h2oai    | 项目源码 | 文件源码
def solver_graph(self):
        proto = caffe_pb2.SolverParameter()
        proto.type = self.cmd.solver_type
        if self.device is not None:
            proto.solver_mode = caffe_pb2.SolverParameter.SolverMode.Value(
                'GPU')
            proto.device_id = self.device
        else:
            proto.solver_mode = caffe_pb2.SolverParameter.SolverMode.Value(
                'CPU')
        proto.lr_policy = 'fixed'
        proto.base_lr = self.cmd.learning_rate
        proto.momentum = self.cmd.momentum
        proto.max_iter = int(2e9)
        proto.random_seed = self.cmd.random_seed + self.rank
        print('Setting seed ', proto.random_seed, file = sys.stderr)
        proto.display = 1

        batch = int(solver.cmd.input_shape[0] / solver.size)
        if self.cmd.graph:
            dir = os.path.dirname(os.path.realpath(__file__))
            proto.net = dir + '/' + self.cmd.graph + '.prototxt'
        else:
            proto.train_net_param.MergeFrom(self.net_def(caffe.TRAIN))
            proto.test_net_param.add().MergeFrom(self.net_def(caffe.TEST))

        proto.test_iter.append(1)
        proto.test_interval = 999999999  # cannot disable or set to 0
        proto.test_initialization = False
        return proto
项目:TattDL    作者:z-harry-sun    | 项目源码 | 文件源码
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)
项目:deep_share    作者:luyongxi    | 项目源码 | 文件源码
def __init__(self, solver_prototxt=None, path=None, base_lr=0.01, lr_policy="step", 
        gamma=0.1, stepsize=20000, momentum=0.9, weight_decay=0.0005,
        regularization_type="L2", clip_gradients=None):

        assert (path is not None) or (solver_prototxt is not None),\
            'Need to specify either path or solver_prototxt.'

        self._solver = caffe_pb2.SolverParameter()

        if solver_prototxt is not None:
            self._solver_prototxt = solver_prototxt
            with open(solver_prototxt, 'rt') as f:
                pb2.text_format.Merge(f.read(), self._solver)                                   
        elif path is not None:
            self._solver_prototxt = osp.join(path, 'solver.prototxt')
            # update proto object
            self._solver.net = osp.join(path, 'train_val.prototxt')
            self._solver.base_lr = base_lr
            self._solver.lr_policy = lr_policy
            self._solver.gamma = gamma
            self._solver.stepsize = stepsize
            self._solver.momentum = momentum
            self._solver.weight_decay = weight_decay
            self._solver.regularization_type = regularization_type
            # caffe solver snapshotting is disabled
            self._solver.snapshot = 0
            # shut down caffe display
            self._solver.display = 0
            # shut down caffe validation
            self._solver.test_iter.append(0)
            self._solver.test_interval = 1000
            if clip_gradients is not None:
                self._solver.clip_gradients = clip_gradients
项目:faster_rcnn_logo    作者:romyny    | 项目源码 | 文件源码
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)
项目:Faster_RCNN_Training_Toolkit    作者:VerseChow    | 项目源码 | 文件源码
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)
项目:KITTI-detection-OHEM    作者:manutdzou    | 项目源码 | 文件源码
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)
项目:ohem    作者:abhi2610    | 项目源码 | 文件源码
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)
项目:py-faster-rcnn-dockerface    作者:natanielruiz    | 项目源码 | 文件源码
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)
项目:caffe_multi_label_code    作者:runningJ    | 项目源码 | 文件源码
def __init__(self):
        if pa.GPU==True:
            caffe.set_device(pa.device)
            caffe.set_mode_gpu()
        else:
            caffe.set_mode_cpu()
        self.solver=caffe.SGDSolver(pa.solver)
        if pa.pretrain!="":
            self.solver.net.copy_from(pa.pretrain)
        self.solver_param=caffe_pb2.SolverParameter()
        with open(pa.solver,'rt') as f:
            pb2.text_format.Merge(f.read(),self.solver_param)

        #self.output_dir=pa.output_dir
        self.solver.net.layers[0].set_queue()
项目:jenova    作者:dungba88    | 项目源码 | 文件源码
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)
项目:PVANet-FACE    作者:twmht    | 项目源码 | 文件源码
def __init__(self, solver_prototxt, imdb, 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_imdb(imdb)
        self.solver.net.layers[0].set_roidb(roidb)
项目:craftGBD    作者:craftGBD    | 项目源码 | 文件源码
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)
项目:py-R-FCN    作者:YuwenXiong    | 项目源码 | 文件源码
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)
项目:objectattention    作者:cdevin    | 项目源码 | 文件源码
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)
项目:lsi-faster-rcnn    作者:cguindel    | 项目源码 | 文件源码
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)
项目:Face_Liveness_Detection    作者:yunfan0621    | 项目源码 | 文件源码
def make_solver(train_net_path, val_net_path, solver_path, snapshot_path, opt, dataset_size):
    s = caffe_pb2.SolverParameter()

    # specify locations of the train and test networks.
    s.train_net = train_net_path
    s.test_net.append(val_net_path)

    # specify parameters for iterations
    s.test_interval = opt.test_interval # interval for invoking testing
    s.test_iter.append(opt.val_batch_size) # number of batches used for testing

    s.max_iter = int(opt.num_epoch * dataset_size / opt.train_batch_size) 

    # specify parameters for learning policy
    s.base_lr = opt.base_lr
    s.lr_policy = opt.lr_policy
    if s.lr_policy == 'step':
        s.gamma = opt.gamma
        s.stepsize = opt.stepsize

    s.type = "Adam"
    s.momentum = 0.9
    s.weight_decay= 5e-4
    s.iter_size = 1 # no gradient accumulation

    # specify other helper parameters
    s.display = 20
    s.snapshot = 2500
    s.snapshot_prefix = snapshot_path
    s.solver_mode = caffe_pb2.SolverParameter.GPU

    print "Writing prototxt file for solver..."
    with open(solver_path, 'w') as f:
        f.write(str(s))
项目:MNC    作者:daijifeng001    | 项目源码 | 文件源码
def __init__(self, solver_prototxt, roidb, maskdb, output_dir, imdb,
                 pretrained_model=None):
        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:
            if not cfg.CFM_MODE:
                print 'Computing bounding-box regression targets...'
                self.bbox_means, self.bbox_stds = add_bbox_regression_targets(roidb)
                print 'done'
            else:
                # Pre-defined mcg bbox_mean and bbox_std
                # We store them on disk to avoid disk level IO
                # multiple times (mcg boxes are stored on disk)
                mean_cache = './data/cache/mcg_bbox_mean.npy'
                std_cache = './data/cache/mcg_bbox_std.npy'
                roidb_dir = imdb._roidb_path
                if os.path.exists(mean_cache) and os.path.exists(std_cache):
                    self.bbox_means = np.load(mean_cache)
                    self.bbox_stds = np.load(std_cache)
                else:
                    self.bbox_means, self.bbox_stds = compute_mcg_mean_std(roidb_dir, imdb.num_classes)

        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)
        if not cfg.CFM_MODE:
            self.solver.net.layers[0].set_roidb(roidb)
            if cfg.MNC_MODE:
                self.solver.net.layers[0].set_maskdb(maskdb)
        else:
            self.solver.net.layers[0].set_image_info(imdb, self.bbox_means, self.bbox_stds)