I have this piece of code, part of a Spikingjelly neural network training functionality, which gets some errors on this line after running. I'm not quite experienced in Python, and I don't understand what class initialization type this is.
The class definition and the __init__ looks like this:
class DVS128Gesture(sjds.NeuromorphicDatasetFolder):
def __init__(
self,
root: str,
train: bool = None,
data_type: str = 'event',
frames_number: int = None,
split_by: str = None,
duration: int = None,
custom_integrate_function: Callable = None,
custom_integrated_frames_dir_name: str = None,
transform: Optional[Callable] = None,
target_transform: Optional[Callable] = None,
) -> None:
And the intialization:
train_data_loader = torch.utils.data.DataLoader(
dataset=DVS128Gesture(dataset_dir, train=True, use_frame=True, frames_num=T,
split_by=split_by, normalization=normalization),
batch_size=batch_size,
shuffle=True,
num_workers=4,
drop_last=True,
pin_memory=True)
test_data_loader = torch.utils.data.DataLoader(
dataset=DVS128Gesture(dataset_dir, train=False, use_frame=True, frames_num=T,
split_by=split_by, normalization=normalization),
batch_size=batch_size,
shuffle=False,
num_workers=4,
drop_last=False,
pin_memory=True)
For example, class DVS128Gesture expects:
A string (root) as the address of the dataset
A bool (train) variable (which is not our interest right now)
A string
An integer value allocated to frames_number
The problem:
However, the initialization (at the bottom of the picture) is not according to that sequence; for example, useframe=True is used as the 3rd parameter while the class's 3rd parameter was datatype: str = 'event' .
Questions:
Is the problem I mentioned above, really an error by the author? or my misunderstanding of something?
What's the meaning of a variable assignment during a class initialization? For example, the 4th parameter of class initialization is written
framesnum=T. Why not write 'T' directly? and why it was usedframesnuminstead of the originalframes_numberwritten in class definition?
I traced the mentioned variables the their declaration and classes they were used in and as much as I can understand, there is no other variables with the same name.
As others mentioned in the comments, this is a keyword argument (kwarg), for which order does not matter. You don't /have/ to use keywords when calling a function, but if you don't, then all of your arguments must be in the correct order and position.
This seems to be an error. You might use
frames_number=Trather than justTso that it doesn't matter if you pass arguments in the correct order, but you're right that there's noframesnumkwarg in the original class declaration. There is also nouse_frameornormalizationkwarg, so I'm skeptical of what's going on here. It is possible to pass on keyword arguments for a parent class without specifically defining them in the child class's__init__, by adding**kwargsto the list of arguments and passing that tosuper.init(), but that isn't being done here, nor does the parent class actually have any of these keyword arguments in the first place.