Skip to content

Commit e9e0afe

Browse files
Martha Morrisseywronk
authored andcommitted
Background ratio (#159)
* fix download_tiles_tms function argument error * docs update for background ratio * background ratio for multi class classification * fix docs * undo older tms commit * fix background ratio in example config * move limit into if statement where it's used * update parameters docs for background ratio
1 parent eb7146e commit e9e0afe

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

config.example.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
{ "name": "Buildings", "filter": ["has", "building"] }
88
],
99
"imagery": "http://a.tiles.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.jpg?access_token=ACCESS_TOKEN",
10-
"background_ratio": 1,
10+
"background_ratio": 0,
1111
"ml_type": "classification"
1212
}

docs/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Retiles the OSM data to the desired zoom level, creates label data (``labels.npz
7171

7272
Accepts one additional flag:
7373

74-
``-s`` or ``--sparse``: boolean
74+
``-s`` or ``--sparse``: boolean
7575
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``.
7676

7777
.. code-block:: bash
@@ -103,6 +103,8 @@ CLI Step 4: images
103103
^^^^^^^^^^^^^^^^^^
104104

105105
Downloads all imagery tiles needed to create the training data. Requires the ``labels.npz`` file from the ``label-maker labels`` step.
106+
The number of background tiles added depends on the `background_ratio` parameter specified in the `config.json` file.
107+
A background_ratio of 0 will return no background tiles.
106108

107109
.. code-block:: bash
108110

docs/parameters.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Here is the full list of configuration parameters you can specify in a ``config.
3838
Optional parameter to specify a username and password for restricted WMS services. For example, ``['my_username', 'my_password']``.
3939

4040
**background_ratio**: float
41-
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.
41+
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.
4242

4343
**ml_type**: string
4444
One of ``'classification'``, ``'object-detection'``, or ``'segmentation'``. This defines the output format for the final label numpy arrays (``y_train`` and ``y_test``).

label_maker/images.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ def class_test(value):
5555
return None
5656
class_tiles = [tile for tile in tiles.files if class_test(tiles[tile])]
5757

58-
# for classification problems with a single class, we also get background
58+
# for classification problems, we also get background
5959
# tiles up to len(class_tiles) * config.get('background_ratio')
6060
background_tiles = []
61-
limit = len(class_tiles) * background_ratio
62-
if ml_type == 'classification' and len(classes) == 1:
61+
if ml_type == 'classification':
62+
limit = len(class_tiles) * background_ratio
6363
background_tiles_full = [tile for tile in tiles.files if tile not in class_tiles]
6464
shuffle(background_tiles_full)
6565
background_tiles = background_tiles_full[:limit]

0 commit comments

Comments
 (0)