Copyright NOTICE: This article for Bo Master hjimce original article, the original address is http://blog.csdn.net/hjimce/article/details/51899683.
I. Course of study
Personal feeling for any deep learning library, such as Mxnet, TensorFlow, Theano, Caffe, and so on, basically I use the same learning process, the general process is as follows:
(1) Training stage : Data Packaging-"network construction, training-" model preservation-"visual view of loss function, verification accuracy
(2) test phase : Model load-"test picture read-" forecast display results
(3) Transplant phase : quantification, Compression acceleration-"fine-tuning-" C + + porting package-"on-line
This way, I'll take tensorflow as an example, to explain the overall structure of the process, to complete a deep learning project needs to be familiar with the process code.
second, training, testing phase
1, tensorflow packaging data
This step for TensorFlow, you can also directly read online:. jpg pictures, tag files, etc., and then through the Phaceholder variable, the data into the network, to calculate.
But this is less efficient, and for large-scale training data we need a more efficient way, and TensorFlow recommends that we use Tfrecoder for efficient data reading. Learn TensorFlow must learn to Tfrecoder file write, read, the specific sample code is as follows:
[Python] View Plain copy #coding =utf-8 #tensorflow高效数据读取训练 import tensorflow& nbsp;as tf import cv2 #把train. txt file format, each line: Picture path name Category Tags #奖数据打包, converted to tfrecords format for subsequent efficient reads def encode_to_tfrecords (Lable_file,data_root, New_name= ' Data.tfrecords ', Resize=none): writer=tf.python_io. Tfrecordwriter (data_root+ '/' +new_name) num_example=0 with open (Lable_file, ' R ') as f: for l in f.readlines (): l=l.split () image=cv2.imread (data_root+ "/" +l[0]) if resize is not none: image=cv2.resize (image,resize) #为了 height,width,nchannel=image.shape label=int (l[1]) example= Tf.train.Example (Features=tf.train.features (feature={ ' height ': tf.train.Feature (Int64_list=tf.train.int64list ( Value=[height]), ' width ': tf.train.Feature (Int64_list=tf.train.int64list (value=[width)), ' Nchannel ': Tf.train.Feature (Int64_list=tf.train.int64list ( Value=[nchannel]), ' image ': Tf.train.Feature (Bytes_list=tf.train.byteslist (Value=[image.tobytes ())), ' label ': Tf.train.Feature (Int64_list=tf.train.int64list (Value=[label)) })) serialized=example. Serializetostring () Writer.write (serialized) num_example+=1 print lable_file, "Sample Data Volume:", Num_example writer.close () #读取tfrecords文件 def decode_from_ Tfrecords (filename,num_epoch=none): filename_queue=tf.train.string_input_ Producer ([Filename],num_epochs=num_epoch) #因为有的训练数据过于庞大, is divided into a number of files, so the first parameter is the file list name parameter   READER=TF. Tfrecordreader () _,serialized=reader.read (filename_queue) example=tf.parse_single_example (serialized,features={ ' height ': tf. Fixedlenfeature ([],tf.int64), ' width ': tf. Fixedlenfeature ([],tf.int64), ' Nchannel '