Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Okan DÜZYEL
Image Captioning
Commits
b5f76334
Commit
b5f76334
authored
2 years ago
by
Okan DÜZYEL
Browse files
Options
Download
Email Patches
Plain Diff
Upload New File
parent
89bcc4ce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
similarity.py
+38
-0
similarity.py
with
38 additions
and
0 deletions
+38
-0
similarity.py
0 → 100644
+
38
-
0
View file @
b5f76334
"""
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
(
"
\n
Score: {:.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
(
"
\n
Score: {:.3f}%"
.
format
(
score
*
100
))
print
(
image_names
[
image_id1
])
print
(
image_names
[
image_id2
])
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets