C++ frontend has no member 'torch::data'

username: yngtodd
cooked: <p>Hey everyone!</p>
<p>I was giving the new rc1 for version 1.0 a shot to checkout the C++ front end. I am using Mac OS and compiled from the master branch.</p>
<p>I was then trying the MNIST CNN example found here: <a href="https://github.com/goldsborough/examples/blob/cpp/cpp/mnist/mnist.cpp" rel="nofollow noopener">https://github.com/goldsborough/examples/blob/cpp/cpp/mnist/mnist.cpp</a></p>
<p>However, I am running into a bit of trouble where <code>torch::data</code> does not seem to be available. Here is build print statements and the error:</p>
<pre><code class="lang-auto">buid cmake -DCMAKE_PREFIX_PATH=$LIBTORCH_PATH ..
-- The C compiler identification is AppleClang 10.0.0.10001044
-- The CXX compiler identification is AppleClang 10.0.0.10001044
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Downloading MNIST dataset
Downloading http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz ...
0% |################################################################| 100%
Unzipped /Users/yngtodd/src/sandbox/pytorch/mnist/buid/data/train-images-idx3-ubyte.gz ...
Downloading http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz ...
0% |################################################################| 100%
Unzipped /Users/yngtodd/src/sandbox/pytorch/mnist/buid/data/train-labels-idx1-ubyte.gz ...
Downloading http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz ...
0% |################################################################| 100%
Unzipped /Users/yngtodd/src/sandbox/pytorch/mnist/buid/data/t10k-images-idx3-ubyte.gz ...
Downloading http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz ...
0% |################################################################| 100%
Unzipped /Users/yngtodd/src/sandbox/pytorch/mnist/buid/data/t10k-labels-idx1-ubyte.gz ...
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/yngtodd/src/sandbox/pytorch/mnist/buid
</code></pre>
<p>And the error:</p>
<pre><code class="lang-auto">buid make
Scanning dependencies of target mnist
[ 50%] Building CXX object CMakeFiles/mnist.dir/mnist.cpp.o
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:61:31: error: no member named 'data' in
      namespace 'torch'
  data_loader.loop([&amp;](torch::data::Example&lt;&gt;&amp; batch) {
                       ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:84:31: error: no member named 'data' in
      namespace 'torch'
  data_loader.loop([&amp;](torch::data::Example&lt;&gt;&amp; batch) {
                       ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:120:30: error: no member named 'data' in
      namespace 'torch'
  auto train_loader = torch::data::data_loader(
                      ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:121:14: error: no member named 'data' in
      namespace 'torch'
      torch::data::datasets::MNIST(options.data_root, /*train=*/true)
      ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:122:23: error: no member named 'data' in
      namespace 'torch'
          .map(torch::data::transforms::Normalize&lt;&gt;(0.1307, 0.3081))
               ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:122:51: error: expected expression
          .map(torch::data::transforms::Normalize&lt;&gt;(0.1307, 0.3081))
                                                  ^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:122:53: warning: expression result unused
      [-Wunused-value]
          .map(torch::data::transforms::Normalize&lt;&gt;(0.1307, 0.3081))
                                                    ^~~~~~
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:123:23: error: no member named 'data' in
      namespace 'torch'
          .map(torch::data::transforms::Stack&lt;&gt;()),
               ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:123:47: error: expected expression
          .map(torch::data::transforms::Stack&lt;&gt;()),
                                              ^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:123:49: error: expected expression
          .map(torch::data::transforms::Stack&lt;&gt;()),
                                                ^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:124:14: error: no member named 'data' in
      namespace 'torch'
      torch::data::DataLoaderOptions().batch_size(options.batch_size));
      ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:126:29: error: no member named 'data' in
      namespace 'torch'
  auto test_loader = torch::data::data_loader(
                     ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:127:14: error: no member named 'data' in
      namespace 'torch'
      torch::data::datasets::MNIST(options.data_root, /*train=*/false)
      ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:128:23: error: no member named 'data' in
      namespace 'torch'
          .map(torch::data::transforms::Normalize&lt;&gt;(0.1307, 0.3081))
               ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:128:51: error: expected expression
          .map(torch::data::transforms::Normalize&lt;&gt;(0.1307, 0.3081))
                                                  ^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:128:53: warning: expression result unused
      [-Wunused-value]
          .map(torch::data::transforms::Normalize&lt;&gt;(0.1307, 0.3081))
                                                    ^~~~~~
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:129:23: error: no member named 'data' in
      namespace 'torch'
          .map(torch::data::transforms::Stack&lt;&gt;()),
               ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:129:47: error: expected expression
          .map(torch::data::transforms::Stack&lt;&gt;()),
                                              ^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:129:49: error: expected expression
          .map(torch::data::transforms::Stack&lt;&gt;()),
                                                ^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:130:14: error: no member named 'data' in
      namespace 'torch'
      torch::data::DataLoaderOptions().batch_size(options.batch_size));
      ~~~~~~~^
2 warnings and 18 errors generated.
make[2]: *** [CMakeFiles/mnist.dir/mnist.cpp.o] Error 1
make[1]: *** [CMakeFiles/mnist.dir/all] Error 2
make: *** [all] Error 2
</code></pre>
<p>Has anyone had success getting a model up and running with the C++ interface?</p>
<p>Thanks!</p>

username: dasayan05
cooked: <p>Thanks for posting. I am getting the same error when I tried PyTorch 1.0.</p>
<p>Although not sure but it looks like <a href="https://github.com/pytorch/pytorch/pull/11918" rel="nofollow noopener">this PR</a> implements the C++ frontend of data loader and it hasn’t been merged yet.</p>

username: yngtodd
cooked: <p>Oh, good catch. Guess I got a little too eager for the C++ interface.</p>

username: yngtodd
cooked: <p>To everyone in the Facebook team, thank you so much for starting up the C++ frontend. I can’t wait to bring Pytorch onto small robotics projects.</p>

username: goldsborough
cooked: <p>Hi everyone, I’m the core maintainer of the C++ frontend. Dataloaders are indeed still WIP and the examples I wrote were based on the version from my PR that <a class="mention" href="/u/dasayan05">@dasayan05</a> linked earlier (<a href="https://github.com/pytorch/pytorch/pull/11918">https://github.com/pytorch/pytorch/pull/11918</a>). We are looking to land it very soon, in the next few days. For now, if you would like to use the pre-built library that you can download from <a href="https://pytorch.org/get-started/locally">https://pytorch.org/get-started/locally</a>, you can use everything in the C++ Frontend except the dataloaders. If you are keen to use the dataloaders already, I would recommend building PyTorch from source and checking out the revision of my pull request. Then the MNIST example should compile too. See <a href="https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md">https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md</a> for steps regarding building from source.</p>
<p>Let me know which route you take and whether you run into any more issues. I’ll be happy to help. Feel free to tag me in future posts in this forum.</p>

username: justusschock
cooked: <p>I can confirm that it is possible to use the C++ API (downloaded <code>torchlib</code> without CUDA support) and I somewhat got around this issue by defining a mixture of dataset and dataloader myself.</p>

username: leemengwei
cooked: <p>Hi, peter, with libtorch1.3.1 built on ARM(JetsonTX2), I got something like this:<br>
code:<br>
<code>at::init_num_threads</code><br>
<code>at::set_num_threads</code><br>
<code>at::get_num_threads</code><br>
error: ‘at’ has no member of init/set/get_num_threads,<br>
thanks!</p>