yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
Raspberry Pi 4B📖
1.Preparation before use
  • 1.1 Download image
  • 1.2 Write image into SD card
  • 1.3 Start up Raspberry Pi
  • 1.4 Linux common commands
  • 1.5 Precautions
2.Basic course
  • 2.1 Log into Raspberry Pi system
  • 2.2 Change password and root account
  • 2.3 Remote transfer file
  • 2.4 Backup image file
  • 2.5 Fixing Raspberry Pi IP
  • 2.6 Set screen keep on
  • 2.7 Get Pi temperature
  • 2.8 Connect WIFI
  • 2.9 Modify Pi time
  • 2.10 Set the boot self-starting program
3.Expand course
  • 3.1 Serial port communicates with external devices
  • 3.2 2.Serial port login Pi
  • 3.3 Configured as a router
  • 3.4 Install Jupyter Lab
  • 3.5 Install Jupyter Widgets
  • 3.6 More Detail for Widgets
  • 3.7 Install OpenCV
  • 3.8 Install Tensorflow
4.Programming course
C language
  • 1.Development environment
  • 2.Print Hello World
  • 3.Pin output level
  • 4.Read pin level
  • 5.PWM output
Python language
  • 1.Development environment
  • 2.Print basic usage
  • 3.Pin output level
  • 4.Read pin level
  • 5.PWM output
5.AI vision course
A.Getting started with OpenCV
  • 6.Picture Rotation
  • 1.Introduction of OpenCV
  • 2.OpenCV image read and display
  • 3.OpenCV image write
  • 4.OpenCV image quality
  • 5.OpenCV pixel operation
B.OpenCV Geometric transformat
  • 1.Picture Zoom
  • 2.Picture Cut
  • 3.Picture Shift
  • 4.Picture Mirroring
  • 5.Affine Map
  • 7.Perspective Transformation
C.OpenCV picture processing
  • 1.Grayscale processing
  • 2.Image Binarization
  • 3.Edge detection
  • 4.Drawing line segment
  • 5.Drawing rectangle circle
  • 6.Drawing text picture
D.OpenCV image beautification
  • 1.Histogram of color pictures
  • 2.Histogram equalization
  • 3.Image restoration
  • 4.Brightness enhancement
  • 5.Skin whitening
  • 6.Gaussian mean filtering
  • 7.Median filtering
F.AI Advanced Course (Ubuntu system)
  • 1. QR code
  • 2. Human posture estimation
  • 3. Target detection
  • 4. Mediapipe development
  • 5. yolov4-tiny
E.Install TensorFlow
  • Install TensorFlow
6.ROS1 coursenew
Basic Course
  • 1.ROS introduction
  • 2.Project file structure
  • 3.Common commands and tools
  • 4.Publisher
  • 5.Subscribers
  • 6.Customize topic messages and use
  • 7.Client
  • 8.Server
  • 9.Custom service messages and usage
  • 10.TF release and monitoring
Visual Image Processing
  • 1. AR vision
  • 2. AR QR code
  • 3. ROS+Opencv foundation
  • 4. ROS+Opencv application
  • 5. MediaPipe development
7.ROS2 coursenew
Docker Course
  • 1.Overview and installation
  • 2.Common commands
  • 3.Understand and publish images
  • 4.Hardware interaction data processing
  • 5.Enter docker container
  • 6.Update docker images
Basic Course
  • 1.Introduction to ROS2
  • 2.Commands and tools
  • 3.ROS2 Topic communications
  • 4.ROS2 service communications
  • 5.ROS2launch file starts
OpenCV Course
  • 1.OpenCV Basic Course
  • 2.ROS+opencv application
  • 3.QR code recognition
  • 4.AR Vision
  • 5.Mediapipe
8.Accessories installation
  • 1. Installation of heat sink
  • 2. Wiring of cooling fan
  • 3. Double fan armor case Installation
  • 4. Argon NEO aluminum case installation
  • 5. Argon ONE aluminum alloy case installation
  • 6. Metal shell with built-in fan installation
  • 7. Acrylic case with cooling fan installation
  • 8. White-red ABS protective case installation
Download
  • Tools
  • C_code
  • Python code
  • ROS System
Download ZIP

Welcome to Raspberry Pi 4B repository

5. yolov4-tiny

5. yolov4-tiny

