[mlpack-git] master: utility for converting legacy GMM XML files to new format (e335d48)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 21:56:01 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

>---------------------------------------------------------------

commit e335d48853e1ab4446ba31a9f63a90ca997ef500
Author: michaelfox99 <michaelfox99 at gmail.com>
Date:   Tue Aug 5 12:57:20 2014 +0000

    utility for converting legacy GMM XML files to new format


>---------------------------------------------------------------

e335d48853e1ab4446ba31a9f63a90ca997ef500
 src/mlpack/methods/gmm/gmm_convert_main.cpp | 63 +++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/src/mlpack/methods/gmm/gmm_convert_main.cpp b/src/mlpack/methods/gmm/gmm_convert_main.cpp
new file mode 100644
index 0000000..e7fb0f9
--- /dev/null
+++ b/src/mlpack/methods/gmm/gmm_convert_main.cpp
@@ -0,0 +1,63 @@
+/**
+ * @author Michael Fox
+ * @file gmm_convert_main.cpp
+ *
+ * This program converts an older GMM XML file to the new format.
+ */
+#include <mlpack/core.hpp>
+#include "gmm.hpp"
+
+
+using namespace mlpack;
+using namespace mlpack::gmm;
+using namespace mlpack::util;
+using namespace std;
+
+PROGRAM_INFO("Gaussian Mixture Model (GMM) file converter",
+    "This program takes a fitted GMM XML file from older MLPACK versions and "
+		"converts it to the current format.");
+
+PARAM_STRING_REQ("input_file", "File containing the fitted model ", "i");
+PARAM_STRING("output_file", "The file to write the model to (as XML).", "o",
+    "gmm.xml");
+
+int main(int argc, char* argv[])
+{
+  CLI::ParseCommandLine(argc, argv);
+	string inputFile = CLI::GetParam<string>("input_file");
+  //data::Load(CLI::GetParam<string>("input_file"), inputFile, true);
+	util::SaveRestoreUtility load;
+
+  if (!load.ReadFile(inputFile))
+    Log::Fatal << " Could not read file '" << inputFile << "'!\n";
+	
+	size_t gaussians, dimensionality;
+	load.LoadParameter(gaussians, "gaussians");
+  load.LoadParameter(dimensionality, "dimensionality");
+	GMM<> gmm(gaussians, dimensionality);
+
+  load.LoadParameter(gmm.Weights(), "weights");
+
+  // We need to do a little error checking here.
+  if (gmm.Weights().n_elem != gmm.Gaussians())
+  {
+    Log::Fatal << "GMM::Load('" << inputFile << "'): file reports "
+				<< gmm.Gaussians() << " gaussians but weights vector only contains "
+				<< gmm.Weights().n_elem << " elements!" << std::endl;
+  }
+
+  
+  for (size_t i = 0; i < gaussians; ++i)
+  {
+    std::stringstream o;
+    o << i;
+    std::string meanName = "mean" + o.str();
+    std::string covName = "covariance" + o.str();
+
+    load.LoadParameter(gmm.Component(i).Mean(), meanName);
+    load.LoadParameter(gmm.Component(i).Covariance(), covName);
+  }
+	
+	gmm.Save(CLI::GetParam<string>("output_file"));
+	
+}



More information about the mlpack-git mailing list