Caffe Python Interface Learning (2) generating a Solver file

Source: Internet
Author: User

Caffe in training, need some parameter setting, we usually set these parameters in a file called Solver.prototxt

There are some parameters that need to be computed and not randomly set.

Assuming we have 50,000 training samples, Batch_size is 64, which is 64 samples per batch, we need to iterate 50000/64=782 times to process all the samples. We have finished processing all the samples, called Generations, epoch. So, the test_interval here is set to 782, which means that once all the training data has been processed, the test is done. If we want to train 100 generations, we need to set Max_iter to 78200.

Similarly, if you have 10,000 test samples, Batch_size is set to 32, then you need to iterate 10000/32=313 times to complete the test once, so set Test_iter to 313.

The change of learning rate we set it down slowly as the number of iterations increases. A total of 78,200 iterations, we will change lr_rate three times, so Stepsize set to 78200/3=26067, that is, 26,067 times per iteration, we will reduce the learning rate.

Here is the Python code that generates the Solver file, which is simple:

#-*-Coding:utf-8-*-"""Created on Sun Jul 18:20:57 2016@author:root"""Path=‘/home/xxx/data/‘solver_file=path+‘Solver.prototxt‘#solver文件保存位置sp={}sp[‘Train_net']= ' "' +path+‘Train.prototxt "‘# Training configuration file sp[‘Test_net']= ' "' +path+‘Val.prototxt "‘# Test configuration file sp[‘Test_iter']=‘313‘# Number of test iterations sp[‘Test_interval']=‘782‘# test Interval sp[‘Base_lr']=‘0.001‘# Basic Learning Rate sp[‘Display']=‘782‘# screen Log display interval sp[‘Max_iter']=‘78200‘# The maximum number of iterations sp[‘Lr_policy']=‘“Step‘# Study Rate Change Law sp[‘Gamma']=‘0.1‘# Learning Rate Change Index sp[‘Momentum']=‘0.9‘# momentum Sp[‘Weight_decay']=‘0.0005‘# Weight Decay sp[‘Stepsize']=‘26067‘# Learning Rate Change Frequency sp[‘Snapshot']=‘7820‘# Save model Interval sp[‘Snapshot_prefix']= '"Snapshot"’# Saved model prefix sp[‘Solver_mode']=‘Gpu‘# whether to use gpusp[‘Solver_type']=‘SGD‘# optimization algorithmDefWrite_solver ():#写入文件 with open (Solver_file,‘W‘) as F:for key, value in sorted ( Sp.items ()): if not (type (value) is str): raise TypeError ( Span style= "COLOR: #800000" > ' all solver parameters must be Strings ) f.write ( ' %s:% S\n '% (key, value)) if Span style= "COLOR: #800080" >__name__ = =  ' __main__ ' : Write_solver ()       

Execute the above file, we will get a solver.prototxt file, with this file, we will be able to train the next step.

Caffe Python Interface Learning (2) generating a Solver file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.