<reponame>o-sapov/image_extrapolation
# -*- coding: utf-8 -*-
"""network/architectures.py

Author -- <NAME>
Contact -- <EMAIL>
Date -- 25.07.2021

###############################################################################

The following copyright statement applies to all code within this file.

Copyright statement:
This material, no matter whether in printed or electronic form, may be used for
personal and non-commercial educational use only. Any reproduction of this
manuscript, no matter whether as a whole or in parts, no matter whether in
printed or in electronic form, requires explicit prior acceptance of the
authors.

###############################################################################

Architectures file for CNN.
"""

import torch.nn as nn


class Ex5Cnn(nn.Module):
    def __init__(self, n_in_channels: int = 1, n_hidden_layers: int = 3, n_kernels: int = 32, kernel_size: int = 7):
        """Ex5Cnn with `n_hidden_layers`, `n_kernels`, and `kernel_size` as hyperparameters"""
        super(Ex5Cnn, self).__init__()

        cnn = []
        for i in range(n_hidden_layers):
            cnn.append(nn.Conv2d(in_channels=n_in_channels, out_channels=n_kernels, kernel_size=kernel_size,
                                 bias=True, padding=int(kernel_size / 2)))
            cnn.append(nn.ReLU())
            n_in_channels = n_kernels
        self.hidden_layers = nn.Sequential(*cnn)
        self.output_layer = nn.Conv2d(in_channels=n_in_channels, out_channels=1,
                                      kernel_size=kernel_size, bias=True, padding=int(kernel_size / 2))

    def forward(self, x):
        """Apply CNN to input `x` of shape (N, n_channels, X, Y), where N=n_samples and X, Y are spatial dimensions"""
        cnn_out = self.hidden_layers(x)  # apply hidden layers (N, n_in_channels, X, Y) -> (N, n_kernels, X, Y)
        pred = self.output_layer(cnn_out)  # apply output layer (N, n_kernels, X, Y) -> (N, 1, X, Y)
        return pred

# -*- coding: utf-8 -*-
"""network/architectures.py

Author -- <NAME>
Contact -- <EMAIL>
Date -- 25.07.2021

###############################################################################

The following copyright statement applies to all code within this file.

Copyright statement:
This material, no matter whether in printed or electronic form, may be used for
personal and non-commercial educational use only. Any reproduction of this
manuscript, no matter whether as a whole or in parts, no matter whether in
printed or in electronic form, requires explicit prior acceptance of the
authors.

###############################################################################

Architectures file for CNN.
"""

import torch.nn as nn


class Ex5Cnn(nn.Module):
    def __init__(self, n_in_channels: int = 1, n_hidden_layers: int = 3, n_kernels: int = 32, kernel_size: int = 7):
        """Ex5Cnn with `n_hidden_layers`, `n_kernels`, and `kernel_size` as hyperparameters"""
        super(Ex5Cnn, self).__init__()

        cnn = []
        for i in range(n_hidden_layers):
            cnn.append(nn.Conv2d(in_channels=n_in_channels, out_channels=n_kernels, kernel_size=kernel_size,
                                 bias=True, padding=int(kernel_size / 2)))
            cnn.append(nn.ReLU())
            n_in_channels = n_kernels
        self.hidden_layers = nn.Sequential(*cnn)
        self.output_layer = nn.Conv2d(in_channels=n_in_channels, out_channels=1,
                                      kernel_size=kernel_size, bias=True, padding=int(kernel_size / 2))

    def forward(self, x):
        """Apply CNN to input `x` of shape (N, n_channels, X, Y), where N=n_samples and X, Y are spatial dimensions"""
        cnn_out = self.hidden_layers(x)  # apply hidden layers (N, n_in_channels, X, Y) -> (N, n_kernels, X, Y)
        pred = self.output_layer(cnn_out)  # apply output layer (N, n_kernels, X, Y) -> (N, 1, X, Y)
        return pred
# -*- coding: utf-8 -*- network/architectures.py  Author -- <NAME> Contact -- <EMAIL> Date -- 25.07.2021  ###############################################################################  The following copyright statement applies to all code within this file.  Copyright statement: This material, no matter whether in printed or electronic form, may be used for personal and non-commercial educational use only. Any reproduction of this manuscript, no matter whether as a whole or in parts, no matter whether in printed or in electronic form, requires explicit prior acceptance of the authors.  ###############################################################################  Architectures file for CNN. Ex5Cnn with `n_hidden_layers`, `n_kernels`, and `kernel_size` as hyperparameters Apply CNN to input `x` of shape (N, n_channels, X, Y), where N=n_samples and X, Y are spatial dimensions # apply hidden layers (N, n_in_channels, X, Y) -> (N, n_kernels, X, Y) # apply output layer (N, n_kernels, X, Y) -> (N, 1, X, Y)