SUGISAKAMASANORI

Journal of Advances in Artificial Life Robotics
Vol. 4(3); December (2023), pp. 138–141
ON LINE ISSN 2435-8061; ISSN-L 2435-8061
https://alife-robotics.org/jallr.html

Research Article

Detecting small sample objects with improved YOLOv5
Yuxuan Gao1, Jiwu Wang1, Zixin Li2

School of Mechanical and Electronic Engineering, Beijing Jiaotong University, Beijing, Haidian District, China
Aero Engine Corporation of China, Beijing, Changping District, China

12

ARTICLE INFO
Article History
Received December 18, 2022
Accepted 28 March 2024
Keywords
YOLOv5
Deep learning
Object detection
Few-shot learning

ABSTRACT

Object detection is widely used in various production and life, such as mask detection andrecognition during epidemics, masked face recognition, etc., but object detection algorithms basedon deep learning have always been an important research topic in the object detection field. It is
an implementation method. Due to the large number of lead seals and fuses, their positions are
not fixed, the sample data set is small, the target background is complex and easily occluded, andthere are strong reflection interferences, which pose problems with conventional image processing
methods. Effectively solving object recognition problems is difficult. In this study, by expanding
the dataset, using various data enrichment methods, and training with improved algorithms, thedetection accuracy, detection speed, and adaptability were effectively improved.

