ObjectDetectionGeoDataConfig
leaves window_opts
empty when created with scene_dataset
#1772
-
I am attempting to use the def make_scene(self, name, image_uri, label_uri, aoi_uri):
'''' Define a Scene with image and labels from the given URIs. '''
raster_source = RasterioSourceConfig(
uris=[image_uri], channel_order=[0, 1, 2])
label_source = ObjectDetectionLabelSourceConfig(
vector_source=GeoJSONVectorSourceConfig(
uri=label_uri,
ignore_crs_field=True,
transformers=[ClassInferenceTransformerConfig(default_class_id=0)]
)
)
aoi_uris = [aoi_uri] if aoi_uri is not None else []
sconf = SceneConfig(
id=name,
raster_source=raster_source,
label_source=label_source,
aoi_uris=aoi_uris
)
return sconf
def _build_scene_ds(self, uris):
scenes = []
for i in range(len(uris["image"])):
s = self.make_scene(
uris["name"][i], uris["image"][i], uris["labels"][i], uris["aoi"][i]
)
scenes.append(s)
return scenes
def build_train_val_scene_ds(self):
train = self._build_scene_ds(self.train_uris)
val = self._build_scene_ds(self.val_uris)
dconf = DatasetConfig(
class_config=self.cc, train_scenes=train, validation_scenes=val)
return dconf
def configure_training(self):
data_cfg = ObjectDetectionGeoDataConfig(
class_names=self.cc.names,
class_colors=self.cc.colors,
scene_dataset=self.build_train_val_scene_ds(),
num_workers=2,
)
print(data_cfg.window_opts) # --> `{}`
solver_cfg = SolverConfig(
batch_sz=4,
lr=1e-3,
)
model = self.build_model()
learner_cfg = ObjectDetectionLearnerConfig(
data=data_cfg,
solver=solver_cfg,
model=model)
learner = ObjectDetectionLearner( # ERROR HERE
cfg=learner_cfg,
output_dir="./demo",
# train_ds=self.build_train_ds(),
# valid_ds=self.build_val_ds()
)
return learner Results in this error: Traceback (most recent call last):
File "/home/aerotract/software/rvml-pipeline/train.py", line 212, in <module>
util.run_if_main(__name__, RVBase)
File "/home/aerotract/software/rvml-pipeline/util.py", line 18, in run_if_main
obj.run()
File "/home/aerotract/software/rvml-pipeline/train.py", line 210, in run
self.train()
File "/home/aerotract/software/rvml-pipeline/train.py", line 205, in train
learner = self.configure_training()
File "/home/aerotract/software/rvml-pipeline/train.py", line 196, in configure_training
learner = ObjectDetectionLearner(
File "/home/aerotract/miniconda3/envs/ml/lib/python3.9/site-packages/rastervision/pytorch_learner/learner.py", line 239, in __init__
self.setup_training(loss_def_path=loss_def_path)
File "/home/aerotract/miniconda3/envs/ml/lib/python3.9/site-packages/rastervision/pytorch_learner/learner.py", line 289, in setup_training
self.setup_data()
File "/home/aerotract/miniconda3/envs/ml/lib/python3.9/site-packages/rastervision/pytorch_learner/learner.py", line 413, in setup_data
train_ds, valid_ds, test_ds = self.build_datasets()
File "/home/aerotract/miniconda3/envs/ml/lib/python3.9/site-packages/rastervision/pytorch_learner/learner.py", line 425, in build_datasets
train_ds, val_ds, test_ds = self.cfg.data.build(
File "/home/aerotract/miniconda3/envs/ml/lib/python3.9/site-packages/rastervision/pytorch_learner/learner_config.py", line 1271, in build
train_ds, val_ds, test_ds = self.make_datasets(
File "/home/aerotract/miniconda3/envs/ml/lib/python3.9/site-packages/rastervision/pytorch_learner/learner_config.py", line 1235, in make_datasets
train_ds_list = [
File "/home/aerotract/miniconda3/envs/ml/lib/python3.9/site-packages/rastervision/pytorch_learner/learner_config.py", line 1236, in <listcomp>
self.scene_to_dataset(s, train_tf, **kwargs) for s in train_scenes
File "/home/aerotract/miniconda3/envs/ml/lib/python3.9/site-packages/rastervision/pytorch_learner/object_detection_learner_config.py", line 98, in scene_to_dataset
opts = self.window_opts[scene.id]
KeyError: 'scene-key-name' Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I was forgetting to set my def configure_training(self):
chip_options = ObjectDetectionChipOptions(**self.kw.get("chip_kw", {}))
chip_sz = self.kw["window_kw"].get("chip_sz", 450)
window_opts = ObjectDetectionGeoDataWindowConfig(
method=GeoDataWindowMethod.random,
size=chip_sz,
size_lims=(chip_sz, chip_sz + 1),
max_windows=self.kw["window_kw"].get("max_windows", None),
clip=True,
neg_ratio=chip_options.neg_ratio,
ioa_thresh=chip_options.ioa_thresh
)
data_cfg = ObjectDetectionGeoDataConfig(
class_names=self.cc.names,
class_colors=self.cc.colors,
scene_dataset=self.build_train_val_scene_ds(),
window_opts=window_opts,
num_workers=2,
)
solver_cfg = SolverConfig(
batch_sz=4,
lr=1e-3,
)
model = self.build_model()
learner_cfg = ObjectDetectionLearnerConfig(
data=data_cfg,
solver=solver_cfg,
model=model)
learner = ObjectDetectionLearner(
cfg=learner_cfg,
output_dir="./demo",
# train_ds=self.build_train_ds(),
# valid_ds=self.build_val_ds()
)
return learner |
Beta Was this translation helpful? Give feedback.
I was forgetting to set my
chip
andwindow
options, the following fixed it for me: