Data-Side Efficiencies for Lightweight Convolutional Neural Networks
We examine how the choice of data-side attributes for two important visual
tasks of image classification and object detection can aid in the choice or
design of lightweight convolutional neural networks. We show by experimentation
how four data attributes - number of classes, object color, image resolution,
and object scale affect neural network model size and efficiency. Intra- and
inter-class similarity metrics, based on metric learning, are defined to guide
the evaluation of these attributes toward achieving lightweight models.
Evaluations made using these metrics are shown to require 30x less computation
than running full inference tests. We provide, as an example, applying the
metrics and methods to choose a lightweight model for a robot path planning
application and achieve computation reduction of 66% and accuracy gain of 3.5%
over the pre-method model.
Bryan Bo Cao, Lawrence O'Gorman, Michael Coss, Shubham Jain
# Data-Side Efficiencies for Lightweight Convolutional Neural Networks

###### Abstract

We examine how the choice of data-side attributes for two important visual tasks of image classification and object detection can aid in the choice or design of lightweight convolutional neural networks. We show by experimentation how four data attributes - number of classes, object color, image resolution, and object scale affect neural network model size and efficiency. Intra- and inter-class similarity metrics, based on metric learning, are defined to guide the evaluation of these attributes toward achieving lightweight models. Evaluations made using these metrics are shown to require \(30\times\) less computation than running full inference tests. We provide, as an example, applying the metrics and methods to choose a lightweight model for a robot path planning application and achieve computation reduction of \(66\%\) and accuracy gain of \(3.5\%\) over the pre-method model.

Efficient Neural Network Convolutional Neural Network Image Classification Object Detection

## 1 Introduction

Traditionally for computer vision applications, an algorithm designer with domain expertise would begin by identifying handcrafted features to help recognize objects of interest. More recently, end-to-end learning (E2E) has supplanted that expert by training a deep neural network to learn important features on its own. Besides the little forethought required about data features, there is usually only basic preprocessing done on the input data; an image is often downsampled and converted to a vector, and an audio signal is often transformed to a spectogram. In this paper, we use the term "data-side" to include operations that are performed on the data before input to the neural network. Our proposal is that a one-time analysis of data-side attributes can aid the design of more efficient convolutional neural networks (CNNs) for the many-times that they are used to perform inferences.

On the data side of the neural network, we examine four independent image attributes and two dependent attributes, the latter which we use as metrics. The independent attributes are **number of classes, object color, image resolution** and **object scale**. The metrics are **intra-** and **inter-class similarity**. Our goal is to optimize the metrics by choice of the independent variables - specifically to maximize intra-class similarity and minimize inter-class similarity - to obtain the most computationally efficient model.

Unlike benchmark competitions such as ImageNet [1], practical applications involve a design stage that can include adjustment of input specifications. In Section 2, we tabulate a selection of applications. The "wildlife" application reduced the number of animal and bird classes from 18 to 6 in the Wildlife Spotter dataset [2]. In the "driving" application [3], the 10 classes of the BDD dataset [4] were reduced to 7 by eliminating the "train" class due to few labeled instances and combining the similar classes of rider, motor, and bike into rider.

The main contributions of this paper are:

1. Four data-side attributes are identified, and experiments are run to show their effects on the computational efficiency of lightweight CNNs.
2. Intra- and inter-class similarity metrics are defined to aid evaluation of the four independent attribute values. Use of these metrics is shown to be about \(30\times\) faster than evaluation by full inference testing.
3. Procedures are described using the similarity metrics to evaluate how changing attribute values can reduce model computation while maintaining accuracy.
4. Starting with the EfficientNet-B0 model, we show how our methods can guide the application designer to smaller "sub-EfficientNets" with greater efficiency and similar or higher accuracy.

We describe related work in Section 2. Each of the attributes is defined in Section 3, procedures are described to apply these toward more efficient models in Section 4, and experimental evidence is shown in Section 5. We conclude in Section 6.

## 2 Related Work

