Unable to read Data using PyTorch C++ API (MNIST)

I found this warning message after nmake command.

Not sure if this has to do with the above problem.

Do the following:
Right click your executable like so:
2019-06-14%2018_25_33-
The run it and wait for windows to report any missing DLL’s.

I tried doing that, it says that it made it compatible for Windows 8 mode and asked to test again. The test fails again.

What is the exception?

I troubleshooted and it then showed the following:

image

When I test the program, the executable file ends just before reading data (without showing any error/exception).

I tried to use cmake -g "Ninja" command and then did ninja to make. After running mnist.exe here is the assertion failed error. After ignoring, it ends immediately.

Add this to the cmake command -DCMAKE_BUILD_TYPE=Release. The debug and release binaries are not ABI compatible when you use MSVC.

Thanks for the response @peterjc123. I tried doing that, but it still stops abruptly without showing any exception or error.

I also tried downloading the Stable Version of libtorch again, but it still doesn’t work.

Just wondering if the warnings during the make command make any sense? If there’s anything wrong?

Please build with the debugging version of this library and use VS GUI with the debug configuration to get more info.

And you can add /EHsc to the compiler flags so that the exceptions could be raised.

Thanks for the suggestions, @peterjc123. Here is the error I get while trying to run the executable file.

By VS GUI, did you mean to try building with Microsoft Visual Studio and not with Ninja?

Yes. I mean IDE. You’ll need to add Include Directories and Linking libraries manually.

I right clicked on the exception and clicked on “Go to source code”:

I then went to the included path of libtorch (debug version) and couldn’t find mnist.cpp in the required location. Is this a mistake?

As you can see, the folder is empty.

@peterjc123 Is there any requirement for the system to have pytorch installed in Python?

I tried going deeper into the error, it says it couldn’t find mnist.cpp file.

Yes, the source files are not included in the distributions. So that’s normal. Just download / clone the repo and point that for VS.

Thanks!

I included the repo in directory by going to the project properties, but here are the errors I get. Any idea why?

