Skip to content

Commit

Permalink
Merge pull request #476 from jamesmcclain/docstrings
Browse files Browse the repository at this point in the history
More Docstrings
  • Loading branch information
jamesmcclain committed Oct 10, 2018
2 parents ae70d38 + 9fc2bdf commit 96f7690
Show file tree
Hide file tree
Showing 22 changed files with 204 additions and 3 deletions.
6 changes: 5 additions & 1 deletion rastervision/backend/backend_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def from_proto(self, msg):
return self.with_pretrained_model(msg.pretrained_model_uri)

def with_task(self, task):
"""Sets the backend up for a specific task type, e.g. rv.OBJECT_DETECTION.
"""Sets a specific task type.
Args:
task: A TaskConfig object.
"""
if task.task_type not in self._applicable_tasks():
raise Exception(
Expand Down
19 changes: 19 additions & 0 deletions rastervision/backend/keras_classification_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def with_template(self, template):
return b

def with_batch_size(self, batch_size):
"""Sets the training batch size."""
return self.with_config({
'trainer': {
'options': {
Expand All @@ -266,6 +267,7 @@ def with_batch_size(self, batch_size):
})

def with_num_epochs(self, num_epochs):
"""Sets the number of training epochs."""
return self.with_config({
'trainer': {
'options': {
Expand Down Expand Up @@ -295,16 +297,33 @@ def with_debug(self, debug):
return b

def with_training_data_uri(self, training_data_uri):
"""Whence comes the training data?
Args:
training_data_uri: The location of the training data.
"""
b = deepcopy(self)
b.config['training_data_uri'] = training_data_uri
return b

def with_training_output_uri(self, training_output_uri):
"""Whither goes the training output?
Args:
training_output_uri: The location where the training
output will be stored.
"""
b = deepcopy(self)
b.config['training_output_uri'] = training_output_uri
return b

def with_model_uri(self, model_uri):
"""Defines the name of the model file that will be created for
this model after training.
"""
b = deepcopy(self)
b.config['model_uri'] = model_uri
return b
Expand Down
25 changes: 23 additions & 2 deletions rastervision/backend/tf_deeplab_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,11 @@ def with_template(self, template):
return b

def with_batch_size(self, batch_size):
"""Sets the training batch size."""
return self.with_config({'trainBatchSize': batch_size})

def with_num_steps(self, num_steps):
"""Sets the number of training steps."""
return self.with_config({'trainingNumberOfSteps': num_steps})

def with_config(self,
Expand Down Expand Up @@ -319,23 +321,42 @@ def with_train_options(self,
ignore_missing_keys=True)

def with_model_uri(self, model_uri):
"""Defines the name of the model file that will be created for
this model after training.
"""
b = deepcopy(self)
b.config['model_uri'] = model_uri
return b

def with_fine_tune_checkpoint_name(self, fine_tune_checkpoint_name):
"""Defines the name of the fine tune checkpoint that will
be created for this model after training."""
"""Defines the name of the fine tune checkpoint that will be created
for this model after training.
"""
b = deepcopy(self)
b.config['fine_tune_checkpoint_name'] = fine_tune_checkpoint_name
return b

def with_training_data_uri(self, training_data_uri):
"""Whence comes the training data?
Args:
training_data_uri: The location of the training data.
"""
b = deepcopy(self)
b.config['training_data_uri'] = training_data_uri
return b

def with_training_output_uri(self, training_output_uri):
"""Whither goes the training output?
Args:
training_output_uri: The location where the training
output will be stored.
"""
b = deepcopy(self)
b.config['training_output_uri'] = training_output_uri
return b
Expand Down
19 changes: 19 additions & 0 deletions rastervision/backend/tf_object_detection_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ def with_template(self, template):
return b

def with_batch_size(self, batch_size):
"""Sets the training batch size."""
return self.with_config(
{
'trainConfig': {
Expand All @@ -321,6 +322,7 @@ def with_batch_size(self, batch_size):
}, set_missing_keys=True)

def with_num_steps(self, num_steps):
"""Sets the number of training steps."""
return self.with_config(
{
'trainConfig': {
Expand Down Expand Up @@ -349,16 +351,33 @@ def with_debug(self, debug):
return b

def with_training_data_uri(self, training_data_uri):
"""Whence comes the training data?
Args:
training_data_uri: The location of the training data.
"""
b = deepcopy(self)
b.config['training_data_uri'] = training_data_uri
return b

def with_training_output_uri(self, training_output_uri):
"""Whither goes the training output?
Args:
training_output_uri: The location where the training
output will be stored.
"""
b = deepcopy(self)
b.config['training_output_uri'] = training_output_uri
return b

def with_model_uri(self, model_uri):
"""Defines the name of the model file that will be created for
this model after training.
"""
b = deepcopy(self)
b.config['model_uri'] = model_uri
return b
Expand Down
6 changes: 6 additions & 0 deletions rastervision/command/analyze_command_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def with_experiment(self, experiment_config):
return b

def with_task(self, task):
"""Sets a specific task type.
Args:
task: A TaskConfig object.
"""
b = deepcopy(self)
b.task = task
return b
Expand Down
6 changes: 6 additions & 0 deletions rastervision/command/bundle_command_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ def with_experiment(self, experiment_config):
return b

def with_task(self, task):
"""Sets a specific task type.
Args:
task: A TaskConfig object.
"""
b = deepcopy(self)
b.task = task
return b
Expand Down
6 changes: 6 additions & 0 deletions rastervision/command/chip_command_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ def with_experiment(self, experiment_config):
return b

def with_task(self, task):
"""Sets a specific task type.
Args:
task: A TaskConfig object.
"""
b = deepcopy(self)
b.task = task
return b
Expand Down
6 changes: 6 additions & 0 deletions rastervision/command/eval_command_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ def with_experiment(self, experiment_config):
return b

def with_task(self, task):
"""Sets a specific task type.
Args:
task: A TaskConfig object.
"""
b = deepcopy(self)
b.task = task
return b
Expand Down
6 changes: 6 additions & 0 deletions rastervision/command/predict_command_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def with_experiment(self, experiment_config):
return b

def with_task(self, task):
"""Sets a specific task type.
Args:
task: A TaskConfig object.
"""
b = deepcopy(self)
b.task = task
return b
Expand Down
6 changes: 6 additions & 0 deletions rastervision/command/train_command_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ def with_experiment(self, experiment_config):
return b

def with_task(self, task):
"""Sets a specific task type.
Args:
task: A TaskConfig object.
"""
b = deepcopy(self)
b.task = task
return b
Expand Down
8 changes: 8 additions & 0 deletions rastervision/data/dataset_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,33 +192,41 @@ def from_proto(self, msg):
.with_augmentors(augmentors)

def with_train_scenes(self, scenes):
"""Sets the scenes to be used for training."""
b = deepcopy(self)
b.config['train_scenes'] = scenes
return b

def with_train_scene(self, scene):
"""Sets the scene to be used for training."""
return self.with_train_scenes([scene])

def with_validation_scenes(self, scenes):
"""Sets the scenes to be used for validation."""
b = deepcopy(self)
b.config['validation_scenes'] = scenes
return b

def with_validation_scene(self, scene):
"""Sets the scene to be used for validation."""
return self.with_validation_scenes([scene])

def with_test_scenes(self, scenes):
"""Sets the scenes to be used for testing."""
b = deepcopy(self)
b.config['test_scenes'] = scenes
return b

def with_test_scene(self, scene):
"""Sets the scene to be used for testing."""
return self.with_test_scenes([scene])

def with_augmentors(self, augmentors):
"""Sets the data augmentors to be used."""
b = deepcopy(self)
b.config['augmentors'] = augmentors
return b

def with_augmentor(self, augmentor):
"""Sets the data augmentor to be used."""
return self.with_augmentors([augmentor])
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def from_proto(self, msg):
.with_infer_cells(conf.infer_cells)

def with_uri(self, uri):
"""Set URI for a GeoJSON used to read/write predictions."""
b = deepcopy(self)
b.config['uri'] = uri
return b
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def from_proto(self, msg):
.with_uri(msg.object_detection_geojson_source.uri)

def with_uri(self, uri):
"""Set URI for a GeoJSON used to read/write predictions."""
b = deepcopy(self)
b.config['uri'] = uri
return b
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def from_proto(self, msg):
.with_uri(msg.uri)

def with_uri(self, uri):
"""Set URI for a GeoJSON used to read/write predictions."""
b = deepcopy(self)
b.config['uri'] = uri
return b
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def from_proto(self, msg):
.with_uri(msg.uri)

def with_uri(self, uri):
"""Set URI for a GeoJSON used to read/write predictions."""
b = deepcopy(self)
b.config['uri'] = uri
return b
1 change: 1 addition & 0 deletions rastervision/data/raster_source/geojson_source_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def from_proto(self, msg):
msg.geojson_file.rasterizer_options.line_buffer)

def with_uri(self, uri):
"""Set URI for a GeoJSON file used to read labels."""
b = deepcopy(self)
b.config['uri'] = uri
return b
Expand Down
2 changes: 2 additions & 0 deletions rastervision/data/raster_source/geotiff_source_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ def from_proto(self, msg):
.with_uris(msg.geotiff_files.uris)

def with_uris(self, uris):
"""Set URIs for a GeoTIFFs containing as raster data."""
b = deepcopy(self)
b.config['uris'] = uris
return b

def with_uri(self, uri):
"""Set URI for a GeoTIFF containing raster data."""
b = deepcopy(self)
b.config['uris'] = [uri]
return b
8 changes: 8 additions & 0 deletions rastervision/data/raster_source/image_source_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ def from_proto(self, msg):
.with_uri(msg.image_file.uri)

def with_uri(self, uri):
"""Set URI for an image.
Args:
uri: A URI pointing to some (non-georeferenced) raster
file (TIFs, PNGs, and JPEGs are supported, and
possibly others).
"""
b = deepcopy(self)
b.config['uri'] = uri
return b
15 changes: 15 additions & 0 deletions rastervision/data/raster_source/raster_source_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,29 @@ def with_channel_order(self, channel_order):
return b

def with_transformers(self, transformers):
"""Transformers to be applied to the raster data.
Args:
transformers: A list of transformers to apply to the
raster data.
"""
b = deepcopy(self)
b.config['transformers'] = transformers
return b

def with_transformer(self, transformer):
"""A transformer to be applied to the raster data.
Args:
transformer: A transformer to apply to the raster
data.
"""
return self.with_transformers([transformer])

def with_stats_transformer(self):
"""Add a stats transformer to the raster source."""
b = deepcopy(self)
transformers = b.config.get('transformers')
if transformers:
Expand Down

0 comments on commit 96f7690

Please sign in to comment.