diff --git a/.gitignore b/.gitignore index 63815e9..8a4ec3d 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ data config.json stdout* /integration* +.idea/ diff --git a/label_maker/package.py b/label_maker/package.py index ecfa085..ba3e40f 100644 --- a/label_maker/package.py +++ b/label_maker/package.py @@ -58,6 +58,8 @@ def package_directory(dest_folder, classes, imagery, ml_type, seed=False, train_ # open the images and load those plus the labels into the final arrays o = urlparse(imagery) _, image_format = op.splitext(o.path) + if image_format == '.tif': # if a local GeoTIFF or a remote Cloud Optimized GeoTIFF is provided, use jpg as tile format + image_format = '.jpg' for tile in tiles: image_file = op.join(dest_folder, 'tiles', '{}{}'.format(tile, image_format)) try: diff --git a/test/fixtures/integration/config.intergration.geotiff_package.json b/test/fixtures/integration/config.intergration.geotiff_package.json new file mode 100644 index 0000000..dd3cd1c --- /dev/null +++ b/test/fixtures/integration/config.intergration.geotiff_package.json @@ -0,0 +1,12 @@ +{ + "country": "sao_tome_and_principe", + "bounding_box": [6.72746119738703,0.3382909054246151,6.72776258384623,0.33878086940393715], + "zoom": 20, + "classes": [ + { "name": "Roads", "filter": ["has", "highway"] }, + { "name": "Buildings", "filter": ["has", "building"] } + ], + "imagery": "integration-tif/drone.tif", + "background_ratio": 1, + "ml_type": "classification" +} diff --git a/test/fixtures/integration/labels-tif.npz b/test/fixtures/integration/labels-tif.npz new file mode 100644 index 0000000..95e41cf Binary files /dev/null and b/test/fixtures/integration/labels-tif.npz differ diff --git a/test/integration/test_geotiff_package.py b/test/integration/test_geotiff_package.py new file mode 100644 index 0000000..a448ae8 --- /dev/null +++ b/test/integration/test_geotiff_package.py @@ -0,0 +1,39 @@ +"""Test that the following CLI command returns the expected outputs +label-maker package -d integration-tif/sao_tome -c test/fixtures/integration/config.intergration.geotiff_package.json""" +import unittest +from os import makedirs +from shutil import copyfile, rmtree +import subprocess + +import numpy as np + +class TestObjectDetectionPackage(unittest.TestCase): + """Tests for local GeoTIFF package creation""" + @classmethod + def setUpClass(cls): + makedirs('integration-tif') + copyfile('test/fixtures/drone.tif', 'integration-tif/drone.tif') + copyfile('test/fixtures/integration/labels-tif.npz', 'integration-tif/labels.npz') + + @classmethod + def tearDownClass(cls): + rmtree('integration-tif') + + def test_cli(self): + """Verify data.npz produced by CLI""" + cmd = 'label-maker images -d integration-tif -c test/fixtures/integration/config.intergration.geotiff_package.json' + cmd = cmd.split(' ') + subprocess.run(cmd, universal_newlines=True) + + cmd = 'label-maker package -d integration-tif -c test/fixtures/integration/config.intergration.geotiff_package.json' + cmd = cmd.split(' ') + subprocess.run(cmd, universal_newlines=True) + + data = np.load('integration-tif/data.npz') + + self.assertEqual(data['x_train'].shape, (3, 256, 256, 3)) + self.assertEqual(data['x_test'].shape, (1, 256, 256, 3)) + + # validate our label data with exact matches in shape + self.assertEqual(data['y_train'].shape, (3, 3)) + self.assertEqual(data['y_test'].shape, (1, 3))