Giter Site home page Giter Site logo

theaiguyscode / yolov4-custom-functions Goto Github PK

View Code? Open in Web Editor NEW
597.0 21.0 374.0 62.01 MB

A Wide Range of Custom Functions for YOLOv4, YOLOv4-tiny, YOLOv3, and YOLOv3-tiny Implemented in TensorFlow, TFLite, and TensorRT.

License: MIT License

Python 100.00%
yolov4 yolov3 object-detection tensorflow tflite custom-yolov4 yolov4-tiny tf2 tensorrt

yolov4-custom-functions's Introduction

yolov4-custom-functions

license

A wide range of custom functions for YOLOv4, YOLOv4-tiny, YOLOv3, and YOLOv3-tiny implemented in TensorFlow, TFLite and TensorRT.

DISCLAIMER: This repository is very similar to my repository: tensorflow-yolov4-tflite. I created this repository to explore coding custom functions to be implemented with YOLOv4, and they may worsen the overal speed of the application and make it not optimized in respect to time complexity. So if you want to run the most optimal YOLOv4 code with TensorFlow than head over to my other repository. This one is to explore cool customizations and applications that can be created using YOLOv4!

Demo of Object Counter Custom Function in Action!

Currently Supported Custom Functions and Flags

If there is a custom function you want to see created then create an issue in the issues tab and suggest it! If enough people suggest the same custom function I will add it quickly!

Getting Started

Conda (Recommended)

# Tensorflow CPU
conda env create -f conda-cpu.yml
conda activate yolov4-cpu

# Tensorflow GPU
conda env create -f conda-gpu.yml
conda activate yolov4-gpu

Pip

# TensorFlow CPU
pip install -r requirements.txt

# TensorFlow GPU
pip install -r requirements-gpu.txt

