Method and apparatus for object detection with a transformer-based model
By employing multiple transformer heads with varying complexity in a transformer-based model, the computational overhead is reduced, enabling efficient and accurate object detection across different image difficulties.
Patent Information
- Application Number
- PCT/CN2024/084413
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2024-03-28
- Publication Date
- 2025-10-02
AI Technical Summary
Transformer-based models for object detection, such as DETR, suffer from high computational overhead, limiting their practical applications due to the significant computational burden of the transformer head, which affects the balance between accuracy and efficiency.
A transformer-based model is configured with multiple transformer heads in parallel, each with different numbers of layers, allowing the model to dynamically select the appropriate head based on the image difficulty, assigning lighter heads to easier images and heavier heads to harder images, using a switching module to optimize computational complexity.
This approach achieves a better balance between accuracy and efficiency by reducing computational cost while maintaining high detection performance, particularly for images of varying difficulties.
Smart Images

Figure CN2024084413_02102025_PF_FP_ABST
Abstract
Description
METHOD AND APPARATUS FOR OBJECT DETECTION WITH A TRANSFORMER-BASED MODELFIELD
[0001] Aspects of the present disclosure relate generally to artificial intelligence, and more particularly, to method and apparatus provided for object detection with a transformer-based model.BACKGROUND
[0002] Object detection is a core issue in the field of computer vision, which aims at detecting all the objects of interest in an image, by predicting a bounding box and a class label for each detected object. Object detection could be widely used in real-world applications, for example, autonomous vehicles, video surveillance and robot vision, etc.
[0003] Transformer-based model is found to be suitable for object detection, which is known as Detection Transformer (DETR) and its variants, has become new paradigm of object detection. However, many existing transformer-based models, such as DETR-like models, suffer from high computational overhead, which limits their practical applications. To be specific, the transformer-based head in the model usually occupies a significant amount of computation, thus it is desired an approach to reduce the computational cost of the heavy transformer head for a better balance between accuracy and efficiency.SUMMARY
[0004] The following presents a simplified summary of one or more aspects to provide a basic understanding of such aspects. This summary is not an extensive overview of all contemplated aspects, and is intended to neither identify key or critical elements of all aspects nor delineate the scope of any or all aspects. Its sole purpose is to present some concepts of one or more aspects in a simplified form as a prelude to the more detailed description that is presented later.
[0005] Transformer-based model is appropriate for object detection task by using Transformer as the detection head to predict a set of objects directly through the interaction between object queries and visual features, free from multiple hand-designed components such as anchors and NMS. However, many existing transformer-based models, such as DETR-like models, suffer from high computational overhead, among which the transformer head usually occupies a significant amount of computation. To address this issue, an approach to reduce the computational cost of the heavy transformer head for a better balance between accuracy and efficiency is expected.
[0006] Intuitively, a transformer head possessing more layers would be more accurate for object detection while more resource consuming. Based on a fact that not all the images are so difficult for object detection, it is not necessary to employ a heavy transformer head for each image. It is proposed herein a method for dynamically processing images of varying difficulties using transformer heads with different computational complexities, enable easy images assigned to a transformer head with fewer layers and hard images assigned to a transformer head with more layers, resulting in a more favorable balance between accuracy and efficiency.
[0007] In an aspect, a computer implemented method for object detection is disclosed. The method comprises inputting an image into a transformer-based model incorporating multiple transformer heads in parallel, wherein at least a first transformer head and a second transformer head of the multiple transformer heads have different number of transformer layers; obtaining a first feature map of the image; selecting one transformer head from the multiple transformer heads to be used for the image based on the first feature map of the image; and outputting a number of predictions of detected objects in the image by the selected one transformer head based on the first feature map.
[0008] In an aspect, a computer implemented method for training a transformer-based model incorporating multiple transformer heads in parallel for object detection is disclosed, wherein at least a first transformer head and a second transformer head of the multiple transformer heads have different number of transformer layers. The method comprises inputting a first image into the transformer-based model; obtaining a first feature map of the first image; outputting a number of predictions of detected objects in the first image by each of the multiple transformer heads respectively based on the first feature map; constructing a loss function for each of the multiple transformer heads based on its predictions and ground-truth annotations corresponding to the first image; and updating the transformer-based model with the multiple transformer heads concurrently based on the constructed loss functions.
[0009] In an aspect, a computer system is disclosed. The computer system comprises one or more processors; and one or more storage devices storing computer-executable instructions that, when executed, cause the one or more processors to perform the operations of one of the methods disclosed herein.
[0010] In an aspect, one or more computer readable storage media storing computer-executable instructions that, when executed, cause one or more processors to perform the operations of one of the methods disclosed herein is disclosed.
[0011] In an aspect, a computer program product comprising computer-executable instructions that, when executed, cause one or more processors to perform the operations of one of the methods disclosed herein is disclosed.
[0012] In an aspect, an apparatus comprising one or more means for performing the operations of one of the methods disclosed herein is disclosed.
[0013] In an aspect, a vehicle comprising one or more means for performing one of the methods disclosed herein is disclosed.BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The disclosed aspects will be described in connection with the appended drawings that are provided to illustrate and not to limit the disclosed aspects.
[0015] Fig. 1 illustrates an example structure 100 of a transformer-based model, in accordance with various aspects of the present disclosure.
[0016] Fig. 2 illustrates an example inference time 200 of a transformer-based model, in accordance with various aspects of the present disclosure.
[0017] Fig. 3A illustrates an example process comparison 301 between a heavy head and a light head for an easy image, in accordance with various aspects of the present disclosure.
[0018] Fig. 3B illustrates an example process comparison 302 between a heavy head and a light head for a hard image, in accordance with various aspects of the present disclosure.
[0019] Fig. 4 illustrates an example structure 400 of a transformer-based model, in accordance with various aspects of the present disclosure.
[0020] Fig. 5 illustrates an example structure 500 of a switching module, in accordance with various aspects of the present disclosure.
[0021] Fig. 6 illustrates an example structure 600 of a transformer-based model for training, in accordance with various aspects of the present disclosure.
[0022] Fig. 7 illustrates an example structure 700 of a transformer-based model for training, in accordance with various aspects of the present disclosure.
[0023] Fig. 8 illustrates an example method 800 for object detection, in accordance with various aspects of the present disclosure.
[0024] Fig. 9 illustrates an example method 900 for training a transformer-based model for object detection, in accordance with various aspects of the present disclosure.
[0025] Fig. 10 illustrates an example method 1000 for training a transformer-based model for object detection, in accordance with various aspects of the present disclosure.
[0026] Fig. 11 illustrates an example computer system 1100, in accordance with various aspects of the present disclosure.
[0027] Fig. 12 illustrates an example vehicle 1200, in accordance with various aspects of the present disclosure.DETAILED DESCRIPTION
[0028] The present disclosure will now be discussed with reference to several example implementations. It is to be understood that these implementations are discussed only for enabling those skilled in the art to better understand and thus implement the embodiments of the present disclosure, rather than suggesting any limitations on the scope of the present disclosure.
[0029] Various embodiments will be described in detail with reference to the accompanying drawings. Wherever possible, the same reference numbers will be used throughout the drawings to refer to the same or like parts. References made to examples and embodiments are for illustrative purposes, and are not intended to limit the scope of the disclosure. It is noted that “based on” used in the disclosure should be understood as “based at least on” , rather than “solely based on” or “merely based on” .
[0030] It is anticipated that applying the disclosed method herein may involve the use of user-related information, such as images or videos captured by sensors or cameras on a vehicle during driving. It should be noted that the use of user-related information requires user authorization and may not exceed the scope of users’ authorization.
[0031] Object detection is an important computer vision task that deals with detecting instances of visual objects of a certain class, such as humans, animals, vehicles or traffic signs, in digital images. The goal of object detection is usually to predict a bounding box and a class label for each object of interest. Object detection could be widely used in real world applications, for example, autonomous driving, video surveillance and robot vision, etc.
[0032] Transformer-based model such as Detection Transformer (DETR) and its variants have grown into a new paradigm for object detection. A transformer-based model usually uses Transformer as the detection head to predict the set of objects directly through the interaction between object queries and visual features, free from multiple hand-designed components such as anchors and NMS.
[0033] Fig. 1 illustrates an example structure 100 of a transformer-based model, in accordance with various aspects of the present disclosure.
[0034] Conditional DETR is taken as an example in Fig. 1, a transformer-based model may comprise a backbone 110, a Transformer head 120 which comprises an encoder 120-1 and a decoder 120-2, wherein the encoder and decoder can each includes multiple transformer layers. Additionally, the Transformer decoder 120-1 could take a fixed number of learnable positional embeddings, which are known as object queries 130, as input to obtain the final predictions 140.
[0035] For example, the transformer-based model may use a Convolutional Neural Network (CNN) as the backbone 110 to learn a feature map of an input image, which in real world applications could be an image captured by a camera or a sensor. Then the feature map Fb may be further processed by the multiple transformer layers of encoder 120-1 to generate an enhanced feature map The enhanced feature map Fe is then fed into the decoder 120-2 to perform cross-attention with N learnable object queries 130, obtaining the final predictions 140, that predict either a detection (class label and bounding box) or a “no object” class. Fig. 1 shown as an example that 4 object queries are learned, and the second and fourth object queries are detected as “no object” in predictions.
[0036] Although the transformer-based models benefit a lot from their ability of directly predicting the set of objects, they still suffer from high computational overhead, which limits their practical applications.
[0037] Fig. 2 illustrates an example inference time 200 of a transformer-based model, in accordance with various aspects of the present disclosure. As shown in Fig. 2, inference time of each critical component of a conditional DETR are illustrated, wherein 42%shows the inference time percentage of backbone 110, 12%shows the inference time percentage of encoder 120-1, and 28%shows the inference time percentage of decoder 120-2, and 18%shows the time cost of pre-processing and post-processing. It can be observed in Fig. 2 that the inference time of the transformer head (including both encoder and decoder) is as large as the inference time of the backbone. It suggests that, apart from backbone, the compression of the transformer head would be essential to improve the efficiency of a transformer-based model.
[0038] Intuitively, a transformer head possessing more layers would be more accurate for object detection while more resource consuming. In the disclosure, a transformer head with more layers either in encoder or decoder may be referred to as a heavy head, and a transformer head with less layers either in encoder or decoder may be referred to as a light head. It is natural that a heavy head may be more accurate than a light head, and a light head may be more efficient than a heavy head.
[0039] Fig. 3A illustrates an example prediction comparison 301 between a heavy head and a light head for an easy image, in accordance with various aspects of the present disclosure. An image with only a few distinct objects may be considered as easy herein, as shown in Fig. 3A, the image with a distinct airplane can be correctly detected by both the heavy head 120-H on the left and the light head 120-L on the right, and the predictions they made may comprise a class label C1 that indicates airplane, and additionally a confidence coefficient, along with a bounding box for the detected object. From the perspective of inference time, the light head is faster than the heavy one which makes it even better.
[0040] Fig. 3B illustrates an example prediction comparison 302 between a heavy head and a light head for a hard image, in accordance with various aspects of the present disclosure. An image with more objects and occlusion may be considered as hard herein, as shown in Fig. 3B, the image with a plurality of elephants and occlusion can be satisfactorily predicted by the heavy head 120-H, but the elephants covered by others or blurred in the background are not detected by the light head 120-L.
[0041] Based on the observation in Fig. 3A and Fig. 3B that a light head is sufficient in producing good results for an easy image, while a heavy head is necessary for a hard image to generate accurate predictions, it is proposed herein a transformer-based model, configured with multiple transformer heads in parallel, that may dynamically switch between the transformer heads with different computational complexities based on varying difficulties of the input images. Some techniques described herein enable the model to assign easy images to lighter heads, while leaving the hard ones to heavier heads, in order to achieve a more favorable balance between accuracy and efficiency.
[0042] Fig. 4 illustrates an example structure 400 of a transformer-based model, in accordance with various aspects of the present disclosure. As shown in Fig. 4, the transformer-based model may be configured with a feature extraction module 410, a switching module 420 attached to the feature extraction module 410, followed by multiple transformer heads 4301 to 430n in parallel.
[0043] During inference, an image may be input to the transformer-based model incorporating multiple transformer heads 4301 to 430n in parallel for object detection. For example, the multiple transformer heads 4301 to 430n can be implemented with a conditional DETR or any of its variants, and other examples are possible. In Fig. 4, a longer head represents a heavier one, such as 403-1, and a shorter head represents a lighter one, such as 403-n.
[0044] Firstly, given an input image afeature map may be obtained by the feature extraction module 410. In an example, the feature extraction module 401 may be implemented with a backbone 110 as described in Fig. 1, and / or may be ResNet, which is a widely used CNN in the art.
[0045] Then, the switching module 420 (denoted as φd) may select one proper transformer head to be used for the image from the multiple transformer heads 4301 to 430n based on the feature map Fb. The head selection can be determined by an onehot vector z∈ {0, 1} n, where n is the number of heads, such that the i-th head is selected if and only if zi=1. Specifically, the module φd could predict the probabilities of selecting each head p=φd (Fb) ∈ (0, 1) n . During inference, the head with the largest probability (denoted as ) may be selected: Details of the switching module 420 may be described with Fig. 5 hereinafter.
[0046] After the transformer head is selected, the selected one may be executed by performing usually transformer operation based on the feature map Fb with its encoder and decoder, to output a number of predictions of detected objects in the image as where is the output of the model, which may include a class label and corresponding bounding box. As illustrated in Fig. 4, the input image with two birds may be considered as easy by the switching module 402 based on the feature map, thus a light head 430n is assigned to the image for outputting corresponding predictions.
[0047] In an aspect, the multiple transformer heads may be of different architecture and / or have different layers, and thus different computational complexity, for example, a conditional DETR, DETR and another variant may be three heads in use in one model.
[0048] In another aspect, the multiple transformer heads may be constructed based on one original head, for example a DETR with 6 layers of encoder and 6 layers of decoder, by reducing the number of transformer layers of either the encoder or the decoder of the original head. As an example, a first light head with 5 layers of encoder and 1 layers of decoder may be constructed based on the original head, a second light head with 3 layers of encoder and 3 layers of decoder may be constructed based on the original head, and a third head with 1 layer of encoder and 3 layers of decoder may be constructed based on the original head, etc.
[0049] Some techniques disclosed herein enable to select suitable number of layers for a transformer head. In an example, the light head may be constructed by reducing the number of transformer layers of the original heavy head based on a quantitative metric, which is referred to as Accuracy Cost Ratio (ACR) herein. ACR may be negatively correlated with the accuracy drop while positively correlated with the efficiency gain.
[0050] In an aspect, the accuracy may be measured by mean Average Precision (mAP) , and the efficiency may be measure by Frames Per Second (FPS) . Then the ACR may be defined as:
[0051] where APo and FPSo denote the mAP and FPS of the original head, respectively, and ΔAP and ΔFPS represent the decrease in mAP and the increase in FPS after reducing the number of layers, respectively. ACR is normalized into. To achieve better accuracy-efficiency trade-off, light heads with higher ACR may be preferred.
[0052] Table 1 shows the ACR comparison of models with encoder and decoder differing in the number of transformer layers. It can be seen that the model with a 1-layer encoder, 3-layer decoder head improves FPS by 66%over the original model with a 6-layer encoder, 6-layer decoder head, while only reducing AP by 14%resulting in an ACR of 0.62. Additionally, the model with a 3-layer encoder, 3-layer decoder head also has an ACR of 0.62. Therefore, if a transformer-based model incorporating three heads is to be constructed, the original head with 6-layer encoder and 6-layer decoder, and a first light head with 3-layer encoder and 3-layer decoder, and a second light with 1-layer encoder and 3-layer decoder may be selected.
[0053] Table 1. ACR comparison of models
[0054] In an example, the switching module 402 may be implemented via a lightweight module such as a 3-layer Multi-Layer Perception (MLP) .
[0055] Additionally or alternatively, a computational budget requirement may be set for at least part of the transformer-based model, for instance, for the whole model or for the transformer head. As a result, the switching module 420 would take into account of the computational budget requirement when selecting the transformer head. In an example, the computational budget may be associated with floating point operations per second (FLOPs) during inference. With a higher computational budget, the switching module is more likely to select a heavier head, and with a lower computational budget the switching module tends to select a lighter one to meet the requirement.
[0056] Fig. 5 illustrates an example structure 500 of a switching module, in accordance with various aspects of the present disclosure.
[0057] The example switching module 500 may be an implementation of switching module 420 in Fig. 4. As described above with Fig. 4, a feature map Fb may be fed into the switching module and one transformer head may be selected by the switching module based on the feature map.
[0058] Specifically, as shown in Fig. 5, the switching module may firstly perform dimensionality reduction to the feature map Fb, for example, by max pooling, average pooling or any other suitable dimensionality reduction techniques in the art. Then the feature map Fb′ with reduced dimensionality may be flatten to a feature column vector, which would be an input to an MLP. The MLP may output a column vector with n elements corresponding to the n transformer heads to be selected. The output of MLP can be processed by a softmax function to be normalized to (0, 1) n as probabilities of selecting each head. In Fig. 5, the first head H1 is shown as having the largest probability, so the switching module would select it for the input image.
[0059] By a transformer-based model incorporating multiple transformer heads in parallel and a switching module to dynamically select among these heads based on difficulty of input image, the disclosed transformer-based model can achieve a better balance between accuracy and efficiency.
[0060] To this end, the proposed transformer-based model needs to be trained before inference. It is disclosed herein a training method for the proposed transformer-based model to accelerate the training of multiple transformer heads, meanwhile minimize accuracy drop when executing the light heads. Also, in addition to the feature extraction module and the transformer heads, the switching module can be finetuned after the feature extraction module and the transformer heads are trained so as to select transformer head more properly.
[0061] Fig. 6 illustrates an example structure 600 of a transformer-based model for training, in accordance with various aspects of the present disclosure. The example transformer-based model has a feature extraction module 610, which may be an implementation of backbone 110 in Fig. 1 and / or feature extraction module 410 in Fig. 4. The example transformer-based model has multiple transformer heads 6301 to 630n, which may be implementations of transformer head 120 in Fig. 1 and / or transformer heads 4301 to 430n in Fig. 4. Additionally, the multiple transformer heads 6301 to 630n can be constructed as described with Fig. 4.
[0062] In a first training phase, the transformer-based model may be trained without selecting among the multiple transformer heads, as shown in Fig. 6, multiple transformer heads 6301 to 630n are attached to the feature extraction module 610 directly in parallel.
[0063] In an example, the transformer-based model may be trained following a general routine, with each transformer head trained independently. Taking transformer head 6301 as an example, an image may be input into the model, and then a feature map of the image can be obtained by the feature extraction module 610. The transformer head 6301 can output predictions corresponding to the image based on the feature map. A loss function for transformer head 6301 may be calculated based on the predictions and ground-truth labels, with which the parameters of head 6301 can be updated. After transformer head 6301 is trained, other transformer heads may be trained in sequence.
[0064] In another example, the transformer-based model may be trained following a general routine, with all the transformer heads trained jointly. An image may be input into the model, and then a feature map of the image can be obtained by the feature extraction module 610. The feature map may be input to each of the transformer heads 6301 to 630n, and all the heads can output predictions corresponding to the image based on the feature map. A loss function for each of transformer heads 6301 to 630n may be calculated respectively based on its predictions and ground-truth labels, with which the parameters of heads 6301 to 630n can be updated concurrently.
[0065] In an example, the feature extraction module 601 may be pre-trained, and the multiple transformer heads 6301 to 630n can be trained with the parameters of feature extraction module 610 frozen. Additionally or alternatively, the feature extraction module 610 may be trained together with the multiple transformer heads 6301 to 630n.
[0066] Additionally or alternatively, in the case of the one or more light heads constructed by reducing transformer layers of an original heavy head are trained with the original heavy head jointly, to minimize accuracy drop when executing the light heads and benefit more from joint training of multiple heads, it is disclosed herein a method to transfer knowledge in the heavy head to the light heads during training, referred to as Online Head Distillation (OHS) herein.
[0067] Knowledge distillation is an effective technique to promote the performance of a low capacity model by transferring "dark knowledge" from a larger model. To realize this the output of the larger model can be provided to the smaller model for constructing "soft targets" for training the smaller. Besides the soft target, the hard target which reflects difference between outputs of the smaller model and ground-truth labels may be a part of the objective function as well, which encourages the smaller model to predict the true targets as well as the labels provided by the larger model.
[0068] In order to transfer the “dark knowledge” from a heavy head such as head 6301 in Fig. 6 to a light head such as head 6302 in Fig. 6, one or more soft target in addition to the difference between the predictions of head 6302 and ground-truth labels may be introduced.
[0069] In an example, feature distillation may be performed at the encoder of the light head. In an aspect, the loss function for a light head such as 6302 may be constructed further based on a Mean Square Error (MSE) between a feature map of its own encoder and a feature map of the encoder of the heavy head such as head 6301, shown as:
[0070] Where denote the encoder feature maps of the heavy head and light head, respectively, λencoder is the loss weight. The l2-norm ||·||2 may be calculated on the channel dimension.
[0071] Intuitively, regions with larger attention weights may have a stronger influence on the final prediction and are thus more important. In a further aspect, to emphasize valuable encoder features, the MSE loss may be weighted by multi-head attention maps at the decoder of the positive object queries (the ones matched the ground-truth objects) .
[0072] where Ah∈ (0, 1) H×W represents the average attention map of multi-head attention of positive object queries in the heavy head. For each light head, this additional part of loss function can be constructed in the above way respectively.
[0073] In an example, the feature distillation may be performed at the decoder of the light head. In order to align object queries of the heavy head and the light head, a bipartite matching between the predictions from the heavy head and the light head, shown as:
[0074] where and represents the predictions from the heavy head and the light head respectively.
[0075] Then, a loss function for a light head such as 6302 may be constructed further based on a detection loss between the matched predictions and a Mean Square Error (MSE) between attention maps of the matched object queries in the heavy head and the light head, shown as:
[0076] where is the detection loss in the transformer-based model, and λatt is a balancing factor. are the attention maps corresponding to the i-th and the -th object queries in the heavy and light heads, respectively. For each light head, this additional part of loss function can be constructed in the above way respectively.
[0077] In an example, the feature distillation can be applied at one or both of the encoder and decoder of a light head.
[0078] By a loss function with additional parts for feature distillation, the transformer-based model can be trained to minimize accuracy drop when executing the light heads and benefit more from joint training of multiple heads. Additionally, it should be understood that although the training may be performed on a basis of a batch of images, a mini-batch of images, etc.
[0079] After the transformer-based model is trained as described above with Fig. 6, the switching module can be attached and trained.
[0080] Fig. 7 illustrates an example structure 700 of a transformer-based model for training, in accordance with various aspects of the present disclosure. The example transformer-based model has a feature extraction module 710, which may be an implementation of backbone 110 in Fig. 1 and / or feature extraction module 410 in Fig. 4, feature extraction module 610 in Fig. 6. The example transformer-based model has a switching module 720, which may be an implementation of switching module 420 in Fig. 4 and / or switching module 500 in Fig. 5. The example transformer-based model has multiple transformer heads 7301 to 730n, which may be implementations of transformer head 120 in Fig. 1 and / or transformer heads 4301 to 430n in Fig. 4, transformer heads 6301 to 630n in Fig. 6.
[0081] In a second training phase, the switching module 720 may be attached to the feature extraction module 710, and be finetuned to select between the multiple transformer heads 7301 to 730n with the parameters of the feature extraction module and the multiple transformer heads frozen.
[0082] In an example, similar to description of Fig. 4, an image may be input into the transformer-based model trained as described with Fig. 6, and a feature map of the image may be obtained by the feature extraction module 710. The switching module 720 may try to select one transformer head from heads 7301 to 730n with the largest probability based on the feature map, such as in a manner described with Fig. 5. The selected transformer head, for example head 7301 shown in Fig. 7, can output a number of predictions of detected objects in the image based on the feature map with its trained parameters. Afterwards, the switching module φd can be solved by gradient descent via wherein denotes the detection loss between the predictions of the head 7301 and ground-truth labels.
[0083] The backward propagation of the head selection poses a discrete optimization problem since argmax used when to select a head with the largest probability is not differentiable. To address this problem, the Gumbel-Softmax technique may be used and the onehot vector z may be calculated as:
[0084] where pi is the probabilities predicted by the switching module 720 for each head, and the noise gi is i.i. d sampled from the Gumbel (0, 1) distribution. The Equation (6) is differentiated with the Straight-Through Gumbel Estimator.
[0085] Additionally or alternatively, the switching module is expected to be finetuned to achieve as high accuracy as possible for a given computational budget. The optimization of the switching module 720 may be formulated as a constrained optimization problem, which minimizes the detection loss under given computational budget constraint In this case, the switching module φd can be solved by gradient descent via where λbudget is a hyperparameter for balancing the computational budget constraint. In an example, the computational budget is associated with floating point operations per second (FLOPs) for at least a part of the whole transformer-based model, like for the multiple transformer heads.
[0086] For example, the computational budget loss can be calculated by estimating the average computational cost within a set of input images, such as for a single image, a batch or a minibatch. When the average computational cost (termed as ) exceeds a target computational budget (termed as Ft) , the loss is positively correlated with the average computational cost; Otherwise, it is 0, denoted as:
[0087] Additionally or alternatively, a set of the switching modules 720 can be finetuned based a set of computation budget in parallel, to enable the model to work well under different scenarios under a variety of budgets.
[0088] In this manner, the switching module may be trained to select a proper transformer head based on a difficulty of an input image, and further under a computation budget constraint.
[0089] The disclosed transformer-based model may be deployed for many applications, as an example, deployed in a vehicle as part of the Advanced Driving Assistance System (ADAS) or at least provides its predictions on images to the ADAS. Taking an image from sensors on the vehicle like a camera or an imaging sensor, the transformer-based model enables to select a detection head based on the image, and to achieve a better balance between accuracy and efficiency. Based on the detection of the images, further strategies of the ADAS for downstream tasks may be better supported.
[0090] Fig. 8 illustrates an example method 800 for object detection, in accordance with various aspects of the present disclosure. As described below, some or all illustrated features may be omitted in an implementation within the scope of the present disclosure, and some illustrated features may not be required for implementation of all embodiments. Further, some of the blocks may be performed parallel or in a different order. In some examples, the method may be carried out by any suitable apparatus or means for carrying out the functions or algorithm described below. The method of Fig. 8 may be implemented by the transformer-based model of Fig. 4, and / or the switching module of Fig. 5.
[0091] The method begins at block 810, with inputting an image into a transformer-based model incorporating multiple transformer heads in parallel, wherein at least a first transformer head and a second transformer head of the multiple transformer heads have different number of transformer layers.
[0092] In an aspect, the transformer-based model may be an implementation of the transformer-based model of Fig. 4.
[0093] In an aspect, the second transformer head is constructed by reducing the number of transformer layers of the first head based on a first metric which is negatively correlated with an accuracy drop while positively correlated with an efficiency gain that compared between the first transformer head and the second transformer head.
[0094] In an aspect, the transformer-based model is pre-trained by a set of images with ground-truth annotations, and wherein the multiple transformer heads are pre-trained jointly.
[0095] In an aspect, the image is obtained by a camera or an imaging sensor.
[0096] The method proceeds to block 820, with obtaining a first feature map of the image.
[0097] In an aspect, the operation of block 820 may be performed by the feature extraction module 410 of Fig. 4.
[0098] The method proceeds to block 830, with selecting one transformer head to be used for the image from the multiple transformer heads based on the first feature map of the image.
[0099] In an aspect, the operation of block 830 may be performed by the switching module 420 of Fig. 4 or the switching module 500 of Fig. 5.
[0100] In an aspect, selecting one transformer head from the multiple transformer heads to be used for the image based on the first feature map of the image further comprises performing dimensionality reduction and flatten operation to the first feature map to obtain a second feature map of the image; obtaining probabilities of selecting each transformer head from the multiple transformer heads based on the second feature map; and selecting the one transformer head with a maximum probability for the image.
[0101] In an aspect, the probabilities of selecting each transformer head from the multiple transformer heads are obtained based on a Multi-Layer Perception (MLP) . In a further aspect, the MLP may be a 3-layer MLP with an input layer, an intermediate layer and an output layer.
[0102] In an aspect, the method further comprises setting a computational budget requirement for at least part of the transformer-based model, and wherein selecting the one transformer head from the multiple transformer heads to be used for the image is further based on the computation budget requirement.
[0103] In a further aspect, the computational budget is associated with floating point operations per second (FLOPs) .
[0104] In a further aspect, the computational budget requirement is set for the transformer head.
[0105] The method proceeds to block 840, with outputting a number of predictions of detected objects in the image by the selected one transformer head based on the first feature map.
[0106] In an aspect, the operation of block 840 may be performed by one of the multiple transformer heads 4301 to 430n.
[0107] In an aspect, the number of predictions of detected objects each includes an object class label and its corresponding bounding box. In a further aspect, the number of predictions of detected objects also include a confidence coefficient for each detected object.
[0108] Fig. 9 illustrates an example method 900 for training a transformer-based model object detection, in accordance with various aspects of the present disclosure. As described below, some or all illustrated features may be omitted in an implementation within the scope of the present disclosure, and some illustrated features may not be required for implementation of all embodiments. Further, some of the blocks may be performed parallel or in a different order. In some examples, the method may be carried out by any suitable apparatus or means for carrying out the functions or algorithm described below. The method of Fig. 9 may be implemented by the transformer-based model of Fig. 6.
[0109] The method begins at block 910, with inputting a first image into the transformer-based model.
[0110] In an aspect, the transformer-based model may be an implementation of the transformer-based model of Fig. 6.
[0111] In an aspect, the transformer-based model incorporates multiple transformer heads in parallel, wherein at least a first transformer head and a second transformer head of the multiple transformer heads have different number of transformer layers.
[0112] In a further aspect, the second transformer head is constructed by reducing the number of transformer layers of the first transformer head based on a first metric which is negatively correlated with an accuracy drop while positively correlated with an efficiency gain that compared between the first transformer head and the second transformer head.
[0113] The method proceeds to block 920, with obtaining a first feature map of the first image.
[0114] In an aspect, the operation of block 920 may be performed by the feature extraction module 610 of Fig. 6.
[0115] The method proceeds to block 930, with outputting a number of predictions of detected objects in the first image by each of the multiple transformer heads respectively based on the first feature map.
[0116] In an aspect, the operation of block 930 may be performed by the transformer heads 6301 to 630n of Fig. 6.
[0117] The method proceeds to block 940, with constructing a loss function for each of the multiple transformer heads based on its predictions and ground-truth annotations corresponding to the first image.
[0118] In an aspect, the loss function for the second transformer head is constructed further based on a Mean Square Error (MSE) between a third feature map of the first image from an encoder of the first transformer head and a fourth feature map of the first image from an encoder of the second transformer head.
[0119] In a further aspect, the MSE is weighted by attention maps in the first transformer head of object queries that matched ground-truth annotations.
[0120] In an aspect, bipartite matching is performed between the predictions of the first transformer head and the second transformer head, and the loss function for the second transformer head is constructed further based on a detection loss between the matched predictions and a Mean Square Error (MSE) between attention maps of the matched object queries in the first transformer head and the second transformer head.
[0121] In an aspect, the number of predictions of detected objects each includes an object class label and its corresponding bounding box. In a further aspect, the number of predictions of detected objects also include a confidence coefficient for each detected object.
[0122] The method proceeds to block 950, with updating the transformer-based model with the multiple transformer heads concurrently based on the constructed loss functions.
[0123] In an aspect, the loss function may be calculated based on one image, a mini-batch of images or a batch of images.
[0124] Fig. 10 illustrates an example method 1000 for training a transformer-based model object detection, in accordance with various aspects of the present disclosure. As described below, some or all illustrated features may be omitted in an implementation within the scope of the present disclosure, and some illustrated features may not be required for implementation of all embodiments. Further, some of the blocks may be performed parallel or in a different order. In some examples, the method may be carried out by any suitable apparatus or means for carrying out the functions or algorithm described below. The method of Fig. 10 may be implemented by the transformer-based model of Fig. 7.
[0125] In an aspect, the method of Fig. 10 is performed after the operation of Fig. 9 are performed.
[0126] In an aspect, the transformer-based model may be an implementation of the transformer-based model of Fig. 7, and has a switching module coupled between the feature extraction module and the multiple transformer heads.
[0127] In an aspect, the switching module is implemented based on a Multi-Layer Perception (MLP) .
[0128] The method begins at block 1010, with inputting a second image into the trained transformer-based model.
[0129] The method proceeds to block 1020, with obtaining a first feature map of the second image by the feature extraction module.
[0130] In an aspect, the operation of block 1020 may be performed by the feature extraction module 710 of Fig. 7.
[0131] The method proceeds to block 1030, with selecting one transformer head from the multiple transformer heads to be used for the second image based on the first feature map of the second image.
[0132] In an aspect, the operation of block 1030 may be performed by the switching module 720 of Fig. 7.
[0133] In an aspect, selecting one transformer head from the multiple transformer heads to be used for the second image based on the first feature map of the second image further comprises performing dimensionality reduction and flatten operation to the first feature map to obtain a second feature map of the second image; obtaining probabilities of selecting each transformer head from the multiple transformer heads based on the second feature map of the second image; and selecting one transformer head with a maximum probability for the second image.
[0134] The method proceeds to block 1040, with constructing a loss function for the switching module based on predictions of the selected transformer head and ground-truth annotations corresponding to the second image and further based on a computation budget for at least a part of the transformer-based model.
[0135] In an aspect, a target computation budget for at least a part of the transformer-based model may be set, and a computational budget for the second image may be calculated, wherein a portion of the loss function is calculated as positively correlated with the calculated computation budget if the calculated computation budget exceeds the target computation budget.
[0136] In an aspect, the target computational budget is set for the transformer head.
[0137] In an aspect, the computational budget is associated with floating point operations per second (FLOPs) .
[0138] In an aspect, the number of predictions of detected objects each includes an object class label and its corresponding bounding box. In a further aspect, the number of predictions of detected objects also include a confidence coefficient for each detected object.
[0139] The method proceeds to block 1040, with updating the switching module based on the loss function for the switching module with the parameters of the feature extraction module and the multiple transformer heads frozen after the transformer-based model is trained with a set of images.
[0140] In an aspect, a set of switching modules are finetuned in parallel under different computation budgets, and wherein one switching module from the set of switching modules can be selected based on a computation budget requirement.
[0141] In an aspect, the switching module is implemented based on a Multi-Layer Perception (MLP) . In a further aspect, the MLP may be a 3-layer MLP with an input layer, an intermediate layer and an output layer.
[0142] Fig. 11 illustrates an exemplary computer system 1100, in accordance with various aspects of the present disclosure.
[0143] The computer system may comprise at least one processor 1110. The computer system may further comprise at least one storage device 1120. It should be appreciated that the storage device 1120 may store computer-executable instructions that, when executed, cause the processor 1110 to perform a method for object detection.
[0144] The method for object detection comprises inputting an image into a transformer-based model incorporating multiple transformer heads in parallel, wherein at least a first transformer head and a second transformer head of the multiple transformer heads have different number of transformer layers; obtaining a first feature map of the image; selecting one transformer head to be used for the image from the multiple transformer heads based on the first feature map of the image; and outputting a number of predictions of detected objects in the image by the selected one transformer head based on the first feature map.
[0145] Further, it should be appreciated that the storage device 1120 may store computer-executable instructions that, when executed, cause the processor 1110 to perform a method for training a transformer-based model for object detection object detection. The method comprises inputting a first image into the transformer-based model; obtaining a first feature map of the first image; outputting a number of predictions of detected objects in the first image by each of the multiple transformer heads respectively based on the first feature map; constructing a loss function for each of the multiple transformer heads based on its predictions and ground-truth annotations corresponding to the first image; and updating the transformer-based model with the multiple transformer heads concurrently based on the constructed loss functions.
[0146] It should be appreciated that the storage device 1120 may store computer-executable instructions that, when executed, cause the processor 1110 to perform any operations according to the embodiments of the present disclosure as described in connection with Figs. 1-10.
[0147] The embodiments of the present disclosure may be embodied in one or more computer-readable medium such as non-transitory computer-readable medium. The non-transitory computer-readable medium may store instructions that, when executed, cause one or more processors to perform any operations according to the embodiments of the present disclosure as described in connection with Figs. 1-10.
[0148] The embodiments of the present disclosure may be embodied in a computer program product comprising computer-executable instructions that, when executed, cause one or more processors to perform any operations according to the embodiments of the present disclosure as described in connection with Figs. 1-10.
[0149] Fig. 12 illustrates an example vehicle 1200, in accordance with various aspects of the present disclosure.
[0150] For example, the vehicle 1200 may be configured with an imaging sensor 1210, such as a camera to capture images of its surrounding. The vehicle 1200 may be configured with a transformer-based model 1220 incorporating multiple transformer heads in parallel trained as described herein, the imaged obtained by the imaging sensor 1210 may be fed into the transformer-based model 1220 for object detection. The vehicle 1200 may be configured with an Advanced Driving Assistance System (ADAS) 1230 which can make further decisions for downstream tasks based on the output of the transformer-based model 1220.
[0151] In an aspect, the transformer-based model 1220 may perform any operations according to the embodiments of the present disclosure as described in connection with Figs. 1-5 and 8.
[0152] In an aspect, the transformer-based model 1220 may be trained by any operations according to the embodiments of the present disclosure as described in connection with Figs. 6-7 and 9-10.
[0153] In an aspect, the transformer-based model 1220 may be a part of the Advanced Driving Assistance System (ADAS) 1230.
[0154] It should be appreciated that all the operations in the methods described above are merely exemplary, and the present disclosure is not limited to any operations in the methods or sequence orders of these operations, and should cover all other equivalents under the same or similar concepts.
[0155] It should also be appreciated that all the modules in the apparatuses described above may be implemented in various approaches. These modules may be implemented as hardware, software, or a combination thereof. Moreover, any of these modules may be further functionally divided into sub-modules or combined together.
[0156] The previous description is provided to enable any person skilled in the art to practice the various aspects described herein. Various modifications to these aspects will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other aspects. Thus, the claims are not intended to be limited to the aspects shown herein. All structural and functional equivalents to the elements of the various aspects described throughout the present disclosure that are known or later come to be known to those of ordinary skill in the art are expressly incorporated herein by reference and are intended to be encompassed by the claims.
Claims
1.A computer implemented method for object detection, comprising:inputting an image into a transformer-based model incorporating multiple transformer heads in parallel, wherein at least a first transformer head and a second transformer head of the multiple transformer heads have different number of transformer layers;obtaining a first feature map of the image;selecting one transformer head to be used for the image from the multiple transformer heads based on the first feature map of the image; andoutputting a number of predictions of detected objects in the image by the selected one transformer head based on the first feature map.2.The computer implemented method of claim 1, wherein the second transformer head is constructed by reducing the number of transformer layers of the first head based on a first metric which is negatively correlated with an accuracy drop while positively correlated with an efficiency gain that compared between the first transformer head and the second transformer head.3.The computer implemented method of claim 1, wherein selecting one transformer head from the multiple transformer heads to be used for the image based on the first feature map of the image, further comprising:performing dimensionality reduction and flatten operation to the first feature map to obtain a second feature map of the image;obtaining probabilities of selecting each transformer head from the multiple transformer heads based on the second feature map; andselecting the one transformer head with a maximum probability for the image.4.The computer implemented method of claim 3, wherein the probabilities of selecting each transformer head from the multiple transformer heads are obtained based on a Multi-Layer Perception (MLP) .5.The computer implemented method of claim 1, further comprising:setting a computational budget requirement for at least part of the transformer-based model, and wherein selecting the one transformer head from the multiple transformer heads to be used for the image is further based on the computation budget requirement.6.The computer implemented method of claim 5, wherein the computational budget is associated with floating point operations per second (FLOPs) .7.The computer implemented method of claim 1, wherein the transformer-based model is pre-trained by a set of images with ground-truth annotations, and wherein the multiple transformer heads are pre-trained jointly.8.The computer implemented method of claim 1, wherein the number of predictions of detected objects each includes an object class label and its corresponding bounding box.9.A computer implemented method for training a transformer-based model incorporating multiple transformer heads in parallel for object detection, wherein at least a first transformer head and a second transformer head of the multiple transformer heads have different number of transformer layers, the method comprising:inputting a first image into the transformer-based model;obtaining a first feature map of the first image;outputting a number of predictions of detected objects in the first image by each of the multiple transformer heads respectively based on the first feature map;constructing a loss function for each of the multiple transformer heads based on its predictions and ground-truth annotations corresponding to the first image; andupdating the transformer-based model with the multiple transformer heads concurrently based on the constructed loss functions.10.The computer implemented method of claim 9, wherein the second transformer head is constructed by reducing the number of transformer layers of the first transformer head based on a first metric which is negatively correlated with an accuracy drop while positively correlated with an efficiency gain that compared between the first transformer head and the second transformer head.11.The computer implemented method of claim 10, further comprising:constructing a loss function for the second transformer head further based on a Mean Square Error (MSE) between a third feature map of the first image from an encoder of the first transformer head and a fourth feature map of the first image from an encoder of the second transformer head.12.The computer implemented method of claim 11, wherein the MSE is weighted by attention maps in the first transformer head of object queries that matched ground-truth annotations.13.The computer implemented method of claim 10, further comprising:performing bipartite matching between the predictions of the first transformer head and the second transformer head;constructing a loss function for the second transformer head further based on a detection loss between the matched predictions and a Mean Square Error (MSE) between attention maps of the matched object queries in the first transformer head and the second transformer head.14.The computer implemented method of claim 9, wherein the transformer-based model comprises a feature extraction module coupled in series to the multiple transformer heads, and a switching module coupled between the feature extraction module and the multiple transformer heads, andwherein the feature extraction module is used for obtain the first feature map of an image, andwherein the switching module is used for selecting one transformer head from the multiple transformer heads to be used for an image based on its first feature map during inference.15.The computer implemented method of claim 14, further comprising:finetuning the switching module with parameters of the feature extraction module and the multiple transformer heads frozen after the transformer-based model is trained with a set of images.16.The computer implemented method of claim 15, wherein finetuning the switching module further comprising:inputting a second image into the trained transformer-based model;obtaining a first feature map of the second image by the feature extraction module;selecting one transformer head from the multiple transformer heads to be used for the second image based on the first feature map of the second image;constructing a loss function for the switching module based on predictions of the selected transformer head and ground-truth annotations corresponding to the second image and further based on a computation budget for at least a part of the transformer-based model; andupdating the switching module based on the loss function for the switching module.17.The computer implemented method of claim 16, wherein selecting one transformer head from the multiple transformer heads to be used for the second image based on the first feature map of the second image, further comprising:performing dimensionality reduction and flatten operation to the first feature map to obtain a second feature map of the second image;obtaining probabilities of selecting each transformer head from the multiple transformer heads based on the second feature map of the second image;selecting one transformer head with a maximum probability for the second image.18.The computer implemented method of claim 16, wherein finetuning the switching module further comprising:setting a target computation budget for at least a part of the transformer-based model, andcalculating a computational budget for the second image,wherein a portion of the loss function is calculated as positively correlated with the calculated computation budget if the calculated computation budget exceeds the target computation budget.19.The computer implemented method of claim 16, wherein a set of switching modules are finetuned in parallel under different computation budgets, and wherein one switching module from the set of switching modules can be selected based on a computation budget requirement.20.The computer implemented method of claim 16, wherein the computational budget is associated with floating point operations per second (FLOPs) .21.The computer implemented method of claim 14, wherein the switching module is implemented based on a Multi-Layer Perception (MLP) .22.The computer implemented method of claim 9, wherein the number of predictions of detected objects each includes an object class label and its corresponding bounding box.23.A computer system, comprising:one or more processors; andone or more storage devices coupled to the one or more processors having computer-executable instructions therein that, when executed, cause the one or more processors to perform the operations of the method of one of claims 1-22.24.One or more computer readable storage medium having computer-executable instructions thereon that, when executed, cause one or more processors to perform the operations of the method of one of claims 1-22.25.A computer program product comprising computer-executable instructions that, when executed, cause one or more processors to perform the operations of the method of one of claims 1-22.26.An apparatus, comprising one or more means for performing the operations of the method of one of claims 1-22.27.A vehicle, the vehicle comprising one or more means for performing the operations of the method of one of claims 1-8.
Citation Information
Patent Citations
Image synthesis method based on dynamic self-attention generative adversarial network
CN113379655A
Distribution reasoning method and device of multi-branch network, electronic equipment and storage medium
CN114972850A
Remote sensing image target detection method based on fusion convolution attention mechanism
CN116229295A
Medical image segmentation method based on Swin Transform and CNN parallel network
CN117351030A