Skip to content

Commit 1aff016

Browse files
authored
Merge pull request #66 from giswqs/master
fix image and tile format inconsistency
2 parents 7ffee3e + 408bac6 commit 1aff016

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ data
1212
config.json
1313
stdout*
1414
/integration*
15+
.idea/

label_maker/package.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def package_directory(dest_folder, classes, imagery, ml_type, seed=False, train_
5858
# open the images and load those plus the labels into the final arrays
5959
o = urlparse(imagery)
6060
_, image_format = op.splitext(o.path)
61+
if image_format == '.tif': # if a local GeoTIFF or a remote Cloud Optimized GeoTIFF is provided, use jpg as tile format
62+
image_format = '.jpg'
6163
for tile in tiles:
6264
image_file = op.join(dest_folder, 'tiles', '{}{}'.format(tile, image_format))
6365
try:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"country": "sao_tome_and_principe",
3+
"bounding_box": [6.72746119738703,0.3382909054246151,6.72776258384623,0.33878086940393715],
4+
"zoom": 20,
5+
"classes": [
6+
{ "name": "Roads", "filter": ["has", "highway"] },
7+
{ "name": "Buildings", "filter": ["has", "building"] }
8+
],
9+
"imagery": "integration-tif/drone.tif",
10+
"background_ratio": 1,
11+
"ml_type": "classification"
12+
}
902 Bytes
Binary file not shown.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Test that the following CLI command returns the expected outputs
2+
label-maker package -d integration-tif/sao_tome -c test/fixtures/integration/config.intergration.geotiff_package.json"""
3+
import unittest
4+
from os import makedirs
5+
from shutil import copyfile, rmtree
6+
import subprocess
7+
8+
import numpy as np
9+
10+
class TestObjectDetectionPackage(unittest.TestCase):
11+
"""Tests for local GeoTIFF package creation"""
12+
@classmethod
13+
def setUpClass(cls):
14+
makedirs('integration-tif')
15+
copyfile('test/fixtures/drone.tif', 'integration-tif/drone.tif')
16+
copyfile('test/fixtures/integration/labels-tif.npz', 'integration-tif/labels.npz')
17+
18+
@classmethod
19+
def tearDownClass(cls):
20+
rmtree('integration-tif')
21+
22+
def test_cli(self):
23+
"""Verify data.npz produced by CLI"""
24+
cmd = 'label-maker images -d integration-tif -c test/fixtures/integration/config.intergration.geotiff_package.json'
25+
cmd = cmd.split(' ')
26+
subprocess.run(cmd, universal_newlines=True)
27+
28+
cmd = 'label-maker package -d integration-tif -c test/fixtures/integration/config.intergration.geotiff_package.json'
29+
cmd = cmd.split(' ')
30+
subprocess.run(cmd, universal_newlines=True)
31+
32+
data = np.load('integration-tif/data.npz')
33+
34+
self.assertEqual(data['x_train'].shape, (3, 256, 256, 3))
35+
self.assertEqual(data['x_test'].shape, (1, 256, 256, 3))
36+
37+
# validate our label data with exact matches in shape
38+
self.assertEqual(data['y_train'].shape, (3, 3))
39+
self.assertEqual(data['y_test'].shape, (1, 3))

0 commit comments

Comments
 (0)