Beispiel #1
0
  static void net_get_loss_diff(MEX_ARGS) {

   mxCHECK(nrhs == 2 && mxIsStruct(prhs[0]),"Usage: caffe_('net_get_loss_diff', hNet, layer_index)");
   Net<float>* net = handle_to_ptr<Net<float> >(prhs[0]);

   int layer_idx = *((int*)mxGetData(prhs[1]));

   shared_ptr<EuclideanLossLayer<float> > loss = boost::dynamic_pointer_cast< EuclideanLossLayer<float> >(net->layers()[layer_idx-1]); 
   if (!loss) {
     const vector< string >  net_layer_names = net->layer_names();
     mexPrintf("layer_name: %s\n",(net_layer_names[layer_idx]).c_str());
     mxERROR("net_get_jacobian may only be called if the layer is a EuclideanLossLayer");
   }else{
     mexPrintf("Found loss layer...\n");  
   }


   Blob<float> tmp_loss_diff(loss->Get_diff_shape(0), loss->Get_diff_shape(1), loss->Get_diff_shape(2), loss->Get_diff_shape(3));
   Blob<float>* actual_diff= (Blob<float>*)loss->Get_internal_diff();
   (&tmp_loss_diff)->CopyFrom(*actual_diff);
   plhs[0] = blob_to_mx_mat(&tmp_loss_diff, DATA);
 }
Beispiel #2
0
// Usage: caffe_('net_get_attr', hNet)
static void net_get_attr(MEX_ARGS) {
	mxCHECK(nrhs == 1 && mxIsStruct(prhs[0]),
		"Usage: caffe_('net_get_attr', hNet)");
	Net<float>* net = handle_to_ptr<Net<float> >(prhs[0]);
	const int net_attr_num = 6;
	const char* net_attrs[net_attr_num] = { "hLayer_layers", "hBlob_blobs",
		"input_blob_indices", "output_blob_indices", "layer_names", "blob_names" };
	mxArray* mx_net_attr = mxCreateStructMatrix(1, 1, net_attr_num,
		net_attrs);
	mxSetField(mx_net_attr, 0, "hLayer_layers",
		ptr_vec_to_handle_vec<Layer<float> >(net->layers()));
	mxSetField(mx_net_attr, 0, "hBlob_blobs",
		ptr_vec_to_handle_vec<Blob<float> >(net->blobs()));
	mxSetField(mx_net_attr, 0, "input_blob_indices",
		int_vec_to_mx_vec(net->input_blob_indices()));
	mxSetField(mx_net_attr, 0, "output_blob_indices",
		int_vec_to_mx_vec(net->output_blob_indices()));
	mxSetField(mx_net_attr, 0, "layer_names",
		str_vec_to_mx_strcell(net->layer_names()));
	mxSetField(mx_net_attr, 0, "blob_names",
		str_vec_to_mx_strcell(net->blob_names()));
	plhs[0] = mx_net_attr;
}
Beispiel #3
0
EXPORT const char *caffe_net_layer_name(void *netAnon, int i)
{ 
	Net<float> *net = (Net<float> *)netAnon;
	return net->layer_names()[i].c_str();
}