|
@@ -1,3 +1,73 @@
|
|
|
# [NA-Birds](http://dl.allaboutbirds.org/nabirds) dataset wrapper
|
|
|
|
|
|
-To see how to use this library take a look at [nabirds/display.py](nabirds/display.py).
|
|
|
+For more deatils to see how to use this library take a look at [nabirds/display.py](nabirds/display.py).
|
|
|
+
|
|
|
+## Annotation and Image Loading
|
|
|
+
|
|
|
+Here is some example code how to load images and use the predefined train-test split.
|
|
|
+
|
|
|
+```python
|
|
|
+# replace NAB_Annotations with CUB_Annotations to load CUB200-2011 annotations
|
|
|
+from nabirds import NAB_Annotations, Dataset
|
|
|
+
|
|
|
+annot = NAB_Annotations("path/to/nab/folder")
|
|
|
+
|
|
|
+train_data = Dataset(annot.train_uuids, annot)
|
|
|
+test_data = Dataset(annot.test_uuids, annot)
|
|
|
+
|
|
|
+print("Loaded {} training and {} test images".format(len(train_data), len(test_data)))
|
|
|
+```
|
|
|
+
|
|
|
+## Dataset Iteration
|
|
|
+```python
|
|
|
+import matplotlib.pyplot as plt
|
|
|
+
|
|
|
+# either access the images directly
|
|
|
+im, parts, label = test_data[100]
|
|
|
+plt.imshow(im)
|
|
|
+plt.show()
|
|
|
+
|
|
|
+# or iterate over the dataset
|
|
|
+for im, parts, label in train_data:
|
|
|
+ plt.imshow(im)
|
|
|
+ plt.show()
|
|
|
+
|
|
|
+```
|
|
|
+
|
|
|
+## Working with Part Annotations
|
|
|
+Both datasets (NAB and CUB) have part annotations. Each annotation has for each of the predefined parts the location of this part and a boolean (`0` or `1`) value whether this part is visible. A [`Dataset`](nabirds/dataset/__init__.py#L5) instance returns besides the image and the class label this information:
|
|
|
+
|
|
|
+```python
|
|
|
+
|
|
|
+im, parts, label = train_data[100]
|
|
|
+
|
|
|
+print(parts)
|
|
|
+# array([[ 0, 529, 304, 1],
|
|
|
+# [ 1, 427, 277, 1],
|
|
|
+# [ 2, 368, 323, 1],
|
|
|
+# [ 3, 0, 0, 0],
|
|
|
+# [ 4, 449, 292, 1],
|
|
|
+# [ 5, 398, 502, 1],
|
|
|
+# [ 6, 430, 398, 1],
|
|
|
+# [ 7, 0, 0, 0],
|
|
|
+# [ 8, 365, 751, 1],
|
|
|
+# [ 9, 0, 0, 0],
|
|
|
+# [ 10, 0, 0, 0]])
|
|
|
+
|
|
|
+```
|
|
|
+
|
|
|
+In order to filter by only visible parts use the [`utils.visible_part_locs`](nabirds/dataset/utils.py#L28) function. It returns the indices and the x-y positions of the visible parts:
|
|
|
+
|
|
|
+```python
|
|
|
+idxs, xy = visible_part_locs(parts)
|
|
|
+print(idxs)
|
|
|
+# array([0, 1, 2, 4, 5, 6, 8])
|
|
|
+print(xy)
|
|
|
+# array([[529, 427, 368, 449, 398, 430, 365],
|
|
|
+# [304, 277, 323, 292, 502, 398, 751]])
|
|
|
+
|
|
|
+x, y = xy
|
|
|
+plt.imshow(im)
|
|
|
+plt.scatter(x,y, marker="x", c=idxs)
|
|
|
+plt.show()
|
|
|
+```
|