The post-AlexNet [5] era (2012-) of convolutional neural networks brought larger and larger networks with the understanding that a larger model yielded higher accuracy (e.g., VGGNet-16 [6] in 2014 with 144M parameters). But the need for more efficiency, especially for embedded systems [7], encouraged the design of lightweight neural networks [8], such as SqueezeNet [9] in 2017 with 1.2M parameters. Models were reduced in size by such architectures as depthwise separable convolution filters [10]. More efficient handling of data was incorporated by using quantization [11, 12, 13], pruning [14, 15, 16, 17], and data saliency [18]. This model-side efficiency quest is a common research trend where new models are evaluated for general purpose classification and object detection on public benchmarks such as ImageNet [1], COCO [19], and VOC [20]. Orthogonal and complementary to these model-side efficiencies [21, 22, 23], we examine efficiencies that can be gained before the model by understanding and adjusting the data attributes within the confines of the application specifications. Early work [24] optimizes models specialized to the target video only for binary-classification. Our work extends to multi-class classification and object detection.

In Table 1, we list a selection of 9 applications whose data attributes are far less complex than common benchmarks. For these applications, class number is often just 2. The largest number of classes, 7, is for the "driving" [4] application. Compare these with 80 classes for the COCO dataset and 1000 for ImageNet. For 2 applications, color is not used. For the "crowd" application, it is not deemed useful and for the "ship, SAR" application, the input data is inherently not color. The resolution range is not broad in this sampling, likely due to matching image size to model input width. Many papers did not describe the scale range; for these, we approximated from the given information or images in the paper. The broadest scale range (as a fraction of image size) is the "driving" application (\(1/32\) to \(1/2\)), and the narrowest is for the "mammals" application, using aerial image capture, with scale from \(1/30\) to \(1/20\).

We use a measure of class similarity to efficiently examine data attributes, based on neural network metric learning. This term describes the use of learned, low-dimensional representations of discrete variables (images in our case). The distance between two instances in the latent space can be measured by L1 [32], L2, or cosine similarity [33]. Previous studies [34, 35, 36] focus on learning a single similarity latent space. Differences between classification [37] and ranking based losses [38] have been studied in [39]. PAN incorporates attributes to visual similarity learning [40]. In Sections 3.6 and 3.7 we extend this line of research by adapting the metric from [33] to measure intra- and inter-class similarity to serve efficiency purposes.

_In contrast to research to improve model performance on public benchmarks, our goal is to develop an empirical understanding of the effects of these attributes on common CNNs, and from this to provide practical guidelines to obtain lightweight CNNs in real-world scenarios._ Our use of intra- and inter-class similarity metrics enables an efficient

\begin{table}
\begin{tabular}{c c c c c} \hline \hline Application & \(N_{Cl}\) & \(N_{Co}\) & \(R_{E}\) & \(S_{C}\) \\ \hline crowd [25] & 2 & no & \(320\times 240\) & \(1/8\), \(1/2\) \\ ship, SAR [26] & 2 & no & \(416\times 416\) & \(1/20\), \(1/6\) \\ cattle [27] & 2 & yes & \(224\times 224\) & \(1/16\), \(1/2\) \\ hardhat [28] & 2 & yes & \(300\times 300\) & \(1/25\), \(1/2\) \\ wildlife [2] & 6 & yes & \(224\times 224\) & \(1/6\), \(1/2\) \\ PCB defect [29] & 6 & yes & \(640\times 640\) & \(1/30\), \(1/15\) \\ ship [30] & 6 & yes & \(416\times 416\) & \(1/20\), \(1/2\) \\ mammals [31] & 6 & yes & \(2\)k \(\times\) 2k & \(1/30\), \(1/20\) \\ driving [3] & 7 & yes & 608 \(\times\) 608 & \(1/32\), \(1/2\) \\ \hline \hline \end{tabular}
\end{table}
Table 1: Examples of data attributes for object detection applications with attributes: number of classes (\(N_{Cl}\)), color (\(N_{Co}\)), input resolution (\(R_{E}\)), and scale range (\(S_{C}\)) as a fraction of image size.
methodology toward this goal. Practical, low-complexity applications as in Table 1 can benefit from our investigation and method.

## 3 Data Attributes and Metrics

This work is centered on the hypothesis that, the easier the input data is to classify, the more computationally efficient the model can be at a fixed or chosen lower accuracy threshold. In this section, we describe each of the data attributes and their relationships to the hypothesis. We define metrics to obtain the dependent variables. And we describe procedures to adjust the independent variables to obtain metrics that guide the design of an efficient model.

