Giter VIP home page Giter VIP logo

cpp-pytorch's People

Contributors

iamhankai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cpp-pytorch's Issues

tracing.py - delimiter for numpy.loadtxt() cannot be \n

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.

make error

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!

CMake Error at find Torch package

I follow your step but meet this error.
But same libtorch/ works well in official doc: https://pytorch.org/tutorials/advanced/cpp_export.html

I am confused!

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!

how can i use forward() when i have Multiple inputs and outputs

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++ ?

run time is very long

When I run the forward prediction, the C++ run time is much longer than python, has someone encountered this problem?

what is the function about this part

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();

Failed build target 'cmTC_5a215'

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

build error

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>

what is the meaning about this,thanks

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);

I met this OpenCV error when cmake.

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.

runtime_error

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");

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.