A caching method, efficient image semantic retrieval method and system
By using cache technology in the image semantic retrieval system, the hash code is compressed into decimal number storage, which solves the problem of excessive time-consuming image semantic retrieval in the big data environment, and realizes efficient metadata retrieval.
Patent Information
- Application Number
- CN202011333525.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-24
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2040-11-24
AI Technical Summary
In a big data environment, image semantic retrieval takes too long. While the existing technology reduces the time to read irrelevant images, it still cannot effectively solve the time overhead problem of retrieving metadata itself.
The hash code in the semantic search results is compressed into a decimal number through partial conversion and stored in the cache as a key-value. When the query requirement comes, the corresponding key is first searched in the cache. If it exists, the value will be read directly, otherwise the search and the result will be stored.
The caching technology significantly improves the retrieval efficiency of metadata, reduces the time-consuming process, and improves the efficiency of image semantic retrieval.
Smart Images

Figure CN112395440B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of semantic storage, and more specifically, relates to a caching method, an efficient image semantic retrieval method and a system. Background Art
[0002] Images are often used for data analysis due to their rich semantic content. Due to the relatively large size of image files, the waiting time to read all images before processing has gradually become a performance bottleneck, especially as the amount of data continues to increase. Taking 100 million images of size 1MB as an example, the average sequential read bandwidth of SATA hard drives on Tencent's servers is about 220MB / s, which takes about 5.26 days to read these images. Although distributed storage provides a preliminary solution to this problem, the ever-increasing amount of image data and the expansion of distributed storage today make this problem still not perfectly solved. Therefore, we believe that a more fundamental solution is needed to solve this problem on a single node, which in turn will complement and enhance the distributed solution.
[0003] To solve the above problems, a current technical solution is to analyze the metadata in advance before reading the analyzed image on the disk, filter out the metadata we need, and then enter the disk to read the corresponding image, so as to reduce the time spent on reading irrelevant images. Specifically, the solution consists of two parts, image hash code extraction and hash code storage. The purpose of image hash code extraction is to extract the hash code that can reflect the semantic association of the image and use it as the metadata of the image. Generally, a similarity hash algorithm is used to obtain the hash code corresponding to each image. The purpose of hash code storage is to organize and save the hash code persistently, while ensuring subsequent efficient query and reading. Generally, a tree structure or graph structure is used for storage. Combining the above two points, the original image comparison process is simplified to the comparison calculation between hash codes. According to the comparison results, the hash code of interest is filtered out, and then the corresponding image is read from the hard disk, which greatly improves the efficiency of image semantic content analysis.
[0004] However, in a big data environment, even searching for metadata itself takes a lot of time. As the amount of data increases and the complexity of search conditions increases, the time consumption will increase significantly. Summary of the invention
[0005] In view of the defects of the prior art and the need for improvement, the present invention provides a caching method, an efficient image semantic retrieval method and a system, the purpose of which is to utilize caching technology to improve the retrieval efficiency of metadata at the cost of a small amount of storage overhead, thereby solving the problem of taking too long to retrieve all metadata in a big data environment.
[0006] To achieve the above object, according to a first aspect of the present invention, a caching method is provided, the method comprising:
[0007] After each semantic search result is obtained, the hash code of the search object of this search is regarded as a binary number, then converted into a decimal number as the key, the hash codes in the search result of this search are concatenated in sequence, the concatenated string is regarded as a binary number, then converted into a decimal number as the value, and the key-value is stored in the cache.
[0008] Preferably, a hashmap structure is used to store key-value pairs.
[0009] Preferably, when the cache occupancy reaches a first set threshold of the original picture set size, the key-value pair is replaced using an LRU algorithm.
[0010] To achieve the above-mentioned purpose, according to the second aspect of the present invention, an efficient image semantic retrieval method is provided. When a query demand comes, first check whether there is a corresponding key in the cache. If so, take out its value as the retrieval result. Otherwise, after the retrieval is completed, the method described in the first aspect is used to compress the retrieval object and retrieval results, and form a key-value stored in the cache.
[0011] Preferably, when a query request comes, first check whether there is a corresponding key in the cache, as follows:
[0012] Treat the retrieved object hash code as a binary number, convert it to a decimal number, and then search it with the key in the cache.
[0013] Preferably, the method of taking out its value as the search result is as follows:
[0014] For value, convert the decimal value into a binary number. When the length of the binary 0-1 string after conversion is not an integer multiple of the optimal length of the hash code, pad the beginning of the binary number with zeros so that its length is exactly an integer multiple of the optimal length of the hash code, and the number of zeros padded is less than the optimal length of the hash code; split the binary 0-1 string according to the optimal length of the hash code and restore it to obtain the similarity hash code.
[0015] To achieve the above-mentioned object, according to a third aspect of the present invention, there is provided an efficient image semantic retrieval system, comprising: a computer-readable storage medium and a processor;
[0016] The computer-readable storage medium is used to store executable instructions;
[0017] The processor is used to read the executable instructions stored in the computer-readable storage medium to execute the efficient image semantic retrieval method described in the second aspect.
[0018] In general, the above technical solutions conceived by the present invention can achieve the following beneficial effects:
[0019] (1) The present invention uses the base conversion compression hash code to compress the character string (or array) originally composed of 01 into a decimal number and store it in an integer variable. In this way, after a single search result is compressed, the storage space required is greatly reduced, so that most of the search results can be stored within an acceptable storage overhead range, and the high-speed read and write characteristics of the cache are brought into full play.
[0020] (2) The present invention utilizes the high read and write efficiency of the cache to store the search results obtained by searching the metadata each time in the cache. In this way, when the next search demand comes, it first checks whether the search results have been stored in the cache. If so, no matter how complex the search conditions are, it can be directly read from the cache, avoiding the time-consuming search process, thereby improving the efficiency of image semantic retrieval. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 A schematic diagram of the retrieval requirement compression method provided by the present invention;
[0022] Figure 2 A schematic diagram of the search result compression method provided by the present invention;
[0023] Figure 3 A schematic diagram of a cache storage object provided by the present invention. DETAILED DESCRIPTION
[0024] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0025] First, the terms involved in the present invention are explained as follows:
[0026] Retrieval object: the image to be analyzed.
[0027] Retrieval requirement: refers to the source data used for searching, which is specifically in the form of a hash code in the computer.
[0028] Search conditions: refers to the conditions that define the similarity of hash codes, such as Hamming distance less than 8.
[0029] Retrieval results: refers to the target data set obtained by the retrieval requirement query. The specific form of the retrieval results in the computer is a set of hash codes that meet the retrieval conditions. They are generally saved in the form of a linked list or array.
[0030] Hash code: a fixed-length string consisting of 01 characters or a fixed-length array consisting of 01.
[0031] The present invention provides a cache method, which includes: after obtaining a semantic search result each time, treating the hash code of the search object of this search as a binary number, converting it into a decimal number and using it as a key, concatenating the hash codes in the search result of this search in sequence, treating the concatenated string as a binary number, converting it into a decimal number and using it as a value, and storing the key-value in a cache.
[0032] like Figure 1 As shown in the figure, for the key composed of 01 in the cache, it is treated as a binary number, converted into a decimal number and stored in an integer variable. Figure 2 As shown, for the value in the cache that is composed of a hash code array, this embodiment first concatenates these hash codes into a long string, then treats it as a binary number, converts it into a decimal number and stores it in an integer variable.
[0033] When a query request comes, the hash code is first compressed into a decimal integer variable, and the cache is checked to see if it already exists. If it exists, its value is returned, the value is decompressed into a long string of characters consisting of 01, and the long string is divided into a fixed-length hash code array according to the original hash code; if it does not exist, the search process is performed, and the search request and search results are compressed according to the compression method mentioned above, forming a key-value pair and stored in the cache.
[0034] The image semantic retrieval result is a hash code that is highly similar to the hash code of the retrieved image. There are many ways to determine the similarity of hash codes. This embodiment uses the Hamming distance. When the Hamming distance is less than a set threshold (8 in the implementation), the two hash codes are considered similar. Figure 3 As shown, the cache stores retrieval requirements and retrieval results in key-value format.
[0035] Preferably, a hashmap structure is used to store key-value pairs to achieve O(1) read and write efficiency.
[0036] Preferably, when the cache occupancy reaches a first set threshold (2% in the embodiment) of the original picture set size, the key-value pair is replaced using an LRU algorithm.
[0037] Although the storage space has been optimized, in some environments with strict storage overhead requirements, the cache may not be enough to store all search results. To this end, a simple and efficient LRU elimination strategy is used to eliminate infrequently used search results at a minimal LRU maintenance cost, ensuring a high cache hit rate and thus ensuring efficient metadata retrieval.
[0038] The present invention provides an efficient image semantic retrieval method. When a query demand comes, it first checks whether there is a corresponding key in the cache. If so, its value is taken out as the retrieval result. Otherwise, after the retrieval is completed, the retrieval object and the retrieval result are compressed using the above method to form a key-value and store it in the cache.
[0039] Preferably, when a query demand comes, first check whether there is a corresponding key in the cache, specifically as follows: regard the hash code of the retrieval object as a binary number, then convert it into a decimal number, and then search with the key in the cache.
[0040] Preferably, the method of taking out its value as the search result is as follows: for value, convert the decimal value into a binary number. When the length of the binary 0-1 string after conversion is not an integer multiple of the optimal length of the hash code (48 in the embodiment), pad zeros at the beginning of the binary number so that its length is exactly an integer multiple of the optimal length of the hash code, and the number of zeros padded is less than the optimal length of the hash code; split the binary 0-1 string according to the optimal length of the hash code, and restore it to obtain a similarity hash code.
[0041] The present invention provides an efficient image semantic retrieval system, comprising: a computer-readable storage medium and a processor; the computer-readable storage medium is used to store executable instructions; the processor is used to read the executable instructions stored in the computer-readable storage medium and execute the above-mentioned efficient image semantic retrieval method.
[0042] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A caching method, characterized in that: The method includes: After each semantic search result is obtained, the hash code of the search object of this search is regarded as a binary number, and then converted into a decimal number as the key. The hash codes in the search results of this search are concatenated in sequence, and the concatenated string is regarded as a binary number, and then converted into a decimal number as the value, and the key-value is stored in the cache; wherein the search object is the image to be analyzed.
2. The method according to claim 1, characterized in that Use hashmap structure to store key-value pairs.
3. The method according to claim 1 or 2, characterized in that When the cache occupancy reaches the first set threshold of the original image set size, the LRU algorithm is used to replace the key-value pairs.
4. An efficient image semantic retrieval method, characterized in that: When a query demand comes, first check whether there is a corresponding key in the cache. If so, take out its value as the search result. Otherwise, after the search is completed, use the method described in any one of claims 1 to 3 to compress the search object and the search result to form a key-value and store it in the cache; When a query request comes, first check whether there is a corresponding key in the cache, as follows: Treat the retrieval object hash code as a binary number, convert it to a decimal number, and then search it with the key in the cache; The specific details of taking out its value as the search result are as follows: For value, convert the decimal value into a binary number. When the length of the binary 0-1 string after conversion is not an integer multiple of the optimal length of the hash code, pad zeros at the beginning of the binary number so that its length is exactly an integer multiple of the optimal length of the hash code, and the number of padding zeros is lower than the optimal length of the hash code; split the binary 0-1 string according to the optimal length of the hash code, and restore the similarity hash code; the Hamming distance is used to determine the similarity of the hash codes. When the Hamming distance is less than the set threshold, the two hash codes are considered similar.
5. An efficient image semantic retrieval system, characterized in that: include: A computer readable storage medium and a processor; The computer-readable storage medium is used to store executable instructions; The processor is used to read the executable instructions stored in the computer-readable storage medium to execute the efficient image semantic retrieval method described in claim 4.
Citation Information
Patent Citations
Data query method of local caches, storage medium and server
CN107784073A
Image storage and retrieval method, client and system
CN109783667A