Wildlife dataset
WildlifeDataset is a class for creating pytorch style datasets by integration of datasets provided by wildlife-datasets library. It has implemented __len__ and __getattr__ methods, which allows using pytorch dataloaders for training and inference.
Metadata dataframe
Integral part of WildlifeDataset is metadata dataframe, which includes all information about images in the dataset. Typical dataset from the wildlife-dataset have following metadata table:
image_id | identity | path | split | bbox | segmentation |
---|---|---|---|---|---|
image_1 | a | images/a/image_1 | train | bbox |
compressed rle |
image_2 | a | images/a/image_2 | test | bbox |
compressed rle |
image_3 | b | images/b/image_3 | train | bbox |
compressed rle |
Columns image_id
, identity
, path
are required, other columns are optional. In the table above, bbox
is bounding box in form [x, y, width, height], and can be stored both as list or string. compressed rle
is segmentation mask in compressed RLE format as described by pycocotools
Loading methods
If metadata table have optional bbox
or segmentation
columns, additional alternative image loading methods can be used.
Argument | Loading effect |
---|---|
full |
Full image |
full_mask |
Full image with redacted background |
full_hide |
Full image with redacted foreground |
bbox |
Bounding box cropp |
bbox_mask |
Bounding box cropp with redacted background |
bbox_hide |
Bounding box cropp with redacted foreground |
crop_black |
Black background cropp, if there is one |
Example
from wildlife_tools.data.dataset import WildlifeDataset
import pandas as pd
metadata = pd.read_csv('ExampleDataset/metadata.csv')
dataset = WildlifeDataset(metadata, 'ExampleDataset')
# View first image in the dataset.
image, label = dataset[0]
Reference
PyTorch-style dataset for a wildlife datasets
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata |
pd.DataFrame
|
A pandas dataframe containing image metadata. |
required |
root |
str | None
|
Root directory if paths in metadata are relative. If None, paths in metadata are used as they are. |
None
|
split |
Callable | None
|
A function that splits metadata, e.g., instance of data.Split. |
None
|
transform |
Callable | None
|
A function that takes in an image and returns its transformed version. |
None
|
img_load |
str
|
Method to load images. Options: 'full', 'full_mask', 'full_hide', 'bbox', 'bbox_mask', 'bbox_hide', and 'crop_black'. |
'full'
|
col_path |
str
|
Column name in the metadata containing image file paths. |
'path'
|
col_label |
str
|
Column name in the metadata containing class labels. |
'identity'
|
load_label |
bool
|
If False, __getitem__ returns only image instead of (image, label) tuple. |
True
|
Attributes:
Name | Type | Description |
---|---|---|
labels |
np.array
|
An integers array of ordinal encoding of labels. |
labels_string |
np.array
|
A strings array of original labels. |
labels_map |
dict
|
A mapping between labels and their ordinal encoding. |
num_classes |
int
|
Return the number of unique classes in the dataset. |
Source code in data/dataset.py
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 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 |
|