Skip to content

Instantly share code, notes, and snippets.

@Simon-Hohberg
Simon-Hohberg / Create binary proto file with mean for Caffe
Last active April 15, 2019 08:08
Create a binary proto file that contains a blob with the mean.
import sys
caffe_root = '/path/to/caffe/'
sys.path.insert(0, caffe_root + 'python')
import caffe.proto.caffe_pb2 as caffe_proto
def create_mean_file(filename, mean):
"""
Create a binaryproto file with a single blob containing the given pixel-wise mean.
Overwrites any existing file with the same name.
@Simon-Hohberg
Simon-Hohberg / Create HDF5 file for Caffe
Created June 24, 2015 14:27
How to create a HDF5 file with data and labels to be used by Berkeley's Caffe framework.
import h5py
import numpy as np
def create_hdf5_for_caffe(hdf5_filename, txt_filename, data, labels, name=None, descr=None, shuffle=False):
"""
Creates a HDF5 file containing given data and labels as HDF5 datasets with names 'data' and 'label'.
:param hdf5_filename: Filename of HDF5 file that is going to be created.
:type hdf5_filename: str
:param txt_filename: Filename of text file to write the HDF5 filename to.