程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Mean value calculation and learning of Caffe picture data in Python format

編輯:Python

Catalog

introduction

One 、 Binary format mean calculation

Two 、python Mean value calculation of format

introduction

After subtracting the mean from the picture , And then training and testing , It improves speed and accuracy . therefore , Generally, this operation can be found in various models .

So how does this mean come from , It's actually the average of all the training samples , After the calculation , Save as an average file , In future tests , You can directly use this mean to subtract , There is no need to recalculate the test image .

One 、 Binary format mean calculation

caffe The mean data format used in is binaryproto, The author provides us with a file for calculating the mean value compute_image_mean.cpp, Put it in caffe In the root directory tools In the folder .

The compiled executable is placed in build/tools/ below , We can just call it directly

# sudo build/tools/compute_image_mean examples/mnist/mnist_train_lmdb examples/mnist/mean.binaryproto

With two parameters :

The first parameter :examples/mnist/mnist_train_lmdb, Indicates the data for which the mean value needs to be calculated , The format is lmdb Training data .

The second parameter :examples/mnist/mean.binaryproto, The calculated results are saved in a file .

Two 、python Mean value calculation of format

If we want to use python Interface , Or we need to do feature visualization , Maybe we'll use python Format mean file . First , We use it lmdb Formatted data , Calculate the mean value of binary format , then , To convert python Mean of format .

We can write a python Script to achieve :

#!/usr/bin/env pythonimport numpy as npimport sys,caffeif len(sys.argv)!=3: print "Usage: python convert_mean.py mean.binaryproto mean.npy" sys.exit()blob = caffe.proto.caffe_pb2.BlobProto()bin_mean = open( sys.argv[1] , 'rb' ).read()blob.ParseFromString(bin_mean)arr = np.array( caffe.io.blobproto_to_array(blob) )npy_mean = arr[0]np.save( sys.argv[2] , npy_mean )

  Save this script as convert_mean.py

The invocation format is :

# sudo python convert_mean.py mean.binaryproto mean.npy

Among them  mean.binaryproto Is the binary mean value calculated in the previous steps .

mean.npy That's what we need python Mean of format .

That's all python Format Caffe Picture data mean calculation learning details , More about python Format Caffe For information on mean value calculation, please pay attention to other relevant articles on software development network !



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved