Skip to content

Commit fa19528

Browse files
authored
Merge pull request #25 from nasa/develop
Release 0.2
2 parents 8caffe8 + 7e59a5d commit fa19528

40 files changed

+1247
-319
lines changed

.github/workflows/docs.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Build documentation and commit to gh-pages branch.
2+
3+
name: Build and Push Documentation to gh-pages Branch
4+
5+
on:
6+
push:
7+
branches: [ 'master']
8+
9+
jobs:
10+
build_and_push_docs:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
with:
17+
path: repo/
18+
- name: Checkout gh-pages
19+
uses: actions/checkout@v2
20+
with:
21+
path: docs/
22+
ref: gh-pages
23+
- name: Set up Python 3.8
24+
uses: actions/setup-python@v2
25+
with:
26+
python-version: 3.8
27+
- name: Install pdoc3
28+
run: |
29+
python3 -m pip install pdoc3
30+
- name: Install DELTA
31+
run: |
32+
cd repo
33+
./scripts/setup.sh
34+
python3 -m pip install .
35+
- name: Build Documentation
36+
run: |
37+
./repo/scripts/docs.sh ./docs/
38+
- name: Commit and Push
39+
run: |
40+
cd repo
41+
EMAIL=`git show -s --format='%ae' HEAD`
42+
NAME=`git show -s --format='%an' HEAD`
43+
cd ..
44+
cd docs/
45+
git add .
46+
git config user.email "$EMAIL"
47+
git config user.name "$NAME"
48+
git commit -m "Automatic update for $GITHUB_SHA."
49+
git push origin gh-pages
50+

bin/delta

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,8 @@
1818
# limitations under the License.
1919

2020
import sys
21-
import argparse
2221

23-
from delta.config import config
24-
from delta.subcommands import commands
25-
26-
def main(args):
27-
parser = argparse.ArgumentParser(description='DELTA Machine Learning Toolkit')
28-
subparsers = parser.add_subparsers()
29-
30-
for d in commands.SETUP_COMMANDS:
31-
d(subparsers)
32-
33-
try:
34-
options = parser.parse_args(args[1:])
35-
except argparse.ArgumentError:
36-
parser.print_help(sys.stderr)
37-
sys.exit(1)
38-
39-
if not hasattr(options, 'function'):
40-
parser.print_help(sys.stderr)
41-
sys.exit(1)
42-
43-
config.initialize(options)
44-
return options.function(options)
22+
from delta.subcommands import main
4523

4624
if __name__ == "__main__":
47-
sys.exit(main(sys.argv))
25+
sys.exit(main.main(sys.argv))

delta/config/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Used in the `delta train` and `delta mlflow_ui` commands to keep track of traini
107107
networks from different stages of training.
108108
* `frequency`: Frequency in batches to save a checkpoint. Networks can require a fair amount of disk space,
109109
so don't save too often.
110-
* `save_latest`: If true, only keep the network file from the most recent checkpoint.
110+
* `only_save_latest`: If true, only keep the network file from the most recent checkpoint.
111111

112112
TensorBoard
113113
-----------

delta/config/config.py

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def validate_positive(num, _):
3535
raise ValueError('%d is not positive' % (num))
3636
return num
3737

