Giter Site home page Giter Site logo

yolov5-libtorch's Introduction

YOLOv5-LibTorch

Real time object detection with deployment of YOLOv5 through LibTorch C++ API

Environment

  • Ubuntu 18.04
  • OpenCV 3.2.0
  • LibTorch 1.6.0
  • CMake 3.10.2

Getting Started

  1. Install OpenCV.

    sudo apt-get install libopencv-dev
  2. Install LibTorch.

    wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip
    unzip libtorch-shared-with-deps-latest.zip
  3. Edit "CMakeLists.txt" to configure OpenCV and LibTorch correctly.

  4. Compile and run.

    cd build
    cmake ..
    make
    ./../bin/YOLOv5LibTorch

Note: COCO-pretrained YOLOv5s model has been provided. For more pretrained models, see yolov5.

yolov5-libtorch's People

Contributors

nebula4869 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

yolov5-libtorch's Issues

make error ...how to solve it ?

[ 50%] Building CXX object CMakeFiles/YOLOv5LibTorch.dir/src/YOLOv5LibTorch.cpp.o
[100%] Linking CXX executable ../bin/YOLOv5LibTorch
CMakeFiles/YOLOv5LibTorch.dir/src/YOLOv5LibTorch.cpp.o:在函数‘main’中:
YOLOv5LibTorch.cpp:(.text.startup+0x14b4):对‘cv::format(char const*, ...)’未定义的引用
YOLOv5LibTorch.cpp:(.text.startup+0x1587):对‘cv::putText(cv::InputOutputArray const&, std::string const&, cv::Point, int, double, cv::Scalar_, int, int, bool)’未定义的引用
YOLOv5LibTorch.cpp:(.text.startup+0x19c3):对‘cv::putText(cv::InputOutputArray const&, std::string const&, cv::Point, int, double, cv::Scalar_, int, int, bool)’未定义的引用
YOLOv5LibTorch.cpp:(.text.startup+0x1a3f):对‘cv::imshow(std::string const&, cv::_InputArray const&)’未定义的引用
collect2: error: ld returned 1 exit status
CMakeFiles/YOLOv5LibTorch.dir/build.make:132: recipe for target '../bin/YOLOv5LibTorch' failed
make[2]: *** [../bin/YOLOv5LibTorch] Error 1
CMakeFiles/Makefile2:94: recipe for target 'CMakeFiles/YOLOv5LibTorch.dir/all' failed
make[1]: *** [CMakeFiles/YOLOv5LibTorch.dir/all] Error 2
Makefile:102: recipe for target 'all' failed
make: *** [all] Error 2

I need help!

//I use the way of torch.jit.trace to convert original pt file to torchscript pt file , but it generates many bugs.....
I find it !! There is a export.py file converting original pt file to torchscript pt file in the YOLOv5 project .

The torchscript weight from YoLoV5 is not workable

Thanks very much for creating this repo.

Now I am facing one problem that the converted torchscript weight from YoLoV5 is not working with the code you provided.

The conversion is followed on this:
ultralytics/yolov5#251

The image size is set to [640, 640] and I also modified your code to be 640.

When loading your existing torchscript weight, it works perfectly.

Do you know which could be the reasons?

Thanks.

Opencv Error when running make

When i run make, it returns a linking error.

/usr/bin/ld: CMakeFiles/YOLOv5LibTorch.dir/src/YOLOv5LibTorch.cpp.o: in function main': YOLOv5LibTorch.cpp:(.text.startup+0xed7): undefined reference to cv::putText(cv::InputOutputArray const&, std::string const&, cv::Point, int, double, cv::Scalar_, int, int, bool)'
/usr/bin/ld: YOLOv5LibTorch.cpp:(.text.startup+0xf5a): undefined reference to cv::imshow(std::string const&, cv::_InputArray const&)' /usr/bin/ld: YOLOv5LibTorch.cpp:(.text.startup+0x1621): undefined reference to cv::format(char const*, ...)'
/usr/bin/ld: YOLOv5LibTorch.cpp:(.text.startup+0x16f6): undefined reference to `cv::putText(cv::InputOutputArray const&, std::string const&, cv::Point, int, double, cv::Scalar_, int, int, bool)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/YOLOv5LibTorch.dir/build.make:160: ../bin/YOLOv5LibTorch] Error 1
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/YOLOv5LibTorch.dir/all] Error 2
make: *** [Makefile:103: all] Error 2

it is can not work when I use my own trained model

Hi, i get a problem when i use my model to inffer. I converted the official yolov5s.pt to yolov5s.torchscript.pt by export.py , but it cannot work in your code, and also my own model can not work too, do you know how can i sovle it ? thank you so much!

memory error

Hi, I've tried your code on your provided weights its working fine, but when I tried my custom weight exported using ultralytics repo, even using older tags is not working. can you please help me with it

Error in inference on other size except (640,640)

Hi,
I want inference my .torchscript.pt which is trained by this command and switch:

python train.py --img 128 128 --rect ...

but, by change resize function in this repo to (128,128), i got error:

RuntimeError: The size of tensor a (32) must match the size of tensor b (80) at non-singleton dimension 3

but, i don't know where should i change to work for me.
please help me.

Question: Have you tried this code with CUDA?

I am pursuing a similar path, and have been able to loop multiple inference calls to module::forward() when using CPU version of libtorch and PT file. CUDA version not so much - the inference call makes it through the first time, but subsequent call results in an exception. Have you tried this, and what are your results? FYI I am using CUDA 10.1.

I also logged an issue on this with pytorch group:
pytorch/pytorch#47590

Thanks,
Rob

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.