5. yolov4-tiny 5.1 Introduction 5.2 Use 5.3 folder structure 5.4 Environmental requirements 5.5 Custom training data set 5.5.1 Making a dataset 5.5.2 Add weight file 5.5.3 Make label file 5.5.4 Modify the train.py file 5.5.5 Model checking

yolov4-tiny official website: https://github.com/AlexeyAB/darknet

Source code: https://github.com/bubbliiiing/yolov4-tiny-tf2

5.1 Introduction

release time point

  • 2020.04: YOLOv4 officially released
  • 2020.06: YOLOv4-Tiny is officially released

The performance of YOLOv4-Tiny on COCO: 40.2% AP50, 371 FPS(GTX 1080 Ti) Whether it is AP or FPS performance, it is a huge improvement compared to YOLOv3-Tiny, Pelee, and CSP, as shown in the figure below :

img

Comparison of YOLOv4 and YOLOv4-Tiny detection results, source network

YOLOv4 detection results

img

Done ! Loaded  162  layers  from  weights - file  
data/dog.jpg :  Predicted  in  27.039000  milli - seconds.
bicycle :  92 % 
dog :  98 % 
truck :  92 % 
pottedplant :  33 % 

YOLOv4-Tiny detection results

img

xxxxxxxxxx
Done ! Loaded  38  layers  from  weights - file  
data/dog.jpg :  Predicted  in  2.609000  milli - seconds.
bicycle :  29 % 
dog :  72 % 
truck :  82 % 
car :  46 % 

We can see that the detection accuracy of Yolov4-tiny has decreased, but Yolov4-tiny has obvious advantages in terms of time consumption: Yolov4-tiny detection takes only 2.6 milliseconds, while Yolov4 detection takes 27 milliseconds, which is faster More than 10 times!

5.2 Use

Raspberry Pi version is supported.

xxxxxxxxxx
roslaunch yahboomcar_yolov4_tiny yolodetect.launch display:=true 
  • [display] parameter: whether to enable the visual interface.

Support real-time monitoring of web pages, such as:

xxxxxxxxxx
192.168.2.89:8080 

View node information

xxxxxxxxxx
rqt_graph 

1364

Print detection information

xxxxxxxxxx
rostopic echo/DetectMsg 

print as follows

xxxxxxxxxx
data :  
  -  
    frame_id :  "person" 
    stamp :  
      secs :  1646128857 
      nsecs :  530594825 
    scores :  0.609634816647 
    ptx :  109.685585022 
    pty :  - 2.94450759888 
    distw : 374.364135742 
    disth : 236.672561646 
    centerx :  187.182067871 
    centery :  118.336280823 
  • frame_id: Identifying name.
  • scores: Identify scores.
  • ptx, pty: the coordinates of the upper left corner of the recognition box.
  • distw, disth: The width and height of the recognition box.
  • centerx, centery: Identify the center.

5.3 folder structure

xxxxxxxxxx
yolov4 - tiny - tf2 
├──  font                                # Store font package 
│    └──  Block_Simplified.TTF 
├──  garbage_data                        # dataset 
│    ├──  GetData.py                      # Get the dataset code 
│    ├──  image                           # target source file 
│    ├──  JPEGImages                      # dataset images(as many as possible) 
│    ├──  texture                         # background image(as many as possible) 
│    └──  train The .txt                       label file corresponding to the dataset image 
├──  img                                 # store the test image 
│    └──  1.j pg 
├──  logs                                # Store the test log and the final training model last1.h5. 
├──  model_data                          # Store the pre-trained model(weight file) 
│    ├──  coco.txt  
│    ──  garbage.h5 
│    ├──  garbage # .txt                     Custom label file(corresponding to the target source file) 
│    ├──  yolo_anchors.txt 
│    ├──  yolov4_tiny_weights_coco.h5     # weights file 
│    └──  yolov4_tiny_weights_voc.h5      # weights file 
├── predict_img .py  # detection Image                      code 
├── predict_video .py  # detection video                    code 
├──  README.md        
├──  train # .py                            training model code 
├──  utils                               # library file 
└──  yolo_nets                           # Network structure library file 

The concept of anchor box was introduced in the YOLO-v2 version, which greatly increased the performance of target detection. The essence of anchor is the reverse of the idea of SPP(spatial pyramid pooling), and what SPP itself does is to combine different sizes The input resize becomes the output of the same size, so the inverse of SPP is to push the output of the same size backward to get the input of different size.