© 2022 The Author. Published by Sugisaka Masanori at ALife Robotics Corporation Ltd.
This is an open access article distributed under the CC BY-NC 4.0 license(http://creativecommons.org/licenses/by-nc/4.0/)

labor-intensive, and can lead to omissions andmislabeling issues.

1. Introduction

In this study, we used various image processing
methods, further expanded the original dataset, and usedother data as well, and automatic annotation of the dataset
was performed through code. Therefore, the accuracy of
the annotation was guaranteed and the detection accuracy
improved as a result of training with his improved
YOLOv5 network.

Visual inspection is important to provide basic support
for realizing automation and promote the development ofindustrial automation [1]. Although feature-based visualdetection methods are widely used in industrial
inspection, this traditional detection method relies on
manually designed feature extractors based on experienceand is therefore sensitive to changes in target morphology
and interference. Detection accuracy decreases
significantly when faced with this problem. With thedevelopment of machine vision and artificial intelligence
technology, deep learning has become a new paradigm
for object detection tasks in the industrial field [2].
However, deep learning relies on large amounts oflabeled sample data during the training stage, which has
drawbacks in real-world application scenarios. In
factories, due to the problem of only one model, it may
not be possible to obtain sufficient sample data [3]. In thiscase, the limited number of labeled samples may lead tosevere overfitting of the deep learning model and reduced
recognition accuracy. Furthermore, even when there is asufficient dataset, data labeling is time-consuming and2. Methodology
2.1. Yolov5 algorithm
The core idea of YOLOv5 algorithm is to treat theobject detection task as a regression problem and segment
the feature map into L×L sized cells, M bounding boxes
are set for each cell to surround the target. Each cell is
responsible for detecting targets that fall within its area.
In one operation, the bounding boxes, localization
confidence, and probability of each category of targets
contained in all cells are predicted. Then, the detectedbounding boxes are filtered using NMS (Non MaximumSuppression) method to obtain the position, category, andconfidence of the target to be tested.

Corresponding author’s E-mail: jwwang@bjtu.edu.cn, 18815511536@163.com, 15311426793@163.com, URL: www.bjtu.edu.cn

138

Where, H and W represent the height and width of thefeature map, and xc represents the input at each channel.
Then the second step is the excitation operation, whichuses the small network of the Fully Connected (FC) layer
to learn the relationship between channels. This network
usually contains two full connected layers. The first fullconnected layer is responsible for mapping the channel
description vector to a low dimensional space, with a
ReLU activation function in the middle, and the second
full connected layer maps it back to the original numberof channels, This process can be regarded as a bottleneckstructure, which aims to extract the dependencies
between channels. The mathematical expression of thisprocess is shown in Eq. (2):(2)
𝑠𝑠 = 𝐹𝐹𝑒𝑒𝑒𝑒 (𝑧𝑧, 𝑊𝑊) = 𝜎𝜎(𝑔𝑔(𝑧𝑧, 𝑊𝑊)) = 𝜎𝜎(𝑊𝑊2 𝜎𝜎(𝑊𝑊1 𝑧𝑧))

The implementation of YOLOv5 algorithm can besummarized as the following steps:(1) Preprocessing. The input image is first preprocessed,including scaling, cropping, and normalization
operations, to convert it into a format suitable for network
input.
(2) Feature extraction. The input image is fed into thebackbone network and the feature is extracted through thebackbone network.
(3) Feature pyramid network. YOLOv5 utilizes Feature
Pyramid Networks (FPN) [4] to fuse feature maps ofdifferent scales, capture targets of different sizes, andimprove detection accuracy.
(4) Predictive header. YOLOv5 uses a prediction headto predict each cell, obtaining bounding boxes (including
the position and size of the target), confidence(probability of target existence), and class probabilities.
(5) Decoding prediction. Decode and convert the outputof the prediction head into actual image coordinates,including adjusting the predicted bounding box to theoriginal image size, and calculating the category andconfidence score of each target.
(6) Non maximum suppression. Use NMS algorithm toremove redundant detection boxes with high overlap, andfinally retain the most likely object detection result.
(7) Post processing. Perform post-processing on thedetection results processed by NMS, including
visualizing and saving the results.
The YOLOv5-7.0 network model structure is shown inFig. 1, which mainly includes Conv, CSPDarkNet, andSPPF modules.

Where, σ Represents the ReLU function, W1 represents
the parameters of the dimension reduction layer, W2
represents the parameters of the dimension increase layer,and z is the output result from the previous compression
step.
The last step is Re-scale, which multiplies thepreviously learned channel weight vector with theoriginal feature map to achieve the function of adaptively
adjusting the feature response of each channel andimprove the performance of the network model. The
network architecture of its algorithm module is shown inFig. 2.
Input
ResidualRe-Scale

C×H×W
Global pooling

C×1×1

Fully connected

C/r ×1×1

ReLU

C/r ×1×1

Fully connected

C×1×1

Sigmoid

C×1×1

C×H×W

OutputFig.2 The diagram of the squeeze-and-excitation block

Fig.1 YOLOv5-7.0 model structure

Adding the SENet attention module to the last layer ofthe Backbone network can effectively reduce the false
detection rate and missing detection rate of lead seals andfuses, and improve the detection accuracy.

2.2. SENetAttention
In order to obtain attention in the channel dimension,
the input characteristic graph is convoluted to obtain thedimension H × W × C, and then compress the input
characteristic graph through global average pooling. Thisstep converts the characteristic graph of each channel into
the scalar of 1 × 1 × C, thus forming a channel description
vector, which captures the global spatial information ofeach channel and corresponds to the initial weight of eachchannel. This step is to compress (squeeze),as shown inEq. (1) [5]:𝐻𝐻𝑊𝑊

1𝑍𝑍𝑐𝑐 = 𝐹𝐹𝑠𝑠𝑠𝑠 (𝑥𝑥𝑐𝑐 ) =� � 𝑥𝑥𝑐𝑐 (𝑖𝑖, 𝑗𝑗)
𝐻𝐻 × 𝑊𝑊𝑖𝑖=1 𝑗𝑗=1

3. Data processing
3.1. image processing
For the image acquisition work of the product object,considering the complex surface structure of the productand the obvious reflective effect of the metal material andpaint surface, the shooting effect is easily affected by thelighting conditions. According to this feature, the productis placed in a variety of lighting conditions, and different
types of camera equipment are used to collect images. At(1)139the same time, local images and unmarked backgroundimages are taken in each lighting environment, in orderto maximize the diversity of target images.Sample isshown in Fig. 3.

a) Low brightness
environmentb) Normal lighting
environment

The new sample image of the original image after image
enhancement is shown in Fig. 5.

c) High brightness
environmenta) Original imageb) New samples 1c) New samples 2d) New samples 3

Fig.3 Shooting in various lighting conditions

Fig.5 New samples after image augmentation

ImgAug is a powerful and flexible image enhancement
library based on Python language, which is mainly usedin the field of deep learning and computer vision. Itsupports a variety of image processing libraries such asOpenCV. By calling ImgAug's API, the image can betransformed in various aspects such as geometry, color,contrast, etc., so as to expand the original image data set
and improve the generalization ability and robustness ofthe model. With the help of its official API document, thecorresponding Python code is written, and the image istransformed as follows. The process can be shown in Fig.
4.

