amaralibey commited on
Commit
ed84340
·
verified ·
1 Parent(s): bb1de42

Upload 2 files

Browse files
Files changed (2) hide show
  1. load_album.py +45 -0
  2. txt_encoder_state_dict.pth +3 -0
load_album.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ----------------------------------------------------------------------------
2
+ # Copyright (c) 2024 Amar Ali-bey
3
+ #
4
+ # OpenVPRLab: https://github.com/amaralibey/nanoCLIP
5
+ #
6
+ # Licensed under the MIT License. See LICENSE file in the project root.
7
+ # ----------------------------------------------------------------------------
8
+
9
+ from pathlib import Path
10
+ from PIL import Image
11
+ from torch.utils.data import Dataset
12
+ from torchvision import transforms as T
13
+
14
+
15
+ class AlbumDataset(Dataset):
16
+ def __init__(self, root_dir='./gallery/photos', transform=None):
17
+ """
18
+ This class is a simple dataset for loading ALL images from a directory and its subdirectories.
19
+ Formats supported: .jpg, .jpeg, .png, .bmp, .tiff
20
+ Args:
21
+ root_dir (str or Path): Path to the root directory containing images (e.g. gallery/).
22
+ transform (callable, optional): A function/transform to apply to the images.
23
+ """
24
+ self.root_dir = Path(root_dir)
25
+ if not self.root_dir.exists():
26
+ raise ValueError(f"Provided path {root_dir} does not exist.")
27
+
28
+ # Gather all image paths
29
+ self.imgs = [p for p in self.root_dir.rglob('*') if p.suffix.lower() in ['.jpg', '.jpeg', '.png', '.bmp', '.tiff']]
30
+ if not self.imgs:
31
+ raise ValueError(f"No images found under {root_dir}.")
32
+
33
+ self.transform = transform
34
+
35
+ def __len__(self):
36
+ return len(self.imgs)
37
+
38
+ def __getitem__(self, idx):
39
+ image_path = self.imgs[idx]
40
+ image = Image.open(image_path).convert("RGB") # Ensure 3-channel RGB
41
+
42
+ if self.transform:
43
+ image = self.transform(image)
44
+
45
+ return image, str(image_path) # Optionally return the path with the image
txt_encoder_state_dict.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7f88cda86a69e423f48efb45dee12406a4d25f95d18a907ab112f9901503f630
3
+ size 90994819