Nvidia Driver (For GPU, if you are not using Conda Environment and haven't set up CUDA yet)

Make sure to use CUDA Toolkit version 10.1 as it is the proper version for the TensorFlow version used in this repository. https://developer.nvidia.com/cuda-10.1-download-archive-update2

Downloading Official Pre-trained Weights

YOLOv4 comes pre-trained and able to detect 80 classes. For easy demo purposes we will use the pre-trained weights. Download pre-trained yolov4.weights file: https://drive.google.com/open?id=1cewMfusmPjYWbrnuJRuKhPMwRe_b9PaT

Copy and paste yolov4.weights from your downloads folder into the 'data' folder of this repository.

If you want to use yolov4-tiny.weights, a smaller model that is faster at running detections but less accurate, download file here: https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v4_pre/yolov4-tiny.weights

Using Custom Trained YOLOv4 Weights

Learn How To Train Custom YOLOv4 Weights here: https://www.youtube.com/watch?v=mmj3nxGT2YQ

Watch me Walk-Through using Custom Model in TensorFlow :https://www.youtube.com/watch?v=nOIVxi5yurE

USE MY LICENSE PLATE TRAINED CUSTOM WEIGHTS: https://drive.google.com/file/d/1EUPtbtdF0bjRtNjGv436vDY28EN5DXDH/view?usp=sharing

Copy and paste your custom .weights file into the 'data' folder and copy and paste your custom .names into the 'data/classes/' folder.

The only change within the code you need to make in order for your custom model to work is on line 14 of 'core/config.py' file. Update the code to point at your custom .names file as seen below. (my custom .names file is called custom.names but yours might be named differently)

Note: If you are using the pre-trained yolov4 then make sure that line 14 remains coco.names.

YOLOv4 Using Tensorflow (tf, .pb model)

To implement YOLOv4 using TensorFlow, first we convert the .weights into the corresponding TensorFlow model files and then run the model.

# Convert darknet weights to tensorflow
## yolov4
python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4 

# Run yolov4 tensorflow model
python detect.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --images ./data/images/kite.jpg

# Run yolov4 on video
python detect_video.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --video ./data/video/video.mp4 --output ./detections/results.avi

# Run yolov4 on webcam
python detect_video.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --video 0 --output ./detections/results.avi

If you want to run yolov3 or yolov3-tiny change --model yolov3 and .weights file in above commands.

Note: You can also run the detector on multiple images at once by changing the --images flag like such --images "./data/images/kite.jpg, ./data/images/dog.jpg"

Result Image(s) (Regular TensorFlow)

You can find the outputted image(s) showing the detections saved within the 'detections' folder.

Pre-trained YOLOv4 Model Example

Result Video

Video saves wherever you point --output flag to. If you don't set the flag then your video will not be saved with detections on it.

YOLOv4-Tiny using TensorFlow

The following commands will allow you to run yolov4-tiny model.

# yolov4-tiny
python save_model.py --weights ./data/yolov4-tiny.weights --output ./checkpoints/yolov4-tiny-416 --input_size 416 --model yolov4 --tiny

# Run yolov4-tiny tensorflow model
python detect.py --weights ./checkpoints/yolov4-tiny-416 --size 416 --model yolov4 --images ./data/images/kite.jpg --tiny

The following commands will allow you to run your custom yolov4 model. (video and webcam commands work as well)

# custom yolov4
python save_model.py --weights ./data/custom.weights --output ./checkpoints/custom-416 --input_size 416 --model yolov4 

# Run custom yolov4 tensorflow model
python detect.py --weights ./checkpoints/custom-416 --size 416 --model yolov4 --images ./data/images/car.jpg

Custom YOLOv4 Model Example (see video link above to train this model)

Custom Functions and Flags

Here is how to use all the currently supported custom functions and flags that I have created.

I have created a custom function within the file core/functions.py that can be used to count and keep track of the number of objects detected at a given moment within each image or video. It can be used to count total objects found or can count number of objects detected per class.

Count Total Objects

To count total objects all that is needed is to add the custom flag "--count" to your detect.py or detect_video.py command.

# Run yolov4 model while counting total objects detected
python detect.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --images ./data/images/dog.jpg --count

Running the above command will count the total number of objects detected and output it to your command prompt or shell as well as on the saved detection as so:

Count Objects Per Class

To count the number of objects for each individual class of your object detector you need to add the custom flag "--count" as well as change one line in the detect.py or detect_video.py script. By default the count_objects function has a parameter called by_class that is set to False. If you change this parameter to True it will count per class instead.

To count per class make detect.py or detect_video.py look like this:

Then run the same command as above:

# Run yolov4 model while counting objects per class
python detect.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --images ./data/images/dog.jpg --count

Running the above command will count the number of objects detected per class and output it to your command prompt or shell as well as on the saved detection as so:

Note: You can add the --count flag to detect_video.py commands as well!

I have created a custom flag called INFO that can be added to any detect.py or detect_video.py commands in order to print detailed information about each detection made by the object detector. To print the detailed information to your command prompt just add the flag --info to any of your commands. The information on each detection includes the class, confidence in the detection and the bounding box coordinates of the detection in xmin, ymin, xmax, ymax format.

If you want to edit what information gets printed you can edit the draw_bbox function found within the core/utils.py file. The line that prints the information looks as follows:

Example of info flag added to command:

python detect.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --images ./data/images/dog.jpg --info

Resulting output within your shell or terminal:

Note: You can add the --info flag to detect_video.py commands as well!

I have created a custom function within the file core/functions.py that can be applied to any detect.py or detect_video.py commands in order to crop the YOLOv4 detections and save them each as their own new image. To crop detections all you need to do is add the --crop flag to any command. The resulting cropped images will be saved within the detections/crop/ folder.

Example of crop flag added to command:

python detect.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --images ./data/images/dog.jpg --crop

Here is an example of one of the resulting cropped detections from the above command.

I have created a custom function to feed Tesseract OCR the bounding box regions of license plates found by my custom YOLOv4 model in order to read and extract the license plate numbers. Thorough preprocessing is done on the license plate in order to correctly extract the license plate number from the image. The function that is in charge of doing the preprocessing and text extraction is called recognize_plate and can be found in the file core/utils.py.

Disclaimer: In order to run tesseract OCR you must first download the binary files and set them up on your local machine. Please do so before proceeding or commands will not run as expected!

Official Tesseract OCR Github Repo: tesseract-ocr/tessdoc

Great Article for How To Install Tesseract on Mac or Linux Machines: PyImageSearch Article

For Windows I recommend: Windows Install

Once you have Tesseract properly installed you can move onwards. If you don't have a trained YOLOv4 model to detect license plates feel free to use one that I have trained. It is not perfect but it works well. Download license plate detector model and learn how to save and run it with TensorFlow here

Running License Plate Recognition on Images (video example below)

The license plate recognition works wonders on images. All you need to do is add the --plate flag on top of the command to run the custom YOLOv4 model.

Try it out on this image in the repository!

# Run License Plate Recognition
python detect.py --weights ./checkpoints/custom-416 --size 416 --model yolov4 --images ./data/images/car2.jpg --plate

Resulting Image Example

The output from the above command should print any license plate numbers found to your command terminal as well as output and save the following image to the detections folder.

You should be able to see the license plate number printed on the screen above the bounding box found by YOLOv4.

Behind the Scenes

This section will highlight the steps I took in order to implement the License Plate Recognition with YOLOv4 and potential areas to be worked on further.

This demo will be showing the step-by-step workflow on the following original image.

First step of the process is taking the bounding box coordinates from YOLOv4 and simply taking the subimage region within the bounds of the box. Since this image is super small the majority of the time we use cv2.resize() to blow the image up 3x its original size.

Then we convert the image to grayscale and apply a small Gaussian blur to smooth it out.

Following this, the image is thresholded to white text with black background and has Otsu's method also applied. This white text on black background helps to find contours of image.

The image is then dilated using opencv in order to make contours more visible and be picked up in future step.

Next we use opencv to find all the rectangular shaped contours on the image and sort them left to right.

As you can see this causes many contours to be found other than just the contours of each character within the license plate number. In order to filter out the unwanted regions we apply a couple parameters to be met in order to accept a contour. These parameters are just height and width ratios (i.e. the height of region must be at least 1/6th of the total height of the image). A couple other parameters on area of region etc are also placed. Check out code to see exact details. This filtering leaves us with.

The individual characters of the license plate number are now the only regions of interest left. We segment each subimage and apply a bitwise_not mask to flip the image to black text on white background which Tesseract is more accurate with. The final step is applying a small median blur on the image and then it is passed to Tesseract to get the letter or number from it. Example of how letters look like when going to tesseract.

Each letter or number is then just appended together into a string and at the end you get the full license plate that is recognized! BOOM!

Running License Plate Recognition on Video

Running the license plate recognition straight on video at the same time that YOLOv4 object detections causes a few issues. Tesseract OCR is fairly expensive in terms of time complexity and slows down the processing of the video to a snail's pace. It can still be accomplished by adding the --plate command line flag to any detect_video.py commands.

However, I believe the best route to go is to run video detections without the plate flag and instead run them with --crop flag which crops the objects found on screen and saves them as new images. See how it works here Once the video is done processing at a higher FPS all the license plate images will be cropped and saved within detections/crop folder. I have added an easy script within the repository called license_plate_recognizer.py that you can run in order to recognize license plates. Plus this allows you to easily customize the script to further enhance any recognitions. I will be working on linking this functionality automatically in future commits to the repository.

Running License Plate Recognition with detect_video.py is done with the following command.

python detect_video.py --weights ./checkpoints/custom-416 --size 416 --model yolov4 --video ./data/video/license_plate.mp4 --output ./detections/recognition.avi --plate

The recommended route I think is more efficient is using this command. Customize the rate at which detections are cropped within the code itself.

python detect_video.py --weights ./checkpoints/custom-416 --size 416 --model yolov4 --video ./data/video/license_plate.mp4 --output ./detections/recognition.avi --crop

Now play around with license_plate_recognizer.py and have some fun!

I have also implemented a generic use of Tesseract OCR with YOLOv4. By enabling the flag --ocr with any detect.py image command you can search detections for text and extract what is found. Generic preprocessing is applied on the subimage that makes up the inside of the detection bounding box. However, so many lighting or color issues require advanced preprocessing so this function is by no means perfect. You will also need to install tesseract on your local machine prior to running this flag (see links and suggestions in above section)

Example command (note this image doesn't have text so will not output anything, just meant to show how command is structured):

python detect.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --images ./data/images/dog.jpg --ocr

YOLOv4 Using TensorFlow Lite (.tflite model)

Can also implement YOLOv4 using TensorFlow Lite. TensorFlow Lite is a much smaller model and perfect for mobile or edge devices (raspberry pi, etc).

# Save tf model for tflite converting
python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4 --framework tflite

# yolov4
python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416.tflite

# yolov4 quantize float16
python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-fp16.tflite --quantize_mode float16

# yolov4 quantize int8
python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-int8.tflite --quantize_mode int8 --dataset ./coco_dataset/coco/val207.txt

# Run tflite model
python detect.py --weights ./checkpoints/yolov4-416.tflite --size 416 --model yolov4 --images ./data/images/kite.jpg --framework tflite

Result Image (TensorFlow Lite)

You can find the outputted image(s) showing the detections saved within the 'detections' folder.

TensorFlow Lite int8 Example

Yolov4 and Yolov4-tiny int8 quantization have some issues. I will try to fix that. You can try Yolov3 and Yolov3-tiny int8 quantization

YOLOv4 Using TensorRT

Can also implement YOLOv4 using TensorFlow's TensorRT. TensorRT is a high-performance inference optimizer and runtime that can be used to perform inference in lower precision (FP16 and INT8) on GPUs. TensorRT can allow up to 8x higher performance than regular TensorFlow.

python save_model.py --weights ./data/yolov3.weights --output ./checkpoints/yolov3.tf --input_size 416 --model yolov3
python convert_trt.py --weights ./checkpoints/yolov3.tf --quantize_mode float16 --output ./checkpoints/yolov3-trt-fp16-416

# yolov3-tiny
python save_model.py --weights ./data/yolov3-tiny.weights --output ./checkpoints/yolov3-tiny.tf --input_size 416 --tiny
python convert_trt.py --weights ./checkpoints/yolov3-tiny.tf --quantize_mode float16 --output ./checkpoints/yolov3-tiny-trt-fp16-416

# yolov4
python save_model.py --weights ./data/yolov4.weights --output ./checkpoints/yolov4.tf --input_size 416 --model yolov4
python convert_trt.py --weights ./checkpoints/yolov4.tf --quantize_mode float16 --output ./checkpoints/yolov4-trt-fp16-416
python detect.py --weights ./checkpoints/yolov4-trt-fp16-416 --model yolov4 --images ./data/images/kite.jpg --framework trt

Command Line Args Reference

save_model.py:
  --weights: path to weights file
    (default: './data/yolov4.weights')
  --output: path to output
    (default: './checkpoints/yolov4-416')
  --[no]tiny: yolov4 or yolov4-tiny
    (default: 'False')
  --input_size: define input size of export model
    (default: 416)
  --framework: what framework to use (tf, trt, tflite)
    (default: tf)
  --model: yolov3 or yolov4
    (default: yolov4)

detect.py:
  --images: path to input images as a string with images separated by ","
    (default: './data/images/kite.jpg')
  --output: path to output folder
    (default: './detections/')
  --[no]tiny: yolov4 or yolov4-tiny
    (default: 'False')
  --weights: path to weights file
    (default: './checkpoints/yolov4-416')
  --framework: what framework to use (tf, trt, tflite)
    (default: tf)
  --model: yolov3 or yolov4
    (default: yolov4)
  --size: resize images to
    (default: 416)
  --iou: iou threshold
    (default: 0.45)
  --score: confidence threshold
    (default: 0.25)
  --count: count objects within images
    (default: False)
  --dont_show: dont show image output
    (default: False)
  --info: print info on detections
    (default: False)
  --crop: crop detections and save as new images
    (default: False)
    
detect_video.py:
  --video: path to input video (use 0 for webcam)
    (default: './data/video/video.mp4')
  --output: path to output video (remember to set right codec for given format. e.g. XVID for .avi)
    (default: None)
  --output_format: codec used in VideoWriter when saving video to file
    (default: 'XVID)
  --[no]tiny: yolov4 or yolov4-tiny
    (default: 'false')
  --weights: path to weights file
    (default: './checkpoints/yolov4-416')
  --framework: what framework to use (tf, trt, tflite)
    (default: tf)
  --model: yolov3 or yolov4
    (default: yolov4)
  --size: resize images to
    (default: 416)
  --iou: iou threshold
    (default: 0.45)
  --score: confidence threshold
    (default: 0.25)
  --count: count objects within video
    (default: False)
  --dont_show: dont show video output
    (default: False)
  --info: print info on detections
    (default: False)
  --crop: crop detections and save as new images
    (default: False)

References

Huge shoutout goes to hunglc007 for creating the backbone of this repository:

yolov4-custom-functions's People

Contributors

theaiguyscode 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yolov4-custom-functions's Issues

--info-function with time measurement

Hi there,

first of all, thx for ur work.
Thru you i started with python. And now i try to learn more about DL and object detection.

Now i wanna test out how much slower the object detection on my GPU is in comparision to the GPU from Google Colab.
In your Colab tutorials u implemented a time measurment for the object detection.

Can u give me a advice how i can implement such a thin in this --info function?

Error with custom model and custom resolution

Hello Thanks for amazing work.

I try to use another resolution on custom model which was trained on low resolution and test on high resolution. But if I try after converting in tf-model to detect something I get the following error:

image

Could you explain how can I solve this issue?
And how can I use more than one GPU. Your solution with
image doesn't work.

Thank you!

Does not return the plate number

Hi
I am having a problem with the return of the plate.
I can detect it but it doesn't return the plate number.
I'm using the command: python detect.py --weights ./checkpoints/custom-416 --size 416 --model yolov4 --images ./data/images/car.jpg --plate

image

Can you help me?

save_model.py gives errors while converting YOLOV4 to tensorflow weights

Previously it was working, i don't know why now it is giving errors. Please i need help
errors are listed below-------->

Current thread 0x00003348 (most recent call first):
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\ops\gen_random_ops.py", line 639 in random_standard_normal
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\ops\random_ops.py", line 94 in random_normal
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\util\dispatch.py", line 201 in wrapper
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\ops\init_ops_v2.py", line 1035 in random_normal
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\ops\init_ops_v2.py", line 385 in call
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\ops\resource_variable_ops.py", line 1651 in _init_from_args
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\ops\resource_variable_ops.py", line 1518 in init
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\ops\variables.py", line 264 in call
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 2597 in default_variable_creator
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\ops\variables.py", line 199 in
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\ops\variables.py", line 221 in _variable_v1_call
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\ops\variables.py", line 260 in call
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\keras\engine\base_layer_utils.py", line 145 in make_variable
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\training\tracking\base.py", line 743 in _add_variable_with_custom_getter
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 614 in add_weight
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\keras\layers\convolutional.py", line 204 in build
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 2643 in _maybe_build
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 1098 in _functional_construction_call
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 926 in call
File "C:\tensorflow1\custom function\yolov4-custom-functions-master\core\common.py", line 31 in convolutional
File "C:\tensorflow1\custom function\yolov4-custom-functions-master\core\backbone.py", line 41 in cspdarknet53
File "C:\tensorflow1\custom function\yolov4-custom-functions-master\core\yolov4.py", line 72 in YOLOv4
File "C:\tensorflow1\custom function\yolov4-custom-functions-master\core\yolov4.py", line 25 in YOLO
File "save_model.py", line 20 in save_tf
File "save_model.py", line 54 in main
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\absl\app.py", line 251 in _run_main
File "C:\ProgramData\Anaconda3\envs\yolov4-gpu\lib\site-packages\absl\app.py", line 303 in run
File "save_model.py", line 58 in

Does not return proper number plate, returns only few letters !

Hi,

The repo is working great, thank you for sharing the work !

However, in most of the cases the plate number returned is not complete, and sometimes fails to recognize the plate number.

Here I have a car image
car9

Below is the result after Dilation and other preprocesses
image

Here is the recognized result (It detects only 5)
image

Sometimes recognition fails when the car is at certain angle !

Can you please help with suggestions regarding certain tunings involved.

Thanks in Advance !

little advice

Your warehouse is very valuable and very exciting work. And I think you can add more work on model compression such as quantification, pruning and distillation.

Streaming videos from an IP.

I wanted to use my phone camera for streaming the video for detections. So I got an app called IP webcam where it sent live camera display to my pc via an IP like https://192.168.0.0.1/camera, it's just a demo.
So how can I use this video in the model?

Plate Characters Recognition

Hi , I would like to know if there is any chance about know how to draw the boxes around the letters or numbers in the plate , just like in the description.
It's just for an educate propuse. I've tried but for the moment I have not been able to do it :c

Can we create an function for Detecting objects within a specified detection boundary.

Hey man first of all awesome video and love the effort that you put in , keep it up. So my question is can we create a function that sets a detection on boundary on the video feed and when the object is in the detection boundary it gets detected or else not.
When the object is within the boundary count goes up and as it leaves the boundary count goes down.

Is pretty much the same thing you done in the video but this time we just need a particular section of the footage to detect and count.
here is a video for the example of what we want to achieve,

https://www.youtube.com/watch?v=u_XOczajfRI

Getting data from ScreenCatpureTools

First, many thanks for the amazing work you've done. It is really detailed and works for basically anything.
Could you please add some indications in this github on how the VideoCaptureFlags works in detect_video.py?
It is so that we can use some kind of screen(monitor) capture tools instead of "0" for webcams, especially mss.mss()* so that we can efficiently use the yolov4-tiny and tensorflow-lite Tutorials you've created.

  • mss "An ultra fast cross-platform multiple screenshots module in pure python using ctypes."
    https://github.com/BoboTiG/python-mss about as many fps as the monitor itself can show (60)
    tiny can fast enough that sometimes the videocapture of the screen is the bottleneck weirdly enough...

By the way,
Here are the commands i used to train a tiny version for a custom yolo to detect birds from multiple cameras streamed to a pc. Maybe you could add them to the shared link of the video "yolov4 in the clouds" with a # as an option for people to train a yolo tiny just as seamlessly as they can train a full blown yolo following your tutorial and pre-made commands.
something along the lines as you did in step 5:
"(uncomment %%capture below if you run into memory issues or your Colab is crashing)"

Here are the commands modified for tiny:

STEP 3
i)
#_ !cp /mydrive/yolov4/yolov4-tiny-obj.cfg ./cfg

STEP 4
#_ !wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v4_pre/yolov4-tiny.conv.29

STEP 5
#_ !./darknet detector train data/obj.data cfg/yolov4-tiny-obj.cfg yolov4-tiny.conv.29 -dont_show -map

and here is the link for the raw version of the config file for yolotiny:
https://raw.githubusercontent.com/AlexeyAB/darknet/master/cfg/yolov4-tiny.cfg

Message when YOLO capturing an object

How should I do so that when it detects an object with some confidence it can send a message saying that YOLO detects an object of class X, for example using a print() function?

Thanks!

yolov3-openimages.weights

Hi,
i have tried to convert and use the yolov3-openimages.weights from darknet
i added the openimages.names to data\classes and adjusted the config.py, and then converted everything the same way as before with the yolov3.weights ...
everything seems to work, but nothing is detected. (even after adding --score 0.01)
Any idea what I might have missed?

yolov4-custom-functions --- API

You're the best and your videos are vey helpful, i would like to create APIs using FastAPI or FlaskAPI for this custom-functions to return image detection and information of detect as json, i appreciate to add it on this repository or such example can help us.

thanks in advance

About counter function issues

Hi there,
First of all, thx for your work. It is a nice program.
I have a question about the counter in the project.
If I want to display the total number of detections and the number of classification detections, instead of showing the classification number and the total number of detections in the current frame. How do I change the function.py?
The first time, I dele the 'else' in the count. But only the items detected in the current frame can be displayed, and the sum function cannot be realized.
Can u give me any advice?
thanks

tensorflow-directml saved model

tensorflow v1 default save format is H5, to save in tf

suggest to state for v1, include the following save_model .py line 51 for darknet yolov4 conversion
model.save(FLAGS.output,overwrite='true',save_format='tf')
in detect_video.py , v1 should be change in line 56 as
saved_model_loaded = tf.compat.v2.saved_model.load(FLAGS.weights, tags=[tag_constants.SERVING])

License Plate detected but the TEXT is half shown

detection1
Using this tutorial i used the provided pretrained mechanism and tried to detect the number plate using my image and it turns out that the text is half detected.

Wanted to know if any specific reason for this? Is the model respected to some region wise license plates, even if that is the case, a normal license text should be detected.

Malaysian Number plate

Hye, i tried the code it's work, but when using Malaysian number plate, the program detect the plate but cant return the plate number. Anybody had any idea with that ?

8

9

Outputting software view to virtual webcam and a few questions

so I am planning on making a program that is controlled by c#, or python I don't know yet but I would like this program to have a view of what you see when you load up webcam detection. If possible could you output the software view to a virtual camera

also how do you make it so it only detects certain classes

also amazing video I love your content! you are one of the most helpful resources I have found for my projects!!

Infer in detect.py outputs zero size matrix for all images except first

I have trained yolov4-640 on the plate detection, exactly like what is said in tutorial. I used save_model.py exactly like what is said for the pre-trained one. I pass some images to detect.py, the first image is ok and the plate is detected but for the next images output of infer is zero size. If I change the sort of images and pass them again, again the first image is ok but the next one are zero size

YOLOv5

can we do the same thing for YOLO v5 model ?

Social distance checker

I think it would be cool to add a social distance checker and display bounding boxes of those persons in a different color. Or some other integration that can visualize if a certain event happens in the video.

Integration with django app

I want to call the detect module in my django app could you tell me possible step I could do to call the function or module directly by passing image to detect.py

How can i predict on more than 1 image on a custom yolov4 model?

When i try to pass a numpy array of a list of images, i have this error. In this case the batch size was 2.
Error Log:
'''
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 23 values, but the requested shape requires a multiple of 2
[[{{node StatefulPartitionedCall/functional_1/tf_op_layer_Reshape_14/Reshape_14}}]] [Op:__inference_signature_wrapper_5588]

Function call stack:
signature_wrapper
'''

YOLOv4 custom function doesnt detect video while running on GPU

Hi everyone, im using YOLOv4 custom function from this repo. Everything works flawlessly, including convert weights file to pb file, run detection on both image and videos, then this error shows up on both pc and colab:

  • When i use only CPU, detection runs fine on both image and video data
  • When i use GPU, detections only runs on image. When run on videos, it still runs, but doesnt detect anything. I assume that the detection only runs on the first frame, but not on the rest ones.
  • Here is the console log when run video detect on CPU :
    Screen Shot 2021-05-01 at 17 32 04
  • Here is the console log when run video detection on GPU ( im sorry if log is a little bit too long )

2021-05-01 10:32:33.098862: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-05-01 10:32:34.935938: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-05-01 10:32:34.936785: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcuda.so.1
2021-05-01 10:32:34.953709: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-01 10:32:34.954371: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties:
pciBusID: 0000:00:04.0 name: Tesla P100-PCIE-16GB computeCapability: 6.0
coreClock: 1.3285GHz coreCount: 56 deviceMemorySize: 15.90GiB deviceMemoryBandwidth: 681.88GiB/s
2021-05-01 10:32:34.954406: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-05-01 10:32:34.957049: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.11
2021-05-01 10:32:34.957129: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.11
2021-05-01 10:32:34.958917: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10
2021-05-01 10:32:34.959305: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10
2021-05-01 10:32:34.961111: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10
2021-05-01 10:32:34.961867: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.11
2021-05-01 10:32:34.962058: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8
2021-05-01 10:32:34.962151: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-01 10:32:34.962729: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-01 10:32:34.963310: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0
2021-05-01 10:32:35.006935: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-05-01 10:32:35.007063: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-01 10:32:35.007689: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties:
pciBusID: 0000:00:04.0 name: Tesla P100-PCIE-16GB computeCapability: 6.0
coreClock: 1.3285GHz coreCount: 56 deviceMemorySize: 15.90GiB deviceMemoryBandwidth: 681.88GiB/s
2021-05-01 10:32:35.007719: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-05-01 10:32:35.007756: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.11
2021-05-01 10:32:35.007781: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.11
2021-05-01 10:32:35.007803: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10
2021-05-01 10:32:35.007839: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10
2021-05-01 10:32:35.007859: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10
2021-05-01 10:32:35.007881: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.11
2021-05-01 10:32:35.007903: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8
2021-05-01 10:32:35.007991: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-01 10:32:35.008575: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-01 10:32:35.009095: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0
2021-05-01 10:32:35.009140: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-05-01 10:32:35.503454: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1261] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-05-01 10:32:35.503505: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1267] 0
2021-05-01 10:32:35.503515: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1280] 0: N
2021-05-01 10:32:35.503690: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-01 10:32:35.504369: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-01 10:32:35.504897: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-01 10:32:35.505452: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1406] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 14975 MB memory) -> physical GPU (device: 0, name: Tesla P100-PCIE-16GB, pci bus id: 0000:00:04.0, compute capability: 6.0)
True: False
2021-05-01 10:32:35.506749: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-05-01 10:32:35.506845: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-01 10:32:35.507388: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties:
pciBusID: 0000:00:04.0 name: Tesla P100-PCIE-16GB computeCapability: 6.0
coreClock: 1.3285GHz coreCount: 56 deviceMemorySize: 15.90GiB deviceMemoryBandwidth: 681.88GiB/s
2021-05-01 10:32:35.507418: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-05-01 10:32:35.507459: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.11
2021-05-01 10:32:35.507472: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.11
2021-05-01 10:32:35.507485: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10
2021-05-01 10:32:35.507497: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10
2021-05-01 10:32:35.507512: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10
2021-05-01 10:32:35.507524: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.11
2021-05-01 10:32:35.507536: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8
2021-05-01 10:32:35.507582: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-01 10:32:35.508113: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-01 10:32:35.508604: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0
2021-05-01 10:32:35.508630: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1261] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-05-01 10:32:35.508640: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1267] 0
2021-05-01 10:32:35.508647: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1280] 0: N
2021-05-01 10:32:35.508710: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-01 10:32:35.509240: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-05-01 10:32:35.509738: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1406] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 14975 MB memory) -> physical GPU (device: 0, name: Tesla P100-PCIE-16GB, pci bus id: 0000:00:04.0, compute capability: 6.0)
Current threshold: 0.5
2021-05-01 10:32:50.238825: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization passes are enabled (registered 2)
2021-05-01 10:32:50.290412: I tensorflow/core/platform/profile_utils/cpu_utils.cc:112] CPU Frequency: 2199995000 Hz
2021-05-01 10:32:50.932916: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8
2021-05-01 10:32:51.960900: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.11
2021-05-01 10:32:52.189146: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.11
FPS: 0.41
FPS: 23.86
FPS: 23.61
FPS: 24.18
FPS: 23.84
FPS: 23.82
FPS: 24.36
FPS: 23.82
FPS: 24.10
FPS: 24.39
FPS: 24.17
FPS: 24.09
FPS: 24.54
FPS: 23.93
FPS: 23.35
FPS: 24.02
FPS: 24.11
FPS: 24.48
FPS: 24.10
FPS: 24.29
FPS: 24.46
FPS: 24.48
FPS: 23.62
FPS: 23.79
FPS: 23.76
FPS: 24.01
FPS: 24.43
FPS: 23.52
FPS: 24.46
FPS: 24.13
FPS: 24.11
FPS: 23.79
FPS: 24.62
FPS: 24.32
FPS: 24.06
FPS: 24.51
FPS: 24.46
FPS: 24.40
FPS: 24.48
FPS: 24.62
Video end

