caffe2_cpp_tutorial icon indicating copy to clipboard operation
caffe2_cpp_tutorial copied to clipboard

Cannot runnetonce on GPU tensored network

Open ColeKOP opened this issue 7 years ago • 2 comments

Hi, I used python script to save the model into .pb file where the tensors and model were in CUDA. But when I try to run the model using pretrained.cc after instruction workspace.runNetOnce, the program aborted. But the .pb model where the model and tensor in CPU can work as expected. May I have any insight on this issue? Thank you.

ColeKOP avatar Sep 12 '18 14:09 ColeKOP

Here is my code

           DeviceOption option;
	option.set_device_type(CUDA);
	new CUDAContext(option);

	// Load Squeezenet model
	NetDef init_net, predict_net;

	init_net.mutable_device_option()->set_device_type(CUDA);
	predict_net.mutable_device_option()->set_device_type(CUDA);
	// >>> with open(path_to_INIT_NET) as f:
	CAFFE_ENFORCE(ReadProtoFromFile(FLAGS_init_net, &init_net));

	// >>> with open(path_to_PREDICT_NET) as f:
	CAFFE_ENFORCE(ReadProtoFromFile(FLAGS_predict_net, &predict_net));

	// >>> p = workspace.Predictor(init_net, predict_net)
	Workspace workspace("tmp");
	CAFFE_ENFORCE(workspace.RunNetOnce(init_net));
	auto input = workspace.CreateBlob("data")->GetMutable<TensorCUDA>();

	input->ResizeLike(tensor);
	input->CopyFrom(tensor);
	CAFFE_ENFORCE(workspace.RunNetOnce(predict_net));


	

	// >>> results = p.run([img])
	auto &output_name = predict_net.external_output(0);
	auto output = workspace.GetBlob(output_name)->Get<TensorCUDA>();

The program will fail after CAFFE_ENFORCE(workspace.RunNetOnce(predict_net)); with Unhandled exception at 0x00007FFB894AA388 in caffe2CPP.exe: Microsoft C++ exception: caffe2::EnforceNotMet at memory location 0x000000F73F30DF50.

Can you help me with the problem. Thank you.

ColeKOP avatar Sep 13 '18 04:09 ColeKOP

i met same you

qingyang-jiandao avatar Jan 03 '19 03:01 qingyang-jiandao