Commit b5f76334 authored by Okan DÜZYEL's avatar Okan DÜZYEL
Browse files

Upload New File

parent 89bcc4ce
Showing with 38 additions and 0 deletions
+38 -0
"""
Created on Sat May 4 12:00:11 2023
@author: okanduzyel
"""
from sentence_transformers import SentenceTransformer, util
from PIL import Image
import glob
import os
print('Loading CLIP Model...')
model = SentenceTransformer('clip-ViT-B-32')
image_names = list(glob.glob('./images/*.jpeg'))
print("Images:", len(image_names))
encoded_image = model.encode([Image.open(filepath) for filepath in image_names], batch_size=128, convert_to_tensor=True, show_progress_bar=True)
processed_images = util.paraphrase_mining_embeddings(encoded_image)
NUM_SIMILAR_IMAGES = 30
print('Finding duplicate images...')
duplicates = [image for image in processed_images if image[0] >= 0.999]
for score, image_id1, image_id2 in duplicates[0:NUM_SIMILAR_IMAGES]:
print("\nScore: {:.3f}%".format(score * 100))
print(image_names[image_id1])
print(image_names[image_id2])
print('Finding near duplicate images...')
threshold = 0.99
near_duplicates = [image for image in processed_images if image[0] < threshold]
for score, image_id1, image_id2 in near_duplicates[0:NUM_SIMILAR_IMAGES]:
print("\nScore: {:.3f}%".format(score * 100))
print(image_names[image_id1])
print(image_names[image_id2])
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment