using std::string;
using ::google::protobuf::Message;
+#define HDF5_NUM_DIMS 4
+
namespace caffe {
void ReadProtoFromTextFile(const char* filename,
hid_t file_id, const char* dataset_name_, int min_dim, int max_dim,
Blob<Dtype>* blob);
+template <typename Dtype>
+void hdf5_save_nd_dataset(
+ const hid_t file_id, const string dataset_name, const Blob<Dtype>& blob);
+
} // namespace caffe
#endif // CAFFE_UTIL_IO_H_
file_id, dataset_name_, blob->mutable_cpu_data());
}
+template <>
+void hdf5_save_nd_dataset<float>(
+ const hid_t file_id, const string dataset_name, const Blob<float>& blob) {
+ hsize_t dims[HDF5_NUM_DIMS];
+ dims[0] = blob.num();
+ dims[1] = blob.channels();
+ dims[2] = blob.height();
+ dims[3] = blob.width();
+ herr_t status = H5LTmake_dataset_float(
+ file_id, dataset_name.c_str(), HDF5_NUM_DIMS, dims, blob.cpu_data());
+ CHECK_GE(status, 0) << "Failed to make float dataset " << dataset_name;
+}
+
+template <>
+void hdf5_save_nd_dataset<double>(
+ const hid_t file_id, const string dataset_name, const Blob<double>& blob) {
+ hsize_t dims[HDF5_NUM_DIMS];
+ dims[0] = blob.num();
+ dims[1] = blob.channels();
+ dims[2] = blob.height();
+ dims[3] = blob.width();
+ herr_t status = H5LTmake_dataset_double(
+ file_id, dataset_name.c_str(), HDF5_NUM_DIMS, dims, blob.cpu_data());
+ CHECK_GE(status, 0) << "Failed to make double dataset " << dataset_name;
+}
+
} // namespace caffe