We first introduce the term, Ease of Classification \(EoC\) and hypothesize the following relationship exists with the data-side attributes,

\[\mathrm{EoC}\leftarrow(S_{1},\frac{1}{S_{2}})\leftarrow(\frac{1}{N_{Cl}}, \frac{1}{N_{Co}},\frac{1}{R_{E}},\frac{1}{S_{C}}). \tag{1}\]

The symbol (\(\leftarrow\)) is used to describe the direct relationships in which the left expressions are related to the right. \(EoC\) increases with intra-class similarity \(S_{1}\) and decreases with inter-class similarity \(S_{2}\). The dependent variable \(S_{1}\) is related to the reciprocals of the independent variables, number of classes \(N_{Cl}\), number of color channels \(N_{Co}\), image resolution \(R_{E}\), and object scale \(S_{C}\). The dependent variable \(S_{2}\) is directly related to these independent variables. The model designer follows an approach to adjust these independent variables to obtain similarity measurements that achieve high \(EoC\). Note that we will sometimes simplify \(N_{Cl}\) to \(CL\) for readability in figures.

In Section 5 we perform experiments on a range of values for each attribute to understand how they affect model size and accuracy. However, these experiments cannot be done independently for each attribute because some have dependencies on others. We call these _interdependencies_ because they are 2-way. We discuss interdependencies below for two groups, {\(S_{C}\), \(R_{E}\)} and {\(S_{1}\), \(S_{2}\), \(N_{Cl}\)}.

### Number of Classes, \(N_{Cl}\)

The \(N_{Cl}\) attribute is the number of classes being classified in the dataset. Experimental results with different numbers of classes are shown in Section 5.2. In Section 5.6 we present results of changing the number of classes for a robot path planning application.

### Object Colors, \(N_{Co}\)

The \(N_{Co}\) attribute is the number of color axes, either 1 for grayscale or 3 for tristimulus color models such as RGB (red, green, blue). When the data has a color format, the first layer of the neural model has 3 channels. For grayscale data input, the model has 1 input channel. In Section 5.3, we show the efficiency gain for 1 versus 3 input channels.

### Image Resolution, \(R_{e}\)

Image resolution, measured in pixels, has the most direct relationship to model size and computation. Increasing the image size by a multiple \(m\) (rows \(I_{r}\) to \(m\times I_{r}/2\) and columns \(I_{c}\) to \(m\times I_{c}\)) increases the computation by at least one-to-one. In Figure 1, MobileNet computation increases proportionally to image size. The lower sized EfficientNet-B0 and -B1 models also increase proportionally, but rise faster with larger models B2, B3, and B4.

It is not the case that higher resolution always yields better accuracy. It usually plateaus, and that plateau is different for different classes involved. The objective is to choose the minimum image resolution before which accuracy drops unacceptably. Note that resolution and scale are dependent attributes, and neither can be adjusted without considering the effect on the other. Experimental results with different resolutions are shown in Section 5.5.

### Object Scale, \(S_{c}\)

For a CNN, the image area, or receptive field, of a \(3\times 3\) filter kernel expands as the following sequence for layers \(L=1,2,3,...,L\),

\[3\times 3,7\times 7,15\times 15,\ldots,(2^{L+1}-1)\times(2^{L+1}-1). \tag{2}\]

For object detection, this means that, if the maximum object size in an image is, for example, \(15\times 15\), the network needs at least 3 layers to yield features that convolve with (or overlap) the full size of these objects. In practice, from the
sequence in equation 2 the minimum number of layers can be found from the maximum sidelength \(b_{max}\) of bounding boxes of objects over all image instances,

\[L\geq\lceil\log_{2}(b_{max}+1)\rceil-1. \tag{3}\]

where \(\lceil x\rceil\) is a ceiling operator, which rounds the \(x\) value to the higher integer. For example, if \(b_{max}\) is 250, the minimum number of layers needed is \(\lceil 7.966\rceil-1=7\).

