kumatheworld / fakeglyph

Fancy brand new letters with generative models
MIT License
0 stars 0 forks source link

Verify function assignment to self.forward in torch.nn.Module subclasses #6

Closed kumatheworld closed 1 year ago

kumatheworld commented 1 year ago

This is related to #5. Is it a good idea to do self.forward = func rather than overriding forward()? So far I don't find any inconvenience but this might be bad practice in Python.

kumatheworld commented 1 year ago

ChatGPT suggested I do the following, but I don't think I need to do so at the moment.

class Functional(nn.Module):
    def __init__(self, func: Callable) -> None:
        super().__init__()
        self._forward_func = func

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        return self._forward_func(x)

    # Rest of the class implementation...