File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616from torchvision import models as vision_models
1717
1818import robomimic .utils .tensor_utils as TensorUtils
19+ import robomimic .utils .obs_utils as ObsUtils
1920
2021
2122CONV_ACTIVATIONS = {
@@ -463,6 +464,20 @@ class ConvBase(Module):
463464 def __init__ (self ):
464465 super (ConvBase , self ).__init__ ()
465466
467+ def __init_subclass__ (cls , ** kwargs ):
468+ """
469+ Hook method to automatically register all valid subclasses so we can keep track of valid observation encoders
470+ in a global dict.
471+
472+ This global dict stores mapping from observation encoder network name to class.
473+ We keep track of these registries to enable automated class inference at runtime, allowing
474+ users to simply extend our base encoder class and refer to that class in string form
475+ in their config, without having to manually register their class internally.
476+ This also future-proofs us for any additional encoder classes we would
477+ like to add ourselves.
478+ """
479+ ObsUtils .register_encoder_backbone (cls )
480+
466481 # dirty hack - re-implement to pass the buck onto subclasses from ABC parent
467482 def output_shape (self , input_shape ):
468483 """
Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ def __init__(
9999
100100 # extract only relevant kwargs for this specific backbone
101101 backbone_kwargs = extract_class_init_kwargs_from_dict (
102- cls = ObsUtils .OBS_ENCODER_CORES [backbone_class ],
102+ cls = ObsUtils .OBS_ENCODER_BACKBONES [backbone_class ],
103103 dic = backbone_kwargs , copy = True )
104104
105105 # visual backbone
Original file line number Diff line number Diff line change 4141# in their config, without having to manually register their class internally.
4242# This also future-proofs us for any additional encoder / randomizer classes we would
4343# like to add ourselves.
44- OBS_ENCODER_CORES = {"None" : None } # Include default None
45- OBS_RANDOMIZERS = {"None" : None } # Include default None
44+ OBS_ENCODER_CORES = {"None" : None } # Per-modality core net as defined in obs_cores.py, e.g., "VisualCore"
45+ OBS_RANDOMIZERS = {"None" : None } # Obs randomizer defined in obs_cores.py, e.g., "CropRandomizer"
46+ OBS_ENCODER_BACKBONES = {"None" : None } # Architecture backbones for encoding obervation, e.g., "ResNet18Conv"
4647
4748
4849def register_obs_key (target_class ):
@@ -59,6 +60,10 @@ def register_randomizer(target_class):
5960 assert target_class not in OBS_RANDOMIZERS , f"Already registered obs randomizer { target_class } !"
6061 OBS_RANDOMIZERS [target_class .__name__ ] = target_class
6162
63+ def register_encoder_backbone (target_class ):
64+ assert target_class not in OBS_ENCODER_BACKBONES , f"Already registered obs encoder backbone { target_class } !"
65+ OBS_ENCODER_BACKBONES [target_class .__name__ ] = target_class
66+
6267
6368class ObservationKeyToModalityDict (dict ):
6469 """
You can’t perform that action at this time.
0 commit comments