In practice, the maximum object size is approximated as the longer sidelength of the bounding box of the object. In terms of model size and minimizing computation, by measuring the bounding box size of objects in a dataset, one can discover the maximum number of layers needed for full-object feature extraction. Furthermore, using filter kernels that are larger than the maximum object size increases extractions of inter-object features. When generalized to a sequence of rectangular filters, these tend toward Gaussian filters with increasing convolution layers, so the filter edge versus middle magnitude lowers as well.

To decouple scale from resolution, we define the scale of an object as a fraction of the longer image dimension. With this definition, one can measure the scale of an object in an image without knowing the resolution. The _size_ of the object is measured in pixels; it is the product of scale times the longer dimension of the resolution. Figure 2 shows the range of scales for objects in the COCO dataset. Although 50% of instances account for \(\leq 10\%\) of image size, still the sizes range from very small to full image size. Conversely, in many applications, scale range is known and much more contained as for some applications in Table 1. Experimental results with different scales are shown in Section 5.5.

### Resolution and Scale Interdependency

The interdependence between the attributes {\(S_{C}\), \(R_{E}\) } is common to any image processing application, and can be described by two cases. For case 1, if the scale of objects within a class in an image is large enough to reduce the image size and still recognize the objects with high accuracy, then there is a resulting benefit of lower computation. However, reducing the image size also reduces resolution, and if there is another class that depends upon a high spatial frequency

Figure 1: As the input image size is increased, the computation for the smaller MobileNet models increase at a similar rate. For the larger EfficientNet models (only up to EfficientNet-B4 are shown for clarity of display), the computation increases at a higher rate.

Figure 2: Histogram of bounding box sizes in COCO training dataset highly skewed at small sizes \(<0.2\).
feature such as texture, then reducing the image would reduce overall accuracy. For case 2, if resolution of the highest frequency features of a class is more than adequate to support image reduction, then computational efficiency can be gained by reducing the image size. However, because that reduction also reduces scale, classes that are differentiated by scale will become more similar, and this situation may cause lower accuracy. We can write these relationships as follows,

\[(S_{C}\;\propto\;R_{E})\;\rightarrow\;\frac{1}{\mathrm{EoC}}, \tag{4}\]

where the expression within parentheses is commutative (a change in \(S_{C}\) will cause a proportional change in \(R_{E}\), and vice versa), and these are inversely related to \(EoC\).

### Intra-Class Similarity, \(S_{1}\)

Intra-class similarity is a measure of visual similarity between members of the same class as measured with vectors in the embedding space of a deep neural network. It is described by the average and variance of pairwise similarities of instances in the class,

\[S_{1}(C_{1})=\frac{1}{N}\sum_{i,j\in C_{1}}\cos(\mathbf{Z}_{i}\mathbf{Z}_{j}), \tag{5}\]

\[\sigma_{S1}^{2}(C_{1})=\frac{1}{N}\sum_{i,j\in C_{1}}(S_{ij}-S_{1})^{2}, \tag{6}\]

where \(C_{1}\) is a class containing a set of instances, \(i\) and \(j\) are indices in set \(C_{1}\), \(i\neq j\), and \(N\) is the total number of similarity pairs \(S_{ij}\) of two different instances in the class. \(\mathbf{Z}\) is the latent vector in the embedding space from a neural network trained by metric learning on instances of the class as well as other classes. (That is, it is the same model trained on the same instances as for inter-class similarity.) This metric is adapted from [33]. We show the use of \(S_{1}\) and \(\sigma_{S1}^{2}\) in Section 4.1.

### Inter-Class Similarity, \(S_{2}\)

Inter-class similarity is a measure of visual similarity between classes as determined by the closeness of instances of two classes in the embedding space of a deep neural network. For 2 classes, it is defined as the average of pairwise similarities of instances between classes,

\[S_{2}(C_{1},C_{2})=\frac{1}{N}\sum_{i\in C_{1},j\in C_{2}}\cos(\mathbf{Z}_{i} \mathbf{Z}_{j}), \tag{7}\]

where \(C_{1}\) and \(C_{2}\) are instance sets of two different classes, \(i\) and \(j\) are indices in sets \(C_{1}\) and \(C_{2}\) respectively, \(N\) is the total number of pairs of two instances in two different classes, and \(\mathbf{Z}\) is the latent vector in the embedding space from a neural network trained by metric learning on instances that include both classes as well as other classes if there are more than 2.