At first i assume that my GPU is not strong enough ( GTX 1050 mobile), but it happens even when running on colab pro with Tesla V100
I appreciate any helps.

won't work saving custom weights to saved_model.pb

tried with cpu & gpu tensorflow

python3 save_model.py --weights ./data/custom.weights --output ./checkpoints/custom-416 --input_size 416 --model yolov4 
2020-11-15 10:47:19.227868: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
2020-11-15 10:47:20.467105: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcuda.so.1
2020-11-15 10:47:21.073388: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:982] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-11-15 10:47:21.074016: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties: 
pciBusID: 0000:00:04.0 name: Tesla V100-SXM2-16GB computeCapability: 7.0
coreClock: 1.53GHz coreCount: 80 deviceMemorySize: 15.75GiB deviceMemoryBandwidth: 836.37GiB/s
2020-11-15 10:47:21.074059: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
2020-11-15 10:47:21.076255: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcublas.so.10
2020-11-15 10:47:21.078071: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcufft.so.10
2020-11-15 10:47:21.078490: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcurand.so.10
2020-11-15 10:47:21.080445: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcusolver.so.10
2020-11-15 10:47:21.082111: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcusparse.so.10
2020-11-15 10:47:21.082262: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudnn.so.7'; dlerror: libcudnn.so.7: cannot open shared object file: No such file or directory
2020-11-15 10:47:21.082281: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1753] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2020-11-15 10:47:21.082669: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-11-15 10:47:21.091500: I tensorflow/core/platform/profile_utils/cpu_utils.cc:104] CPU Frequency: 2300000000 Hz
2020-11-15 10:47:21.092099: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x6544520 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-11-15 10:47:21.092130: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-11-15 10:47:21.094041: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-11-15 10:47:21.094074: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]      
Traceback (most recent call last):
 File "save_model.py", line 58, in <module>
   app.run(main)
 File "/home/ubuntu/.local/lib/python3.5/site-packages/absl/app.py", line 303, in run
   _run_main(main, args)
 File "/home/ubuntu/.local/lib/python3.5/site-packages/absl/app.py", line 251, in _run_main
   sys.exit(main(argv))
 File "save_model.py", line 54, in main
   save_tf()
 File "save_model.py", line 49, in save_tf
   utils.load_weights(model, FLAGS.weights, FLAGS.model, FLAGS.tiny)
 File "/home/ubuntu/yolov4-custom-functions/core/utils.py", line 143, in load_weights
   conv_weights = conv_weights.reshape(conv_shape).transpose([2, 3, 1, 0])
