This repository has been archived by the owner on Dec 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CNN.hpp
64 lines (54 loc) · 1.77 KB
/
CNN.hpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// Created by rege on 21.03.19.
//
#ifndef THECAR_CNN_HPP
#define THECAR_CNN_HPP
/**
* Note:
* This class doesn't claim to be a real convolution neural network. However it was conceived thus at begin.
* Now it contain a small functional basis needs to build a CNN. Function "process" performs a very simple
* single layer CNN with manual set parameters. It cannot be trained, which makes each neural network a neural network.
*/
class CNN
{
/**
* It's a simple convolutional layer realisation.
* Run kernel for one-channel image and write result to dst, kernel can be sized for 3x3 or 5x5.
* @note thread-safe
*/
void runKernel (const cv::Mat1f & src, cv::Mat1f & dst, const cv::Mat1f & kernel);
/**
* get kernel based by specified coordinates on the source image
* @note thread-safe
*/
void getKernelByPoint (int x, int y, const cv::Mat1f & src, cv::Mat1f & outputKernel, int kernelSize);
/**
* @note thread-safe
*/
void maxPooling (cv::Mat1f & src, cv::Mat1f & dst, int kernelWidth, int kernelHeight);
/**
* Simple ReLU (p > 0 ? p : 0)
* @param mat
*/
void runReLU (cv::Mat1f & mat);
public:
/**
* Constrains a number to be within a range.
* @note thread-safe
*/
template<typename number>
inline number constrain (number value, number min, number max)
{
if (value > max) return max;
if (value < min) return min;
return value;
}
/**
* The uniting function. Takes a prepared image as source, and writes to destination
* with applying convolution, pooling, uniting to one matrix and applying ReLU.
* @param src
* @param dst
*/
void process (const cv::Mat1b & src, cv::Mat1f & dst);
};
#endif //THECAR_CNN_HPP