Skip to content

Instantly share code, notes, and snippets.

@ih4cku
Created January 6, 2015 09:37
Show Gist options
  • Save ih4cku/becb94f377d5b912c6c7 to your computer and use it in GitHub Desktop.
Save ih4cku/becb94f377d5b912c6c7 to your computer and use it in GitHub Desktop.
#include <iostream>
#include "caffe/util/io.hpp"
#include "caffe/proto/caffe.pb.h"
using namespace std;
int main(int argc, char const *argv[])
{
caffe::BlobProto blob;
const char filename[] = "mean.binaryproto";
bool success = caffe::ReadProtoFromBinaryFile(filename, &blob);
assert(success);
cout << blob.num() << endl;
cout << blob.channels() << endl;
cout << blob.height() << endl;
cout << blob.width() << endl;
return 0;
}
from caffe.proto import caffe_pb2
import numpy as np
import matplotlib.pyplot as plt
def main():
fn = 'mean.binaryproto'
with open(fn, 'rb') as f:
s = f.read()
blob = caffe_pb2.BlobProto()
blob.ParseFromString(s)
shape = (blob.num, blob.channels, blob.height, blob.width)
data = blob.data
arr = np.array(data)
im = arr.astype(np.uint8).reshape(shape)[0]
im = im.transpose((1,2,0))
plt.imshow(im)
plt.show()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment