Note that my semantic segmentation ground truths are arrays that are 0 for background and 255 for buildings. Images are RGB. Most likely the ground truth should be changed before passing it to raster-vision but I'm not sure what's the expected format. The following is the semantic segmentation module I've set up.
import os
from os.path import join, basename
from rastervision.core.rv_pipeline import *
from rastervision.core.backend import *
from rastervision.core.data import *
from rastervision.core.analyzer import *
from rastervision.pytorch_backend import *
from rastervision.pytorch_learner import *
from rastervision.pytorch_backend.examples.utils import (get_scene_info,
save_image_crop)
from rastervision.pytorch_backend.examples.semantic_segmentation.utils import (
example_multiband_transform, example_rgb_transform, imagenet_stats,
Unnormalize)
# INRIA dataset in total contains 360 images of size 5000 x 5000 across 10 cities
TRAIN_CITIES = ["austin", "chicago", "kitsap", "tyrol-w", "vienna"]
VAL_CITIES = ["vienna", "kitsap"]
# Debug
TRAIN_CITIES = ["austin"]
VAL_CITIES = ["vienna"]
TEST_CITIES = ["bellingham", "bloomington", "innsbruck", "sfo", "tyrol-e"]
NUM_IMAGES_PER_CITY = 3 #36
CLASS_NAMES = ["Building"]
CLASS_COLORS = ["red"]
raw_uri = "/opt/data/inria/AerialImageDataset"
root_uri = "/opt/src/code/output"
nochip = False
augment = False
test= False
def get_config(runner,
raw_uri: str,
root_uri: str,
augment: bool = False,
nochip: bool = False,
test: bool = False):
channel_order = [0, 1, 2]
channel_display_groups = None
aug_transform = example_rgb_transform
if augment:
mu, std = imagenet_stats['mean'], imagenet_stats['std']
mu, std = mu[channel_order], std[channel_order]
base_transform = A.Normalize(mean=mu.tolist(), std=std.tolist())
plot_transform = Unnormalize(mean=mu, std=std)
aug_transform = A.to_dict(aug_transform)
base_transform = A.to_dict(base_transform)
plot_transform = A.to_dict(plot_transform)
else:
aug_transform = None
base_transform = None
plot_transform = None
chip_sz = 256
img_sz = chip_sz
if nochip:
chip_options = SemanticSegmentationChipOptions()
else:
chip_options = SemanticSegmentationChipOptions(
window_method=SemanticSegmentationWindowMethod.sliding,
stride=chip_sz)
class_config = ClassConfig(names=CLASS_NAMES, colors=CLASS_COLORS)
class_config.ensure_null_class()
def make_scene(id) -> SceneConfig:
raster_uri = f'{raw_uri}/train/images/{id}.tif'
label_uri = f'{raw_uri}/train/gt/{id}.tif'
raster_source = RasterioSourceConfig(
uris=[raster_uri], channel_order=[0,1,2])
label_source = SemanticSegmentationLabelSourceConfig(
raster_source=RasterioSourceConfig(uris=[label_uri]))
# URI will be injected by scene config.
# Using rgb=True because we want prediction TIFFs to be in
# RGB format.
label_store = SemanticSegmentationLabelStoreConfig(
rgb=True, vector_output=[PolygonVectorOutputConfig(class_id=0)])
scene = SceneConfig(
id=id,
raster_source=raster_source,
label_source=label_source,
label_store=label_store)
return scene
scene_dataset = DatasetConfig(
class_config=class_config,
train_scenes=[make_scene(city + str(n)) for city in TRAIN_CITIES for n in range(1, NUM_IMAGES_PER_CITY + 1)],
validation_scenes=[make_scene(city + str(n)) for city in VAL_CITIES for n in range(1, NUM_IMAGES_PER_CITY + 1)])
if nochip:
window_opts = {}
# set window configs for training scenes
for s in scene_dataset.train_scenes:
window_opts[s.id] = GeoDataWindowConfig(
# method=GeoDataWindowMethod.sliding,
method=GeoDataWindowMethod.random,
size=img_sz,
# size_lims=(200, 300),
h_lims=(200, 300),
w_lims=(200, 300),
max_windows=2209,
)
# set window configs for validation scenes
for s in scene_dataset.validation_scenes:
window_opts[s.id] = GeoDataWindowConfig(
method=GeoDataWindowMethod.sliding,
size=img_sz,
stride=img_sz // 2)
data = SemanticSegmentationGeoDataConfig(
scene_dataset=scene_dataset,
window_opts=window_opts,
img_sz=img_sz,
img_channels=len(channel_order),
num_workers=4,
channel_display_groups=channel_display_groups)
else:
data = SemanticSegmentationImageDataConfig(
img_sz=img_sz,
img_channels=len(channel_order),
num_workers=4,
channel_display_groups=channel_display_groups,
base_transform=base_transform,
aug_transform=aug_transform,
plot_options=PlotOptions(transform=plot_transform))
model = SemanticSegmentationModelConfig(backbone=Backbone.resnet50)
backend = PyTorchSemanticSegmentationConfig(
data=data,
model=model,
solver=SolverConfig(
lr=1e-4,
num_epochs=10,
test_num_epochs=2,
batch_sz=8,
test_batch_sz=2,
one_cycle=True),
log_tensorboard=True,
run_tensorboard=False,
test_mode=test)
pipeline = SemanticSegmentationConfig(
root_uri=root_uri,
dataset=scene_dataset,
backend=backend,
channel_display_groups=channel_display_groups,
train_chip_sz=chip_sz,
predict_chip_sz=chip_sz,
chip_options=chip_options)
return pipeline
Error encountered:
....
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [831,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [1,0,0], thread: [960,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [1,0,0], thread: [961,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [1,0,0], thread: [962,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [1,0,0], thread: [963,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [1,0,0], thread: [189,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [1,0,0], thread: [190,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [1,0,0], thread: [191,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [1,0,0], thread: [698,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [1,0,0], thread: [699,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [1,0,0], thread: [700,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [1,0,0], thread: [701,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [1,0,0], thread: [702,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [1,0,0], thread: [703,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [530,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [531,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [19,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [20,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [21,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [22,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [23,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [273,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [274,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [275,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [276,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [277,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [278,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [279,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [280,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/SpatialClassNLLCriterion.cu:103: void cunn_SpatialClassNLLCriterion_updateOutput_kernel(T *, T *, T *, long *, T *, int, int, int, int, int, long) [with T = float, AccumT = float]: block: [4,0,0], thread: [281,0,0] Assertion `t >= 0 && t < n_classes` failed.
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/opt/conda/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/opt/src/rastervision_pipeline/rastervision/pipeline/cli.py", line 248, in <module>
main()
File "/opt/conda/lib/python3.6/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/opt/conda/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/conda/lib/python3.6/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/conda/lib/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/opt/src/rastervision_pipeline/rastervision/pipeline/cli.py", line 240, in run_command
runner=runner)
File "/opt/src/rastervision_pipeline/rastervision/pipeline/cli.py", line 217, in _run_command
command_fn()
File "/opt/src/rastervision_core/rastervision/core/rv_pipeline/rv_pipeline.py", line 115, in train
backend.train(source_bundle_uri=self.config.source_bundle_uri)
File "/opt/src/rastervision_pytorch_backend/rastervision/pytorch_backend/pytorch_learner_backend.py", line 75, in train
learner.main()
File "/opt/src/rastervision_pytorch_learner/rastervision/pytorch_learner/learner.py", line 146, in main
self.train()
File "/opt/src/rastervision_pytorch_learner/rastervision/pytorch_learner/learner.py", line 1149, in train
train_metrics = self.train_epoch()
File "/opt/src/rastervision_pytorch_learner/rastervision/pytorch_learner/learner.py", line 1083, in train_epoch
loss.backward()
File "/opt/conda/lib/python3.6/site-packages/torch/tensor.py", line 118, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph)
File "/opt/conda/lib/python3.6/site-packages/torch/autograd/__init__.py", line 93, in backward
allow_unreachable=True) # allow_unreachable flag
RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED
/opt/src/code/output/Makefile:12: recipe for target '2' failed
make: *** [2] Error 1