ValueError: cannot reshape array of size 4554552 into shape (1024,512,3,3)

Getting a constant ValueError

i have made the already necessary changes but every time I try
!python save_model.py --weights /content/drive/MyDrive/yolov4/tensorflow-yolov4-tflite-master/data/custom.weights --output ./checkpoints/custom-416 --input_size 416 --model yolov4

I get a value error as:
File "save_model.py", line 49, in save_tf
utils.load_weights(model, FLAGS.weights, FLAGS.model, FLAGS.tiny)
File "/content/drive/MyDrive/yolov4/tensorflow-yolov4-tflite-master/core/utils.py", line 63, in load_weights
conv_weights = conv_weights.reshape(conv_shape).transpose([2, 3, 1, 0])
ValueError: cannot reshape array of size 173840 into shape (256,128,3,3)

can anyone please suggest a solution to this?

Need help!!

Can you guide me below:

  1. Add a unique id for each person detected and boxed.
  2. Generate Json file to capture per frame detection result
  3. Add trajectory for each object tracked.

ocr not working

pytesseract is not working well on my number plates which is indonesian number plates could you suggest me other ocr methods that works on these type of number plates.

How can I can add another label in box?

how can I add another label in box for example, the left side is the label is truck ,dog, and bicycle but for the right side i want to be like a timer object detected or bike 1, dog 1, bicycle 1, if more than 1 then it would be bike 2, dog 2, bicycle 2