For an application involving more than two classes, we choose the inter-class similarity measure to be the maximum of inter-class similarity measures over all class pairs,

\[\hat{S_{2}}(\{C_{K}\})=\max\{S_{2}(C_{m},C_{n})\}, \tag{8}\]

where \(\{C_{K}\}\) is the set of all classes for \(0<=k<K\), and \(\{(C_{m},C_{n})\}\) is all class pairs for \(0<=m,n<K\), \(m\neq n\). We choose the maximum of similarity results of class pairs because maximum similarity represents the worst case - most difficult to distinguish - between two classes. Alternatively, one could calculate the average of inter-class similarities for each pair, however the operation of averaging will hide the effect of one pair of very similar classes among other dissimilar classes, and this effect is worse for larger \(N_{Cl}\). We show the use of \(\hat{S_{2}}\) in Section 4.2.

We also use a measure that is the normalized difference between the maximum and the average,

\[\Delta S_{2}(\{C_{K}\})=\frac{\hat{S_{2}}-S_{2}}{S_{2}}. \tag{9}\]

A larger \(\Delta S_{2}\) indicates a higher value of worst case \(\hat{S_{2}}\), so we seek low \(\Delta S_{2}\) in the methods described in Sections 4.1 and 4.3.
### Intra- and Inter-Class Interdependency

There is a strong interdependence between \(S_{1}\) and \(S_{2}\) with a secondary dependence upon \(N_{Cl}\), as we will describe. With other factors fixed, smaller intra-class similarity increases inter-class similarity because more heterogeneous classes with wider attribute ranges are being compared, thus reducing \(EoC\). As \(N_{Cl}\) is increased, this effect is exacerbated because there is higher probability of low \(S_{1}\) and high \(S_{2}\) pairs, and (similarly) because we use worst-case maximum in equation 8. We can write these dependent relationships as follows,

\[(S_{1}\propto 1/S_{2})\,\rightarrow\mathrm{EoC}\,,\,\mathrm{for}N_{Cl}\geq 2, \tag{10}\]