Through the above image enhancement method, each
initial image is expanded to 6 new images, and finally
441 images are obtained as the final data set.
4. Experiment and Comparison
After completing the dataset production and modifying
the YOLOv5 model, conduct training and compare thetraining results of the unimproved model. At the sametime, verify the accuracy of the same image.
Baseline is the yolov5 model without adding SE
attention mechanism, and the training is carried out using
the non-expanded dataset. The dataset is as shown in thefigure. SENet is the yolov5 model with adding SE
attention mechanism, and the training is carried out using
the non-expanded dataset. SENet+dataset is the yolov5
model with adding SE attention mechanism, and thetraining is carried out using the expanded dataset. The
unexpanded dataset has 63 pictures, and the expanded
dataset has 441 pictures, as shown in the following Fig.
6.

Fig.4 Image enhancement process
Write python code to execute the above image
enhancement operation, and realize the automatic
annotation function of new images while realizing
various transformations of images. By reading the XML
annotation file corresponding to the original image, theposition and coordinate information of all the annotation
boxes are extracted, and according to the randomenhancement process of each new image, the codeautomatically calculates and adjusts the information of
the annotation box, thus generating a new XML file thatis completely aligned with the target position in the newimage. This method avoids the tedious work of manual
marking and saves a lot of human resources. By
automatically updating the annotation information, theenhanced image is consistent with the original annotation,
thus improving the accuracy and reliability of the model.

a) Baselineb) Expand the dataset

Fig.6 Image expansion

The key data of the training results are shown in Table
1. Among them, mAP (mean Average Precision) refers to
the average precision, which comprehensively considers
precision and recall to measure the performance of themodel on detecting targets.
140

Table1. Comparison of data under different training
conditions

Baseline
SENet
SENet+ dataset

mAP
（%）
81.4
87.5
96.3

precision
（%）
81.4
89.5
96.9

5. Conclusion
In this study, we improved the YOLOv5 model andexpanded the dataset to improve learning accuracy. The
experimental results showed that this method can meetthe measurement accuracy requirements. Compared withthe unimproved method, the method proposed in thispaper improves the detection accuracy and precision, andthe method allows deep learning-based object detection.
However, the complexity of the algorithm calculation
increases, which increases the execution time. Future
work will need to further improve the speed of thealgorithms to meet the real-time requirements of object
detection.

time（ms）
9.9
9.3
12.3

From the table, it can be seen that compared to thebaseline reference benchmark, the use of SENet attention
mechanism in mAP has improved by 6.1%, and thecombination of SENet and expanded dataset has
improved by 8.2%; In terms of accuracy, compared toBaseline, the use of SENet attention mechanism
improved by 7.9%, and the combination of SENet andexpanded dataset improved by 7.4%.

References
1.

The above data results demonstrate the advantages ofSENet+augmented dataset. The best weight files trainedusing Baseline, SENet, and SENet+augmented dataset
are tested on the images in the test set. The image
detection results are shown in Fig. 7.

2.
3.
4.

5.
a) Baselineb) SENet

Fu Binbin Application and development trend of industrial
machine vision [J] China Industry and Informatization,
2021 (11): 18-24
Guo Jing, Luo Hua, Zhang Tao Machine Vision andApplication [J] Electronic Science and Technology, 2014,
27 (07): 185-188
Xing Z, Chen X. Lightweight algorithm of insulator
identification applicable to electric power engineering[J].
Energy Reports, 2022, 8: 353-362.
Lin T Y, Dollár P, Girshick R, et al. Feature pyramid
networks for object detection[C]//Proceedings of theIEEE conference on computer vision and patternrecognition. 2017: 2117-2125.
Hu J, Shen L, Sun G. Squeeze-and-excitation
networks[C]//Proceedings of the IEEE conference on
computer vision and pattern recognition. 2018: 71327141.

Authors Introduction
Dr. Jiwu Wangc) NSENet+ Expand the dataset

He is an associate professor, Beijing
Jiaotong University. His research interests
are Intelligent Robot, Machine Vision, andImage Processing.

Mr. Yuxuan Gao
He is a postgraduate in Beijing Jiaotong
University. His research interests are deeplearning and yolo

Fig.7 Comparison of detection under different training
conditions
From the figure, it can be seen that the effect issignificantly improved after adding the SENet modulenetwork. However, due to the limited amount of data,
there are still issues of false positives and missed alarms.
After expanding the dataset, it can be clearly observedthat not only is the accuracy further improved, but also
false positives are reduced. In summary, the addition ofSENet attention mechanism and the scalability of thedataset are helpful for model training and improving
detection accuracy.

Ms. Zixin Li141

She is an engineer at Aero Engine
Corporation of China. Her research direction
is 3D reconstruction