@@ -478,6 +478,29 @@ static void read_mean(MEX_ARGS) {
478
478
mxFree (mean_proto_file);
479
479
}
480
480
481
+ // Usage: caffe_('write_mean', mean_data, mean_proto_file)
482
+ static void write_mean (MEX_ARGS) {
483
+ mxCHECK (nrhs == 2 && mxIsSingle (prhs[0 ]) && mxIsChar (prhs[1 ]),
484
+ " Usage: caffe_('write_mean', mean_data, mean_proto_file)" );
485
+ char * mean_proto_file = mxArrayToString (prhs[1 ]);
486
+ int ndims = mxGetNumberOfDimensions (prhs[0 ]);
487
+ mxCHECK (ndims >= 2 && ndims <= 3 , " mean_data must have at 2 or 3 dimensions" );
488
+ const mwSize *dims = mxGetDimensions (prhs[0 ]);
489
+ int width = dims[0 ];
490
+ int height = dims[1 ];
491
+ int channels;
492
+ if (ndims == 3 )
493
+ channels = dims[2 ];
494
+ else
495
+ channels = 1 ;
496
+ Blob<float > data_mean (1 , channels, height, width);
497
+ mx_mat_to_blob (prhs[0 ], &data_mean, DATA);
498
+ BlobProto blob_proto;
499
+ data_mean.ToProto (&blob_proto, false );
500
+ WriteProtoToBinaryFile (blob_proto, mean_proto_file);
501
+ mxFree (mean_proto_file);
502
+ }
503
+
481
504
/* * -----------------------------------------------------------------
482
505
** Available commands.
483
506
**/
@@ -515,6 +538,7 @@ static handler_registry handlers[] = {
515
538
{ " get_init_key" , get_init_key },
516
539
{ " reset" , reset },
517
540
{ " read_mean" , read_mean },
541
+ { " write_mean" , write_mean },
518
542
// The end.
519
543
{ " END" , NULL },
520
544
};
0 commit comments