obj

Yolo v4 Python has stopped working in CPU mode

when i enter "conda activate yolov4",then after that when i run this command "python save_model.py --weights ./data/custom.weights --output ./checkpoints/custom-416 --input_size 416 --model yolov4 " it shows a pop up like - Python has stopped working.....please help me out

Does not return the plate number

Hi
I am having a problem with the return of the plate.
I can detect it but it doesn't return the plate number.
I'm using the command: python detect.py --weights ./checkpoints/custom-416 --size 416 --model yolov4 --images ./data/images/car.jpg --plate

image

Can you help me?

In need of urgent help please! Tell me how to fix this error

Traceback (most recent call last):
File "save_model.py", line 58, in
app.run(main)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\absl\app.py", line 303, in run
_run_main(main, argv)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\absl\app.py", line 251, in _run_main
sys.exit(main(argv))
File "save_model.py", line 54, in main
save_tf()
File "save_model.py", line 49, in save_tf
utils.load_weights(model, FLAGS.weights, FLAGS.model, FLAGS.tiny)
File "C:\Repos\yolov4-custom-functions\core\utils.py", line 143, in load_weights
conv_weights = conv_weights.reshape(conv_shape).transpose([2, 3, 1, 0])
ValueError: cannot reshape array of size 4554552 into shape (1024,512,3,3)

