leovandriel / caffe2_cpp_tutorial

C++ transcripts of the Caffe2 Python tutorials and other C++ example code
BSD 2-Clause "Simplified" License
431 stars 94 forks source link

Cannot runnetonce on GPU tensored network #80

Open ColeKOP opened 6 years ago

ColeKOP commented 6 years ago

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 commented 6 years ago

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.

qingyang-jiandao commented 5 years ago

i met same you