1 #ifndef CAFFE_UTIL_IO_H_ 2 #define CAFFE_UTIL_IO_H_ 4 #include <boost/filesystem.hpp> 9 #include "google/protobuf/message.h" 11 #include "caffe/common.hpp" 12 #include "caffe/proto/caffe.pb.h" 13 #include "caffe/util/format.hpp" 15 #ifndef CAFFE_TMP_DIR_RETRIES 16 #define CAFFE_TMP_DIR_RETRIES 100 21 using ::google::protobuf::Message;
22 using ::boost::filesystem::path;
24 inline void MakeTempDir(
string* temp_dirname) {
25 temp_dirname->clear();
27 boost::filesystem::temp_directory_path()/
"caffe_test.%%%%-%%%%";
28 for (
int i = 0; i < CAFFE_TMP_DIR_RETRIES; i++ ) {
29 const path& dir = boost::filesystem::unique_path(model).string();
30 bool done = boost::filesystem::create_directory(dir);
32 *temp_dirname = dir.string();
36 LOG(FATAL) <<
"Failed to create a temporary directory.";
39 inline void MakeTempFilename(
string* temp_filename) {
40 static path temp_files_subpath;
41 static uint64_t next_temp_file = 0;
42 temp_filename->clear();
43 if ( temp_files_subpath.empty() ) {
44 string path_string=
"";
45 MakeTempDir(&path_string);
46 temp_files_subpath = path_string;
49 (temp_files_subpath/caffe::format_int(next_temp_file++, 9)).
string();
52 bool ReadProtoFromTextFile(
const char* filename, Message* proto);
54 inline bool ReadProtoFromTextFile(
const string& filename, Message* proto) {
55 return ReadProtoFromTextFile(filename.c_str(), proto);
58 inline void ReadProtoFromTextFileOrDie(
const char* filename, Message* proto) {
59 CHECK(ReadProtoFromTextFile(filename, proto));
62 inline void ReadProtoFromTextFileOrDie(
const string& filename, Message* proto) {
63 ReadProtoFromTextFileOrDie(filename.c_str(), proto);
66 void WriteProtoToTextFile(
const Message& proto,
const char* filename);
67 inline void WriteProtoToTextFile(
const Message& proto,
const string& filename) {
68 WriteProtoToTextFile(proto, filename.c_str());
71 bool ReadProtoFromBinaryFile(
const char* filename, Message* proto);
73 inline bool ReadProtoFromBinaryFile(
const string& filename, Message* proto) {
74 return ReadProtoFromBinaryFile(filename.c_str(), proto);
77 inline void ReadProtoFromBinaryFileOrDie(
const char* filename, Message* proto) {
78 CHECK(ReadProtoFromBinaryFile(filename, proto));
81 inline void ReadProtoFromBinaryFileOrDie(
const string& filename,
83 ReadProtoFromBinaryFileOrDie(filename.c_str(), proto);
87 void WriteProtoToBinaryFile(
const Message& proto,
const char* filename);
88 inline void WriteProtoToBinaryFile(
89 const Message& proto,
const string& filename) {
90 WriteProtoToBinaryFile(proto, filename.c_str());
93 bool ReadFileToDatum(
const string& filename,
const int label, Datum* datum);
95 inline bool ReadFileToDatum(
const string& filename, Datum* datum) {
96 return ReadFileToDatum(filename, -1, datum);
99 bool ReadImageToDatum(
const string& filename,
const int label,
100 const int height,
const int width,
const bool is_color,
101 const std::string & encoding, Datum* datum);
103 inline bool ReadImageToDatum(
const string& filename,
const int label,
104 const int height,
const int width,
const bool is_color, Datum* datum) {
105 return ReadImageToDatum(filename, label, height, width, is_color,
109 inline bool ReadImageToDatum(
const string& filename,
const int label,
110 const int height,
const int width, Datum* datum) {
111 return ReadImageToDatum(filename, label, height, width,
true, datum);
114 inline bool ReadImageToDatum(
const string& filename,
const int label,
115 const bool is_color, Datum* datum) {
116 return ReadImageToDatum(filename, label, 0, 0, is_color, datum);
119 inline bool ReadImageToDatum(
const string& filename,
const int label,
121 return ReadImageToDatum(filename, label, 0, 0,
true, datum);
124 inline bool ReadImageToDatum(
const string& filename,
const int label,
125 const std::string & encoding, Datum* datum) {
126 return ReadImageToDatum(filename, label, 0, 0,
true, encoding, datum);
129 bool DecodeDatumNative(Datum* datum);
130 bool DecodeDatum(Datum* datum,
bool is_color);
133 cv::Mat ReadImageToCVMat(
const string& filename,
134 const int height,
const int width,
const bool is_color);
136 cv::Mat ReadImageToCVMat(
const string& filename,
137 const int height,
const int width);
139 cv::Mat ReadImageToCVMat(
const string& filename,
140 const bool is_color);
142 cv::Mat ReadImageToCVMat(
const string& filename);
144 cv::Mat DecodeDatumToCVMatNative(
const Datum& datum);
145 cv::Mat DecodeDatumToCVMat(
const Datum& datum,
bool is_color);
147 void CVMatToDatum(
const cv::Mat& cv_img, Datum* datum);
152 #endif // CAFFE_UTIL_IO_H_ A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition: blob.hpp:14