issues with detect_video.py on colab

Hey,

Thank you for another amazing tutorial/repo.

There seems to be a few issues for running some of the functions on colab.

Converting to TFLite works for detect.py.

But, for videos, the classifications and detections are way off. For example, in people videos, no people are being detected, instead, elephants and zebras are detected with high confidence. In car videos, no cars are detected.
Restricting the classification to allowed classes (people and cars) doesn't work either, as nothing gets detected anymore.

Ran into errors of "cannot connect to server X"
To bypass error, commented the following in detect_video.py
"#cv2.namedWindow()
#cv2.destroyAllWindows()

reproduce issue:
Colab

!git clone "https://github.com/theAIGuysCode/yolov4-custom-functions.git"
!pip3 install -r /content/yolov4-custom-functions/requirements-gpu.txt

Convert darknet weights to tensorflow

The weights folder is on my google drive.

%cd /content/yolov4-custom-functions
!ls
# convert the model from yolov4 to tensorflow then TFLite
# Save tf model for tflite converting
!python3 /content/yolov4-custom-functions/save_model.py --weights /content/drive/MyDrive/object_counting_yolov4/pre-trained_weights/yolov4.weights --output ./checkpoints/yolov4-416 --input_size 416 --model yolov4 --framework tflite

# yolov4
!python3 /content/yolov4-custom-functions/convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416.tflite