38+
class _NotSpecified: #pylint:disable=too-few-public-methods
39+
pass
40+
3841
class DeltaConfigComponent:
3942
"""
4043
DELTA configuration component.
@@ -78,7 +81,7 @@ def register_component(self, component, name : str, attr_name = None):
7881
attr_name = name
7982
setattr(self, attr_name, component)
8083

81-
def register_field(self, name : str, types, accessor = None, cmd_arg = None, validate_fn = None, desc = None):
84+
def register_field(self, name : str, types, accessor = None, validate_fn = None, desc = None):
8285
"""
8386
Register a field in this component of the configuration.
8487
@@ -92,7 +95,6 @@ def register_field(self, name : str, types, accessor = None, cmd_arg = None, val
9295
self._fields.append(name)
9396
self._validate[name] = validate_fn
9497
self._types[name] = types
95-
self._cmd_args[name] = cmd_arg
9698
self._descs[name] = desc
9799
if accessor:
98100
def access(self) -> types:
@@ -101,14 +103,44 @@ def access(self) -> types:
101103
access.__doc__ = desc
102104
setattr(self.__class__, accessor, access)
103105

106+
def register_arg(self, field, argname, **kwargs):
107+
"""
108+
Registers a command line argument in this component.
109+
110+
field is the (registered) field this argument modifies.
111+
argname is the name of the flag on the command line (i.e., '--flag')
112+
**kwargs are arguments to ArgumentParser.add_argument.
113+
114+
If help and type are not specified, will use the ones for the field.
115+
If default is not specified, will use the value from the config files.
116+
"""
117+
assert field in self._fields, 'Field %s not registered.' % (field)
118+
if 'help' not in kwargs:
119+
kwargs['help'] = self._descs[field]
120+
if 'type' not in kwargs:
121+
kwargs['type'] = self._types[field]
122+
elif kwargs['type'] is None:
123+
del kwargs['type']
124+
if 'default' not in kwargs:
125+
kwargs['default'] = _NotSpecified
126+
self._cmd_args[argname] = (field, kwargs)
127+
128+
def to_dict(self) -> dict:
129+
"""
130+
Returns a dictionary representing the config object.
131+
"""
132+
if isinstance(self._config_dict, dict):
133+
exp = self._config_dict.copy()
134+
for (name, c) in self._components.items():
135+
exp[name] = c.to_dict()
136+
return exp
137+
return self._config_dict
138+
104139
def export(self) -> str:
105140
"""
106-
Returns a YAML string of all configuration options.
141+
Returns a YAML string of all configuration options, from to_dict.
107142
"""
108-
exp = self._config_dict.copy()
109-
for (name, c) in self._components.items():
110-
exp[name] = c.export()
111-
return yaml.dump(exp)
143+
return yaml.dump(self.to_dict())
112144

113145
def _set_field(self, name : str, value : str, base_dir : str):
114146
if name not in self._fields:
@@ -139,12 +171,9 @@ def setup_arg_parser(self, parser, components = None) -> None:
139171
"""
140172
if self._section_header is not None:
141173
parser = parser.add_argument_group(self._section_header)
142-
for name in self._fields:
143-
c = self._cmd_args[name]
144-
if c is None:
145-
continue
146-
parser.add_argument(c, dest=c.replace('-', '_'), required=False,
147-
type=self._types[name], help=self._descs[name])
174+
for (arg, value) in self._cmd_args.items():
175+
(field, kwargs) = value
176+
parser.add_argument(arg, dest=field, **kwargs)
148177

149178
for (name, c) in self._components.items():
150179
if components is None or name in components:
@@ -157,14 +186,12 @@ def parse_args(self, options):
157186
configuration values.
158187
"""
159188
d = {}
160-
for name in self._fields:
161-
c = self._cmd_args[name]
162-
if c is None:
189+
for (field, _) in self._cmd_args.values():
190+
if not hasattr(options, field) or getattr(options, field) is None:
163191
continue
164-
n = c.replace('-', '_')
165-
if not hasattr(options, n) or getattr(options, n) is None:
192+
if getattr(options, field) is _NotSpecified:
166193
continue
167-
d[name] = getattr(options, n)
194+
d[field] = getattr(options, field)
168195
self._load_dict(d, None)
169196

170197
for c in self._components.values():
@@ -183,6 +210,7 @@ def load(self, yaml_file: str = None, yaml_str: str = None):
183210
"""
184211
base_path = None
185212
if yaml_file:
213+
#print("Loading config file: " + yaml_file)
186214
if not os.path.exists(yaml_file):
187215
raise Exception('Config file does not exist: ' + yaml_file)
188216
with open(yaml_file, 'r') as f:

delta/config/delta.yaml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
general:
22
# negative is all
33
gpus: -1
4+
stop_on_input_error: true # If false skip past bad input files without halting training
45

56
io:
67
threads: 1
@@ -10,12 +11,16 @@ io:
1011
interleave_images: 5
1112
# ratio of tile width and height when loading images
1213
tile_ratio: 5.0
14+
# When resuming training with a log_folder, skip input image where we have
15+
# already loaded this many tiles.
16+
resume_cutoff: 5000
1317
cache:
1418
# default is OS-specific, in Linux, ~/.cache/delta
1519
dir: default
1620
limit: 8
1721

1822
dataset:
23+
log_folder: ~ # Storage location for any record keeping files about the input dataset
1924
images:
2025
type: tiff
2126
# preprocess the images when loading (i.e., scaling)
@@ -39,11 +44,33 @@ dataset:
3944
file_list: ~
4045
files: ~
4146

47+
# can either be a list of classes or the number of classes,
48+
# if the labels are 0, 1, 2, 3
49+
classes: 4
50+
# labels are 1, 2, 3, 4; with names and display colors
51+
# weight is optional, but required for either all or none
52+
#classes:
53+
# - 1:
54+
# name: Water
55+
# color: 0x67a9cf
56+
# weight: 5.0
57+
# - 2:
58+
# name: No Water
59+
# color: 0xf6eff7
60+
# weight: 1.0
61+
# - 3:
62+
# name: Maybe Water
63+
# color: 0xbdc9e1
64+
# weight: 1.0
65+
# - 4:
66+
# name: Cloud
67+
# color: 0x02818a
68+
# weight: 1.0
69+
4270
train:
4371
network:
4472
chunk_size: 16
4573
output_size: 8
46-
classes: 4
4774
model:
4875
yaml_file: networks/convpool.yaml
4976
params: ~
@@ -91,8 +118,8 @@ mlflow:
91118
experiment_name: Default
92119
# rate in batches to save model checkpoints
93120
checkpoints:
94-
frequency: 10000
95-
save_latest: true
121+
frequency: 10000
122+
only_save_latest: true
96123

97124
tensorboard:
98125
enabled: false

delta/config/modules.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright © 2020, United States Government, as represented by the
2+
# Administrator of the National Aeronautics and Space Administration.
3+
# All rights reserved.
4+
#
5+
# The DELTA (Deep Earth Learning, Tools, and Analysis) platform is
6+
# licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0.
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
"""
19+
Registers all config modules.
20+
"""
21+
22+
import delta.imagery.imagery_config
23+
import delta.ml.ml_config
24+
25+
_config_initialized = False
26+
def register_all():
27+
global _config_initialized #pylint: disable=global-statement
28+
# needed to call twice when testing subcommands and when not
29+
if _config_initialized:
30+
return
31+
delta.imagery.imagery_config.register()
32+
delta.ml.ml_config.register()
33+
_config_initialized = True

delta/config/networks/autoencoder_conv.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@ layers:
22
- Input:
33
shape: in_shape
44
- Conv2D:
5-
filters: 300
5+
filters: 50
66
kernel_size: [3, 3]
77
activation: relu
88
padding: same
99
- MaxPooling2D:
1010
pool_size: [2, 2]
1111
- Conv2D:
12-
filters: 150
12+
filters: 50
1313
kernel_size: [3, 3]
1414
activation: relu
1515
padding: same
1616
- MaxPooling2D:
1717
pool_size: [2, 2]
1818
- Conv2D:
19-
filters: 75
19+
filters: 50
2020
kernel_size: [3, 3]
2121
activation: relu
2222
padding: same
2323
- UpSampling2D:
2424
size: [2, 2]
2525
- Conv2D:
26-
filters: 150
26+
filters: 50
2727
kernel_size: [3, 3]
2828
activation: relu
2929
padding: same
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
layers:
2+
- Input:
3+
shape: in_shape
4+
- Conv2D:
5+
filters: 50
6+
kernel_size: [5, 5]
7+
activation: relu
8+
padding: same
9+
- MaxPooling2D:
10+
pool_size: [2, 2]
11+
- Conv2D:
12+
filters: 50
13+
kernel_size: [5, 5]
14+
activation: relu
15+
padding: same
16+
- MaxPooling2D:
17+
pool_size: [2, 2]
18+
- Conv2D:
19+
filters: 50
20+
kernel_size: [5, 5]
21+
activation: relu
22+
padding: same
23+
- UpSampling2D:
24+
size: [2, 2]
25+
- Conv2D:
26+
filters: 50
27+
kernel_size: [5, 5]
28+
activation: relu
29+
padding: same
30+
- UpSampling2D:
31+
size: [2, 2]
32+
- Conv2D:
33+
filters: num_bands
34+
kernel_size: [5, 5]
35+
activation: relu
36+
padding: same

0 commit comments

Comments
 (0)