Consider the following code
import torch
import torch.nn as nn
from collections import OrderedDict
class sum_t(nn.Module):
def __init__(self):
super().__init__()
def forward(self, x, y):
return x + y
model = nn.Sequential(OrderedDict([
('conv1', nn.Conv2d(3, 3, 1)),
('relu1', nn.ReLU()),
('conv2', nn.Conv2d(3, 3, 1)),
('relu2', nn.ReLU()),
('sum0', sum_t()),
('sum1', sum_t())
]))
x = torch.randn(3, 3, 64, 64)
y = torch.randn(3, 3, 64, 64)
I want to pass two inputs x, y
to the last two modules only, but one input x
to the first four layers. Is it possible to do with nn.Sequential
? How can I do model(x,y)
?
If possible, I want to do it so that I can use the code from PyTorch and hook my codes.