Skip to content

fix image and tile format inconsistency #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ data
config.json
stdout*
/integration*
.idea/
2 changes: 2 additions & 0 deletions label_maker/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/integration/config.intergration.geotiff_package.json
Original file line number Diff line number Diff line change
@@ -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"
}
Binary file added test/fixtures/integration/labels-tif.npz
Binary file not shown.
39 changes: 39 additions & 0 deletions test/integration/test_geotiff_package.py
Original file line number Diff line number Diff line change
@@ -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))