# yolov4 quantize float16
#!python3 /content/yolov4-custom-functions/convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-fp16.tflite --quantize_mode float16

# yolov4 quantize int8 - for whatever reason the /coco_dataset/coco/val207.txt is missing. RPi is a float based anyways.
#!python3 /content/yolov4-custom-functions/convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-int8.tflite --quantize_mode int8 --dataset ./coco_dataset/coco/val207.txt

# to change the count from total number of objects to number of objects per class:
# change 
#if FLAGS.count:
# by_class = True

# Run tflite model
!python3 detect.py --weights ./checkpoints/yolov4-416.tflite --size 416 --model yolov4 --images ./data/images/dog.jpg --framework tflite --count

Number of bicycles: 1
Number of dogs: 1
Number of trucks: 1

Testing on another image

# Run tflite model
!python3 detect.py --weights ./checkpoints/yolov4-416.tflite --size 416 --model yolov4 --images ./data/images/kite.jpg --framework tflite --count

Number of persons: 7
Number of kites: 6

# Run yolov4 on video
# similarly, change total count type from total number to total count per class
# by changing
#if FLAGS.count:
# by_class = True  
!python3 detect_video.py --weights ./checkpoints/yolov4-416 --model yolov4 --video ./data/video/cars.mp4 --output ./detections/results.avi --dont_show --framework tf --info

