#include <neural_net.h>
Definition at line 31 of file neural_net.h.
◆ NeuralNet()
tesseract::NeuralNet::NeuralNet |
( |
| ) |
|
◆ ~NeuralNet()
tesseract::NeuralNet::~NeuralNet |
( |
| ) |
|
|
virtual |
Definition at line 28 of file neural_net.cpp.
30 for (
int vec = 0; vec < static_cast<int>(
wts_vec_.size()); vec++) {
36 for (
int node_idx = 0; node_idx <
neuron_cnt_; node_idx++) {
vector< vector< float > * > wts_vec_
vector< Node > fast_nodes_
◆ AllocWgt()
float * tesseract::NeuralNet::AllocWgt |
( |
int |
wgt_cnt | ) |
|
|
protected |
Definition at line 195 of file neural_net.cpp.
vector< vector< float > * > wts_vec_
static const int kWgtChunkSize
◆ Clear()
void tesseract::NeuralNet::Clear |
( |
| ) |
|
|
inlineprotected |
◆ CreateFastNet()
bool tesseract::NeuralNet::CreateFastNet |
( |
| ) |
|
|
protected |
Definition at line 133 of file neural_net.cpp.
137 for (
int node_idx = 0; node_idx <
neuron_cnt_; node_idx++) {
141 node->fan_in_cnt = 0;
159 node->inputs =
new WeightedNode[node->fan_in_cnt];
160 for (
int fan_in = 0; fan_in < node->fan_in_cnt; fan_in++) {
164 if (
id >= node_idx) {
168 node->inputs[fan_in].input_node = &
fast_nodes_[id];
183 node->inputs[fan_in].input_weight = wgt_val;
186 wts_cnt += node->fan_in_cnt;
Neuron * fan_in(int idx) const
vector< float > inputs_max_
float fan_in_wts(int idx) const
vector< float > inputs_min_
vector< float > inputs_std_dev_
vector< float > inputs_mean_
vector< Node > fast_nodes_
◆ FastFeedForward()
template<typename Type >
template bool tesseract::NeuralNet::FastFeedForward |
( |
const Type * |
inputs, |
|
|
Type * |
outputs |
|
) |
| |
|
protected |
Definition at line 61 of file neural_net.cpp.
66 for (node_idx = 0; node_idx <
in_cnt_; node_idx++, node++) {
67 node->out = inputs[node_idx] - node->bias;
71 double activation = -node->bias;
72 for (
int fan_in_idx = 0; fan_in_idx < node->fan_in_cnt; fan_in_idx++) {
73 activation += (node->inputs[fan_in_idx].input_weight *
74 node->inputs[fan_in_idx].input_node->out);
80 for (node_idx = 0; node_idx <
out_cnt_; node_idx++, node++) {
81 outputs[node_idx] = node->out;
static float Sigmoid(float activation)
vector< Node > fast_nodes_
◆ FastGetNetOutput()
template<typename Type >
template bool tesseract::NeuralNet::FastGetNetOutput |
( |
const Type * |
inputs, |
|
|
int |
output_id, |
|
|
Type * |
output |
|
) |
| |
|
protected |
Definition at line 234 of file neural_net.cpp.
240 for (node_idx = 0; node_idx <
in_cnt_; node_idx++, node++) {
241 node->out = inputs[node_idx] - node->bias;
246 for (;node_idx < hidden_node_cnt; node_idx++, node++) {
247 double activation = -node->bias;
248 for (
int fan_in_idx = 0; fan_in_idx < node->fan_in_cnt; fan_in_idx++) {
249 activation += (node->inputs[fan_in_idx].input_weight *
250 node->inputs[fan_in_idx].input_node->out);
257 double activation = -node->bias;
258 for (
int fan_in_idx = 0; fan_in_idx < node->fan_in_cnt; fan_in_idx++) {
259 activation += (node->inputs[fan_in_idx].input_weight *
260 node->inputs[fan_in_idx].input_node->out);
static float Sigmoid(float activation)
vector< Node > fast_nodes_
◆ FeedForward()
template<typename Type >
template bool tesseract::NeuralNet::FeedForward |
( |
const Type * |
inputs, |
|
|
Type * |
outputs |
|
) |
| |
Definition at line 88 of file neural_net.cpp.
98 for (
int in = 0; in <
in_cnt_; in++) {
103 for (
int in = 0; in <
in_cnt_; in++) {
vector< float > inputs_max_
bool FastFeedForward(const Type *inputs, Type *outputs)
vector< float > inputs_min_
vector< float > inputs_std_dev_
void set_output(float out_val)
vector< float > inputs_mean_
◆ FromFile()
NeuralNet * tesseract::NeuralNet::FromFile |
( |
const string |
file_name | ) |
|
|
static |
Definition at line 210 of file neural_net.cpp.
212 InputFileBuffer input_buff(file_name);
static NeuralNet * FromInputBuffer(InputFileBuffer *ib)
◆ FromInputBuffer()
◆ GetNetOutput()
template<typename Type >
template bool tesseract::NeuralNet::GetNetOutput |
( |
const Type * |
inputs, |
|
|
int |
output_id, |
|
|
Type * |
output |
|
) |
| |
Definition at line 268 of file neural_net.cpp.
272 if (output_id < 0 || output_id >=
out_cnt_) {
287 (*output) = outputs[output_id];
bool FeedForward(const Type *inputs, Type *outputs)
bool FastGetNetOutput(const Type *inputs, int output_id, Type *output)
◆ in_cnt()
int tesseract::NeuralNet::in_cnt |
( |
| ) |
const |
|
inline |
◆ Init()
void tesseract::NeuralNet::Init |
( |
| ) |
|
|
protected |
Definition at line 43 of file neural_net.cpp.
vector< float > inputs_max_
vector< vector< float > * > wts_vec_
vector< float > inputs_min_
vector< float > inputs_std_dev_
vector< float > inputs_mean_
◆ out_cnt()
int tesseract::NeuralNet::out_cnt |
( |
| ) |
const |
|
inline |
◆ ReadBinary()
template<class ReadBuffType >
template bool tesseract::NeuralNet::ReadBinary |
( |
ReadBuffType * |
input_buff | ) |
|
|
inlineprotected |
Definition at line 115 of file neural_net.h.
119 unsigned int read_val;
120 unsigned int auto_encode;
122 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
128 if (input_buff->Read(&auto_encode,
sizeof(auto_encode)) !=
129 sizeof(auto_encode)) {
134 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
144 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
152 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
172 for (
int node_idx = 0; node_idx <
neuron_cnt_; node_idx++) {
174 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
178 int fan_out_cnt = read_val;
179 for (
int fan_out_idx = 0; fan_out_idx < fan_out_cnt; fan_out_idx++) {
181 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
191 for (
int node_idx = 0; node_idx <
neuron_cnt_; node_idx++) {
void set_node_type(NeuronTypes type)
bool SetConnection(int from, int to)
vector< float > inputs_max_
vector< float > inputs_min_
bool ReadBinary(ReadBuffType *input_buff)
vector< float > inputs_std_dev_
static const unsigned int kNetSignature
vector< float > inputs_mean_
◆ SetConnection()
bool tesseract::NeuralNet::SetConnection |
( |
int |
from, |
|
|
int |
to |
|
) |
| |
|
protected |
Definition at line 121 of file neural_net.cpp.
void AddFromConnection(Neuron *neuron_vec, float *wts_offset, int from_cnt)
float * AllocWgt(int wgt_cnt)
◆ alloc_wgt_cnt_
int tesseract::NeuralNet::alloc_wgt_cnt_ |
|
protected |
◆ auto_encoder_
bool tesseract::NeuralNet::auto_encoder_ |
|
protected |
◆ fast_nodes_
vector<Node> tesseract::NeuralNet::fast_nodes_ |
|
protected |
◆ in_cnt_
int tesseract::NeuralNet::in_cnt_ |
|
protected |
◆ inputs_max_
vector<float> tesseract::NeuralNet::inputs_max_ |
|
protected |
◆ inputs_mean_
vector<float> tesseract::NeuralNet::inputs_mean_ |
|
protected |
◆ inputs_min_
vector<float> tesseract::NeuralNet::inputs_min_ |
|
protected |
◆ inputs_std_dev_
vector<float> tesseract::NeuralNet::inputs_std_dev_ |
|
protected |
◆ kNetSignature
const unsigned int tesseract::NeuralNet::kNetSignature = 0xFEFEABD0 |
|
staticprotected |
◆ kWgtChunkSize
const int tesseract::NeuralNet::kWgtChunkSize = 0x10000 |
|
staticprotected |
◆ neuron_cnt_
int tesseract::NeuralNet::neuron_cnt_ |
|
protected |
◆ neurons_
Neuron* tesseract::NeuralNet::neurons_ |
|
protected |
◆ out_cnt_
int tesseract::NeuralNet::out_cnt_ |
|
protected |
◆ read_only_
bool tesseract::NeuralNet::read_only_ |
|
protected |
◆ wts_cnt_
int tesseract::NeuralNet::wts_cnt_ |
|
protected |
◆ wts_vec_
vector<vector<float> *> tesseract::NeuralNet::wts_vec_ |
|
protected |
The documentation for this class was generated from the following files: