Skip to content

Commit 9c7a993

Browse files
rbgirshickshelhamer
authored andcommitted
add initialization key for verifying state
1 parent ba10066 commit 9c7a993

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

matlab/caffe/matcaffe.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ using namespace caffe; // NOLINT(build/namespaces)
1616

1717
// The pointer to the internal caffe::Net instance
1818
static shared_ptr<Net<float> > net_;
19+
static int init_key = -2;
1920

2021
// Five things to be aware of:
2122
// caffe uses row-major order
@@ -199,6 +200,10 @@ static void set_device(MEX_ARGS) {
199200
Caffe::SetDevice(device_id);
200201
}
201202

203+
static void get_init_key(MEX_ARGS) {
204+
plhs[0] = mxCreateDoubleScalar(init_key);
205+
}
206+
202207
static void init(MEX_ARGS) {
203208
if (nrhs != 2) {
204209
LOG(ERROR) << "Only given " << nrhs << " arguments";
@@ -213,6 +218,11 @@ static void init(MEX_ARGS) {
213218

214219
mxFree(param_file);
215220
mxFree(model_file);
221+
222+
init_key = rand();
223+
if (nlhs == 1) {
224+
plhs[0] = mxCreateDoubleScalar(init_key);
225+
}
216226
}
217227

218228
static void forward(MEX_ARGS) {
@@ -251,6 +261,7 @@ static handler_registry handlers[] = {
251261
{ "set_phase_test", set_phase_test },
252262
{ "set_device", set_device },
253263
{ "get_weights", get_weights },
264+
{ "get_init_key", get_init_key },
254265
// The end.
255266
{ "END", NULL },
256267
};

0 commit comments

Comments
 (0)