From 1203cacffb0be35a343454cccb694d9ea7944fbc Mon Sep 17 00:00:00 2001 From: martham93 Date: Mon, 9 Dec 2019 15:33:00 -0700 Subject: [PATCH 1/8] fix download_tiles_tms function argument error --- label_maker/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/label_maker/utils.py b/label_maker/utils.py index cce8ca0..f0218e8 100644 --- a/label_maker/utils.py +++ b/label_maker/utils.py @@ -24,7 +24,7 @@ def class_match(ml_type, label, i): return np.count_nonzero(label == i) return None -def download_tile_tms(tile, imagery, folder, kwargs): +def download_tile_tms(tile, imagery, folder, imagery_offset, kwargs): """Download a satellite image tile from a tms endpoint""" o = urlparse(imagery) _, image_format = op.splitext(o.path) From 3e1d56fda8e2955521d9ab14000942f5a88e5be4 Mon Sep 17 00:00:00 2001 From: martham93 Date: Mon, 9 Dec 2019 15:49:00 -0700 Subject: [PATCH 2/8] docs update for background ratio --- docs/index.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index 3820d32..ca74af1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -71,7 +71,7 @@ Retiles the OSM data to the desired zoom level, creates label data (``labels.npz Accepts one additional flag: - ``-s`` or ``--sparse``: boolean + ``-s`` or ``--sparse``: boolean Specifies if features in the class of interest are sparse. If ``True``, only save labels for up to ``n`` background tiles, where ``n`` is equal to ``background_ratio`` times the number of tiles with a class label. Defaults to ``False``. .. code-block:: bash @@ -103,6 +103,8 @@ CLI Step 4: images ^^^^^^^^^^^^^^^^^^ Downloads all imagery tiles needed to create the training data. Requires the ``labels.npz`` file from the ``label-maker labels`` step. +The number of background tiles added depends on the `background_ratio` parameter specified in the `config.json` file. +A background_ratio of -1 or 0 will return no background tiles. .. code-block:: bash From fd2ad062e7f1a824f635bd5edba61cb1d76e8928 Mon Sep 17 00:00:00 2001 From: martham93 Date: Mon, 9 Dec 2019 15:49:22 -0700 Subject: [PATCH 3/8] background ratio for multi class classification --- label_maker/images.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/label_maker/images.py b/label_maker/images.py index ebf0975..e309a42 100644 --- a/label_maker/images.py +++ b/label_maker/images.py @@ -55,11 +55,11 @@ def class_test(value): return None class_tiles = [tile for tile in tiles.files if class_test(tiles[tile])] - # for classification problems with a single class, we also get background + # for classification problems, we also get background # tiles up to len(class_tiles) * config.get('background_ratio') background_tiles = [] limit = len(class_tiles) * background_ratio - if ml_type == 'classification' and len(classes) == 1: + if ml_type == 'classification': background_tiles_full = [tile for tile in tiles.files if tile not in class_tiles] shuffle(background_tiles_full) background_tiles = background_tiles_full[:limit] From 92e3fce48d7813fcb86e6b3e6d5d9ccf0f7caa6b Mon Sep 17 00:00:00 2001 From: martham93 Date: Mon, 9 Dec 2019 16:04:40 -0700 Subject: [PATCH 4/8] fix docs --- docs/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index ca74af1..88f1e46 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -104,7 +104,7 @@ CLI Step 4: images Downloads all imagery tiles needed to create the training data. Requires the ``labels.npz`` file from the ``label-maker labels`` step. The number of background tiles added depends on the `background_ratio` parameter specified in the `config.json` file. -A background_ratio of -1 or 0 will return no background tiles. +A background_ratio of 0 will return no background tiles. .. code-block:: bash From eed97b248ccf42181e9800a57deb0db7ec95c6f7 Mon Sep 17 00:00:00 2001 From: martham93 Date: Mon, 9 Dec 2019 17:45:17 -0700 Subject: [PATCH 5/8] undo older tms commit --- label_maker/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/label_maker/utils.py b/label_maker/utils.py index f0218e8..cce8ca0 100644 --- a/label_maker/utils.py +++ b/label_maker/utils.py @@ -24,7 +24,7 @@ def class_match(ml_type, label, i): return np.count_nonzero(label == i) return None -def download_tile_tms(tile, imagery, folder, imagery_offset, kwargs): +def download_tile_tms(tile, imagery, folder, kwargs): """Download a satellite image tile from a tms endpoint""" o = urlparse(imagery) _, image_format = op.splitext(o.path) From a1ab35d0975da43c6f639e2fa3bbe59ef6b8f7e1 Mon Sep 17 00:00:00 2001 From: martham93 Date: Mon, 9 Dec 2019 17:46:49 -0700 Subject: [PATCH 6/8] fix background ratio in example config --- config.example.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.example.json b/config.example.json index 4463e7c..94592f3 100644 --- a/config.example.json +++ b/config.example.json @@ -7,6 +7,6 @@ { "name": "Buildings", "filter": ["has", "building"] } ], "imagery": "http://a.tiles.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.jpg?access_token=ACCESS_TOKEN", - "background_ratio": 1, + "background_ratio": 0, "ml_type": "classification" } From 9bc93218fc365d37e557c8a00f06280c7bc607ce Mon Sep 17 00:00:00 2001 From: martham93 Date: Tue, 10 Dec 2019 10:09:53 -0700 Subject: [PATCH 7/8] move limit into if statement where it's used --- label_maker/images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/label_maker/images.py b/label_maker/images.py index e309a42..27c7b5d 100644 --- a/label_maker/images.py +++ b/label_maker/images.py @@ -58,8 +58,8 @@ def class_test(value): # for classification problems, we also get background # tiles up to len(class_tiles) * config.get('background_ratio') background_tiles = [] - limit = len(class_tiles) * background_ratio if ml_type == 'classification': + limit = len(class_tiles) * background_ratio background_tiles_full = [tile for tile in tiles.files if tile not in class_tiles] shuffle(background_tiles_full) background_tiles = background_tiles_full[:limit] From be45bcd3c81f2c1dc7386453d1171b3becc08f6a Mon Sep 17 00:00:00 2001 From: martham93 Date: Wed, 11 Dec 2019 21:09:40 -0700 Subject: [PATCH 8/8] update parameters docs for background ratio --- docs/parameters.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/parameters.rst b/docs/parameters.rst index 904dd29..d8266ca 100644 --- a/docs/parameters.rst +++ b/docs/parameters.rst @@ -38,7 +38,7 @@ Here is the full list of configuration parameters you can specify in a ``config. Optional parameter to specify a username and password for restricted WMS services. For example, ``['my_username', 'my_password']``. **background_ratio**: float - Specify how many background (or "negative") training examples to create when there is only one class specified with the ``classes`` parameter. Label Maker will generate ``background_ratio`` times the number of images matching the one class. + Specify how many background (or "negative") training examples to create. Label Maker will generate ``background_ratio`` times the number of images matching the total number class tiles. **ml_type**: string One of ``'classification'``, ``'object-detection'``, or ``'segmentation'``. This defines the output format for the final label numpy arrays (``y_train`` and ``y_test``).