Skip to content
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

MultiBands, and tools improvements (mostly) #138

Open
wants to merge 100 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
213540e
Display Hyperparameters weights, only if needed and used by the choos…
ocourtin Oct 10, 2018
6991719
Data Augmentation: Add upscale_factor, remove useless CenterCrop
ocourtin Oct 12, 2018
bbd86a3
Add in rs download, TMS and WMS services support. Expose timeout in u…
ocourtin Oct 13, 2018
9c9b307
Homogenize reprojection calls, pass throught rasterio
ocourtin Oct 14, 2018
d51393d
Add GeoJSON MultiPolygon support
ocourtin Oct 15, 2018
d8f1686
Add url in user error message. Neat for WMS use cases
ocourtin Oct 15, 2018
43a6050
Change image_upscale hyperparameter name and add entry in log
ocourtin Oct 15, 2018
b20e5a4
Fix mIoU to be 0 div resilient
ocourtin Oct 18, 2018
73933fd
Move to PIL Image to OpenCV H,W,C RGB for DataAugmentation. Refactor …
ocourtin Oct 18, 2018
fd4ca3b
add tile tools
ocourtin Oct 22, 2018
29935f6
black format
ocourtin Oct 22, 2018
2e97d16
refactor resize data augmentation
ocourtin Oct 22, 2018
dd15457
typo
ocourtin Oct 22, 2018
822bae7
Fix issue relative to OpenCV switch.
ocourtin Oct 22, 2018
0b86808
Fix axes order on labels tiles. Add label_thresold option. Few clean …
ocourtin Oct 23, 2018
1e43632
Add masks_ouput option in predict tool
ocourtin Oct 26, 2018
48115d2
Update comments (related to output_masks)
ocourtin Oct 26, 2018
82c2bcd
in train, resume option don't need an explicit yes. User Friendly
ocourtin Oct 27, 2018
f2e6405
Add leaflet ouput option
ocourtin Oct 27, 2018
b0c554c
reverse map templates changes. Add leaflet html template
ocourtin Oct 27, 2018
fab73f9
Move from pillow to pillow-simd. Significant perf improvement. Did'nt…
ocourtin Oct 28, 2018
e68d8f5
Variable name homogenize
ocourtin Oct 28, 2018
236f471
Add robosat log handling. User friendly log output if some tiles was …
ocourtin Oct 28, 2018
69ef557
Add bbox option to cover tool
ocourtin Oct 28, 2018
249107b
remove period from extension
ocourtin Oct 28, 2018
1407730
Tile tool: few debug fixes and cleanup
ocourtin Oct 28, 2018
2fe3864
add complemenraty_palette function
ocourtin Oct 30, 2018
3f27682
allow to explicitly choose open file mode, in log
ocourtin Oct 30, 2018
8da0e8b
Use NaN rather than Inf on 0 div exception. Allow to use metric eithe…
ocourtin Oct 30, 2018
b2a76dd
Bugfix on leaflet tiles
ocourtin Oct 30, 2018
4946f6f
Whole refactor of compare tool. Now with 3 modes: side, diff, list
ocourtin Oct 30, 2018
de654a4
Remove rio-tiler overhead dependancy.
ocourtin Oct 30, 2018
bf30a22
Use the latest rasterio version, and deal with boundless vrt issue, i…
ocourtin Oct 30, 2018
173a60d
add slippy map option in cover tool
ocourtin Nov 5, 2018
98efc71
rather than removing edges, deal with no_data values to keep only the…
ocourtin Nov 6, 2018
350d46f
Give a human a chance to read it back once black formatted ^^
ocourtin Nov 6, 2018
7a5eae4
revert perf setting, as they lead to issues on some platforms. Deploy…
ocourtin Nov 9, 2018
275f017
Use cuda if available, and so no model config file needed anymore
ocourtin Nov 9, 2018
47364ea
Avoid to recompute palette on each tile generation
ocourtin Nov 9, 2018
9b0588c
black and clean stuff
ocourtin Nov 9, 2018
9457880
switch from Pillow to OpenCV for predict. Refactor buffer tiling. Lea…
ocourtin Nov 9, 2018
f9e788b
Avoid to create directory if not sure to write tile in it...
ocourtin Nov 9, 2018
c874a04
Merge branch 'multi' of https://github.com/ocourtin/robosat into multi
ocourtin Nov 9, 2018
2270d49
remove cuda parameter in config model. Use all visible GPUs, and if n…
ocourtin Nov 9, 2018
6a55b2b
Merge branch 'multi' of https://github.com/ocourtin/robosat into multi
ocourtin Nov 9, 2018
b75c3b1
Step backward on switching all PIL to OpenCV, as still not found a ri…
ocourtin Nov 10, 2018
13d4f7c
Better to write output dir before to try to log in...
ocourtin Nov 10, 2018
d260eef
typo
ocourtin Nov 10, 2018
7c88599
Fix issue if GPU available (with PyTorch 0.4.1)
ocourtin Nov 10, 2018
7083cb9
Upgrade to Torch 0.4.1 and switch to deprecated upsample to interpola…
ocourtin Nov 10, 2018
aad94fc
Multibands handling (at last). First prune export feature. Improve tr…
ocourtin Nov 12, 2018
8f1faca
Improve multidataset configuration
ocourtin Nov 12, 2018
5ade9f2
allow to unzoom, by providing a vector grid
ocourtin Nov 13, 2018
e6a5f87
improve userland type value resilience
ocourtin Nov 13, 2018
1bf590a
refactor GeoJson parsing. Handle cleanly Polygon, MultiPolygon, Geome…
ocourtin Nov 13, 2018
4e795e0
Fix leaflet tiles parameter. Add comment on geojson input projection
ocourtin Nov 13, 2018
23b9b96
Black is Black...
ocourtin Nov 14, 2018
ce12ab5
auto promote
ocourtin Nov 14, 2018
9ce1782
Switch default minimum to 0. Far more user-friendly
ocourtin Nov 14, 2018
3218253
Allow to specify which tile to grid on the leaflet client. Far more u…
ocourtin Nov 15, 2018
f79fa97
Prevent to delete an existing output directory while training. User f…
ocourtin Nov 16, 2018
b20561d
Be more explicit if yes or no coverage is fully downloaded.
ocourtin Nov 16, 2018
ccc7e8d
not needed anymore
ocourtin Nov 16, 2018
16a985d
As types are not yet implemented no reason to ask yet for ^^
ocourtin Nov 16, 2018
bc82113
Handle all CSS3 colors or hex pattern #RRGGBB. Use webcolors package
ocourtin Nov 24, 2018
008398e
Remove deprecated train checkpoint dir. Add forgotten pretrained para…
ocourtin Nov 24, 2018
583f1ce
Improve log resilience. Add train out parameter mandatory. web_ui switch
ocourtin Nov 24, 2018
47d91a4
new tile_image function
ocourtin Nov 24, 2018
293673e
Whole refactor, on my previous whole refactor ^^
ocourtin Nov 24, 2018
e3cfd3a
web_ui switch. Color process harmonization
ocourtin Nov 24, 2018
cce48b6
web_ui switch
ocourtin Nov 24, 2018
30a68ad
Use the cover filter as a filter (rather than parsing the whole tiles…
ocourtin Nov 24, 2018
42c110b
Improve GeoJSON tiles: add x,y,z properties, ligthweight coordinates …
ocourtin Nov 24, 2018
6ead578
Use external GeoJSON grid file. Ajax loading
ocourtin Nov 24, 2018
6aba3a7
New compare template. Able to perform prev/next and selection on imag…
ocourtin Nov 24, 2018
a0fd555
remove tile_to_bbox, and use mercantile.xy_bounds instead
ocourtin Nov 24, 2018
d3dbd89
Use the right cover separator
ocourtin Nov 24, 2018
57f3bc4
Handle 1-N geojson features files. Few cleanup.
ocourtin Nov 25, 2018
01ea0b2
use args.parse choices
ocourtin Nov 26, 2018
b4391d3
Update to latest rasterio version
ocourtin Nov 26, 2018
3612d70
Dynamic handler arch.
ocourtin Nov 26, 2018
0433e26
Use a single type parameter, more user understandable prototype
ocourtin Nov 26, 2018
ed16e8f
add web_ui_template parameter. order args in tools to put optionals f…
ocourtin Nov 26, 2018
53b0b4e
Protect already existing data in dest dir to be overwritten
ocourtin Nov 26, 2018
e02dffd
update existing tests to pass
ocourtin Nov 26, 2018
1a451d3
few cleanup. Add path parameter to allow an user to set his own exten…
ocourtin Nov 27, 2018
0fa123e
Black is black
ocourtin Nov 27, 2018
0c6fff7
Merge branch 'master' into multi
ocourtin Nov 27, 2018
24716db
One rasterio version is enough ^^
ocourtin Nov 27, 2018
bcf13ce
Create destination repository if needed
ocourtin Nov 27, 2018
552ffb5
add expanduser path
ocourtin Nov 27, 2018
0504df5
additional stdout log by default
ocourtin Nov 27, 2018
9f3eb8f
Add user hint
ocourtin Nov 28, 2018
0aa7f46
Allow to override most common train option from the command line (lr …
ocourtin Nov 28, 2018
d7e8559
Refactor config file, to a single one. Allow to override dataset path…
ocourtin Nov 28, 2018
c628975
polish
ocourtin Nov 28, 2018
a59d971
Add geojson slicer
ocourtin Nov 29, 2018
9b8f94e
Fix: propagate config classes titles
ocourtin Nov 30, 2018
bb2dcf8
Typo
ocourtin Nov 30, 2018
b28b2c1
Add pillow-simd dependancy libs
ocourtin Nov 30, 2018
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: 2 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Daniel J. Hofmann <[email protected]> https://github.com/daniel-j-h

Bhargav Kowshik <[email protected]> https://github.com/bkowshik

Olivier Courtin <[email protected]> https://github.com/ocourtin
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks for all your work so far!

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ The following describes the installation from scratch.
- Install native system dependencies required for Python 3 bindings

```bash
apt-get install build-essential libboost-python-dev libexpat1-dev zlib1g-dev libbz2-dev libspatialindex-dev
apt-get install build-essential libboost-python-dev libexpat1-dev zlib1g-dev libbz2-dev libspatialindex-dev libjpeg-turbo8-dev libwebp-dev
```

- Use a virtualenv for installing this project locally
Expand Down
55 changes: 55 additions & 0 deletions config/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# RoboSat Configuration
# For syntax see: https://github.com/toml-lang/toml#table-of-contents

[dataset]
# The slippy map dataset's base directory.
path = '/tmp/slippy-map-dir/'

# Dataset specific class weights computes on the training data.
# Needed by 'mIoU' and 'CrossEntropy' losses to deal with unbalanced classes.
# Note: use `./rs weights -h` to compute these for new datasets.
weights = [1.6248, 5.762827]


[classes]
# Human representation for classes.
titles = ['background', 'parking']

# Color map for visualization and representing classes in masks.
# Note: available colors are either CSS3 colors names or #RRGGBB hexadecimal representation.
colors = ['denim', 'orange']


# Channels configuration let your indicate wich dataset sub-directory and bands to take as input
# You could so, add several channels blocks to compose your input Tensor. Orders are meaningful.
[[channels]]
sub = "images"
bands = [1,2,3]


# Model specific attributes.
[model]

# Batch size for training.
batch_size = 2

# Image side size in pixels.
image_size = 512

# Total number of epochs to train for.
epochs = 10

# Learning rate for the optimizer.
lr = 0.0001

# Weight decay l2 penalty for the optimizer
decay = 0.0001

# Loss function name (e.g 'Lovasz', 'mIoU' or 'CrossEntropy')
loss = 'Lovasz'

# Data augmentation, Flip or Rotate probability
data_augmentation = 0.75

# Use ImageNet weights pretraining
pretrained = true
23 changes: 0 additions & 23 deletions config/dataset-parking.toml

This file was deleted.

34 changes: 0 additions & 34 deletions config/model-unet.toml

This file was deleted.

3 changes: 2 additions & 1 deletion deps/requirements-lock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pyparsing==2.2.2
pyproj==1.9.5.1
pytest==3.9.1
python-dateutil==2.7.3
rasterio==1.0.8
rasterio==1.0.10
requests==2.20.0
Rtree==0.8.3
scikit-learn==0.20.0
Expand All @@ -43,3 +43,4 @@ torchvision==0.2.1
tqdm==4.27.0
urllib3==1.24
Werkzeug==0.14.1
webcolors==1.8.1
3 changes: 2 additions & 1 deletion deps/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
torchvision
numpy
pillow
pillow-simd
scipy
opencv-contrib-python
tqdm
Expand All @@ -17,3 +17,4 @@ rtree
pyproj
toml
pytest
webcolors
2 changes: 1 addition & 1 deletion docker/Dockerfile.cpu
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ FROM ubuntu:16.04
# See: https://github.com/skvark/opencv-python/issues/90
RUN apt-get update -qq && \
apt-get install -qq -y -o quiet=1 \
python3 python3-dev python3-tk python3-pip build-essential libboost-python-dev libexpat1-dev zlib1g-dev libbz2-dev libspatialindex-dev libsm6
python3 python3-dev python3-tk python3-pip build-essential libboost-python-dev libexpat1-dev zlib1g-dev libbz2-dev libspatialindex-dev libsm6 libwebp-dev libjpeg-turbo8-dev
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add these new system-wide native deps to the readme installation instructions, too. For users not running the dockerized image.


WORKDIR /app
ADD . /app
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.gpu
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ FROM nvidia/cuda:9.1-cudnn7-runtime-ubuntu16.04
# See: https://github.com/skvark/opencv-python/issues/90
RUN apt-get update -qq && \
apt-get install -qq -y -o quiet=1 \
python3 python3-dev python3-tk python3-pip build-essential libboost-python-dev libexpat1-dev zlib1g-dev libbz2-dev libspatialindex-dev libsm6
python3 python3-dev python3-tk python3-pip build-essential libboost-python-dev libexpat1-dev zlib1g-dev libbz2-dev libspatialindex-dev libsm6 libwebp-dev libjpeg-turbo8-dev

WORKDIR /app
ADD . /app
Expand Down
88 changes: 28 additions & 60 deletions robosat/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,30 @@
"""

import colorsys

from enum import Enum, unique


# Todo: user should be able to bring her own color palette.
# Functions need to account for that and not use one palette.


def _rgb(v):
r, g, b = v[1:3], v[3:5], v[5:7]
return int(r, 16), int(g, 16), int(b, 16)


@unique
class Mapbox(Enum):
"""Mapbox-themed colors.

See: https://www.mapbox.com/base/styling/color/
"""

dark = _rgb("#404040")
gray = _rgb("#eeeeee")
light = _rgb("#f8f8f8")
white = _rgb("#ffffff")
cyan = _rgb("#3bb2d0")
blue = _rgb("#3887be")
bluedark = _rgb("#223b53")
denim = _rgb("#50667f")
navy = _rgb("#28353d")
navydark = _rgb("#222b30")
purple = _rgb("#8a8acb")
teal = _rgb("#41afa5")
green = _rgb("#56b881")
yellow = _rgb("#f1f075")
mustard = _rgb("#fbb03b")
orange = _rgb("#f9886c")
red = _rgb("#e55e5e")
pink = _rgb("#ed6498")
import webcolors
import numpy as np


def make_palette(*colors):
"""Builds a PIL-compatible color palette from color names.
"""Builds a PIL-compatible color palette from CSS3 color names, or hex values patterns as #RRGGBB

Args:
colors: variable number of color names.
"""

rgbs = [Mapbox[color].value for color in colors]
flattened = sum(rgbs, ())
return list(flattened)


def color_string_to_rgb(color):
"""Convert color string to a list of RBG integers.
assert 0 < len(colors) <= 256

Args:
color: the string color value for example "250,0,0"

Returns:
color: as a list of RGB integers for example [250,0,0]
"""
hexs = [webcolors.CSS3_NAMES_TO_HEX[color] if color[0] != "#" else color for color in colors]
rgbs = [(int(h[1:3], 16), int(h[3:5], 16), int(h[5:7], 16)) for h in hexs]

return [*map(int, color.split(","))]
return list(sum(rgbs, ()))


def continuous_palette_for_color(color, bins=256):
"""Creates a continuous color palette based on a single color.

Args:
color: the rgb color tuple to create a continuous palette for.
color: the CSS3 color name or it's hex values as #RRGGBB, to create a continuous palette for.
bins: the number of colors to create in the continuous palette.

Returns:
Expand All @@ -81,15 +35,29 @@ def continuous_palette_for_color(color, bins=256):
# A quick and dirty way to create a continuous color palette is to convert from the RGB color
# space into the HSV color space and then only adapt the color's saturation (S component).

r, g, b = [v / 255 for v in Mapbox[color].value]
hexs = webcolors.CSS3_NAMES_TO_HEX[color] if color[0] != "#" else color
r, g, b = [(int(h[1:3], 16), int(h[3:5], 16), int(h[5:7], 16)) for h in hexs]
h, s, v = colorsys.rgb_to_hsv(r, g, b)

palette = []
assert 0 < bins <= 256

palette = []
for i in range(bins):
ns = (1 / bins) * (i + 1)
palette.extend([int(v * 255) for v in colorsys.hsv_to_rgb(h, ns, v)])

assert len(palette) // 3 == bins
r, g, b = [int(v * 255) for v in colorsys.hsv_to_rgb(h, (1 / bins) * (i + 1), v)]
palette.extend(r, g, b)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice refactor


return palette


def complementary_palette(palette):
"""Creates a PIL complementary colors palette based on an initial PIL palette"""

comp_palette = []
colors = [palette[i : i + 3] for i in range(0, len(palette), 3)]

for color in colors:
r, g, b = [v for v in color]
h, s, v = colorsys.rgb_to_hsv(r, g, b)
comp_palette.extend(map(int, colorsys.hsv_to_rgb((h + 0.5) % 1, s, v)))

return comp_palette
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

Loading