12 #ifndef MLPACK_CORE_DATA_LOAD_MODEL_IMPL_HPP 13 #define MLPACK_CORE_DATA_LOAD_MODEL_IMPL_HPP 20 #include <cereal/archives/xml.hpp> 21 #include <cereal/archives/binary.hpp> 22 #include <cereal/archives/json.hpp> 29 bool Load(
const std::string& filename,
30 const std::string& name,
35 if (f == format::autodetect)
37 std::string extension = Extension(filename);
39 if (extension ==
"xml")
41 else if (extension ==
"bin")
43 else if (extension ==
"json")
48 Log::Fatal <<
"Unable to detect type of '" << filename <<
"'; incorrect" 49 <<
" extension?" << std::endl;
51 Log::Warn <<
"Unable to detect type of '" << filename <<
"'; load " 52 <<
"failed. Incorrect extension?" << std::endl;
60 #ifdef _WIN32 // Open non-text in binary mode on Windows. 61 if (f == format::binary)
62 ifs.open(filename, std::ifstream::in | std::ifstream::binary);
64 ifs.open(filename, std::ifstream::in);
66 ifs.open(filename, std::ifstream::in);
72 Log::Fatal <<
"Unable to open file '" << filename <<
"' to load object '" 73 << name <<
"'." << std::endl;
75 Log::Warn <<
"Unable to open file '" << filename <<
"' to load object '" 76 << name <<
"'." << std::endl;
84 cereal::XMLInputArchive ar(ifs);
85 ar(cereal::make_nvp(name.c_str(), t));
87 else if (f == format::json)
89 cereal::JSONInputArchive ar(ifs);
90 ar(cereal::make_nvp(name.c_str(), t));
92 else if (f == format::binary)
94 cereal::BinaryInputArchive ar(ifs);
95 ar(cereal::make_nvp(name.c_str(), t));
100 catch (cereal::Exception& e)
static MLPACK_EXPORT util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
Definition: log.hpp:90
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
static MLPACK_EXPORT util::PrefixedOutStream Warn
Prints warning messages prefixed with [WARN ].
Definition: log.hpp:87
bool Load(const std::string &filename, arma::Mat< eT > &matrix, const bool fatal=false, const bool transpose=true, const arma::file_type inputLoadType=arma::auto_detect)
Loads a matrix from file, guessing the filetype from the extension.
Definition: load_impl.hpp:89
format
Define the formats we can read through cereal.
Definition: format.hpp:20