Spaces:
Runtime error
Runtime error
Upload 21 files
Browse files- images.zip +2 -2
- model/db_vit_b_16.index +2 -2
- src/.DS_Store +0 -0
- src/build_vector_database.py +5 -5
- src/config/.DS_Store +0 -0
- src/config/__pycache__/__init__.cpython-311.pyc +0 -0
- src/config/__pycache__/settings.cpython-311.pyc +0 -0
- src/modules/__pycache__/__init__.cpython-311.pyc +0 -0
- src/modules/__pycache__/config_extractor.cpython-311.pyc +0 -0
- src/modules/__pycache__/feature_extractor.cpython-311.pyc +0 -0
images.zip
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:91d47f3d7ab1beeaf5618e6dc1a8a6ce0047e468fed1ffdaa9995651e29b1a98
|
| 3 |
+
size 22677465
|
model/db_vit_b_16.index
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4a689e3a0812adb264cc25d857a73292fd0d71ded0b73841117a730ee9c93a75
|
| 3 |
+
size 98349
|
src/.DS_Store
CHANGED
|
Binary files a/src/.DS_Store and b/src/.DS_Store differ
|
|
|
src/build_vector_database.py
CHANGED
|
@@ -22,21 +22,21 @@ import os
|
|
| 22 |
from modules import FeatureExtractor
|
| 23 |
from config import *
|
| 24 |
|
| 25 |
-
|
|
|
|
| 26 |
def main(args=None):
|
| 27 |
# initialize the feature extractor with the base model specified in the arguments
|
| 28 |
feature_extractor = FeatureExtractor(base_model=args.feat_extractor)
|
| 29 |
# initialize the vector database indexing
|
| 30 |
index = faiss.IndexFlatIP(feature_extractor.feat_dims)
|
| 31 |
# get the list of images in sorted order
|
| 32 |
-
image_list = sorted(os.listdir(
|
| 33 |
|
| 34 |
with torch.no_grad():
|
| 35 |
# iterate over the images and add their extracted features to the index
|
| 36 |
for img_filename in tqdm(image_list):
|
| 37 |
# load image
|
| 38 |
-
img = PIL.Image.open(os.path.join(
|
| 39 |
-
# extract features
|
| 40 |
output = feature_extractor.extract_features(img)
|
| 41 |
# keep only batch dimension
|
| 42 |
output = output.view(output.size(0), -1)
|
|
@@ -47,7 +47,7 @@ def main(args=None):
|
|
| 47 |
index.add(output.numpy())
|
| 48 |
|
| 49 |
# save the index
|
| 50 |
-
index_filepath = os.path.join(
|
| 51 |
faiss.write_index(index, index_filepath)
|
| 52 |
|
| 53 |
|
|
|
|
| 22 |
from modules import FeatureExtractor
|
| 23 |
from config import *
|
| 24 |
|
| 25 |
+
images_dir = "../webp_images/images"
|
| 26 |
+
data_dir = "../webp_images"
|
| 27 |
def main(args=None):
|
| 28 |
# initialize the feature extractor with the base model specified in the arguments
|
| 29 |
feature_extractor = FeatureExtractor(base_model=args.feat_extractor)
|
| 30 |
# initialize the vector database indexing
|
| 31 |
index = faiss.IndexFlatIP(feature_extractor.feat_dims)
|
| 32 |
# get the list of images in sorted order
|
| 33 |
+
image_list = sorted(os.listdir(images_dir))
|
| 34 |
|
| 35 |
with torch.no_grad():
|
| 36 |
# iterate over the images and add their extracted features to the index
|
| 37 |
for img_filename in tqdm(image_list):
|
| 38 |
# load image
|
| 39 |
+
img = PIL.Image.open(os.path.join(images_dir, img_filename)).convert("RGB")
|
|
|
|
| 40 |
output = feature_extractor.extract_features(img)
|
| 41 |
# keep only batch dimension
|
| 42 |
output = output.view(output.size(0), -1)
|
|
|
|
| 47 |
index.add(output.numpy())
|
| 48 |
|
| 49 |
# save the index
|
| 50 |
+
index_filepath = os.path.join(data_dir, f"db_{args.feat_extractor}.index")
|
| 51 |
faiss.write_index(index, index_filepath)
|
| 52 |
|
| 53 |
|
src/config/.DS_Store
CHANGED
|
Binary files a/src/config/.DS_Store and b/src/config/.DS_Store differ
|
|
|
src/config/__pycache__/__init__.cpython-311.pyc
CHANGED
|
Binary files a/src/config/__pycache__/__init__.cpython-311.pyc and b/src/config/__pycache__/__init__.cpython-311.pyc differ
|
|
|
src/config/__pycache__/settings.cpython-311.pyc
CHANGED
|
Binary files a/src/config/__pycache__/settings.cpython-311.pyc and b/src/config/__pycache__/settings.cpython-311.pyc differ
|
|
|
src/modules/__pycache__/__init__.cpython-311.pyc
CHANGED
|
Binary files a/src/modules/__pycache__/__init__.cpython-311.pyc and b/src/modules/__pycache__/__init__.cpython-311.pyc differ
|
|
|
src/modules/__pycache__/config_extractor.cpython-311.pyc
CHANGED
|
Binary files a/src/modules/__pycache__/config_extractor.cpython-311.pyc and b/src/modules/__pycache__/config_extractor.cpython-311.pyc differ
|
|
|
src/modules/__pycache__/feature_extractor.cpython-311.pyc
CHANGED
|
Binary files a/src/modules/__pycache__/feature_extractor.cpython-311.pyc and b/src/modules/__pycache__/feature_extractor.cpython-311.pyc differ
|
|
|