Created
January 6, 2015 09:37
-
-
Save ih4cku/becb94f377d5b912c6c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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