ez-frcnn.utils
def utils.collate_fn(batch):
Custom collate function to merge a list of samples into a batch.
Inputs
batch (list): List of samples, where each sample is a tuple of data elements.
Output
tuple: Tuple of tuples, where each inner tuple contains all elements of a given type from the batch (e.g., images, targets).
Source code in library/utils.py
21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
def utils.get_loaders(train_dataset, valid_dataset, BATCH_SIZE, collate_fn):
Create DataLoader objects for training and validation datasets.
Inputs
train_dataset (Dataset): PyTorch Dataset object for training data. valid_dataset (Dataset): PyTorch Dataset object for validation data. BATCH_SIZE (int): Number of samples per batch to load. collate_fn (callable): Function to merge a list of samples into a mini-batch, used for handling variable-size inputs.
Output
list: A list containing two DataLoader objects: - train_loader: DataLoader for the training dataset with shuffling enabled. - valid_loader: DataLoader for the validation dataset without shuffling.
Source code in library/utils.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
class utils.getDataset(Dataset):
Bases: Dataset
Custom PyTorch Dataset for loading images and corresponding bounding box annotations from a directory containing image files and Pascal VOC-style XML annotation files.
Attributes:
Name | Type | Description |
---|---|---|
dir_path |
str
|
Directory path containing images and XML annotation files. |
width |
int
|
Desired image width after resizing. |
height |
int
|
Desired image height after resizing. |
transforms |
callable
|
Optional transformations to be applied on the images and bounding boxes. |
classes |
list
|
List of unique class names parsed from annotation XML files, with 'background' as the first class. |
all_images |
list
|
Sorted list of image filenames in the dataset directory. |
Methods:
Name | Description |
---|---|
get_classes_from_annotations |
Parses XML annotation files to extract all unique classes. |
__getitem__ |
Loads and processes the image and its annotations at index |
__len__ |
Returns the total number of images in the dataset. |
Usage
dataset = getDataset(dir_path='path/to/data', width=224, height=224, transforms=transform_function) image, target = dataset[0]
Source code in library/utils.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|
get_classes_from_annotations()
Parse all XML files in the dataset directory to build a list of unique classes.
Source code in library/utils.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|