Smorodov / Multitarget-tracker

Multiple Object Tracker, Based on Hungarian algorithm + Kalman filter.
Apache License 2.0
2.17k stars 647 forks source link

tiny- Yolo V3 #91

Closed scp-sjrim closed 5 years ago

scp-sjrim commented 6 years ago

Hi Smorodov

I want to use Yolo v3 tiny model.

So I downloaded .cfg and .weight files.

but it doesn't work How I can fix it ?

OpenCV(4.0.0-pre) Error: Unspecified error (Requested layer "detection_out" not found) in cv::dnn::experimental_dnn_v4::Net::Impl::getLayerData, file c:\opencv-master\modules\dnn\src\dnn.cpp, line 936

Nuzhny007 commented 6 years ago

Fixed: https://github.com/Smorodov/Multitarget-tracker/pull/92 And before this pull request will be approved you can read code from my fork.

scp-sjrim commented 6 years ago

@Nuzhny007 Thank you so much. It works well!

bleakie commented 6 years ago

OpenCV4.0 is open? why i can not find it?

Nuzhny007 commented 6 years ago

You can use mastrr branch

akde commented 6 years ago

Hi Thx for the awesome repo.

I can run yolo as stated in the yolo web site by the following command ./darknet detector demo cfg/coco.data cfg/yolov3-tiny.cfg yolov3-tiny.weights ~/darknet/teklerbad.mp4 res

However, when I try to run Multitracker with the following command

./MultitargetTracker /home/akde/Desktop/badmington/teklerbad.mp4 -e=5 -o=/home/akde/Desktop/result.avi

I get this error: **OpenCL not used OpenCV Error: Parsing error (Unknown layer type: yolo) in ReadDarknetFromCfgFile, file /home/akde/opencv/modules/dnn/src/darknet/darknet_io.cpp, line 503 terminate called after throwing an instance of 'cv::Exception' what(): /home/akde/opencv/modules/dnn/src/darknet/darknet_io.cpp:503: error: (-212) Unknown layer type: yolo in function ReadDarknetFromCfgFile

Aborted (core dumped)**

So considering the fact that yolov3 and yolov3-tiny can run in my pc, what am I doing wrong? PS: I can run Multitargettracker with the following:

./MultitargetTracker /home/akde/Desktop/badmington/teklerbad.mp4 -e=5 -o=/home/akde/Desktop/result.avi

Nuzhny007 commented 6 years ago

Hi! Do you use OpenCV 4.0 for MultitargetTracker? This version wasn't released now but you can download and compile it from master branch: https://github.com/opencv/opencv

akde commented 6 years ago

Thx for the quick response! I am using opencv 3.3.1. Do I have to use opencv 4.0 to use yolo?

Nuzhny007 commented 6 years ago

Yes, I'm using OpenCV 4.0

akde commented 6 years ago

I have CUDA installed and working on my PC. Can I use CUDA in YOLO case?

Nuzhny007 commented 6 years ago

If you use OpenCV than only OpeCL acceleration. For CUDA you need the original darknet.

deimsdeutsch commented 6 years ago

@Nuzhny007 Which is faster OpenCL or CUDA ?

Nuzhny007 commented 6 years ago

Hi! OpenCL from opencv_dnn have now 2 problems:

  1. Neural networks can use OpenCL only on Intel integrate GPU. So networks runs faster on GPU with CUDA.
  2. The quality of the opencv_dnn inference is worse than original darknet. It's strange, but it's true.

If anyone needs it, then I can try to integrate a darknet-based detector into this project.

deimsdeutsch commented 6 years ago

@Nuzhny007 I am currently using this repo for darknet. This also has a c++ wrapper. This is pure CUDA based. https://github.com/alexeyab/darknet

I love the other work you have done hungarian+kalman tracker+optflow with smart pointers in the code. But the problem is alexeyab's repo only works with 3.4.0 opencv while yours work in opencv 4.0 with GCC support for c++14 which doesn't work on Centos 7/Redhat because they only support c++11.

Can you look into this ? c++11 support+opencv 3.4.0+cuda+darknet+hungarian algo+kalman ukf+optflow ?

Nuzhny007 commented 6 years ago
  1. Darknet isn't pure CUDA library, it can works only on CPU: https://github.com/AlexeyAB/darknet/blob/master/Makefile#L1 You can modify the first line in Makefile.

  2. This projects works with OpenCV 3.4.0 well but this version of OpenCV don't support YOLO v3! You can use it with YOLO v2.

deimsdeutsch commented 6 years ago

@Nuzhny007 I have integrated the CUDA compiled .lib file into your code from https://github.com/AlexeyAB/darknet repository.


