Project: s41467-024-55594-z | Function: _upsample_add (python)

system: You are an expert Python programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow Python best practices and maintain consistent code style.
Return **only** the complete Python function code.

user: Complete this Python function:

**DESCRIPTION:** Implements upsampling and element-wise addition for Feature Pyramid Network (FPN), enabling multi-scale feature fusion in 3D medical imaging

**KEY TERMS:** {
  "x": "higher-level feature map",
  "y": "lateral connection feature map",
  "interpolate": "upsampling operation",
  "trilinear": "3D interpolation method"
}

**CONTEXT CODE:**         self.maxpool = nn.MaxPool3d(kernel_size=(3, 3, 3), stride=2, padding=1)
        self.layer1 = self._make_layer(block, first_features, layers[0], shortcut_type)
        self.layer2 = self._make_layer(block, 128, layers[1], shortcut_type, stride=2)
        self.layer3 = self._make_layer(block, 256, layers[2], shortcut_type, stride=2)
        self.layer4 = self._make_layer(block, 512, layers[3], shortcut_type, stride=2)
        
        self.toplayer=nn.Conv3d(512,first_features,1,stride=(1, 1, 1),bias=False)
        
        #横向连接，保证通道数相同
        self.latlayer1=nn.Conv3d(256,first_features,1,stride=(1, 1, 1),bias=False)
        self.latlayer2=nn.Conv3d(128,first_features,1,stride=(1, 1, 1),bias=False)
        self.latlayer3=nn.Conv3d(first_features,first_features,1,stride=(1, 1, 1),bias=False)
        #3x3卷积融合特征
        self.smooth1=nn.Conv3d(first_features,first_features,3,1,1)
        self.smooth2=nn.Conv3d(first_features,first_features,3,1,1)
        self.smooth3=nn.Conv3d(first_features,first_features,3,1,1)
        
        #for p in self.parameters():
        #    p.requires_grad = False

        self.fc1 = nn.Sequential(nn.Linear(first_features, first_features),
                                 nn.BatchNorm1d(first_features),
                                 nn.ReLU())
        self.fc2 = nn.Sequential(nn.Linear(first_features, first_features),
                                 nn.BatchNorm1d(first_features),
                                 nn.ReLU())
        self.fc3 = nn.Sequential(nn.Linear(first_features, first_features),
                                 nn.BatchNorm1d(first_features),
                                 nn.ReLU())
        self.fc4 = nn.Sequential(nn.Linear(first_features, first_features),
                                 nn.BatchNorm1d(first_features),
                                 nn.ReLU())
        
        self.classify_add = nn.Sequential(nn.Linear(first_features, self.fc_num),
                                 nn.BatchNorm1d(self.fc_num),
                                 nn.ReLU(),
                                 nn.Linear(self.fc_num, 2)) 
        
        self.classify_con = nn.Sequential(nn.Linear(first_features*4, self.fc_num),
                                 nn.BatchNorm1d(self.fc_num),
                                 nn.ReLU(),
                                 nn.Linear(self.fc_num, 2))
        
        for m in self.modules():
            if isinstance(m, nn.Conv3d):
                m.weight = nn.init.kaiming_normal_(m.weight, mode='fan_out')
            elif isinstance(m, nn.BatchNorm3d):
                m.weight.data.fill_(1)
                m.bias.data.zero_()
    #自上而下的采样模块
    def _upsample_add(self,x,y):
        raise NotImplementedError("Function implementation has been masked")
    
    def _make_layer(self, block, planes, blocks, shortcut_type, stride=1):
        downsample = None
        if stride != 1 or self.inplanes != planes * block.expansion:
            if shortcut_type == 'A':
                downsample = partial(
                    downsample_basic_block,
                    planes=planes * block.expansion,
                    stride=stride)
            else:
                downsample = nn.Sequential(
                    nn.Conv3d(
                        self.inplanes,
                        planes * block.expansion,
                        kernel_size=1,
                        stride=stride,
                        bias=False), nn.BatchNorm3d(planes * block.expansion))

        layers = []
        layers.append(block(self.inplanes, planes, stride, downsample))
        self.inplanes = planes * block.expansion
        for i in range(1, blocks):
            layers.append(block(self.inplanes, planes))

        return nn.Sequential(*layers)

    def forward(self, x):
        raise NotImplementedError("Function implementation has been masked")

if __name__ == '__main__':
    net = ResFPN(BasicBlock,[2,2,2,2])
    img_size = (64, 64, 64)
    x = torch.randn(3,1,img_size[0],img_size[1],img_size[2])
    out = net(x)
    print(out.shape)

Complete the function implementation replacing "raise NotImplementedError".