where the expression within brackets is commutative (either \(S_{1}\) or \(S_{2}\) can cause inverse change in the other, and the relationship becomes stronger as \(N_{Cl}\) increases.

## 4 Method

The general approach toward finding the most efficient model is to select ranges of the independent attribute values [\(N_{Cl}\), \(N_{Co}\), \(R_{E}\), \(S_{C}\)], calculate the similarity measures {\(S_{1}\), \(S_{2}\)} for selected values in the range, and choose those independent attribute values that minimize \(S_{2}\) and maximize \(S_{1}\). Step-by-step procedures for selecting each of the independent attributes are described below. These procedures should be followed in the order of the sections below.

### Selection of \(N_{Cl}\)

If the application permits adjustment of the number of classes, then the following procedure can help finding class groupings and an associated \(N_{Cl}\) that supports a more efficient model. Initialize \(\Delta S_{2}=\infty\), and follow these steps,

1. Choose class groupings.
2. Calculate \(\Delta S_{2}\) from equation 9. If this is less than the current smallest \(\Delta S_{2}\) then this grouping is the most efficient so far.
3. If \(\Delta S_{2}\) is low, one can choose to exit, or continue.
4. If one decides to continue, calculate \(\hat{S_{1}}\) from equation 5 and \(\sigma_{S1}^{2}\) from equation 6 for each class. The value of \(S_{1}\) is for guidance to help understand why the current \(S_{2}\) is good or bad (low or high) to give guidance on choosing the next groupings. In general, class grouping with high \(S_{1}\) and low \(\sigma_{S1}^{2}\) will yield higher accuracy. Repeat these steps.

We want to stop when inter-class similarity is low, indicated by a low value of \(\Delta S_{2}\). However there is subjectivity in this step due to the manual choice of groupings and because different applications will have different levels of intra-class homogeneity and inter-class distinguishability. In practice, the procedure is usually run for a few iterations to understand relative \(\Delta S_{2}\) values for different groupings, and the lowest is chosen.

### Selection of \(N_{Co}\)

The application can gain computational advantage if _all_ classes can be reduced to grayscale; if all classes cannot be reduced, then the model must handle color and there is no computational advantage. Following are the steps to choose grayscale or color,

1. For all classes in color and grayscale, calculate \(\hat{S_{2}}\).
2. If \(\hat{S_{2}}\) for grayscale is less than or equal to \(\hat{S_{2}}\) for color, choose a grayscale model and grayscale for all instances of all classes.

If the procedure above does not result in the choice of grayscale, there is a second option. This requires more testing and does not directly yield computation reduction, but may improve accuracy.

1. For each class, calculate \(\hat{S_{2}}\) against every other class for these four combinations of the \((C_{1},C_{2})\) pairs: (grayscale, grayscale), (grayscale, color), (color, grayscale), and (color, color).
2. For each class \(C_{1}\) whose \(\hat{S_{2}}\) for (grayscale, grayscale) and (grayscale, color) is smaller than for (color, grayscale) and (color, color), choose to use grayscale for the \(C_{1}\) class.

### Selection of \(R_{e}\) and \(S_{c}\)

We first adjust the attribute \(R_{E}\) to find the lower bound of resolution with respect to acceptable accuracy. Initialize \(\Delta S_{2}=\infty\), and follow these steps,
Calculate \(\Delta S_{2}\) from equation 9. If this is less than the current smallest \(\Delta S_{2}\) then this resolution is the most efficient so far.
* If \(\Delta S_{2}\) is low, one can choose to exit, or continue.
* Reduce the resolution by half and repeat these steps.

In practice, a few iterations is run to see when \(\Delta S_{2}\) rises, then choose the resolution where it is lowest.

After the resolution has been chosen, maximum object scale is multiplied by resolution to find the maximum object size in pixels. Equation 3 is used to find an estimate of the lower bound of number of layers needed in the model.

## 5 Experiments

In this section, we perform experiments on the data attributes to show how their values relate to model efficiency and accuracy. Note that our level of experimentation is not even across all attributes. We believe that the experiments upon number of classes, intra- and inter-class similarities, and resolution are sufficient to support the Ease of Classification relationship of equation 1. For color, we give a quantitative comparison of color versus grayscale computation, and then because the difference is small, leave further investigation of accuracy and efficiency to cited literature. For scale, one aspect of this attribute is covered by its interdependency in the resolution experiments. However another aspect, the relationship of scale to model levels (equation 2), we leave to future work. This is because scale is less easily separated from particular applications - specifically the size range of objects in an application - than for other attributes. Our plan is to investigate this in a more application-oriented paper in the future.

### Similarity Metric Efficiency

We could discover the effects of data attributes by training and inference testing all combinations of attribute values. For \(N_{CL}\) classes, binary classification of pairs would require \(\binom{N_{CL}}{2}\) training and inference operations. In comparison, for similarity metrics, we need to train once for all combinations of binary classifications. During testing, the similarity model (SM) caches the latent space, thus only indices of each instance need to be paired with other instances to obtain their cosine similarities.

For the CIFAR10 dataset for example, there is a one-time task of feeding all test images into SM, which takes 0.72 seconds, and then caching, which takes 0.63 seconds. In contrast, we feed each image into the CNN to obtain its prediction in order to calculate its accuracy in the conventional pipeline. We show the runtime in Table 2.

### Number of Classes, \(N_{Cl}\)

It is well known that accuracy is reduced when more classes are involved since more visual features are needed for a CNN to learn in the feature extractor backbone, as well as more complex decision boundary to learn in the fully connected layers for classification. However, we perform experiments here, first to confirm this relationship with test data, but secondly to gain any extra insight into the relationship between number of classes and accuracy.

We performed three sets of experiments. The first was for object detection using the YOLOv5-nano [22] backbone upon increasing-size class groupings of the COCO dataset [19]. Ten groups with \(Cl\) of \(\{1,2,3,4,5,10,20,40,60,80\}\) were prepared. For each group, we trained a separate YOLOv5-nano model from scratch. As seen in Figure 3 (left), accuracy decreases with number of classes. An added insight is that the accuracy decrease is steep for very few classes, say 5-10 or fewer, and flattens beyond 10.

The second set of experiments was for image classification on the CIFAR-10 dataset. With many fewer classes in CIFAR-10 [41] than COCO (10 versus 80), we expect to see how the number of classes and accuracy relate for this smaller range. We extracted subsets of classes -- which we call groups - from CIFAR-10 with \(N_{Cl}\) ranging from 2 to 9.

\begin{table}
\begin{tabular}{l l l} \hline \hline Model & \(t_{train}\) & \(t_{test}\) \\  & (s/epoch) & (s/pair) \\ \hline VGG19 & 0.69 & 4.49 \\ EfficientNet-B0 & 3.13 & 21.82 \\ MobileNetV2 & 2.19 & 15.05 \\
**Similarity Metrics** & 3.31 & **0.76** \\ \hline \hline \end{tabular}
\end{table}
Table 2: Results of runtime comparison of Similarity Metrics and existing models. s: second, pair: all pair of instances in two classes.
For example, a group with \(N_{Cl}=4\) might contain airplane, cat, automobile, and ship classes. We trained classifiers from scratch for each group.

Results of the image classification experiments are shown in Figure 3 (middle). The three classifiers used for testing, EfficientNet-B0, VGG19 [6], and MobileNetV2 [42] showed the expected trend of accuracy reduction as \(N_{Cl}\) per group increased. However, the trend was not as monotonic as might be expected. We hypothesized that this might be due to the composition of each group, specifically if the group classes were largely similar or dissimilar. This insight led to the experiments on class similarity in the next section.

The third set of experiments involved reducing model size for different numbers of classes. We prepared 90 class groupings extracted from the COCO minitrain dataset [43]. There are 80 datasets for \(N_{Cl}=1\), each containing a single class from 80 classes. There are 8 datasets for \(N_{Cl}=10\) combining the 8 single-class datasets. The final dataset is the original COCO minitrain with \(N_{Cl}=80\).

We scale YOLOv5 layers and channels with the depth and width multiples already used for scaling the family between nano and x-large. Starting with depth and width multiples of 0.33 and 0.25 for YOLOv5-nano, we reduce these in step sizes of 0.04 for depth and 0.03 for width. In this way, we design a monotonically decreasing sequence of sub-YOLO models denoted as SY1 to SY8. We train each model separately for each of the six datasets.

Results of sub-YOLO detection are shown in Figure 3 (right). There are three lines where each point of \(mAP@.5\) is averaged across all models in all datasets for a specific \(N_{Cl}\). An overall trend is observed that fewer-class models (upper-left blue star) achieve higher efficiency than many-class models. Another finding of interest here is that, whereas the accuracies for 80 classes drops steadily from the YOLOv5-nano size, accuracy for 10 classes is fairly flat down to SY2, which corresponds to a 36% computation reduction, and for 1 class down to SY4, which corresponds to a 72% computation reduction.

### Color, \(N_{Co}\)

Because reduction from color to grayscale only affects the number of multiplies in the first layer, the efficiency gain depends upon the model size. For a large model such as VGG-19, percentage efficiency gain will be much smaller than for a small model such as EfficientNet-B0, as shown in Table 3. However, even for small networks, the effect of reducing from color to grayscale processing is small relative to effects of other attributes, so we perform experiments on these more impactful attributes. For further investigation of color computation, refer to previous work on this topic [44].

\begin{table}
\begin{tabular}{l|c|c|c|c|c} \hline \hline Model & \multicolumn{2}{c|}{Layer-1} & \multicolumn{2}{c|}{All Layers} & Ratio \\ \cline{2-5}  & color & gray & color & gray & [\%] \\ \hline VGG-19 & 1835.01 & 655.36 & 399474 & 398295 & 99.7 \\ EN-B0 & 884.7 & 294.9 & 31431 & 30841 & 98.1 \\ \hline \hline \end{tabular}
\end{table}
Table 3: Difference between color and grayscale computation [kFLOPS] for the large VGG-19 classifier and much smaller EfficientNet-B0 classifier. Ratio is grayscale-to-color computation for all layers.

Figure 3: Overall relationship of performance and \(N_{CL}\). (Left) Object detection accuracy and recall (R) decrease for the YOLOv5-nano when the number of classes is increased from 1 to 80. (Middle) CIFAR-10 Image classification accuracy decreases for the classifiers tested when the number of classes per group is increased from 2 to 10. (Right) Accuracy plot for increasingly smaller models from YOLOv5-nano through 8 sub-YOLO models (SY1-8) and class groupings of 1 (\(N_{CL}\):1), 10 (\(N_{CL}\):10), and 80 (\(N_{CL}\):80).
### Intra- and Inter-Class Similarity, \(S_{1}\), \(S_{2}\)

In equation 1, we hypothesized that accuracy is lower if inter-class similarity is higher. Table 4 shows accuracy and inter-class similarity results for groups of 2 and 4 classes from the CIFAR-10 dataset that we have subjectively designated similar (S) or dissimilar (D). "S4" indicates a similar group of 4 classes, and "D2" indicates a dissimilar group of 2 classes. The results indicate that our subjective labels correspond to our hypothesis, and that our objective measure of inter-class similarity in equation 7 both corresponds to the subjective, and is consistent with the hypothesis.
### Resolution and Scale, \(R_{e}\) and \(S_{c}\)

In Table 1, the applications often downsize images to much smaller than the originals. Designers of these applications likely determined that accuracy didn't suffer when images were reduced to the degree that they chose. This is also the case for our experiment of YOLOv5 nano on the COCO dataset in Figure 5 (left). One can see that accuracies drop slowly for image reduction from \(640^{2}\) to \(448^{2}\) - and further depending upon the degree of accuracy reduction that can be tolerated. Because scale drops with resolution, this plot includes the effects on accuracy reduction for both. In Figure 5 (right) we see the object detection performance almost flattens when reducing \(R_{E}\) from 4k down to 1080p, and SY1-3 models' accuracies are very close to nano but with about half the required computation (4.2 GFLOPs for nano versus 2.2 GFLOPs for SY3.

We also verify by experiment that \(R_{E}\) has a direct impact on inference runtime per image [45, 46]. Experiments on YOLOv5 nano in the COCO validation set are conducted, and results are shown in Table 6. One observation is that runtime almost doubles from 7.4ms for \(1280^{2}\) to 13.4ms for \(2560^{2}\) on a GPU, while it rises dramatically from 64.1 for \(640^{2}\) to 4396.7 for \(1280^{2}\) on a CPU.

### Robot Path Planning Application

We briefly mention results of methods from this paper used for efficient model design for our own application. The application is to detect times, locations, and densities of human activity on a factory floor for robot path planning. Initial labelling comprised 5 object classes: 2 of humans engaged in different activities, and 3 of different types of robots. Similarity metrics guided a reduction to 2 classes enabling a smaller model with computation reduction of 66% and accuracy gain of 3.5%. See [48] for a more complete description of this application.

## 6 Conclusion

We conclude that for applications requiring lightweight CNNs, data attributes can be examined and adjusted to obtain more efficient models. We examined four independent data-side variables, and results from our experiments indicate the following ranking upon computation reduction. Resolution has the greatest effect on computation. Most practitioners already perform resolution reduction, but many simply to fit the model of choice. We show that, for small (few-class) applications the model size can be reduced (to sub-YOLO models) to achieve more efficiency with similar accuracy, and this can be done efficiently using similarity metrics. Number of classes is second in rank. This is dependent on the application, but our methods using similarity metrics enable the application designer to compare different class groupings efficiently. We showed that the choice of color or grayscale had a relatively small (1-2%) effect on computation for small models. We don't rank scale because scale was only tested with interdependency to resolution.

\begin{table}
\begin{tabular}{c|c c c c c c c} \hline \hline \(R_{E}\) & \(80^{2}\) & \(160^{2}\) & \(320^{2}\) & \(640^{2}\) & \(1280^{2}\) & \(2560^{2}\) & \(5120^{2}\) \\ \hline GPU & 6.4 & 6.2 & 6.3 & 6.4 & 7.4 & 13.4 & 48.7 \\ CPU & 14.0 & 24.7 & 52.8 & 64.1 & 4396.7 & 4728.3 & 5456.9 \\ \hline \hline \end{tabular}
\end{table}
Table 6: YOLOv5 runtimes [ms/img] for resolutions of the COCO validation set. Each number is averaged for 5 runs.

Figure 5: (Left) Effect of resolution on accuracy for YOLOv5-nano object detection on the COCO dataset, and (Right) effect on accuracy of YOLOv5 and sub-YOLO models for 80 classes of the PANDA 4k dataset [47].