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

Hey everyone!

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.

I was then trying the MNIST CNN example found here: https://github.com/goldsborough/examples/blob/cpp/cpp/mnist/mnist.cpp

However, I am running into a bit of trouble where torch::data does not seem to be available. Here is build print statements and the error:

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

And the error:

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([&](torch::data::Example<>& batch) {
                       ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:84:31: error: no member named 'data' in
      namespace 'torch'
  data_loader.loop([&](torch::data::Example<>& 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<>(0.1307, 0.3081))
               ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:122:51: error: expected expression
          .map(torch::data::transforms::Normalize<>(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<>(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<>()),
               ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:123:47: error: expected expression
          .map(torch::data::transforms::Stack<>()),
                                              ^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:123:49: error: expected expression
          .map(torch::data::transforms::Stack<>()),
                                                ^
/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<>(0.1307, 0.3081))
               ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:128:51: error: expected expression
          .map(torch::data::transforms::Normalize<>(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<>(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<>()),
               ~~~~~~~^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:129:47: error: expected expression
          .map(torch::data::transforms::Stack<>()),
                                              ^
/Users/yngtodd/src/sandbox/pytorch/mnist/mnist.cpp:129:49: error: expected expression
          .map(torch::data::transforms::Stack<>()),
                                                ^
/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

Has anyone had success getting a model up and running with the C++ interface?

Thanks!

1 Like

Thanks for posting. I am getting the same error when I tried PyTorch 1.0.

Although not sure but it looks like this PR implements the C++ frontend of data loader and it hasn’t been merged yet.

1 Like

Oh, good catch. Guess I got a little too eager for the C++ interface.

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.

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 @dasayan05 linked earlier (https://github.com/pytorch/pytorch/pull/11918). 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 https://pytorch.org/get-started/locally, 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 https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md for steps regarding building from source.

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.

5 Likes

I can confirm that it is possible to use the C++ API (downloaded torchlib without CUDA support) and I somewhat got around this issue by defining a mixture of dataset and dataloader myself.

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