In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use pycaffe to generate solver.prototxt files and train them. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
The following is the main record of how to generate sovler files, solver files are training, need to use the prototxt file, it indicates the train.prototxt and test.prototxt or train_test.prototxt. Solver is the optimization method used to minimize loss.
1. Solver.prototxt parameter description
Still take cifar10_quick_solver.prototxt as an example, the content is as follows:
# reduce the learning rate after 8 epochs (4000 iters) by a factor of 1 million The train/test net protocol buffer definitionnet: "examples/cifar10/cifar10_quick_train_test.prototxt" # test_iter specifies how many forward passes the test should carry out.# In the case of MNIST, we have test batch size 100 and 100 test iterations,# covering the full 10000 testing images.test_iter: 10 million Carry out testing every 500 training iterations.test_interval: 50 million The base learning rate Momentum and the weight decay of the network.base_lr: 0.001momentum: 0.9weight_decay: 0.003 The learning rate policylr_policy: "fixed" # Display every 100 iterationsdisplay: 10 million The maximum number of iterationsmax_iter: 400 million snapshot intermediate resultssnapshot: 4000snapshot_format: HDF5snapshot_prefix: "examples/cifar10/cifar10_quick" # solver mode: CPU or GPUsolver_mode: GPU
These parameters are set on a basis and are described from top to bottom:
Net: specify the configuration file, and the prototxt file specified in the cifar10_quick_solver.prototx file is examples/cifar10/cifar10_quick_train_test.prototxt, which can be specified using train_net and test_net, respectively.
Test_iter: number of test iterations. For example, if there are 10000 test samples and the batch_size is set to 32, then you need to iterate 10000Universe 32mm 313 times to complete the test, so set the test_iter to 313.
Test_interval: every training iteration test_interval carries on a test, for example, 50000 training samples, batch_size is 64, then it takes 50000 ppm 64mm 782 times to process all the training samples, which is recorded as 1 epoch. So the test_interval is set to 782, that is, all the training data are processed at once before going to the test.
Base_lr: basic learning rate, parameters used in learning strategies.
Momentum: momentum.
Weight_decay: weight falloff.
Lr_policy: learning strategies. Optional parameters: fixed, step, exp, inv, multistep.
Lr_prolicy parameter description:
Fixed: keep base_lr unchanged
Step: step: if set to step, you need to set a stepsize and return base_lr * gamma ^ (floor (iter / stepsize)), where iter represents the current number of iterations
Exp: returns the current number of iterations for base_lr * gamma ^ iter,iter
Inv: how to set it to inv, you also need to set a power, which returns base_lr * (1 + gamma * iter) ^ (- power)
Multistep: if set to multistep, you also need to set a stepvalue. This parameter is similar to step. Step changes evenly at equal intervals, while multistep changes according to the step value.
Stepvalue parameter description:
Poly: the learning rate carries on the polynomial error and returns base_lr (1-iter/max_iter) ^ (power)
Sigmoid: the learning rate attenuates sigmod and returns base_lr (1 / (1 + exp (- gamma * (iter-stepsize).
Display: the results are displayed display times per iteration.
Max_iter: the maximum number of iterations. If you want to train 100 epoch, you need to set max_iter to 100*test_intervel=78200.
Snapshot: saves the number of iterations of the temporary model.
Snapshot_format: the save format of the temporary model. There are two options: HDF5 and BINARYPROTO, the default is BINARYPROTO
Snapshot_prefix: the model prefix is the name that is trained to generate model. The number of iter_ iterations without prefix is .caffemodel, and after addition is the number of lenet_iter_ iterations .caffemodel.
Solver_mode: optimization mode. You can use GPU or CPU.
Use python to generate solver.prototxt files
Take the analyzed cifar10_quick_solver.prototxt file as an example, use the python program to generate this file.
1. The code is as follows:
#-*-coding: UTF-8-*-import caffe # Import caffe package def write_sovler (): my_project_root = "/ home/Jack-Cui/caffe-master/my-caffe-project/" # my-caffe-project directory sovler_string = caffe.proto.caffe_pb2.SolverParameter () # sovler storage solver _ file = my_project_root + 'solver.prototxt' # sovler File Save location sovler_string.train_net = my_project_root +' train.prototxt' # train.prototxt location specify sovler_string.test_net.append (my_project_root + 'test.prototxt') # test.prototxt location specify sovler_string.test_iter.append # Test iterations sovler_string.test_interval = 500# one test per training iteration sovler_string.base_lr = 0.001 # basic learning rate sovler_string.momentum = 0.001 # momentum sovler_string.weight_decay = 0.004 # weight decay sovler_string.lr_policy = 'fixed' # Learning Strategy sovler_string.display = 100 # display display result per iteration sovler_string.max_iter = 4000 # maximum number of iterations sovler_string.snapshot = 4000 # number of iterations saved temporary model sovler_string.snapshot_format = 0 # Save format of temporary model 0 represents HDF5,1 for BINARYPROTOsovler_string.snapshot_prefix = 'examples/cifar10/cifar10_quick' # model prefix sovler_string.solver_mode = caffe.proto.caffe_pb2.SolverParameter.GPU # optimization mode with open (solver_file,' w') as f: f.write (str (sovler_string)) if _ _ name__ = ='_ main__': write_sovler ()
two。 Running result:
Third, training model
From the first note, we have learned how to convert jpg images into db (levelbd/lmdb) files used by Caffe, how to calculate the data mean, and how to use python to generate solver.prototxt, train.prototxt, and test.prototxt files. Next, you can take the final step of the training, using the python interface provided by caffe to train the generation model. If you want to get a final training model without visualization, you can use the following code:
Import caffemy_project_root = "/ home/Jack-Cui/caffe-master/my-caffe-project/" # my-caffe-project directory solver_file = my_project_root + 'solver.prototxt' # sovler file save location caffe.set_device (0) # Select GPU-0caffe.set_mode_gpu Solver = caffe.SGDSolver (solver_file) solver.solve ()
Now, the simple steps of how to train to generate a model are over. Next, take a mnist example, integrate what you have learned, train to generate model, and use the generated model for prediction.
On how to use pycaffe to generate solver.prototxt files and training to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.