# more details for each detection, inlcuding confidence, BBox coordinates: --info    instead of    --count  

# Run yolov4 on webcam
# !python3 detect_video.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --video 0 --output ./detections/results.avi

custom.weights and custom-416

Hello, please help
So
python save_model.py --weights ./data/custom.weights --output ./checkpoints/custom-416 --input_size 416 --model yolov4

I get error
File "C:\Users\va\Documents\Arduino\yolov4-custom-functions-master\core\utils.py", line 143, in load_weights conv_weights = conv_weights.reshape(conv_shape).transpose([2, 3, 1, 0]) ValueError: cannot reshape array of size 4554552 into shape (1024,512,3,3)
Where custom.names file?

Please help

The variable timed the object to appear in the frame, any advice is useful to me!

Thank you for your enthusiasm and dedicated guidance, I am a newbie and have learned a lot from you.
Thank you so much!

And now I'm trying to customize some of the flags, which timed the object's appearance in the video. For example, the parking time of each car in the parking lot.

I look forward to receiving your great help. Once again, thanks very much!

run detection on multiple images at once

Hi, I very much appreciate the work you've done here.
I was wondering if there's a way to edit the code so that I can run detection on multiple images and save results in a text file. The results being the coordinates and the image name. (Trying to create more training data for a larger dataset)

Functionality of integrating license_plate_recognizer automatically after crop

Hey Mate,

like a lot of other people here and at our YT channel I can just tell the same and am really grateful for your effort and coding skills.

I just wanted to know, if you already wrote the connection/ functionality mentioned above?

It's the one you quoted it here:
"However, I believe the best route to go is to run video detections without the plate flag and instead run them with --crop flag which crops the objects found on screen and saves them as new images. See how it works here Once the video is done processing at a higher FPS all the license plate images will be cropped and saved within detections/crop folder. I have added an easy script within the repository called license_plate_recognizer.py that you can run in order to recognize license plates. Plus this allows you to easily customize the script to further enhance any recognitions. I will be working on linking this functionality automatically in future commits to the repository."

If yes, i'd be grateful for it, otherwise I try to code it by my own :)

thanks again and stay healthy mate!

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.