Бұл жазба автоматты түрде орыс тілінен аударылған. English
🎯 Мақсаты: Мүмкіндіктерді алу үшін ResNet50 көмегімен кескін іздеу жүйесінің логикасын және ұқсас кескіндерді іздеу үшін косинус ұқсастығын көрсету.
Бұл Кескінді Іздеу Алгоритмінің идеясы-k үміткерлерінің индекстерін қайтару үшін берілген кескін мен негізгі деректер жиынындағы барлық басқа кескіндер арасындағы ұқсастықтарды есептеу.
2 кескіннің ұқсастығын бағалау үшін біз барлық кескіндерді ерекшеліктерге айналдыруымыз керек ~ ендіру / векторлар деп аталатын сандық мәндер жиынтығы. Біз ResNet50-ді суреттерден мүмкіндіктерді алу үшін Қолданамыз, Жақын арада ResNet50 туралы.
Resnet50s есептеу тиімділігінің үйлесімі, ауқымды мәліметтер базасында алдын-ала дайындық (ImageNet) және әмбебаптығы оны компьютерлік көру тапсырмаларының кең ауқымында мүмкіндіктерді алу үшін тамаша таңдау жасайды. ResNet50 архитектурасы (несиелер: Викимедиа)

Косинус ұқсастығы екі кескін арасындағы ұқсастық көрсеткішін бағалау үшін пайдаланылады, себебі ол олардың мүмкіндік векторларының туралануын тиімді өлшейді, жоғары өлшемді және сирек деректерді жақсы өңдейді және есептеу жағынан тиімді. Косинус Ұқсастығының формуласы (несиелер: Википедия):

Кескін іздеу функциясының Коды:
def search_similar_images (сұрау_симиляр_индексі, кескін_қасиеттері, кескін_файлдары, k=5):
query_feature = image_features[query_image_index].пішінін өзгерту(1, -1)
ұқсастықтар = косинус_симилярлығы (сұрау_симилярлығы, кескін_симилярлығы).тегістеу()
top_k_indices = ұқсастықтар.аргсорт () [- к-1:-1][::-1] # ~ сұрау кескінінің өзін алып тастаңыз
топ_к_индикаттарды қайтару
Сілтемелер:
1. https://www.tensorflow.org/api_docs/python/tf/keras/applications/resnet
2. https://en.wikipedia.org/wiki/Cosine_similarity
Kaggle Дәптері: https://www.kaggle.com/code/armanzhalgasbayev/image-search-engine-demo-resnet-cossim
🎯 Goal: demonstrating the logic of an image search engine using ResNet50 for feature extraction and cosine similarity for searching similar images.
The idea behind of this Image Search Algorithm is to calculate similarities between a given image and all other images from the main dataset for returning the indices of the top k candidates.
For evaluating similarity score between 2 images, we need to convert all images into features ~ set of numeric values called embeddings / vectors. We use ResNet50 for extracting features from images, shortly about ResNet50.
ResNet50’s combination of computational efficiency, pre-training on a large-scale dataset (ImageNet), and versatility make it an excellent choice for feature extraction in a wide range of computer vision tasks. Architecture of ResNet50 (credits: WikiMedia)

Cosine similarity is used for evaluating the similarity score between two images because it effectively measures the alignment of their feature vectors, handles high-dimensional and sparse data well, and is computationally efficient. Formula of Cosine Similarity (credits: Wikipedia):

Image Search function Code:
def search_similar_images(query_image_index, image_features, image_files, k=5):
query_feature = image_features[query_image_index].reshape(1, -1)
similarities = cosine_similarity(query_feature, image_features).flatten()
top_k_indices = similarities.argsort()[-k-1:-1][::-1] # ~ exclude the query image itself
return top_k_indices
References:
1. https://www.tensorflow.org/api_docs/python/tf/keras/applications/resnet
2. https://en.wikipedia.org/wiki/Cosine_similarity
Kaggle Notebook: https://www.kaggle.com/code/armanzhalgasbayev/image-search-engine-demo-resnet-cossim