add initialization key for verifying state
authorRoss Girshick <rbg@eecs.berkeley.edu>
Mon, 13 Jan 2014 21:34:34 +0000 (13:34 -0800)
committerEvan Shelhamer <shelhamer@imaginarynumber.net>
Thu, 20 Mar 2014 02:12:57 +0000 (19:12 -0700)
matlab/caffe/matcaffe.cpp

index 99ef3f4..524393a 100644 (file)
@@ -16,6 +16,7 @@ using namespace caffe;  // NOLINT(build/namespaces)
 
 // The pointer to the internal caffe::Net instance
 static shared_ptr<Net<float> > net_;
+static int init_key = -2;
 
 // Five things to be aware of:
 //   caffe uses row-major order
@@ -199,6 +200,10 @@ static void set_device(MEX_ARGS) {
   Caffe::SetDevice(device_id);
 }
 
+static void get_init_key(MEX_ARGS) {
+  plhs[0] = mxCreateDoubleScalar(init_key);
+}
+
 static void init(MEX_ARGS) {
   if (nrhs != 2) {
     LOG(ERROR) << "Only given " << nrhs << " arguments";
@@ -213,6 +218,11 @@ static void init(MEX_ARGS) {
 
   mxFree(param_file);
   mxFree(model_file);
+
+  init_key = rand();
+  if (nlhs == 1) {
+    plhs[0] = mxCreateDoubleScalar(init_key);
+  }
 }
 
 static void forward(MEX_ARGS) {
@@ -251,6 +261,7 @@ static handler_registry handlers[] = {
   { "set_phase_test",     set_phase_test  },
   { "set_device",         set_device      },
   { "get_weights",        get_weights     },
+  { "get_init_key",       get_init_key    },
   // The end.
   { "END",                NULL            },
 };