-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeatureExtraction.py
More file actions
38 lines (29 loc) · 1.13 KB
/
Copy pathfeatureExtraction.py
File metadata and controls
38 lines (29 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
""" The Code is for extracting features from the image dataset and storing then into a database. """
# Importing the required modules
from FeatureExtractor import featureExtractorClass
from pathlib import Path
from PIL import Image
import numpy as np
import tensorflow as tf
# Checking for the GPU for faster computation
print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))
print(tf.test.is_built_with_cuda())
# Initializing the Variables
features = []
fe = featureExtractorClass()
feature_path = "./featureDatabase.npy"
# Iterate through images for feature extraction
# And storing the images path in a list
img_paths = []
for img_path in sorted(Path("./combined_datasets").glob("*.jpg")):
print(img_path)
img_paths.append(img_path)
# Extract Features
feature = fe.extract(img = Image.open(img_path))
features.append(feature)
# Save the Numpy array (.npy) on designated path
np.save(feature_path, features)
# Saving the image paths in a text file for further use
with open("imgPaths.txt", 'w') as f :
for img_path in img_paths :
f.write(str(img_path) + '\n')