Last active
May 24, 2023 13:49
-
-
Save LeeSinLiang/b4a51e2e930d803c1450d0aafff73835 to your computer and use it in GitHub Desktop.
Enables nn.Sequential to accept multiple inputs, enhancing the flexibility of sequential neural network models.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch.nn as nn | |
class MultiInputSequential(nn.Sequential): | |
def forward(self, *inputs): | |
for module in self._modules.values(): | |
if type(inputs) == tuple: | |
inputs = module(*inputs) | |
else: | |
inputs = module(inputs) | |
return inputs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment