harbor run -t swe-rebench/omni-us__jsonargparse-707harbor download swe-rebench/omni-us__jsonargparse-707instantiate_classes does not instantiate my classes with configured args when classes are added to subparser.
Hey, I am trying to add a subparser to my parser, read in a config specific to that parser and subsequently instantiate classes tied to that subparser. However, while my configuration gets read in seemingly properly, instantiate_classes does not use the parameters from my configuration to actually instantiate the classes.
I have roughly the following code
def parse_opt(imported=False, config_file=""):
parser = ArgumentParser(description="Pytorch augmentations testing",
default_config_files=["../config/test/config_data_proc"],
add_help=True)
parser.add_class_arguments(adapters.Blur, prefix + "pixel.blur")
def main():
parser = ArgumentParser()
augment_parser = parse_opt()
parser.add_argument("--augmentations", action=ActionParser(parser=augment_parser))
args = parser.parse_args()
init = parser.instantiate_classes(args)
adapters.Blur would for instance be a class with typed init arguments.
class Blur(A.Blur):
def __init__(self,
blur_limit: tuple[int, int] | int = (3, 7),
p:float = 0.0):
self.blur_limit = blur_limit
self.p = p
Then I have the following yaml to read in:
augmentations:
pixel:
blur:
p: 1.0
blur_limit: [3,7]
I expect init.augmentations or init.augmentations.pixel to contain a list of instantiated classes according to my configuration. But what I see currently in my debugger is that args.augmentations.spatial.blur would have the correct configuration: Namespace(p=1.0, blur_limit: [3,7]), as well as init.augmentations.spatial.
But then init also contains what I presume are the instantiated classes (init.spatial and init.pixel in the full code I have, init.pixel in the example above). But those are instantiated with the default arguments for the classes, not the values from my config file.
I am not sure from the documentation how to do all of this properly, and it feels like I'm kind of stuck at this point. It would already help to know what the expected structure for 'args' and 'init' should look like and how I could best structure my parser and config file to work with this.