title: Image Mean Subtraction in Custom Caffe Dataset?
body: <p>I am currently in the process of creating a dataset of images to train, validate, and test a basic custom ConvNet using Caffe. </p>
  
  <p>Specifically, I have collected my JPG images (RGB), and am now deciding how to preprocess the images for my network. I am looking to apply basic normalization to the images, such as subtracting the image mean to 'center' the images.</p>
  
  <p>The ImageNet tutorial <a href="http://caffe.berkeleyvision.org/gathered/examples/imagenet.html" rel="nofollow noreferrer">http://caffe.berkeleyvision.org/gathered/examples/imagenet.html</a> mentions this operation, describing how to generate a mean <code>.binaryproto</code> file for the dataset by passing the LMDB to the <code>compute_image_mean</code> executable in <code>$CAFFE_HOME/build/tools</code>.</p>
  
  <p>I have done this, and now have a <code>.binaryproto</code> file for my training LMDB. To my understanding, this file essentially contains a representation of the mean pixel values of all images in the passed LMDB. Therefore, I suppose that it is storing some form of array containing pixel values for the three channels.</p>
  
  <hr>
  
  <p><strong>Questions:</strong></p>
  
  <p>How do I use this <code>.binaryproto</code> file to perform the mean subtraction?</p>
  
  <p>Should I be creating separate <code>.binaryproto</code> files for each of my LMDBs (train, validate, test)? Or should I create one LMDB containing all images in the dataset first, generate the mean from that, and apply the subtraction to all subsets?</p>
  
  <p>Any advice would be greatly appreciated.</p>