pytorch / examples

A set of examples around pytorch in Vision, Text, Reinforcement Learning, etc.
https://pytorch.org/examples
BSD 3-Clause "New" or "Revised" License
22.21k stars 9.51k forks source link

dcgan example ( Pytorch C++ API frontend) #878

Open Hazimelhussieny opened 3 years ago

Hazimelhussieny commented 3 years ago

I am trying to build a simple CNN model using libtorch, I am following the tutorial : https://github.com/pytorch/examples/tree/master/cpp/dcgan I got this error : hazim@hazim-virtual-machine:~/Documents/dcgan/build$ ./dcgan terminate called after throwing an instance of 'c10::Error' what(): Error opening images file at /home/hazim/Downloads/MNIST_DATASET/MNIST_DATASET/train-images-idx3-ubyte Exception raised from read_images at ../torch/csrc/api/src/data/datasets/mnist.cpp:66 (most recent call first): frame #0: c10::Error::Error(c10::SourceLocation, std::cxx11::basic_string<char, std::char_traits, std::allocator >) + 0x69 (0x7f33c5145b89 in /home/hazim/Documents/dcgan/libtorch/lib/libc10.so) frame #1: + 0x337429c (0x7f33b7aaf29c in /home/hazim/Documents/dcgan/libtorch/lib/libtorch_cpu.so) frame #2: torch::data::datasets::MNIST::MNIST(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, torch::data::datasets::MNIST::Mode) + 0x46 (0x7f33b7ab0e06 in /home/hazim/Documents/dcgan/libtorch/lib/libtorch_cpu.so) frame #3: main + 0x7a2 (0x4c0fab in ./dcgan) frame #4: libc_start_main + 0xf0 (0x7f33b366e840 in /lib/x86_64-linux-gnu/libc.so.6) frame #5: _start + 0x29 (0x4bf7d9 in ./dcgan)

Aborted (core dumped)

I hope someone can help me with this error

lixiang-cn commented 3 years ago

Did you solve your problem? @Hazimelhussieny

ClintRajaniemi commented 2 years ago

I ran into this issue and I had two problems.

The first was I put the mnist/ directory at the same level as build/. This means I needed to change the code to go up one directory as such: auto dataset = torch::data::datasets::MNIST("../mnist") Note the two dots in front of /mnist. If you have the mnist directory inside of build/ then don't change this part.

The second issue is that I had outsmarted myself and deleted the .gz files in the mnist directory. Don't do that. Leave it just as the Python script pulled it.

After these, I was able to print out the file contents.