5.4 Environmental requirements

The factory image is already configured, no need to install

xxxxxxxxxx
tensorflow-gpu==2.2.0 
lxml 
matplotlib 
pandas  
Pillow 
scikit-learn 
seaborn 
tqdm 
imgaug 

Installation example

xxxxxxxxxx
pip install imgaug 

5.5 Custom training data set

5.5.1 Making a dataset

Method 1: Take some photos first, use the annotation tool to mark the target on each photo, create a [train.txt] file under the [garbage_data] folder, and write the target information in a specific format.

Method 2: Put background images(as many as possible) in the [garbage_data/texture] folder, modify the [GetData.py] code as required, and execute [GetData.py] to generate a dataset(as many as possible).

The name of the image and the label file should correspond. The label format in the [train.txt] file is as follows:

xxxxxxxxxx
./garbage_data/JPEGImages/0.j, pg, 113, 163 293  #, 298, image, 9 label y  y + w, x + h, 

Take method 2 as an example.

Open the [GetData.py] file

xxxxxxxxxx
sudo vim GetData.py 

Modify the total number of generated datasets and fill in as required. [More], too few datasets will lead to suboptimal training results.

xxxxxxxxxx
img_total = 10000 

Run the [GetData.py] file to get the dataset

xxxxxxxxxx
python GetData.py 

5.5.2 Add weight file

There are good weight files(pre-training model) [yolov4_tiny_weights_coco.h5] and [yolov4_tiny_weights_voc.h5] under the [model_data] file. Choose one of the two, and recommend coco's weight file.

If you need the latest weight file, you can download it by Baidu search.

5.5.3 Make label file

Be careful not to use Chinese labels and no spaces in the folder!

For example: garbage.txt

xxxxxxxxxx
Zip_top_can 
Old_school_bag 
Newspaper 
Book 
Toilet_paper 
 … 

5.5.4 Modify the train.py file

According to your needs, refer to the notes to modify.

xxxxxxxxxx
#tag position 
annotation_path  =  'garbage_data/train.txt' 
# Get the location of classes and anchors 
classes_path  =  'model_data/garbage.txt' 
anchors_path  =  'model_data/yolo_anchors.txt' 
# The location of the pretrained model 
weights_path  =  'model_data/yolov4_tiny_weights_coco.h5' 
# get classes and anchors 
class_names  =  get_classes(classes_path) 
anchors  =  get_anchors(anchors_path) 
# How many classes are there in total 
num_classes  =  len(class_names) 
num_anchors  =  len(anchors) 
# The location where the trained model is saved 
log_dir  =  'logs/' 
# Enter the image size, if the video memory is relatively large, you can use 608x608 
input_shape  =(416, 416) 
# initial eTOCh value 
Init_eTOCh  =  0 
# Freeze training eTOCh values 
Freeze_eTOCh  =  50 
# The size of Batch_size, which indicates how much data is fed each time. If OOM or insufficient video memory, please reduce it. 
batch_size  =  16 
# max learning rate 
learning_rate_base  =  1e-3 
# total eTOCh value 
ETOCh  =  100 

According to the above process, after the operation is completed, you can directly run the [train.py] file for training.

xxxxxxxxxx
python3.7 train.py 

5.5.5 Model checking

  • Modify the yolov4-tiny-tf2/utils/yolo.py file
xxxxxxxxxx
class  YOLO(object): 
    _defaults  = { 
        # For detection, the trained model path. 
        "model_path" :  'model_data/garbage.h5', 
        # yolo's model parameter anchors path 
        "anchors_path" :  'model_data/yolo_anchors.txt', 
        # Custom label file path 
        "classes_path" :  'model_data/garbage.txt', 
        "score"  :  0.5, 
        "iou"  :  0.3, 
        "eager"  :  False, 
        # Use 416x416 by default(image size) 
        "model_image_size"  :(416, 416) 
} 
 … 
# font package path 
self.font_path  =  'font/Block_Simplified.TTF' 
  • Image detection
xxxxxxxxxx
python3.7 predict_img.py 

During this period, you need to manually input the image to be detected, as shown below:

image-20220302102751259

  • Video detection
xxxxxxxxxx
python3.7 predict_video.py 

Mediapipe development
Install TensorFlow

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文