class YoloTinyExample : public VideoExample
{
public:
    YoloTinyExample(const cv::CommandLineParser& parser)
        :
        VideoExample(parser)
    {
    }

protected:
    ///
    /// \brief InitTracker
    /// \param grayFrame
    ///
    bool InitTracker(cv::UMat frame)
    {
        config_t config;
        config["modelConfiguration"] = "../data/vehicle-tiny.cfg";
        config["modelBinary"] = "../data/vehicle_final.weights";
        config["classNames"] = "../data/vehicles.names";
        config["confidenceThreshold"] = "0.25";

        m_detector = std::unique_ptr<BaseDetector>(CreateDetector(tracking::Detectors::YoloTiny, config, m_useLocalTracking, frame));
        if (!m_detector.get())
        {
            return false;
        }
        m_detector->SetMinObjectSize(cv::Size(frame.cols / 20, frame.rows / 20));

        TrackerSettings settings;
        settings.m_useLocalTracking = m_useLocalTracking;
        settings.m_distType = tracking::DistJaccard;
        settings.m_kalmanType = tracking::KalmanUnscented;
        settings.m_filterGoal = tracking::FilterCenter;
        settings.m_lostTrackType = tracking::TrackKCF;    // Use KCF tracker for collisions resolving
        settings.m_matchType = tracking::MatchHungrian;
        settings.m_dt = 0.3f;                             // Delta time for Kalman filter
        settings.m_accelNoiseMag = 0.2f;                  // Accel noise magnitude for Kalman filter
        settings.m_distThres = 0.8f;           // Distance threshold between region and object on two frames
        settings.m_maximumAllowedSkippedFrames = m_fps / 2;   // Maximum allowed skipped frames
        settings.m_maxTraceLength = 5 * m_fps;            // Maximum trace length

        m_tracker = std::make_unique<CTracker>(settings);

        return true;
    }

    ///
    /// \brief DrawData
    /// \param frame
    ///
    void DrawData(cv::Mat frame, int framesCounter, int currTime)
    {
        if (m_showLogs)
        {
            std::cout << "Frame " << framesCounter << ": tracks = " << m_tracker->tracks.size() << ", time = " << currTime << std::endl;
        }

        for (const auto& track : m_tracker->tracks)
        {
            if (track->IsRobust(8,                           // Minimal trajectory size
                0.4f,                        // Minimal ratio raw_trajectory_points / trajectory_lenght
                cv::Size2f(0.1f, 8.0f))      // Min and max ratio: width / height
                )
            {
                DrawTrack(frame, 1, *track);
            }
        }

        m_detector->CalcMotionMap(frame);
    }
};

// ----------------------------------------------------------------------
Frame 2: tracks = 2, time = 34
Frame 3: tracks = 3, time = 34
Frame 4: tracks = 3, time = 34
Frame 5: tracks = 3, time = 33
Frame 6: tracks = 4, time = 33
Frame 7: tracks = 4, time = 34
Frame 8: tracks = 4, time = 33
Frame 9: tracks = 4, time = 33
Frame 10: tracks = 5, time = 33
Frame 11: tracks = 5, time = 33
Frame 12: tracks = 5, time = 33
Frame 13: tracks = 5, time = 33
Frame 14: tracks = 4, time = 33
Frame 15: tracks = 4, time = 33
Frame 16: tracks = 5, time = 33
Frame 17: tracks = 5, time = 33

The detector alone is giving me 50 fps but when i integrated it with your code i am not getting real time fps. I just want to track objects so that while putting them in db i can avoid duplicates. Can you suggest why the FPS is low ...

Nuzhny007 commented 6 years ago

Reason: settings.m_lostTrackType = tracking::TrackKCF Try to set: settings.m_lostTrackType = tracking::TrackNone

deimsdeutsch commented 6 years ago

Yes Much Better.

Frame 2: tracks = 1, time = 24
Frame 3: tracks = 1, time = 27
Frame 4: tracks = 1, time = 28
Frame 5: tracks = 2, time = 28
Frame 6: tracks = 3, time = 23
Frame 7: tracks = 3, time = 27
Frame 8: tracks = 3, time = 27
Frame 9: tracks = 4, time = 24
Frame 10: tracks = 4, time = 27
Frame 11: tracks = 4, time = 27
Frame 12: tracks = 4, time = 27
Frame 13: tracks = 4, time = 28
Frame 14: tracks = 4, time = 23
Frame 15: tracks = 4, time = 27
Frame 16: tracks = 4, time = 23
Frame 17: tracks = 4, time = 28
Frame 18: tracks = 4, time = 28

I have another question. Can you tell which tracker is being used in this video-> https://www.youtube.com/watch?v=aE1kA0Jy0Xg

Nuzhny007 commented 6 years ago

Maybe Deep sort + netflow tracking algorithms. See thhey here: https://github.com/Nuzhny007/Multitarget-tracker/blob/master/TODO This algorithms are modern and the best in MOT: https://motchallenge.net/ I don't sure about performance, but quality are awesome. I want very mutch to integrate some to the this projects. But this project is onle hobby for me and I have not anough time for this. If you want to contribute some algorithm implementation - welcome!

deimsdeutsch commented 6 years ago

This also http://www.votchallenge.net/vot2017/trackers.html

Nuzhny007 commented 6 years ago

Yes. But VOT is about single tracking. We are using KCF etc but it is optional parameters.

iraadit commented 5 years ago

@deimsdeutsch, could you publish your code with Darknet?

Thanks

pengguoqing commented 5 years ago

Yes, I'm using OpenCV 4.0

The OpenCV4.0.0-alpha can use YOLOv3.weights?????

pengguoqing commented 5 years ago

Hi Smorodov

I want to use Yolo v3 tiny model.

So I downloaded .cfg and .weight files.

but it doesn't work How I can fix it ?

OpenCV(4.0.0-pre) Error: Unspecified error (Requested layer "detection_out" not found) in cv::dnn::experimental_dnn_v4::Net::Impl::getLayerData, file c:\opencv-master\modules\dnn\src\dnn.cpp, line 936

I have encountered the same problem as you. Can you tell me some details?

Nuzhny007 commented 5 years ago

OpenCV is released now. Use it for YOLO 3

pengguoqing commented 5 years ago

OpenCV is released now. Use it for YOLO 3

thanks. I just installed Opencv4.0 and made it successful