1 // Copyright Yangqing Jia 2013
3 #ifndef CAFFE_UTIL_IO_H_
4 #define CAFFE_UTIL_IO_H_
6 #include <google/protobuf/message.h>
8 #include <string>
10 #include "caffe/blob.hpp"
11 #include "caffe/proto/caffe.pb.h"
13 using std::string;
15 namespace caffe {
17 void ReadImageToProto(const string& filename, BlobProto* proto);
19 template <typename Dtype>
20 inline void ReadImageToBlob(const string& filename, Blob<Dtype>* blob) {
21 BlobProto proto;
22 ReadImageToProto(filename, &proto);
23 blob->FromProto(proto);
24 }
26 void WriteProtoToImage(const string& filename, const BlobProto& proto);
28 template <typename Dtype>
29 inline void WriteBlobToImage(const string& filename, const Blob<Dtype>& blob) {
30 BlobProto proto;
31 blob.ToProto(&proto);
32 WriteProtoToImage(filename, proto);
33 }
35 void ReadProtoFromTextFile(const char* filename,
36 ::google::protobuf::Message* proto);
37 inline void ReadProtoFromTextFile(const string& filename,
38 ::google::protobuf::Message* proto) {
39 ReadProtoFromTextFile(filename.c_str(), proto);
40 }
42 } // namespace caffe
44 #endif // CAFFE_UTIL_IO_H_