Skip to content

Commit 7719954

Browse files
committed
Merge branch 'master' of github.com:developmentseed/label-maker
2 parents 83e8d26 + 3644a70 commit 7719954

File tree

5 files changed

+98
-3
lines changed

5 files changed

+98
-3
lines changed

.circleci/config.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,16 @@ jobs:
4747
cp -r test/fixtures/integration/tiles integration-sg/tiles
4848
label-maker labels --dest integration-sg --config test/fixtures/integration/config.integration.segmentation.json
4949
python test/verify-labels-sg.py
50-
50+
51+
# object detection integration tests
52+
mkdir integration-od
53+
cp -r test/fixtures/integration/tiles integration-od/tiles
54+
cp test/fixtures/integration/portugal-z17.mbtiles integration-od/
55+
label-maker labels -d integration-od -c test/fixtures/integration/config.integration.object_detection.json
56+
python test/verify-labels-od.py
57+
label-maker package -d integration-od -c test/fixtures/integration/config.integration.object_detection.json
58+
python test/verify-package-od.py
59+
5160
# Retest that `label-maker labels` works, but from outside the module directory
5261
cd ~
5362
label-maker labels --dest label-maker/integration-cl --config label-maker/test/fixtures/integration/config.integration.json > stdout

label_maker/package.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
from PIL import Image
88

9+
910
def package_directory(dest_folder, classes, imagery, ml_type, seed=False, train_size=0.8, **kwargs):
1011
"""Generate an .npz file containing arrays for training machine learning algorithms
1112
@@ -44,8 +45,8 @@ def package_directory(dest_folder, classes, imagery, ml_type, seed=False, train_
4445
# find maximum number of features in advance so numpy shapes match
4546
if ml_type == 'object-detection':
4647
max_features = 0
47-
for tile in tiles.files:
48-
features = len(tiles[tile][0])
48+
for tile in labels.files:
49+
features = len(labels[tile])
4950
if features > max_features:
5051
max_features = features
5152

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"country": "portugal",
3+
"bounding_box": [
4+
-9.4575,
5+
38.8467,
6+
-9.4510,
7+
38.8513
8+
],
9+
"zoom": 17,
10+
"classes": [
11+
{ "name": "Water Tower", "filter": ["==", "man_made", "water_tower"] },
12+
{ "name": "Building", "filter": ["has", "building"] },
13+
{ "name": "Farmland", "filter": ["==", "landuse", "farmland"] },
14+
{ "name": "Ruins", "filter": ["==", "historic", "ruins"] },
15+
{ "name": "Parking", "filter": ["==", "amenity", "parking"] },
16+
{ "name": "Roads", "filter": ["has", "highway"] }
17+
],
18+
"imagery": "https://api.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.jpg?access_token=ACCESS_TOKEN",
19+
"background_ratio": 1,
20+
"ml_type": "object-detection",
21+
"seed": 19
22+
}

test/verify-labels-od.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""Validate that the output produced by integration testing on 'label-maker labels'
2+
matches our expectations, specifically for object detection tasks"""
3+
import numpy as np
4+
5+
labels = np.load("integration-od/labels.npz")
6+
7+
expected_num = dict()
8+
expected_num['62092-50162-17'] = np.array([])
9+
expected_num['62092-50163-17'] = np.array([
10+
[209, 192, 259, 259, 6], [251, 251, 259, 259, 6]
11+
])
12+
expected_num['62092-50164-17'] = np.array([
13+
[209, -4, 250, 28, 6], [242, -4, 259, 28, 6],
14+
[222, 13, 235, 66, 6], [87, 20, 250, 259, 6]
15+
])
16+
expected_num['62093-50162-17'] = np.array([
17+
[81, 145, 128, 259, 6], [124, -4, 218, 259, 6],
18+
[207, -4, 247, 153, 6], [140, 108, 193, 259, 6],
19+
[125, 236, 152, 259, 6], [162, 177, 176, 216, 6],
20+
[170, 151, 214, 179, 6], [141, 166, 244, 259, 6],
21+
[203, 88, 259, 186, 6]
22+
])
23+
expected_num['62093-50163-17'] = np.array([
24+
[81, -4, 125, 15, 6], [117, -4, 133, 17, 6],
25+
[119, -4, 151, 36, 6], [125, -4, 140, 7, 6],
26+
[141, -4, 187, 7, 6], [64, 32, 91, 60, 4],
27+
[84, 50, 106, 64, 6], [111, 9, 127, 26, 6],
28+
[111, 18, 127, 35, 6], [84, 15, 119, 52, 6],
29+
[74, 6, 129, 69, 5], [93, 24, 123, 46, 6],
30+
[88, 27, 127, 93, 6], [-4, 85, 96, 213, 6],
31+
[-2, 85, 96, 259, 6], [115, 38, 259, 100, 6]
32+
])
33+
expected_num['62094-50162-17'] = np.array([
34+
[67, -4, 172, 248, 6], [-4, 172, 90, 259, 6],
35+
[91, 170, 259, 227, 6]
36+
])
37+
expected_num['62093-50164-17'] = np.array([
38+
[-4, -4, 12, 22, 6], [207, 158, 259, 195, 6]
39+
])
40+
expected_num['62094-50163-17'] = np.array([
41+
[73, -4, 259, 78, 6], [30, 166, 60, 196, 1],
42+
[30, 166, 60, 196, 2], [203, 129, 259, 259, 6],
43+
[-4, 90, 259, 138, 6]
44+
])
45+
expected_num['62094-50164-17'] = np. array([
46+
[158, -4, 216, 82, 6], [-4, 108, 147, 173, 6],
47+
[139, 74, 254, 143, 6], [240, 90, 259, 232, 6]
48+
])
49+
50+
assert len(labels.files) == len(expected_num.keys())

test/verify-package-od.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Validate that the output produced by integration testing on 'label-maker package' matches our expectations"""
2+
import numpy as np
3+
4+
data = np.load('integration-od/data.npz')
5+
6+
assert np.sum(data['x_train']) == 144752757
7+
assert np.sum(data['x_test']) == 52758414
8+
assert data['x_train'].shape == (6, 256, 256, 3)
9+
assert data['x_test'].shape == (2, 256, 256, 3)
10+
11+
# validate our label data with exact matches in shape
12+
assert data['y_train'].shape == (6, 16, 5)
13+
assert data['y_test'].shape == (2, 16, 5)

0 commit comments

Comments
 (0)