<filename>network/base_h3i_net_with_pytorch.py
import torch
from torch import Module, Tensor


class BaseHidingImagesIntoImagesNetworkWithPyTorch(Module):
    def __init__(
            self,
            p_net: Module,
            h_net: Module,
            r_net: Module,
            is_use_residual=False
    ) -> None:
        super(BaseHidingImagesIntoImagesNetworkWithPyTorch, self).__init__()
        self.p_net = p_net
        self.h_net = h_net
        self.r_net = r_net
        self.is_use_residual = is_use_residual

    def forward(self, host: Tensor, hidden: Tensor):
        p = self.p_net(hidden)
        h_input = torch.cat([p, host], dim=1)
        if self.is_use_residual:
            residual = self.h_net(h_input)
            container = residual + host
            secret = self.r_net(container)
            return residual, container, secret
        else:
            container = self.h_net(h_input)
            secret = self.r_net(container)
            return container, secret

<filename>network/base_h3i_net_with_pytorch.py
import torch
from torch import Module, Tensor


class BaseHidingImagesIntoImagesNetworkWithPyTorch(Module):
    def __init__(
            self,
            p_net: Module,
            h_net: Module,
            r_net: Module,
            is_use_residual=False
    ) -> None:
        super(BaseHidingImagesIntoImagesNetworkWithPyTorch, self).__init__()
        self.p_net = p_net
        self.h_net = h_net
        self.r_net = r_net
        self.is_use_residual = is_use_residual

    def forward(self, host: Tensor, hidden: Tensor):
        p = self.p_net(hidden)
        h_input = torch.cat([p, host], dim=1)
        if self.is_use_residual:
            residual = self.h_net(h_input)
            container = residual + host
            secret = self.r_net(container)
            return residual, container, secret
        else:
            container = self.h_net(h_input)
            secret = self.r_net(container)
            return container, secret
