Skip to content

Background ratio #159

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 8 commits into from
Dec 12, 2019
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
2 changes: 1 addition & 1 deletion config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
4 changes: 3 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 0 will return no background tiles.

.. code-block:: bash

Expand Down
2 changes: 1 addition & 1 deletion docs/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``).
Expand Down
6 changes: 3 additions & 3 deletions label_maker/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
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]
Expand Down