summaryrefslogtreecommitdiff
path: root/neural_network.py
blob: 827b0665a728e8337f4c296e4e5798cc51f5e492 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import numpy as np
from utils import random_array

CYRILLIC_ALPHABET = ['I', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ë', 'Ж', 'З',
                     'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С',
                     'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы',
                     'Ь', 'Э', 'Ю', 'Я']

"""The neural network class."""
class NeuralNetwork:
    def __init__(self, learning_rate: float, input_resolution: int) -> None:
        self.learning_rate = learning_rate
        self.output_layer_size = len(CYRILLIC_ALPHABET)
        self.input_layer_size = input_resolution ** 2
        self.hidden_layer_size = round((self.input_layer_size + self.output_layer_size) / 2)
        self._hidden_weights = random_array(self.hidden_layer_size, self.input_layer_size)
        self._output_weights = random_array(self.output_layer_size, self.hidden_layer_size)


    """
    Train the neural network. It loads the dataset contained in ./data,
    converts each image into a numpy array and uses that data for training.
    """
    def train():
        pass

    """
    Guess the letter contained in the image file pointed by
    input_image (a path).
    """
    def guess(input_image: str) -> str:
        pass

    """
    Save the weights to a csv file.
    """
    def save():
        pass

    """
    Load the weights from a csv file.
    """
    def load(weights_file: str):
        pass

    """
    Feedforwarding.
    """
    def _predict(input_layer: np.array):
        pass