extension-script icon indicating copy to clipboard operation
extension-script copied to clipboard

Instructions do not work

Open SethHWeidman opened this issue 6 years ago • 3 comments

Hello,

The instructions worked for me right up until make -j. When I run that, I get:

Scanning dependencies of target warp_perspective
[ 25%] Building CXX object warp_perspective/CMakeFiles/warp_perspective.dir/op.cpp.o
/home/example_app/warp_perspective/op.cpp:23:78: warning: 'torch::jit::RegisterOperators::RegisterOperators(const string&, Implementation&&) [with Implementation = at::Tensor (*)(at::Tensor, at::Tensor); std::string = std::basic_string<char>]' is deprecated [-Wdeprecated-declarations]
   torch::jit::RegisterOperators("my_ops::warp_perspective", &warp_perspective);
                                                                              ^
In file included from /libtorch/include/torch/script.h:5:0,
                 from /home/example_app/warp_perspective/op.cpp:2:
/libtorch/include/torch/csrc/jit/custom_operator.h:28:3: note: declared here
   RegisterOperators(const std::string& name, Implementation&& implementation) {
   ^
[ 50%] Linking CXX shared library libwarp_perspective.so
[ 50%] Built target warp_perspective
Scanning dependencies of target example_app
[ 75%] Building CXX object CMakeFiles/example_app.dir/main.cpp.o
/home/example_app/main.cpp: In function 'int main(int, const char**)':
/home/example_app/main.cpp:14:74: error: conversion from 'torch::jit::script::Module' to non-scalar type 'std::shared_ptr<torch::jit::script::Module>' requested
 std::shared_ptr<torch::jit::script::Module> module = torch::jit::load(argv[1]);
                                                                      ^
CMakeFiles/example_app.dir/build.make:62: recipe for target 'CMakeFiles/example_app.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/example_app.dir/main.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/example_app.dir/all' failed
make[1]: *** [CMakeFiles/example_app.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

@goldsborough, is there a chance you could take a look? I'm working on revising the PyTorch tutorials for the 1.3 release, and this is currently how we recommend students run the Extending TorchScript with Custom C++ Operators tutorial. Please let me know if there's any way I can help!

SethHWeidman avatar Aug 28 '19 19:08 SethHWeidman

Update: based on feedback from @suo, I tried changing this line to:

torch::jit::script::Module module = torch::jit::load(argv[1]);

That seemed to fix one error, but now this line:

torch::Tensor output = module->forward(std::move(inputs)).toTensor();

seems to be causing an issue. Here's the full output of make -j:

(base) root@5eaf291a71b3:/home/example_app/build# make -j
Scanning dependencies of target warp_perspective
[ 25%] Building CXX object warp_perspective/CMakeFiles/warp_perspective.dir/op.cpp.o
/home/example_app/warp_perspective/op.cpp:23:78: warning: 'torch::jit::RegisterOperators::RegisterOperators(const string&, Implementation&&) [with Implementation = at::Tensor (*)(at::Tensor, at::Tensor); std::string = std::basic_string<char>]' is deprecated [-Wdeprecated-declarations]
   torch::jit::RegisterOperators("my_ops::warp_perspective", &warp_perspective);
                                                                              ^
In file included from /libtorch/include/torch/script.h:5:0,
                 from /home/example_app/warp_perspective/op.cpp:2:
/libtorch/include/torch/csrc/jit/custom_operator.h:28:3: note: declared here
   RegisterOperators(const std::string& name, Implementation&& implementation) {
   ^
[ 50%] Linking CXX shared library libwarp_perspective.so
[ 50%] Built target warp_perspective
Scanning dependencies of target example_app
[ 75%] Building CXX object CMakeFiles/example_app.dir/main.cpp.o
/home/example_app/main.cpp: In function 'int main(int, const char**)':
/home/example_app/main.cpp:20:34: error: base operand of '->' has non-pointer type 'torch::jit::script::Module'
     torch::Tensor output = module->forward(std::move(inputs)).toTensor();
                                  ^
CMakeFiles/example_app.dir/build.make:62: recipe for target 'CMakeFiles/example_app.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/example_app.dir/main.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/example_app.dir/all' failed
make[1]: *** [CMakeFiles/example_app.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

@suo, could you take a look? Thanks! cc @goldsborough

SethHWeidman avatar Sep 01 '19 17:09 SethHWeidman

Change -> to . torch::Tensor output = module.forward(std::move(inputs)).toTensor();

qizhen816 avatar Oct 31 '19 09:10 qizhen816

Change -> to . torch::Tensor output = module.forward(std::move(inputs)).toTensor();

Thanks, it solved my problem. But I was wondering why "->" did,t work. Can you explain??

abhiyanthrik avatar Nov 10 '22 14:11 abhiyanthrik