no viable conversion from 'script::Module' to 'std::shared_ptrtorch::jit::script::Module' std::shared_ptrtorch::jit::script::Module module = torch::jit::load(argv[1]);

yuchao86: <p>int main(int argc, const char* argv[]) {<br>
if (argc != 2) {<br>
std::cerr &lt;&lt; “usage: example-app \n”;<br>
return -1;<br>
}</p>
<p>cv::VideoCapture stream(0);<br>
cv::namedWindow(“Gesture Detect”, cv::WINDOW_AUTOSIZE);</p>
<p>std::shared_ptrtorch::jit::script::Module module = torch::jit::load(argv[1]);</p>
<p>module-&gt;to(at::kCUDA);<br>
…</p>
<p>it error fellow :</p>
<p>/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/yuchao/CLionProjects/untitled/cmake-build-debug --target untitled – -j 2<br>
Scanning dependencies of target untitled<br>
[ 50%] Building CXX object CMakeFiles/untitled.dir/main.cpp.o<br>
/Users/yuchao/CLionProjects/untitled/main.cpp:53:49: error: no viable conversion from ‘script::Module’ to ‘std::shared_ptrtorch::jit::script::Module’<br>
std::shared_ptrtorch::jit::script::Module module = torch::jit::load(argv[1]);<br>
^ ~~~~~~~~~~~~~~~~~~~~~~~~~<br>
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3753:23: note: candidate constructor not viable: no known conversion from ‘script::Module’ to ‘std::nullptr_t’ (aka ‘nullptr_t’) for 1st argument<br>
_LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;<br>
^<br>
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3767:5: note: candidate constructor not viable: no known conversion from ‘script::Module’ to ‘const std::__1::shared_ptrtorch::jit::script::Module &amp;’ for 1st argument<br>
shared_ptr(const shared_ptr&amp; __r) _NOEXCEPT;<br>
^<br>
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3775:5: note: candidate constructor not viable: no known conversion from ‘script::Module’ to ‘std::__1::shared_ptrtorch::jit::script::Module &amp;&amp;’ for 1st argument<br>
shared_ptr(shared_ptr&amp;&amp; __r) _NOEXCEPT;<br>
^<br>
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3770:9: note: candidate template ignored: could not match ‘shared_ptr’ against ‘torch::jit::script::Module’<br>
shared_ptr(const shared_ptr&lt;_Yp&gt;&amp; __r,<br>
^<br>
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3776:52: note: candidate template ignored: could not match ‘shared_ptr’ against ‘torch::jit::script::Module’<br>
template _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr&lt;_Yp&gt;&amp;&amp; __r,<br>
^<br>
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3785:9: note: candidate template ignored: could not match ‘auto_ptr’ against ‘torch::jit::script::Module’<br>
shared_ptr(auto_ptr&lt;_Yp&gt;&amp;&amp; __r,<br>
^<br>
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3795:9: note: candidate template ignored: could not match ‘unique_ptr&lt;type-parameter-0-0, type-parameter-0-1&gt;’ against ‘torch::jit::script::Module’<br>
shared_ptr(unique_ptr&lt;_Yp, _Dp&gt;&amp;&amp;,<br>
^<br>
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3804:9: note: candidate template ignored: could not match ‘unique_ptr&lt;type-parameter-0-0, type-parameter-0-1&gt;’ against ‘torch::jit::script::Module’<br>
shared_ptr(unique_ptr&lt;_Yp, _Dp&gt;&amp;&amp;,<br>
^<br>
1 error generated.<br>
make[3]: *** [CMakeFiles/untitled.dir/main.cpp.o] Error 1<br>
make[2]: *** [CMakeFiles/untitled.dir/all] Error 2<br>
make[1]: *** [CMakeFiles/untitled.dir/rule] Error 2<br>
make: *** [untitled] Error 2</p>

albanD: <p>Why don’t you use <code>auto module = torch::jit::load(argv[1])</code> ?</p>

wanchaol: <p>IIRC torch::jit::load now returns a Module rather than a shared_ptr in C++ frontend, starting from PyTorch 1.2 release,<br>
<code>script::Module</code>  is now a reference type, please see the release notes here <a href="https://github.com/pytorch/pytorch/releases" rel="nofollow noopener">https://github.com/pytorch/pytorch/releases</a></p>