Hook for processing input data in LightningCLI #17594
-
Hi, I have a model that accepts a couple of files as input and I want to run prediction on it. Since I know the file structure, I'm not passing the paths directly via Argparse for now, I just provide directory and get all required paths programatically. I want to integrate my current approach with LightningCLI, but I don't see a place to somehow parse/process input arguments. LightningCLI implementation:
Data module that operates on separate files:
Is there a way to combine these two approaches or I should not mixed them? I tried overriding "parse_arguments" in LightningCLI, but unfortunately "args" are null at the time. Is there a better place to hook? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
My recommendation would be that you think of If you want to load data from a directory, then implement a data module that receives as parameter that directory. This could be a subclass of your module that gets files. Something like: class FilesData(pl.LightningDataModule):
def __init__(self, file1, file2, file3):
super().__init__()
self._file1 = file1
self._file2 = file2
self._file3 = file3
class DirectoryData(FilesData):
def __init__(self, input_dir: os.PathLike):
file1, file2, file3 = self.get_files_from_dir(input_dir)
super().__init__(file1, file2, file3) Then to |
Beta Was this translation helpful? Give feedback.
My recommendation would be that you think of
LightningCLI
as a class that automatically exposes signature parameters in a CLI. However, the logic to run in most cases is not implemented as part of the CLI class. The parameters come from other classes that you can even use without the CLI.If you want to load data from a directory, then implement a data module that receives as parameter that directory. This could be a subclass of your module that gets files. Something like: