Color recognition model training method, color recognition method, device and storage medium
By performing multi-channel feature extraction and loss calculation in the color recognition model, the problem of low color recognition accuracy in the existing technology is solved, and efficient color recognition under different lighting conditions is achieved.
Patent Information
- Application Number
- CN202411049490.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-01
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-08-01
AI Technical Summary
Existing color recognition methods have low color recognition accuracy under different lighting conditions and cannot effectively handle color changes in images.
By inputting the sample image and sample label to be identified into the model for training, multi-channel feature extraction and color recognition processing are performed, the joint loss of contrast loss and classification loss is calculated, and the model parameters are adjusted to improve the accuracy of color recognition.
It improves the accuracy of color recognition and can accurately identify colors in images under different lighting conditions, achieving efficient and accurate color recognition.
Smart Images

Figure CN118570589A
Abstract
Description
Technical Field
[0001] The present application relates to the field of image recognition technology, and in particular to a color recognition model training method, a color recognition method, a device and a storage medium. Background Art
[0002] Image recognition technology is an important field of artificial intelligence. With the development of image recognition technology, it has been widely used in various scenarios.
[0003] The current image recognition technology mainly recognizes features such as shape and texture in images, but rarely recognizes colors in images. In fact, accurate color recognition also has great practical value. Existing color recognition methods mainly include methods based on color difference comparison between the image to be recognized and the standard color template, or color classification methods based on machine learning or deep learning.
[0004] Existing color recognition methods mainly achieve color recognition based on the similarity between the pixel color in the image to be recognized and the standard color. However, in actual application scenarios, even the same color may have different display effects under different lighting conditions, which leads to low color recognition accuracy in scenarios such as low exposure and high exposure. Summary of the invention
[0005] The present application at least provides a color recognition model training method, a color recognition method, an apparatus, a device, and a computer-readable storage medium.
[0006] In a first aspect, the present application provides a color recognition model training method, comprising: inputting a sample image to be identified and a sample label of the sample image to be identified into a model to be trained for model training; performing multi-channel feature extraction processing on the sample image to be identified based on the model to be trained to obtain the multi-channel features of the sample image to be identified, and performing color recognition processing on the sample image to be identified to obtain the target color category of the sample image to be identified; performing contrast loss calculation based on the multi-channel features to obtain the contrast loss of the sample image to be identified, and performing classification loss calculation based on the target color category and the sample label to obtain the classification loss of the sample image to be identified; constructing a joint loss of the contrast loss and the classification loss; adjusting the model parameters of the model to be trained based on the joint loss of each model training until the joint loss reaches a preset standard, thereby obtaining a trained color recognition model.
[0007] In one embodiment, the multi-channel feature extraction processing is performed on the sample image to be identified based on the model to be trained to obtain the multi-channel features of the sample image to be identified, including: performing multi-channel feature extraction processing on the sample image to be identified to obtain the three primary color channel features, hue channel features and saturation channel features of the sample image to be identified; the contrast loss calculation is performed based on the multi-channel features to obtain the contrast loss of the sample image to be identified, including: performing contrast loss calculation based on a first contrast result between the three primary color channel features and the hue channel features, and a second contrast result between the three primary color channel features and the saturation channel features to obtain the contrast loss of the sample image to be identified.
[0008] In one embodiment, the multi-channel feature extraction processing is performed on the sample image to be identified to obtain the three-primary color channel features, hue channel features and saturation channel features of the sample image to be identified, including: obtaining the three-primary color channel images of the sample image to be identified under the three-primary color channels, the hue channel images of the sample image to be identified under the hue channel and the saturation channel images of the sample image to be identified under the saturation channel; performing feature mapping processing on the hue channel image and the saturation channel image respectively to obtain a mapped hue channel image and a mapped saturation channel image, wherein the mapped hue channel image, the mapped saturation channel image and the three-primary color channel images have the same number of channels; extracting the three-primary color initial features of the sample image to be identified based on the three-primary color channel images, extracting the hue initial features based on the mapped hue channel image and extracting the saturation initial features based on the mapped saturation channel image; performing pooling processing on the three-primary color initial features, the hue initial features and the saturation initial features respectively to obtain the three-primary color channel features, the hue channel features and the saturation channel features.
[0009] In one embodiment, the performing multi-channel feature extraction processing on the sample image to be identified based on the model to be trained to obtain the multi-channel features of the sample image to be identified, including: performing multi-channel feature extraction processing on the sample image to be identified to obtain the three-primary color channel features and the hue-saturation combined features of the sample image to be identified; the performing contrast loss calculation based on the multi-channel features to obtain the contrast loss of the sample image to be identified, including: performing contrast loss calculation based on the contrast result between the three-primary color channel features and the hue-saturation combined features to obtain the contrast loss of the sample image to be identified.
[0010] In one embodiment, the multi-channel feature extraction processing is performed on the sample image to be identified to obtain the three-primary color channel features and the hue-saturation merged features of the sample image to be identified, including: obtaining the three-primary color channel images of the sample image to be identified under the three-primary color channels, the hue channel image of the sample image to be identified under the hue channel, and the saturation channel image of the sample image to be identified under the saturation channel; performing channel merging processing on the hue channel image and the saturation channel image to obtain a hue-saturation merged image; performing feature mapping processing on the hue-saturation merged image to obtain a mapped hue-saturation merged image, wherein the mapped hue-saturation merged image has the same number of channels as the three-primary color channel image; extracting the three-primary color initial features of the sample image to be identified based on the three-primary color channel images, and extracting the hue-saturation merged initial features based on the mapped hue-saturation merged image; performing pooling processing on the three-primary color initial features and the hue-saturation merged initial features, respectively, to obtain the three-primary color channel features and the hue-saturation merged features.
[0011] In one embodiment, the color recognition processing of the sample image to be identified to obtain the target color category of the sample image to be identified includes: performing color recognition processing on the sample image to be identified to obtain the color type of the sample image to be identified; in response to the color types being at least two, obtaining the number of pixels corresponding to each color type; and determining the color type with the largest number of pixels as the target color category of the sample image to be identified.
[0012] In one embodiment, the sample label includes a color label and a mask label, and the classification loss calculation based on the target color category and the sample label to obtain the classification loss of the sample image to be identified includes: performing classification loss calculation between the target color category and the color label to obtain the color loss of the sample image to be identified; binarizing the sample image to be identified based on the target color category to obtain the mask image of the sample image to be identified; performing classification loss calculation between the mask image and the mask label to obtain the mask loss of the sample image to be identified; and determining the classification loss of the sample image to be identified based on the color loss and the mask loss.
[0013] The second aspect of the present application provides a color recognition method, comprising: inputting the acquired image to be recognized into a pre-trained color recognition model, and extracting the color features of the image to be recognized based on the color recognition model; the color recognition model is trained by the method described in any of the above embodiments; classifying and identifying the color features of the image to be recognized to obtain the color type of the image to be recognized; in response to the fact that there are at least two color types, obtaining the number of pixels corresponding to each color type; determining the color type with the largest number of pixels as the target color category of the image to be recognized The third aspect of the present application provides a color recognition model training device, including: an input module, used to input a sample image to be identified and a sample label of the sample image to be identified into a model to be trained for model training; a feature extraction module, used to perform multi-channel feature extraction processing on the sample image to be identified based on the model to be trained to obtain the multi-channel features of the sample image to be identified, and perform color recognition processing on the sample image to be identified to obtain the target color category of the sample image to be identified; a loss calculation module, used to perform contrast loss calculation based on the multi-channel features to obtain the contrast loss of the sample image to be identified, and perform classification loss calculation based on the target color category and the sample label to obtain the classification loss of the sample image to be identified; a joint loss construction module, used to construct a joint loss of the contrast loss and the classification loss; a model parameter adjustment module, used to adjust the model parameters of the model to be trained based on the joint loss of each model training until the joint loss reaches a preset standard, thereby obtaining a trained color recognition model.
[0014] In a fourth aspect, the present application provides a color recognition device, comprising: a feature extraction module, used to input the acquired image to be recognized into a pre-trained color recognition model, and extract the color features of the image to be recognized based on the color recognition model; the color recognition model is trained by the color recognition model training method described in any one of the above embodiments; a color classification and recognition module, used to classify and recognize the color features of the image to be recognized, and obtain the color type of the image to be recognized; a pixel acquisition module, used to obtain the number of pixels corresponding to each color type in response to the color type being at least two; a color determination module, used to determine the color type with the largest number of pixels as the target color category of the image to be recognized.
[0015] A fifth aspect of the present application provides an electronic device, including a memory and a processor, wherein the processor is used to execute program instructions stored in the memory to implement the above-mentioned color recognition model training method and / or color recognition method.
[0016] In a sixth aspect, the present application provides a computer-readable storage medium having program instructions stored thereon, which implement the above-mentioned color recognition model training method and / or color recognition method when executed by a processor.
[0017] In the above scheme, the sample image to be identified and the sample label of the sample image to be identified are input into the model to be trained for model training, the sample image to be identified is subjected to multi-channel feature extraction processing by the model to be trained to obtain the channel features of the sample image to be identified in multiple color space channels, that is, to obtain the multi-channel features, and the sample image to be identified is subjected to color recognition processing to obtain the target color category of the sample image to be identified; contrast loss calculation is performed based on the multi-channel features to obtain the contrast loss of the sample image to be identified, and classification loss calculation is performed based on the target color category and the sample label to obtain the classification loss of the sample image to be identified; a joint loss of contrast loss and classification loss is constructed, thereby constraining the training process of the model to be trained through the joint loss, so that the color recognition accuracy of the trained model is higher; the model parameters of the model to be trained are adjusted based on the joint loss of each model training until the joint loss reaches a preset standard, thereby obtaining a trained color recognition model; in the subsequent specific application process of the model, the image to be identified is input into the trained color recognition model, so that the color category of the image to be identified output by the color recognition model can be accurately obtained, thereby realizing efficient and accurate color recognition of the image to be identified.
[0018] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and are used together with the specification to illustrate the technical solution of the present application.
[0020] Figure 1 is a flowchart of an exemplary embodiment of the color recognition model training method of the present application; Figure 2 It is a simplified flowchart of determining contrast loss in the color recognition model training method of the present application; Figure 3 is another flow chart of determining contrast loss in the color recognition model training method of the present application; Figure 4 It is another flow chart of determining contrast loss in the color recognition model training method of the present application; Figure 5 It is a flowchart of color recognition processing performed by a saliency classification module in the color recognition model training method of the present application; Figure 6is an exemplary flow chart of the color recognition model training method of the present application; Figure 7 is another exemplary flow chart of the color recognition model training method of the present application; Figure 8 is a block diagram of a color recognition model training device shown in an exemplary embodiment of the present application; Fig. 9 is a block diagram of a color recognition device shown in an exemplary embodiment of the present application; Fig.10 It is a structural schematic diagram of an embodiment of the electronic device of the present application; Fig.11 It is a structural diagram of an embodiment of a computer-readable storage medium of the present application. DETAILED DESCRIPTION
[0021] The scheme of the embodiment of the present application is described in detail below in conjunction with the drawings of the specification.
[0022] In the following description, for the purpose of explanation rather than limitation, specific details such as specific system structures, interfaces, and technologies are provided to facilitate a thorough understanding of the present application.
[0023] The term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the objects associated before and after are in an "or" relationship. In addition, "many" in this article means two or more than two. In addition, the term "at least one" in this article means any combination of at least two of any one or more of a plurality of, for example, including at least one of A, B, and C, can mean including any one or more elements selected from the set consisting of A, B, and C.
[0024] For ease of understanding, common color recognition methods are now explained by way of example. Existing color recognition methods mostly use 1) a method based on color difference: construct a standard color template in a certain color space (such as RGB, YUV, HSI, etc.), and calculate the difference between the input image and the standard color template. The smaller the difference, the greater the probability of belonging to a certain color category; 2) a color classification method based on machine learning or deep learning. The above two types of methods focus more on how to select representative (high probability) color areas and color spaces, while ignoring the generalization of the method itself, which may lead to problems such as low color recognition accuracy in scenes with different lighting intensities.
[0025] It should be noted that the color recognition method of the present application can be deployed in a variety of application scenarios, such as color recognition of pure color images and / or mixed color images, color recognition of the entire image and / or color recognition of a partial image area in the entire image, wherein the partial image area can be a pre-specified divided area and / or an image area determined using target recognition technology, etc., which is not limited here.
[0026] Exemplarily, in a target recognition scenario, combining color information can improve the accuracy of target recognition. For example, if there are one or more objects to be recognized in an image to be recognized, the color information of one or more objects to be recognized in the image to be recognized can be determined using the color recognition method of the present application. Another exemplary example is that in the field of intelligent transportation, the body color is one of the basic attributes of a vehicle and can be used for functions such as vehicle retrieval and vehicle tracking. Accurately identifying the body color has significant practical value. Therefore, in the specific application scenario of the color recognition method of the present application, it can also be used to determine the body color of the target vehicle in the image to be recognized, etc., which will not be elaborated here.
[0027] See also Figure 1 , Figure 1 : is a flowchart of an exemplary embodiment of the color recognition model training method of the present application. Specifically, it may include the following steps: Step S110: input the sample images to be identified and the sample labels of the sample images to be identified into the model to be trained to perform model training.
[0028] The sample image to be identified refers to the sample image of the color to be identified for model training. Each sample image to be identified may be provided with a corresponding sample label. During the model training process, the sample image to be identified and the corresponding sample label may be input into the model to be trained for model training. Among them, the sample label of the sample image to be identified may include but is not limited to a color label and a mask label. Taking the vehicle body color recognition scene as an example, the color label represents the vehicle body color of the vehicle to be identified in the sample image to be identified, and the mask label represents the vehicle body area of the vehicle to be identified in the sample image to be identified or other significant areas of the vehicle to be identified that can be used to accurately represent its color (such as one or more of the door area, the hood area and / or the trunk area, etc., which are not limited here). The mask label can be used to determine the significant area for color recognition in the sample image to be identified, so as to avoid the color information in other areas of the sample image to be identified except the significant area from interfering with the color recognition process, thereby reducing the color recognition accuracy.
[0029] For example, in the vehicle body color recognition scenario, the tire color may be different from the vehicle body color, so in the process of identifying the vehicle body color, the hood area can be set as a prominent area by setting a mask tag, thereby determining the vehicle body color through the hood color; or the door area can be set as a prominent area, thereby determining the vehicle body color through the door color; or the hood area and the door area can be set as prominent areas to determine the vehicle body color, etc., which will not be described here. This avoids determining the color of other areas in the image as the color of the target area in the color recognition scenario, or the color of other areas affecting the recognition and judgment of the color of the target area.
[0030] It should be noted that before the sample image to be identified and its sample label are input into the model to be trained, a process of making a sample data set may also be included, and then the data in the sample data set may be used for model training. Among them, it may at least include the preparation of image data and the preparation of label data. For example, the resolution of the mask label of each sample image to be identified can be the same as the resolution of the sample image to be identified, and each pixel value of the mask label is 1 or 0, where 1 is the significant area referred to in the above example, and 0 represents the non-significant area (other areas in the sample image to be identified except the significant area). Subsequently, these data can be divided into training sets and validation sets according to a reasonable ratio, which will not be elaborated here.
[0031] Step S120, performing multi-channel feature extraction processing on the sample image to be identified based on the model to be trained to obtain multi-channel features of the sample image to be identified, and performing color recognition processing on the sample image to be identified to obtain a target color category of the sample image to be identified.
[0032] Channel refers to the color space channel. Common color spaces include RGB, HIS, YUV, HSV, CMYK, etc., which are not limited here. Taking the RGB color space as an example, R (Red), G (Green), and B (Blue) are three channels respectively, and the multi-channel of this application refers to the channels of multiple color spaces. Multi-channel feature extraction processing refers to extracting features of the sample image to be identified based on different color space channels, and obtaining the image features of the sample image to be identified in different channels, thereby obtaining multi-channel features.
[0033] It should be noted that if you want to extract channel features of multiple color spaces, you also need to convert the same image to be identified. For example, the sample image to be identified is usually obtained in RGB channels, which means that the three channel features of R, G, and B can be extracted; in addition, the sample image to be identified can be converted from the RGB color space to the HSI color space, thereby extracting the three channel features of H, S, and I. The same is true for other color spaces such as YUV, which will not be described here.
[0034] Furthermore, the sample image to be identified may be subjected to color recognition processing to obtain the target color category of the sample image to be identified. For example, color recognition is performed on the RGB feature map of the sample image to be identified to obtain the target color category of the sample image to be identified.
[0035] It should also be noted that in the color recognition model training method of the present application, the order of execution between the multi-channel feature extraction processing process and the color recognition processing process is not limited, and the multi-channel feature extraction processing process and the color recognition processing process can be executed synchronously or asynchronously, which is not limited.
[0036] Step S130, performing contrast loss calculation based on multi-channel features to obtain contrast loss of the sample image to be identified, and performing classification loss calculation based on the target color category and the sample label to obtain classification loss of the sample image to be identified.
[0037] Combined with the above steps, it can be known that images based on different color spaces can respectively extract channel features corresponding to the corresponding color spaces, for example, RGB channel features can be extracted based on RGB images, and HSI channel features can be extracted based on HSI images. However, it is understandable that the multi-channel features obtained by the feature extraction process based on different channels may be the same or different, and the degree of difference between different channel features can reflect the degree of deviation of the current feature extraction process in processing different channel images. For example, in actual application scenarios, it is usually expected that the features extracted from the same image in different color spaces are as similar as possible, so in the model training process, the feature difference between the channel features of different color spaces can be compared and calculated to determine the loss value of the feature extraction process and obtain the contrast loss. Adjusting the model parameters during the model training process based on the contrast loss can make the model more accurate in the feature extraction process.
[0038] Furthermore, the color recognition model of the present application needs to identify color categories. Therefore, in addition to the feature contrast loss in the feature extraction process, the classification loss in the color recognition process can also be considered, such as color classification loss or color prediction loss. The calculation method is mainly based on the classification loss calculation between the target color category of the sample image to be identified output by the model and the color label actually annotated by the sample image to be identified. The specific calculation process can refer to the existing loss calculation process, which will not be repeated here. In this way, it can be judged whether the color recognition result (target color category) output by the model is accurate. If the target color category of an image output by the model matches the color label of the image, the classification loss of the model is small; on the contrary, if the target color category of an image output by the model does not match the color label of the image, the classification loss of the model is large, and it is necessary to continue model training and adjust the model parameters.
[0039] Step S140, constructing a joint loss of contrast loss and classification loss.
[0040] Combined with the above steps, in traditional color recognition methods, if a neural network model is used for color recognition, the model parameters are usually adjusted based on the loss value between the color recognized by the neural network model for the sample image and the color actually marked in the sample image, and then the model training is completed. The reference data of this type of model training method is relatively one-sided, and the color recognition accuracy of the trained model is low.
[0041] The color recognition model training method of the present application is based on the joint construction and processing of the contrast loss and classification loss output by the model to be trained, and the joint loss of the model to be trained is obtained, thereby realizing the joint consideration and analysis of the losses in the feature extraction process and color recognition process of the image by the neural network model, optimizing the training process of the neural network model, and being able to improve the accuracy of subsequent color recognition. Among them, the process of constructing the joint loss may include but is not limited to weighted summation of the contrast loss and the classification loss to obtain a joint loss function. Each loss has a corresponding set weight value, and the weight value of each loss can be pre-fixed or adjustable as needed, and the weight values of different losses can be the same or different, which is not limited here.
[0042] Step S150, adjusting the model parameters of the model to be trained based on the joint loss of each model training until the joint loss reaches a preset standard, thereby obtaining a trained color recognition model.
[0043] Combined with the above steps, after each model training, the joint loss value output by the joint loss function constructed based on the above steps can be obtained. If the joint loss value reaches the preset standard (for example, the joint loss value is less than the preset joint loss threshold), it can be characterized that the currently trained neural network model meets the accuracy requirements, and the current neural network model can be used as a trained color recognition model; if the joint loss value does not meet the preset representation (for example, the joint loss value is greater than or equal to the joint loss threshold), it indicates that the currently trained neural network model does not meet the accuracy requirements and the model training process needs to continue.
[0044] Furthermore, a method for determining whether the color recognition model of the present application has been trained may also be to use the above-mentioned joint loss function for back propagation, and after each model training cycle is completed, evaluate the accuracy of the neural network model on the validation set, and save the neural network model with the highest accuracy on the validation set as the preferred model (the trained color recognition model), which is used for model inference in subsequent color recognition application scenarios.
[0045] For example, taking the vehicle body color recognition application scenario as an example, when the color recognition model of the present application is specifically applied, the RGB image to be recognized can be input into the color recognition model, and the feature extraction network of the color recognition model performs feature extraction to obtain an RGB feature map. ; Then input it into the classification module to obtain the color recognition results of H*W pixels output by the classification module; and the color category with the largest number of pixels can be taken as the recognition result of the body color; or the color category with a number of pixels greater than a preset pixel number threshold can be taken as the recognition result of the body color; or the color category with a pixel ratio greater than a preset pixel ratio threshold can be taken as the recognition result of the body color, that is, the target color category is obtained, which will not be elaborated here.
[0046] It can be seen that the present application inputs the sample image to be identified and the sample label of the sample image to be identified into the model to be trained for model training, performs multi-channel feature extraction processing on the sample image to be identified by the model to be trained to obtain the channel features of the sample image to be identified in multiple color space channels, that is, to obtain the multi-channel features, and performs color recognition processing on the sample image to be identified to obtain the target color category of the sample image to be identified; performs contrast loss calculation based on the multi-channel features to obtain the contrast loss of the sample image to be identified, and performs classification loss calculation based on the target color category and the sample label to obtain the classification loss of the sample image to be identified; constructs a joint loss of contrast loss and classification loss, thereby constraining the training process of the model to be trained through the joint loss, so that the color recognition accuracy of the trained model is higher; adjusts the model parameters of the model to be trained based on the joint loss of each model training until the joint loss reaches the preset standard, and obtains a trained color recognition model; in the subsequent specific application of the model, the image to be identified is input into the trained color recognition model, and the color category of the image to be identified output by the color recognition model can be accurately obtained, thereby realizing efficient and accurate color recognition of the image to be identified.
[0047] On the basis of the above embodiments, the embodiment of the present application describes the steps of extracting multi-channel features of the sample image to be identified based on the model to be trained to obtain the multi-channel features of the sample image to be identified and calculating the contrast loss based on the multi-channel features to obtain the contrast loss of the sample image to be identified. Specifically, the method of this embodiment includes the following steps: A multi-channel feature extraction process is performed on the sample image to be identified to obtain the three primary color channel features, hue channel features and saturation channel features of the sample image to be identified; a contrast loss calculation is performed based on a first contrast result between the three primary color channel features and the hue channel features, and a second contrast result between the three primary color channel features and the saturation channel features to obtain the contrast loss of the sample image to be identified.
[0048] In combination with the above-mentioned embodiments, in the multi-channel feature extraction process of the present application, feature extraction can be performed on the sample image to be identified in the RGB color space to obtain RGB channel features, that is, three primary color channel features (in the field of image processing technology, the three primary colors refer to the three colors of RGB); in addition, feature extraction can also be performed on the sample image to be identified in the HSI color space to obtain hue H channel features and saturation S channel features. Among them, I in the HSI color space refers to brightness (Intensity). In the color recognition model training method of the present application, the brightness feature of the image is separated, and there is no need to extract the brightness I channel feature for model training, so that the feature information extracted in the HSI color space is only related to the hue and saturation of the image, but not to the brightness, so as to achieve the brightness adaptive effect and obtain a brightness adaptive feature extraction network. Optionally, in other embodiments, feature extraction may be performed on the sample image to be identified in the HSV color space to obtain hue H channel features and saturation S channel features, while ignoring lightness V channel features; or, feature extraction may be performed on the sample image to be identified in the YUV color space to obtain hue channel features and saturation channel features represented by U and V, while ignoring lightness Y channel features.
[0049] It should be noted that, for the sake of ease of explanation and understanding, the following text of this application mainly uses RGB color space and HSI color space as examples for illustration, but this does not affect the application of the method of this application to other color spaces such as HSV or YUV.
[0050] Further, please refer to Figure 2 , Figure 2 This is a simplified flowchart for determining contrast loss in the color recognition model training method of the present application. In the process of calculating contrast loss based on multi-channel features to obtain contrast loss of the sample image to be identified, the three primary colors RGB channel features (F1) and the hue H channel features (F2) are compared to obtain a first contrast result, and the three primary colors RGB channel features (F1) and the saturation S channel features (F3) are compared to obtain a second contrast result; based on the first contrast result (Feature similarity) and second comparison results (Feature Similarity) Determine the Contrastive Loss Function , where F1, F2, and F3 are all in the data form of feature matrices, @ represents matrix multiplication, and t represents matrix transposition. For details, please refer to the calculation process of the following example, which will not be described in detail here:
[0051] Based on the above embodiments, the embodiment of the present application exemplarily illustrates the steps of performing multi-channel feature extraction processing on the sample image to be identified to obtain the three primary color channel features, hue channel features and saturation channel features of the sample image to be identified. Specifically, the method of this embodiment includes the following steps: Obtain the three primary color channel images of the sample image to be identified under the three primary color channels, the hue channel images of the sample image to be identified under the hue channel, and the saturation channel images of the sample image to be identified under the saturation channel; perform feature mapping processing on the hue channel image and the saturation channel image respectively to obtain a mapped hue channel image and a mapped saturation channel image, and the mapped hue channel image, the mapped saturation channel image, and the three primary color channel images have the same number of channels; extract the three primary color initial features of the sample image to be identified based on the three primary color channel images, extract the hue initial features based on the mapped hue channel image, and extract the saturation initial features based on the mapped saturation channel image; perform pooling processing on the three primary color initial features, the hue initial features, and the saturation initial features respectively to obtain the three primary color channel features, the hue channel features, and the saturation channel features.
[0052] In combination with the above-mentioned embodiments, the process of performing multi-channel feature extraction processing on the sample image to be identified at least includes: converting the sample image to be identified into various color spaces; aligning the channels between images in different color spaces; extracting the channel features of the images in various color spaces respectively; and performing pooling processing on the extracted channel features.
[0053] Specifically, the scheme of extracting the three primary color channel features from the RGB channels of the RGB image, extracting the hue channel features from the H channel of the HSI image, and extracting the saturation channel features from the S channel of the HSI image in the aforementioned embodiment is taken as an example for explanation.
[0054] For example, reference may be made to Figure 3 , Figure 3 It is another flow chart for determining contrast loss in the color recognition model training method of the present application. In the specific implementation process of the present application, the sample image to be identified in RGB format can be input into the model to be trained as training data, and then the model to be trained converts its RGB image from RGB color space to HSI color space to obtain an HSI image, and then the HSI image is subjected to channel separation processing, and then an H channel image, an S channel image, and an I channel image can be obtained respectively. Among them, methods such as color space conversion and channel separation can refer to existing image processing technologies, which will not be described in detail here. Or, before inputting the model to be trained, various channel images are prepared and then input into the model to be trained together, which is not limited here.
[0055] It is understandable that, since the RGB channel image is a three-channel image, and the H channel image and the S channel image are both single-channel images, in order to facilitate subsequent feature extraction and feature comparison and other processing, it is also necessary in this application to perform feature mapping processing on the H channel image and the S channel image so that the channels of the RGB channel image, the H channel image and the S channel image are aligned. The H channel image and the S channel image are respectively input into a preset feature mapping module, and the H channel image and the S channel image are respectively mapped into three-channel images (i.e., a mapped hue channel image and a mapped saturation channel image) through the feature mapping module. Among them, the feature mapping module includes at least one convolution layer for changing the number of channels of the image to three.
[0056] Furthermore, the H channel image and the S channel image after feature mapping can share the same feature extraction network with the RGB channel image, and the feature extraction network may include but is not limited to using common convolution related layers, Transformer related layers, etc. Therefore, the RGB channel image, the mapped H channel image, and the mapped S channel image are input into the feature extraction network for feature extraction processing to obtain the three primary color initial features of the RGB channel image, the hue initial features of the H channel image, and the saturation initial features of the S channel image; and then the three primary color initial features, the hue initial features, and the saturation initial features are respectively subjected to global pooling processing to obtain the RGB channel pooling features (i.e., the three primary color channel features), the H channel pooling features (i.e., the hue channel features), and the S channel pooling features (i.e., the saturation channel features) output by the feature extraction network. It should be noted that the global pooling operation may include but is not limited to global average pooling or global maximum pooling, etc., which are not limited here. Then, the contrast loss calculation can be performed with reference to the description of the aforementioned embodiment. Exemplarily, the contrast loss calculation process can refer to the calculation process of the following example, which is not repeated here:
[0057] On the basis of the above embodiments, the embodiment of the present application describes the steps of extracting multi-channel features of the sample image to be identified based on the model to be trained to obtain the multi-channel features of the sample image to be identified and calculating the contrast loss based on the multi-channel features to obtain the contrast loss of the sample image to be identified. Specifically, the method of this embodiment includes the following steps: A multi-channel feature extraction process is performed on the sample image to be identified to obtain the three primary color channel features and the hue and saturation combined features of the sample image to be identified; a contrast loss calculation is performed based on the comparison results between the three primary color channel features and the hue and saturation combined features to obtain the contrast loss of the sample image to be identified.
[0058] The description is made in conjunction with the foregoing embodiment. In the foregoing embodiment, an implementable contrast loss determination process is described. In this embodiment, another implementable contrast loss determination process is provided.
[0059] It should be noted that, in this embodiment, the extraction of RGB channel features of the RGB channel image can still be performed in the same manner as the method in the aforementioned embodiment, the main difference being the extraction process of the H channel features and the S channel features.
[0060] Specifically, in this embodiment, after obtaining the H channel image and the S channel image, it is necessary to perform channel merging processing on the H channel image and the S channel image to obtain an HS dual-channel image, which is equivalent to an image with the I brightness channel removed from the HSI three-channel image. Feature extraction processing is performed on the HS dual-channel image to obtain HS channel features, that is, hue saturation merged features. Similarly, referring to the contrast loss calculation process of the aforementioned embodiment, the contrast loss calculation is performed based on the comparison results between the RGB channel features and the HS channel features to obtain the contrast loss of the sample image to be identified.
[0061] Compared with the implementations provided in the previous embodiments, the implementation provided in this embodiment combines the H channel image and the S channel image together, so that subsequent feature extraction processing, contrast loss calculation and other processes are reduced, thereby improving processing efficiency. In the specific implementation process, one of the two possible implementation modes can be selected for execution according to the requirements of accuracy and efficiency.
[0062] Based on the above embodiments, the embodiment of the present application exemplarily illustrates the steps of performing multi-channel feature extraction processing on the sample image to be identified to obtain the three primary color channel features and hue saturation combined features of the sample image to be identified. Specifically, the method of this embodiment includes the following steps: Obtain the three primary color channel images of the sample image to be identified under the three primary color channels, the hue channel image of the sample image to be identified under the hue channel, and the saturation channel image of the sample image to be identified under the saturation channel; perform channel merging processing on the hue channel image and the saturation channel image to obtain a hue-saturation merged image; perform feature mapping processing on the hue-saturation merged image to obtain a mapped hue-saturation merged image, and the mapped hue-saturation merged image has the same number of channels as the three primary color channel image; extract the three primary color initial features of the sample image to be identified based on the three primary color channel images, and extract the hue-saturation merged initial features based on the mapped hue-saturation merged image; perform pooling processing on the three primary color initial features and the hue-saturation merged initial features, respectively, to obtain the three primary color channel features and the hue-saturation merged features.
[0063] This embodiment specifically describes the second possible implementation method in the above embodiment. Figure 4 , Figure 4 It is another flowchart for determining contrast loss in the color recognition model training method of the present application. In combination with the above-mentioned embodiment, it should be noted that in this embodiment, the RGB image is input into the model to be trained, the RGB image is converted to the HSI color space, the HSI image is obtained, and the H channel image and the S channel image are obtained; then the H channel image and the S channel image are processed by channel merging to obtain a HS dual-channel image, that is, a hue and saturation merged image.
[0064] It can be understood that the HS channel image has two channels, while the RGB channel image has three channels. Therefore, the HS channel image can also be subjected to feature mapping processing through the feature mapping module to obtain the mapped HS channel image; the feature extraction network then performs feature extraction processing on the mapped HS channel image to obtain the HS channel initial features; the HS channel initial features are pooled to obtain the HS channel features, that is, the hue and saturation merged features.
[0065] It should be noted that the extraction of RGB channel features of the RGB channel image in this embodiment is similar to the implementation method of the previous embodiment, so it is not repeated here. In the subsequent calculation of the contrast loss between the RGB channel features (F1) and the HS channel features (F4), the specific calculation process can refer to the following calculation process:
[0066] Based on the above embodiments, the embodiment of the present application exemplarily illustrates the steps of performing color recognition processing on the sample image to be identified to obtain the target color category of the sample image to be identified. Specifically, the method of this embodiment includes the following steps: Perform color recognition processing on the sample image to be identified to obtain the color type of the sample image to be identified; in response to there being at least two color types, obtain the number of pixels corresponding to each color type; and determine the color type with the largest number of pixels as the target color category of the sample image to be identified.
[0067] It should be noted that, in this embodiment, the color recognition processing of the sample image to be identified needs to obtain the image features of the sample image to be identified for color recognition processing. The image features of the sample image to be identified may include but are not limited to the RGB channel feature map of the sample image to be identified. Or feature maps obtained from other color spaces. In addition, the RGB channel feature map used here can be generated when the RGB image passes through the feature extraction network in the aforementioned step, thereby saving the time of re-processing the feature extraction of the RGB image; of course, it can also be obtained by re-processing the feature extraction of the RGB image, which is not limited here.
[0068] Specifically, in the process of color recognition, the main process is to determine the color type corresponding to each pixel in the RGB channel feature map, and determine the color type of the RGB image according to the color type corresponding to each pixel.
[0069] On the one hand, it can be understood that there can be one or more types of colors recognized in the sample image to be recognized. If one type of color is recognized in the sample image to be recognized, it means that the color type is the target color category of the sample image to be recognized. If multiple types of colors (two or more) are recognized in the sample image to be recognized, it means that the sample image to be recognized is composed of multiple colors. In order to determine the main color of the sample image to be recognized, the number of pixels corresponding to each color type in the sample image to be recognized can be used. The color type with the largest number of pixels also represents the main color of the sample image to be recognized. Therefore, in this embodiment, the color type with the largest number of pixels in the sample image to be recognized can be determined as the target color category of the sample image to be recognized. In addition, in addition to determining the target color category of the sample image to be recognized by comparing the number of pixels of each color type, it can also be based on the number of pixels of each color type and the total number of pixels of the sample image to be recognized. Determine the pixel ratio of each color type in the sample image to be recognized, and determine the color type with the largest pixel ratio as the target color category of the sample image to be recognized.
[0070] On the other hand, the above example illustrates one possible implementation method for determining the target color category of the sample image to be identified. In fact, there are more possible implementation methods in the present application. For example, the above example mainly illustrates that the color category with the largest proportion in the sample image to be identified is determined as the target color category. In fact, the main color of the sample image to be identified or the main color of the object to be identified in the sample image to be identified may include multiple types. Therefore, in the color recognition process, it is also possible to determine the color category greater than the pixel number threshold or greater than the pixel ratio threshold as the target color category of the sample image to be identified (or the target color category of the object to be identified in the sample image to be identified) by setting a pixel number threshold or a pixel ratio threshold. Further, the color categories greater than the threshold can also be sorted according to their respective pixel numbers or pixel ratios, thereby characterizing the priority of each color of the sample image to be identified or the object to be identified. For example, it is currently necessary to perform color recognition on the body of the vehicle to be identified in the sample image to be identified, and the body color of the vehicle is a color matching style (such as 60% black and 40% white). If black is determined as the target color category of the vehicle with reference to the method of the above example, it seems biased. In this example, assuming that the proportion threshold is set to 20%, both black and white can be determined as the target color categories of the vehicle, that is, the target color categories of the vehicle can be obtained as black and white (by sorting black before white so that it is easy to know that the proportion of black is greater than that of white), thereby more accurately reflecting the color composition of the vehicle body.
[0071] Based on the above embodiment, the embodiment of the present application describes the steps of calculating the classification loss based on the target color category and the sample label to obtain the classification loss of the sample image to be identified. The sample label includes a color label and a mask label. Specifically, the method of this embodiment includes the following steps: The classification loss is calculated between the target color category and the color label to obtain the color loss of the sample image to be identified; the sample image to be identified is binarized based on the target color category to obtain the mask image of the sample image to be identified; the classification loss is calculated between the mask image and the mask label to obtain the mask loss of the sample image to be identified; the classification loss of the sample image to be identified is determined based on the color loss and the mask loss.
[0072] In conjunction with the above-mentioned embodiments, the color recognition model of the present application can be used for color recognition of the entire area of the image, and can also be used for color recognition of the target object (object to be recognized) or a partial area in the image. If the target object or a partial area in the image is to be color recognized, it is necessary to consider the problem of target detection or the problem of area division. Therefore, in the specific implementation process of the present application, an image mask can be introduced for processing. Among them, the image mask refers to the area or processing process of image processing controlled by blocking the selected image, graphic or object, the image to be processed (all or part). For example, if the body color of the target vehicle in the image needs to be recognized, the mask can be used to block the area in the image except the body of the target vehicle (including but not limited to the surrounding environment of the target vehicle, windows, lights, bumpers, tires, etc. that interfere with the body color recognition), and the remaining body area is the target area that needs to be color recognized, or the significant area that can significantly characterize the body color. Specifically, in the process of making a data set, each sample image to be recognized needs to be labeled with a mask label. Taking vehicle body color recognition as an example, the mask label of the vehicle body color salient area has the same image data resolution as the sample image to be recognized, and each pixel takes a value of 0 or 1, where 0 represents the vehicle body color non-salient area (such as windows, lights, bumpers, rearview mirrors, vehicle surroundings, etc.), and 1 represents the vehicle body color salient area (such as door area, hood area, trunk area, etc.).
[0073] Exemplarily, the steps of this embodiment can be performed by setting a saliency classification module in a color recognition model. Figure 5 As shown, Figure 5 It is a flowchart of color recognition processing performed by a saliency classification module in the color recognition model training method of the present application.
[0074] Specifically, the RGB channel feature map of the sample image to be identified is input into the saliency classification module, and the upsampling module therein (including but not limited to the segmentation head structure of the common segmentation network such as FCN, PSPNet) performs image segmentation processing to obtain the image segmentation result, and the resolution of the image segmentation result should be the same as the resolution of the sample image to be identified input into the model to be trained (for example, the resolution is H*W), and the number of output channels is set to the recognized color type (for example, if the three colors of red, green and blue are recognized, a three-channel feature map is output, and if red, green, blue, white and yellow are recognized, a five-channel feature map can be output). Among them, first, after the image segmentation result passes through network layers such as softmax and argmax, the color recognition results corresponding to H*W pixels will be obtained (the color recognition result of each pixel can be between 0 and n, where n is the color category), and then the color category with the largest number of pixels or the largest proportion of pixels can be taken as the output target color category, or multiple color categories can be output as the target color category by setting the threshold as mentioned in the above embodiment.
[0075] It can be understood that the target color category currently output is equivalent to the color recognition obtained by the trained model based on the input sample image to be identified. The target color category may or may not conform to the true color of the sample image to be identified. Therefore, the classification loss can be calculated based on the output target color category and the color label of the sample image to be identified to obtain the color loss of the sample image to be identified. One of the possible implementations of the present application may be to convert the color loss As classification loss, based on color loss And the preset color loss weight, and the contrast loss of the aforementioned embodiment and the preset contrast loss weight construct a joint loss. Another embodiment of the present application may be to binarize the above-mentioned image classification results based on the target color category, that is, the pixel values of pixels in the image classification results that are the same as the target color category are set to 1, and the pixel values of pixels in the image classification results that are different from the target color category are set to 0, which is equivalent to obtaining a mask result (mask image) based on the target color category, that is, it represents the salient area mask determined by the model to be trained according to the target color category; then the classification loss is calculated for the mask image and the mask label to obtain the mask loss of the sample image to be identified. Then the mask loss and color loss can be used together as classification loss, and a joint loss is constructed based on the classification loss and contrast loss. The mask loss weight corresponding to the mask loss and the color loss weight corresponding to the color loss can be the same or different, which is not limited here. The specific calculation process of constructing the joint loss can refer to the following calculation process:
[0076] Among them, the joint loss is recorded as L, α is the preset contrast loss weight corresponding to the contrast loss, β is the preset color loss weight corresponding to the color loss, and λ is the preset mask loss weight corresponding to the mask loss. , the weights may be the same or different, which is not limited here. For example, in order to focus on the color recognition effect, the proportion of color loss weight may be increased.
[0077] In summary, the above joint loss function can be used for back propagation. After each model training cycle is completed, the accuracy of the model on the validation set (joint loss) is evaluated, and the model with the highest accuracy (lowest loss) on the validation set during several model training processes is saved as the optimal model, that is, the trained color recognition model is obtained for subsequent model reasoning (color recognition). Alternatively, the joint loss obtained after each model training is compared with the preset joint loss threshold to determine whether the loss of the currently trained model meets the preset standard, and then determine whether the training is completed.
[0078] Based on the above embodiments, the embodiments of the present application provide a general description of the practicable steps in the color recognition model training method of the present application. The color recognition model training method of the present application may include but is not limited to the following two exemplified practicable implementation methods.
[0079] 1. For reference Figure 6 , Figure 6 It is an exemplary flow chart in the color recognition model training method of the present application. Among them, the RGB three-channel image of the sample image to be identified is input into the model to be trained, and the feature extraction network of the model to be trained performs feature extraction processing and pooling processing on the RGB three-channel image to obtain RGB pooling features. In addition, the RGB image is converted to the HSI color space and channel separation is performed to obtain an H channel image and an S channel image. It should be noted that this step can be performed synchronously or successively with the aforementioned steps, and the present application does not limit it. Then the H channel image and the S channel image are respectively sent to the feature mapping module of the model to be trained for feature mapping processing, so that the mapped H channel image and the mapped S channel image are both three-channel images, so as to achieve channel alignment with the RGB channel image. Then the mapped H channel image and the mapped S channel image are respectively sent to the feature extraction network for feature extraction processing and pooling processing to obtain H pooling features and S pooling features. Then based on the RGB pooling features, the H pooling features and the S pooling features, the loss calculation is performed to obtain the contrast loss. It should also be noted that after the feature extraction network performs feature extraction processing on the RGB three-channel image, the RGB feature map can also be obtained. . Input the RGB feature map into the saliency classification module of the model to be trained to calculate the classification loss, and the mask loss and color loss can be obtained. It should be noted that the process of calculating the mask loss and color loss can be executed synchronously or asynchronously with the process of calculating the contrast loss, and this application does not limit it. Construct a joint loss based on contrast loss, mask loss and color loss, and judge whether the model training is successful based on the joint loss during the model training process. Please refer to the description of the previous embodiment here and do not elaborate on it.
[0080] 2. For reference Figure 7 , Figure 7 It is another exemplary flow chart in the color recognition model training method of the present application. Among them, the RGB three-channel image of the sample image to be identified is input into the model to be trained, and the feature extraction network of the model to be trained performs feature extraction processing and pooling processing on the RGB three-channel image to obtain RGB pooling features. In addition, the RGB image is converted to the HSI color space and channel separation is performed to obtain an H channel image and an S channel image, and then the H channel image and the S channel image are spliced and merged to obtain an HS channel image. It should be noted that this step can be performed synchronously or sequentially with the aforementioned steps, and the present application does not limit it. The HS channel image is then sent to the feature mapping module of the model to be trained for feature mapping processing, so that the mapped HS channel image is a three-channel image to achieve channel alignment with the RGB channel image. The mapped HS channel images are then sent to the feature extraction network for feature extraction processing and pooling processing to obtain HS pooling features. Then, loss calculation is performed based on the RGB pooling features and the HS pooling features to obtain contrast loss. It should also be noted that after the feature extraction network performs feature extraction processing on the RGB three-channel image, an RGB feature map can also be obtained. . Similarly, the RGB feature map is input into the saliency classification module of the model to be trained to calculate the classification loss, and the mask loss and color loss can be obtained. It should be noted that the process of calculating the mask loss and color loss can be executed synchronously or asynchronously with the process of calculating the contrast loss, and this application does not limit it. A joint loss is constructed based on the contrast loss, mask loss and color loss. During the model training process, whether the model training is successful is judged based on the joint loss. Please refer to the description of the previous embodiment here and do not elaborate on it.
[0081] The above embodiments mainly illustrate the training method for the color recognition model. It should be noted that the present application may also provide a color recognition method. The color recognition method of the present application needs to use the color recognition model trained in the above embodiments.
[0082] Specifically, the acquired image to be identified (RGB image) is input into a pre-trained color recognition model (i.e., the color recognition model obtained by referring to the above-mentioned model training method), and the color features of the image to be identified are extracted based on the feature extraction network of the color recognition model to obtain the RGB feature map of the image to be identified; the RGB feature map is input into the saliency classification module in the color recognition model for classification and identification to obtain the color type of the image to be identified; in response to the color types being at least two, the number of pixels corresponding to each color type is obtained; the color type with the largest number of pixels is determined as the target color category of the image to be identified; in response to the color type being one, the color type can be directly determined as the target color category of the image to be identified. In addition, it should be noted that in this embodiment, if there are multiple color types, the method of the aforementioned embodiment can still be referred to. In addition to determining the color type with the largest number of pixels as the target color category of the image to be identified, the color type with the largest pixel proportion can also be determined as the target color category of the image to be identified, etc., which will not be elaborated here.
[0083] In addition, in the color recognition method of the present application, although the image to be recognized is used as an example for explanation, in fact, the color recognition can be performed on the object to be recognized in the image to be recognized, and the target color category finally obtained is also the color category of the object to be recognized. The specific implementation process can refer to the above-mentioned embodiment using the vehicle body color recognition scenario as an example, which will not be repeated here.
[0084] In summary, the present application can improve the efficiency and accuracy of the color recognition process by combining the training method of the color recognition model with the color training method. The color recognition model of the present application is easy to deploy (predict) and has high accuracy: usually, when deploying (predicting), only the image to be recognized needs to be input, and there is no need to obtain the area to be recognized in the image to be recognized in advance. Through reasonable training methods and model design, the target color category of the area to be recognized in the image to be recognized can be determined. The color recognition method of the present application can achieve brightness adaptation (brightness-independent): through the model training method of the present application, a brightness-adaptive feature extraction network is obtained, and no additional brightness removal algorithm is required. And the color recognition method of the present application will perform saliency classification: the final recognition result of the color depends on the color recognition results of most pixels, which is more statistically significant. The conventional classification head gives the entire image a recognition result; while the saliency classification module of the present application gives each pixel a recognition result, and finally the color type with the largest number of pixels can be taken as the target color category.
[0085] It should be further explained that the execution subject of the color recognition model training method may be a color recognition model training device, for example, the color recognition model training method may be executed by a terminal device or a server or other processing device, wherein the terminal device may be a user equipment (UE), a computer, a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. In some possible implementations, the color recognition model training method may be implemented by a processor calling a computer-readable instruction stored in a memory.
[0086] Figure 8 FIG. 1 is a block diagram of a color recognition model training device shown in an exemplary embodiment of the present application. Figure 8 As shown, the exemplary color recognition model training device 800 includes: an input module 810, a feature extraction module 820, a loss calculation module 830, a joint loss construction module 840 and a model parameter adjustment module 850. Specifically: The input module 810 is used to input the sample images to be identified and the sample labels of the sample images to be identified into the model to be trained for model training.
[0087] The feature extraction module 820 is used to perform multi-channel feature extraction processing on the sample image to be identified based on the model to be trained to obtain multi-channel features of the sample image to be identified, and to perform color recognition processing on the sample image to be identified to obtain a target color category of the sample image to be identified.
[0088] The loss calculation module 830 is used to perform contrast loss calculation based on multi-channel features to obtain the contrast loss of the sample image to be identified, and to perform classification loss calculation based on the target color category and sample label to obtain the classification loss of the sample image to be identified.
[0089] The joint loss construction module 840 is used to construct the joint loss of contrast loss and classification loss.
[0090] The model parameter adjustment module 850 is used to adjust the model parameters of the model to be trained based on the joint loss of each model training until the joint loss reaches a preset standard to obtain a trained color recognition model.
[0091] In the exemplary color recognition model training device, the sample image to be recognized and the sample label of the sample image to be recognized are input into the model to be trained for model training, the sample image to be recognized is subjected to multi-channel feature extraction processing by the model to be trained to obtain the channel features of the sample image to be recognized in multiple color space channels, that is, to obtain the multi-channel features, and the sample image to be recognized is subjected to color recognition processing to obtain the target color category of the sample image to be recognized; contrast loss calculation is performed based on the multi-channel features to obtain the contrast loss of the sample image to be recognized, and classification loss calculation is performed based on the target color category and the sample label to obtain the classification loss of the sample image to be recognized; a joint loss of contrast loss and classification loss is constructed, thereby constraining the training process of the model to be trained through the joint loss, so that the color recognition accuracy of the trained model is higher; the model parameters of the model to be trained are adjusted based on the joint loss of each model training until the joint loss reaches a preset standard, thereby obtaining a trained color recognition model; in the subsequent specific application process of the model, the image to be recognized is input into the trained color recognition model, so that the color category of the image to be recognized output by the color recognition model can be accurately obtained, thereby realizing efficient and accurate color recognition of the image to be recognized.
[0092] Fig. 9 FIG. 1 is a block diagram of a color recognition device shown in an exemplary embodiment of the present application. Fig. 9 As shown, the exemplary color recognition device 900 includes: a feature extraction module 910, a color classification recognition module 920, a pixel acquisition module 930 and a color determination module 940. Specifically: The feature extraction module 910 is used to input the acquired image to be identified into a pre-trained color recognition model and extract the color features of the image to be identified based on the color recognition model; the color recognition model is trained by the color recognition model training method of any one of the above embodiments.
[0093] The color classification and recognition module 920 is used to classify and recognize the color features of the image to be recognized to obtain the color type of the image to be recognized.
[0094] The pixel acquisition module 930 is configured to acquire the number of pixels corresponding to each color type in response to the fact that there are at least two color types.
[0095] The color determination module 940 is used to determine the color category with the largest number of pixels as the target color category of the image to be recognized.
[0096] In this exemplary color recognition device, the image to be recognized is sent to a pre-trained color recognition model, and the feature extraction network in the color recognition model performs feature extraction to obtain color features of the image to be recognized; the color features of the image to be recognized are then sent to the saliency classification module of the feature extraction network for classification and recognition to obtain the color recognition result of each pixel in the image to be recognized (that is, the color type); in response to there being at least two color types, the number of pixels corresponding to each color type is obtained, and the color type with the largest number of pixels is determined as the target color category of the image to be recognized, thereby completing color recognition.
[0097] It should be noted that the device provided in the above embodiment and the method provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs the operation has been described in detail in the method embodiment, and will not be repeated here. In practical applications, the device provided in the above embodiment can distribute the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not limited here.
[0098] Among them, the functions of each module can be found in the embodiment of the color recognition model training method, which will not be repeated here.
[0099] See also Fig.10 , Fig.10 1 is a schematic diagram of the structure of an embodiment of an electronic device of the present application. The electronic device 100 includes a memory 101 and a processor 102, and the processor 102 is used to execute program instructions stored in the memory 101 to implement the steps in any of the above color recognition model training method embodiments. In a specific implementation scenario, the electronic device 100 may include but is not limited to: a microcomputer, a server, and in addition, the electronic device 100 may also include a mobile device such as a laptop computer and a tablet computer, which is not limited here.
[0100] Specifically, the processor 102 is used to control itself and the memory 101 to implement the steps in any of the above-mentioned color recognition model training method embodiments. The processor 102 can also be called a CPU (Central Processing Unit). The processor 102 may be an integrated circuit chip with signal processing capabilities. The processor 102 can also be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field-programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 102 can be implemented by an integrated circuit chip.
[0101] In this exemplary electronic device, a sample image to be identified and a sample label of the sample image to be identified are input into a model to be trained for model training; a multi-channel feature extraction process is performed on the sample image to be identified by the model to be trained to obtain channel features of the sample image to be identified in multiple color space channels, that is, to obtain multi-channel features; and a color recognition process is performed on the sample image to be identified to obtain a target color category of the sample image to be identified; a contrast loss is calculated based on the multi-channel features to obtain the contrast loss of the sample image to be identified; and a classification loss is calculated based on the target color category and the sample label to obtain the classification loss of the sample image to be identified; a joint loss of the contrast loss and the classification loss is constructed, thereby constraining the training process of the model to be trained through the joint loss, so that the color recognition accuracy of the trained model is higher; based on the joint loss of each model training, the model parameters of the model to be trained are adjusted until the joint loss reaches a preset standard, thereby obtaining a trained color recognition model; in the subsequent specific application of the model, the image to be identified is input into the trained color recognition model, so that the color category of the image to be identified output by the color recognition model can be accurately obtained, thereby realizing efficient and accurate color recognition of the image to be identified.
[0102] See also Fig.11 , Fig.11 The computer-readable storage medium 110 stores program instructions 111 that can be executed by a processor, and the program instructions 111 are used to implement the steps in any of the above color recognition model training method embodiments.
[0103] In this exemplary storage medium, by running the program instructions in the storage medium, the sample image to be identified and the sample label of the sample image to be identified are input into the model to be trained for model training, the sample image to be identified is subjected to multi-channel feature extraction processing by the model to be trained to obtain the channel features of the sample image to be identified in multiple color space channels, that is, to obtain the multi-channel features, and the sample image to be identified is subjected to color recognition processing to obtain the target color category of the sample image to be identified; contrast loss calculation is performed based on the multi-channel features to obtain the contrast loss of the sample image to be identified, and classification loss calculation is performed based on the target color category and the sample label to obtain the classification loss of the sample image to be identified; a joint loss of contrast loss and classification loss is constructed, thereby constraining the training process of the model to be trained through the joint loss, so that the color recognition accuracy of the trained model is higher; based on the joint loss of each model training, the model parameters of the model to be trained are adjusted until the joint loss reaches a preset standard, thereby obtaining a trained color recognition model; in the subsequent specific application process of the model, the image to be identified is input into the trained color recognition model, and the color category of the image to be identified output by the color recognition model can be accurately obtained, thereby realizing efficient and accurate color recognition of the image to be identified.
[0104] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.
[0105] The above description of various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other, and for the sake of brevity, they will not be repeated herein.
[0106] In the several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation, such as units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0107] In addition, each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or part of the contribution to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (processor) to perform all or part of the steps of each implementation method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
Claims
1. A color recognition model training method, characterized in that: The method comprises: Inputting the sample image to be identified and the sample label of the sample image to be identified into the model to be trained to perform model training; Performing multi-channel feature extraction processing on the sample image to be identified based on the model to be trained to obtain multi-channel features of the sample image to be identified, and performing color recognition processing on the sample image to be identified to obtain a target color category of the sample image to be identified; Performing contrast loss calculation based on the multi-channel features to obtain the contrast loss of the sample image to be identified, and performing classification loss calculation based on the target color category and the sample label to obtain the classification loss of the sample image to be identified; Constructing a joint loss of the contrast loss and the classification loss; Based on the joint loss of each model training, the model parameters of the model to be trained are adjusted until the joint loss reaches a preset standard to obtain a trained color recognition model.
2. The method according to claim 1, characterized in that The step of performing multi-channel feature extraction processing on the sample image to be identified based on the model to be trained to obtain the multi-channel features of the sample image to be identified includes: Performing multi-channel feature extraction processing on the sample image to be identified to obtain three primary color channel features, hue channel features, and saturation channel features of the sample image to be identified; The step of calculating the contrast loss based on the multi-channel features to obtain the contrast loss of the sample image to be identified includes: Based on a first comparison result between the three primary color channel features and the hue channel features, and a second comparison result between the three primary color channel features and the saturation channel features, a contrast loss calculation is performed to obtain a contrast loss of the sample image to be identified.
3. The method according to claim 2, characterized in that The performing multi-channel feature extraction processing on the sample image to be identified to obtain the three primary color channel features, hue channel features and saturation channel features of the sample image to be identified includes: Acquire three primary color channel images of the sample image to be identified under the three primary color channels, a hue channel image of the sample image to be identified under the hue channel, and a saturation channel image of the sample image to be identified under the saturation channel; Performing feature mapping processing on the hue channel image and the saturation channel image respectively to obtain a mapped hue channel image and a mapped saturation channel image, wherein the mapped hue channel image, the mapped saturation channel image and the three primary color channel image have the same number of channels; Extracting the initial three-primary-color features of the sample image to be identified based on the three-primary-color channel images, extracting the initial hue features based on the mapped hue channel images, and extracting the initial saturation features based on the mapped saturation channel images; Pooling is performed on the three primary color initial features, the hue initial features, and the saturation initial features, respectively, to obtain the three primary color channel features, the hue channel features, and the saturation channel features.
4. The method according to claim 1, characterized in that: The step of performing multi-channel feature extraction processing on the sample image to be identified based on the model to be trained to obtain the multi-channel features of the sample image to be identified includes: Performing multi-channel feature extraction processing on the sample image to be identified to obtain three primary color channel features and hue and saturation combined features of the sample image to be identified; The step of calculating the contrast loss based on the multi-channel features to obtain the contrast loss of the sample image to be identified includes: The contrast loss is calculated based on the contrast result between the three primary color channel features and the hue saturation combined features to obtain the contrast loss of the sample image to be identified.
5. The method according to claim 4, characterized in that The performing multi-channel feature extraction processing on the sample image to be identified to obtain the three primary color channel features and the hue and saturation combined features of the sample image to be identified includes: Acquire three primary color channel images of the sample image to be identified under the three primary color channels, a hue channel image of the sample image to be identified under the hue channel, and a saturation channel image of the sample image to be identified under the saturation channel; Performing channel merging processing on the hue channel image and the saturation channel image to obtain a hue-saturation merged image; Performing feature mapping processing on the hue-saturation merged image to obtain a mapped hue-saturation merged image, wherein the mapped hue-saturation merged image has the same number of channels as the three-primary color channel image; Extracting the three primary color initial features of the sample image to be identified based on the three primary color channel images, and extracting the hue saturation merged initial features based on the mapped hue saturation merged image; Pooling processing is performed on the three primary color initial features and the hue and saturation combined initial features respectively to obtain the three primary color channel features and the hue and saturation combined features.
6. The method according to claim 1, characterized in that The step of performing color recognition processing on the sample image to be identified to obtain a target color category of the sample image to be identified includes: Performing color recognition processing on the sample image to be identified to obtain the color type of the sample image to be identified; In response to the color types being at least two, obtaining the number of pixels corresponding to each color type; The color category with the largest number of pixels is determined as the target color category of the sample image to be identified.
7. The method according to claim 1, characterized in that The sample label includes a color label and a mask label, and the classification loss calculation based on the target color category and the sample label to obtain the classification loss of the sample image to be identified includes: Calculating the classification loss between the target color category and the color label to obtain the color loss of the sample image to be identified; Binarizing the sample image to be identified based on the target color category to obtain a mask image of the sample image to be identified; Calculating the classification loss between the mask image and the mask label to obtain the mask loss of the sample image to be identified; The classification loss of the sample image to be identified is determined based on the color loss and the mask loss.
8. A color recognition method, characterized in that: The method comprises: Inputting the acquired image to be identified into a pre-trained color recognition model, and extracting the color features of the image to be identified based on the color recognition model; the color recognition model is trained by the method described in any one of claims 1 to 7; Classifying and identifying the color features of the image to be identified to obtain the color type of the image to be identified; In response to the color types being at least two, obtaining the number of pixels corresponding to each color type; The color category with the largest number of pixels is determined as the target color category of the image to be recognized.
9. An electronic device, characterized in that: The method comprises a memory and a processor, wherein the processor is used to execute program instructions stored in the memory to implement the method described in any one of claims 1 to 7 and / or the method described in claim 8.
10. A computer-readable storage medium having program instructions stored thereon, characterized in that: When the program instructions are executed by a processor, the method according to any one of claims 1 to 7 and / or the method according to claim 8 are implemented.
Citation Information
Patent Citations
A Method of Rubik's Cube Color Recognition Based on Support Vector Machine (svm)
CN109284759A
Vehicle color identification method based on target identification area interception
CN110322522A
Plant color identification method and device based on neural network
CN114821120A
Contraband detection method fusing image color features
CN116912519A
Color recognition method and apparatus for cupping mark image
WO2024103892A1
Cited By
Training sample construction method and device for perforated plate color recognition and computer equipment
CN121505364A
Method and device for constructing training sample of color recognition of multi-well plate and computer equipment
CN121505364B
