breadbread1984 / Caffe2-C-demo

Show how to use Caffe2 in C++ through a simple LeNet sample project
60 stars 26 forks source link

使用GPU前向 #4

Closed beichen2012 closed 6 years ago

beichen2012 commented 6 years ago

preprocess函数是空的,没有写明是怎么转换成TensorCUDA的。 我做了如下尝试: 0,把predict net的device option 设置成:CUDA; 1,predict net添加一个Operator(CopyCPUToCUDA),他的输入是一个tensorCPU, 输出就是tensorCUDA了,当然了,这个输出,就是网络的输入 "data"。这个Op的device option是CUDA。 2, 把cv::Mat转换成TensorCPU,输入到网络中去

但是报错: Cannot create operator of type conv on the device CUDA.

breadbread1984 commented 6 years ago

你需要学习下c++再来开发Caffe2。空的preprocess函数是基类的纯虚函数。你需要做的事继承Caffe2Net类,然后至少实现哪几个纯虚函数。你也可以考虑继承这个模板基类,会更方便。手动创建pb在caffe2中虽然是可行的,但是是十分容易出错而且费尽的。推荐你看下我的另一个项目 https://github.com/breadbread1984/caffe2_cpp_tutorial 。这套c++接口在pytorch上也可以用。

beichen2012 commented 6 years ago

嗯, sorry, .只看了"Caffe2Net.cpp",没看头文件,纯虚函数也弄了个函数体。 init_net使用CUDA报了一个GivenTensorFill没有实现的错误。

breadbread1984 commented 6 years ago

用我给你的那个库创建网络吧。如果不知道怎么用那个库创建网络可以看下 https://github.com/breadbread1984/2DFAN4 。如果有需要的还没有在caffe2_cpp_tutorial里面实现的操作符可以告诉我,我可以实现好更新上去。

breadbread1984 commented 6 years ago

我可以帮你解答我的代码的问题