Error (active)	E0135	namespace "at" has no member "WeakIValue"	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\tracer.h	68	
Error	C2039	 'WeakIValue': is not a member of 'at'	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\tracer.h	68	
Error	C2061	 syntax error: identifier 'WeakIValue'	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\tracer.h	68	
Error	C4430	 missing type specifier - int assumed. Note: C++ does not support default-int	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\tracer.h	71	
Error	C2143	 syntax error: missing ',' before '&'	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\tracer.h	71	
Error	C4430	 missing type specifier - int assumed. Note: C++ does not support default-int	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\tracer.h	77	
Error	C2143	 syntax error: missing ',' before '&'	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\tracer.h	77	
Error	C2065	 'WeakIValue': undeclared identifier	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\tracer.h	82	
Error	C2923	 'std::unordered_map': 'WeakIValue' is not a valid template type argument for parameter '_Kty'	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\tracer.h	82	
Error	C3203	 'pair': unspecialized class template can't be used as a template argument for template parameter '_Ty', expected a real type	example	C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\unordered_map	75	
Error	C2923	 'std::unordered_map': 'WeakIValue' is not a valid template type argument for parameter '_Kty'	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\tracer.h	82	
Error	C3203	 'unordered_map': unspecialized class template can't be used as a template argument for template parameter '_Ty', expected a real type	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\tracer.h	83	
Error	C2065	 't': undeclared identifier	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\tracer.h	72	
Error	C2065	 't1': undeclared identifier	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\tracer.h	78	
Error	C2065	 't2': undeclared identifier	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\tracer.h	78	
Error	C2660	 'c10::ClassType::create': function does not take 3 arguments	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\script\module.h	117	
Error	C2440	 'return': cannot convert from 'torch::jit::script::CompilationUnit' to 'std::shared_ptr<torch::jit::script::CompilationUnit>'	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\script\module.h	407	
Error	C2440	 'return': cannot convert from 'torch::jit::script::CompilationUnit' to 'std::shared_ptr<const torch::jit::script::CompilationUnit>'	example	C:\Users\krshr\OneDrive\Documents\pytorch\torch\csrc\jit\script\module.h	410	
Error	C2953	 'torch::OrderedDict': class template has already been defined	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	178	
Error	C2427	 'torch::OrderedDict<Key,Value>::Item': cannot define class in this scope	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	183	
Error	C2244	 'torch::OrderedDict::OrderedDict': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	238	
Error	C2244	 'torch::OrderedDict::OrderedDict': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	242	
Error	C2244	 'torch::OrderedDict::operator =': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	252	
Error	C2244	 'torch::OrderedDict::OrderedDict': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	265	
Error	C2244	 'torch::OrderedDict::begin': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	275	
Error	C2244	 'torch::OrderedDict::begin': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	281	
Error	C2244	 'torch::OrderedDict::end': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	286	
Error	C2244	 'torch::OrderedDict::end': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	292	
Error	C2244	 'torch::OrderedDict::front': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	297	
Error	C2244	 'torch::OrderedDict::front': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	304	
Error	C2244	 'torch::OrderedDict::back': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	310	
Error	C2244	 'torch::OrderedDict::back': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	317	
Error	C2244	 'torch::OrderedDict::operator []': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	324	
Error	C2244	 'torch::OrderedDict::operator []': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	331	
Error	C2244	 'torch::OrderedDict::operator []': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	337	
Error	C2244	 'torch::OrderedDict::operator []': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	345	
Error	C2244	 'torch::OrderedDict::insert': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	354	
Error	C2244	 'torch::OrderedDict::insert': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	364	
Error	C2244	 'torch::OrderedDict::update': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	369	
Error	C2244	 'torch::OrderedDict::update': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	378	
Error	C2244	 'torch::OrderedDict::find': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	387	
Error	C2244	 'torch::OrderedDict::find': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	396	
Error	C2244	 'torch::OrderedDict::contains': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	405	
Error	C2244	 'torch::OrderedDict::clear': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	410	
Error	C2244	 'torch::OrderedDict::size': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	416	
Error	C2244	 'torch::OrderedDict::is_empty': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	421	
Error	C2244	 'torch::OrderedDict::key_description': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	426	
Error	C2244	 'torch::OrderedDict::items': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	433	
Error	C2244	 'torch::OrderedDict::keys': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	438	
Error	C2244	 'torch::OrderedDict::values': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	448	
Error	C2244	 'torch::OrderedDict::pairs': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	458	
Error	C2244	 'torch::OrderedDict::reserve': unable to match function definition to an existing declaration	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\ordered_dict.h	468	
Error	C2662	 'size_t torch::OrderedDict<Key,Value>::size(void) noexcept const': cannot convert 'this' pointer from 'torch::OrderedDict' to 'const torch::OrderedDict<Key,Value> &'	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\nn\modules\sequential.h	109	
Error	C2663	 'torch::OrderedDict<Key,Value>::begin': 2 overloads have no legal conversion for 'this' pointer	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\nn\modules\sequential.h	110	
Error	C2663	 'torch::OrderedDict<Key,Value>::end': 2 overloads have no legal conversion for 'this' pointer	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\nn\modules\sequential.h	110	
Error	C3536	 '<begin>$L0': cannot be used before it is initialized	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\nn\modules\sequential.h	110	
Error	C3536	 '<end>$L0': cannot be used before it is initialized	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\nn\modules\sequential.h	110	
Error	C2100	 illegal indirection	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\nn\modules\sequential.h	110	
Error	C2672	 'std::move': no matching overloaded function found	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\nn\modules\sequential.h	111	
Error	C2780	 '_DestTy *std::move(_InIt,_InIt,_DestTy (&)[_DestSize])': expects 3 arguments - 1 provided	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\nn\modules\sequential.h	111	
Error	C2780	 '_OutIt std::move(_InIt,_InIt,_OutIt)': expects 3 arguments - 1 provided	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\nn\modules\sequential.h	111	
Error	C2672	 'std::move': no matching overloaded function found	example	C:\Users\krshr\Downloads\Compressed\libtorch\include\torch\csrc\api\include\torch\nn\modules\sequential.h	111	

This error appears when using Microsoft Visual Studio 2019 x64 instead of Ninja.

When trying Ninja, the error is same. It says it can not find c:\w\1\s\windows\pytorch\torch\csrc\api\src\data\datasets\mnist.cpp. Is there anything wrong with the initials of the path: c:\w\1\s\windows\? This path doesn’t exist, right?

Oh! Finally done. Looks like there was a problem with path to the source repo of PyTorch.

Thanks @peterjc123 for your patience! :+1: