geowatch.tasks.landcover.detector module

geowatch.tasks.landcover.detector.run(model, image, metadata)[source]
geowatch.tasks.landcover.detector.pad(fn)[source]
geowatch.tasks.landcover.detector.predict_image(image, *args, **kwargs)[source]
geowatch.tasks.landcover.detector.normalize(image, invalid_mask, low=2, high=98)[source]

Example

>>> from geowatch.tasks.landcover.detector import *  # NOQA
>>> import kwimage
>>> # orig_image = np.random.rand(32, 32, 3)
>>> orig_image = kwimage.ensure_float01(kwimage.grab_test_image())
>>> image = kwimage.Polygon.random().scale(orig_image.shape[0]).fill(orig_image.copy(), np.nan)
>>> invalid_mask = np.isnan(image)
>>> output = normalize(image, invalid_mask)
>>> assert np.isnan(image).sum() == np.isnan(output).sum()
>>> # xdoctest: +REQUIRES(--show)
>>> import kwplot
>>> kwplot.autompl()
>>> kwplot.imshow(image, pnum=(1, 2, 1), doclf=True)
>>> kwplot.imshow(output, pnum=(1, 2, 2))

Example

>>> from geowatch.tasks.landcover.detector import *  # NOQA
>>> # Test 100% nan case
>>> image = np.full((32, 32, 3), fill_value=np.nan)
>>> invalid_mask = np.isnan(image)
>>> import pytest
>>> with pytest.raises(ValueError):
>>>     output = normalize(image, invalid_mask)
>>> # Test 100% nan in a single band case
>>> image = np.random.rand(32, 32, 3)
>>> image[..., 1] = np.nan
>>> invalid_mask = np.isnan(image)
>>> with pytest.raises(ValueError):
>>>     output = normalize(image, invalid_mask)
geowatch.tasks.landcover.detector.get_device()[source]
geowatch.tasks.landcover.detector.get_model_device(model)[source]

Return the device associated with the model

geowatch.tasks.landcover.detector.load_model(filename, num_outputs, num_channels, device='auto')[source]