iamhankai / cpp-pytorch Goto Github PK
View Code? Open in Web Editor NEWA bite of cpp api in PyTorch-1.0
A bite of cpp api in PyTorch-1.0
Hi, @iamhankai What is your platform to build this repo? Thanks.
The delimiter is actually \t
(single tabulation). The following line
labels = np.loadtxt('synset_words.txt', dtype=str, delimiter='\n')
needs to be changed to
labels = np.loadtxt('synset_words.txt', dtype=str, delimiter='\t')
In CSV files new line means new row, that is a new entry. A delimiter is something the splits the columns in a single row.
i can run 'camke ..' successfully, but when i run 'make', it shows :
/home/workplace/cpp-pytorch/example-app.cpp:44:49: error: ‘class at::DeprecatedTypeProperties’ has no member named ‘tensorFromBlob’
auto img_tensor = torch::CPU(torch::kFloat32).tensorFromBlob(img_float.data, {1, 224, 224, 3});
^
what can i do next to solve it, thx!
I follow your step but meet this error.
But same libtorch/ works well in official doc: https://pytorch.org/tutorials/advanced/cpp_export.html
CMake Error at CMakeLists.txt:18 (find_package):
By not providing "FindTorch.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Torch", but
CMake did not find one.
Could not find a package configuration file provided by "Torch" with any of
the following names:
TorchConfig.cmake
torch-config.cmake
Add the installation prefix of "Torch" to CMAKE_PREFIX_PATH or set
"Torch_DIR" to a directory containing one of the above files. If "Torch"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
I print the results of image preprocessing, and they are a little different.
[图片]
$ ./example-app ../model.pt ../dog.png ../synset_words.txt
load model ok
execution time = 4.47019s
Segmentation fault: 11
Can anyone help me out? Thanks
Hello. It appears error: No rule to make target TORCH_LIBRARY-NOTFOUND
, need by example-app
when making. How to fix it ?
In my python code my forward is defined as:
def forward(self, input_seq, hidden):
output_seq, hidden = self.gru(input_seq, hidden)
if isinstance(output_seq, torch.nn.utils.rnn.PackedSequence):
output_seq, _ = torch.nn.utils.rnn.pad_packed_sequence(
output_seq, batch_first=False)
mean = self.linear_mean2(F.relu(self.linear_mean1(output_seq)))
return mean, hidden
how can i use forward() in c++ ?
When I run the forward prediction, the C++ run time is much longer than python, has someone encountered this problem?
this part is neccesary ,can i remove it only leave " std::vectortorch::jit::IValue inputs;"
// Create a vector of inputs.
std::vectortorch::jit::IValue inputs;
inputs.push_back(torch::rand({64, 3, 224, 224}));
module->forward(inputs).toTensor();
inputs.pop_back();
An error occours at: traced_script_module.save("model.pt")
It seems that traced_script_module has no attribute 'save'.
Hello I am trying to run your code however I have problem while compiling using cmake. I have this error.
Run Build Command:"/usr/bin/make" "cmTC_84084/fast"
/usr/bin/make -f CMakeFiles/cmTC_84084.dir/build.make CMakeFiles/cmTC_84084.dir/build
make[1]: Entering directory '/media/mspl/17C9559C215E2AF1/Pytorch_CPP/cpp-pytorch/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_84084.dir/CheckSymbolExists.c.o
/usr/bin/cc -o CMakeFiles/cmTC_84084.dir/CheckSymbolExists.c.o -c /media/mspl/17C9559C215E2AF1/Pytorch_CPP/cpp-pytorch/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTC_84084
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_84084.dir/link.txt --verbose=1
/usr/bin/cc CMakeFiles/cmTC_84084.dir/CheckSymbolExists.c.o -o cmTC_84084 -rdynamic
CMakeFiles/cmTC_84084.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x16): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_84084.dir/build.make:97: recipe for target 'cmTC_84084' failed
make[1]: *** [cmTC_84084] Error 1
make[1]: Leaving directory '/media/mspl/17C9559C215E2AF1/Pytorch_CPP/cpp-pytorch/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_84084/fast' failed
make: *** [cmTC_84084/fast] Error 2
File /media/mspl/17C9559C215E2AF1/Pytorch_CPP/cpp-pytorch/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <pthread.h>
int main(int argc, char** argv)
{
(void)argv;
#ifndef pthread_create
return ((int*)(&pthread_create))[argc];
#else
(void)argc;
return 0;
#endif
}
Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /media/mspl/17C9559C215E2AF1/Pytorch_CPP/cpp-pytorch/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_5a215/fast"
/usr/bin/make -f CMakeFiles/cmTC_5a215.dir/build.make CMakeFiles/cmTC_5a215.dir/build
make[1]: Entering directory '/media/mspl/17C9559C215E2AF1/Pytorch_CPP/cpp-pytorch/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_5a215.dir/CheckFunctionExists.c.o
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_5a215.dir/CheckFunctionExists.c.o -c /usr/share/cmake-3.5/Modules/CheckFunctionExists.c
Linking C executable cmTC_5a215
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_5a215.dir/link.txt --verbose=1
/usr/bin/cc -DCHECK_FUNCTION_EXISTS=pthread_create CMakeFiles/cmTC_5a215.dir/CheckFunctionExists.c.o -o cmTC_5a215 -rdynamic -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_5a215.dir/build.make:97: recipe for target 'cmTC_5a215' failed
make[1]: *** [cmTC_5a215] Error 1
make[1]: Leaving directory '/media/mspl/17C9559C215E2AF1/Pytorch_CPP/cpp-pytorch/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_5a215/fast' failed
make: *** [cmTC_5a215/fast] Error 2
cmake -DCMAKE_PREFIX_PATH=$PWD/../libtorch ..
got error:
[ 50%] Building CXX object CMakeFiles/example-app.dir/example-app.cpp.o
/home/luban/cpp-pytorch/example-app.cpp:3:27: fatal error: torch/Tensor.h: No such file or directory
#include <torch/Tensor.h>
img_tensor[0][0] = img_tensor[0][0].sub_(0.485).div_(0.229);
img_tensor[0][1] = img_tensor[0][1].sub_(0.456).div_(0.224);
img_tensor[0][2] = img_tensor[0][2].sub_(0.406).div_(0.225);
Hello, I wonder to know which CUDA and cudnn version in your project.
I am using CUDA9.0 cudnn7, but there's an error that occurred.
I am confused and guess if this is because I modified files using this:
https://medium.com/@mengjiunchiou/build-opencv-caffe-with-cuda-9-0-on-ubuntu-16-04-b2794a41612d
And I modified this way becuz OpenCV2.4 is incompatible with CUDA9.0.
Now this seems to bother me much more...
Hi, @iamhankai
I met this error when cmake.
Kerb:build Apple$ cmake -DCMAKE_PREFIX_PATH=~/libtorch CMakeLists.txt ..
-- The C compiler identification is AppleClang 10.0.1.10010046
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/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: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/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
-- Found torch: /Users/Apple/libtorch/lib/libtorch.dylib
CMake Error at CMakeLists.txt:6 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
What's wrong to me?
My machine: MacOSX Mojave, Libtorch, OpenCV installed.
My opencv is here:
Kerb:build Apple$ pkg-config --cflags --libs /usr/local/Cellar/opencv/4.1.0_2/lib/pkgconfig/opencv4.pc
-I/usr/local/Cellar/opencv/4.1.0_2/include/opencv4/opencv -I/usr/local/Cellar/opencv/4.1.0_2/include/opencv4 -L/usr/local/Cellar/opencv/4.1.0_2/lib -lopencv_gapi -lopencv_stitching -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_quality -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_sfm -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_dnn -lopencv_plot -lopencv_videostab -lopencv_video -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core
Thanks in advance .
Best,
from @bemoregt.
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: Magic number mismatch in PyTorch file. File may be corrupted or is not actually a PyTorch file.
Abort trap: 6
/Python2C++/main.cpp:18:107: 错误:请求从‘torch::jit::script::Module’转换到非标量类型‘std::shared_ptrtorch::jit::script::Module’ 有人遇到这种问题吗
std::shared_ptrtorch::jit::script::Module module = torch::jit::load("/model.pt");
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.