#include <neural_net.h>
Definition at line 22 of file neural_net.h.
tesseract::NeuralNet::NeuralNet |
( |
| ) |
|
tesseract::NeuralNet::~NeuralNet |
( |
| ) |
|
|
virtual |
Definition at line 19 of file neural_net.cpp.
21 for (
int vec = 0; vec < static_cast<int>(
wts_vec_.size()); vec++) {
27 for (
int node_idx = 0; node_idx <
neuron_cnt_; node_idx++) {
vector< Node > fast_nodes_
vector< vector< float > * > wts_vec_
float * tesseract::NeuralNet::AllocWgt |
( |
int |
wgt_cnt | ) |
|
|
protected |
Definition at line 189 of file neural_net.cpp.
static const int kWgtChunkSize
vector< vector< float > * > wts_vec_
void tesseract::NeuralNet::Clear |
( |
| ) |
|
|
inlineprotected |
bool tesseract::NeuralNet::CreateFastNet |
( |
| ) |
|
|
protected |
Definition at line 124 of file neural_net.cpp.
128 for (
int node_idx = 0; node_idx <
neuron_cnt_; node_idx++) {
132 node->fan_in_cnt = 0;
150 node->inputs =
new WeightedNode[node->fan_in_cnt];
151 if (node->inputs ==
NULL) {
154 for (
int fan_in = 0; fan_in < node->fan_in_cnt; fan_in++) {
158 if (
id >= node_idx) {
162 node->inputs[fan_in].input_node = &
fast_nodes_[id];
177 node->inputs[fan_in].input_weight = wgt_val;
180 wts_cnt += node->fan_in_cnt;
vector< float > inputs_min_
float fan_in_wts(int idx) const
vector< float > inputs_mean_
vector< float > inputs_std_dev_
Neuron * fan_in(int idx) const
vector< Node > fast_nodes_
vector< float > inputs_max_
template<typename Type >
template bool tesseract::NeuralNet::FastFeedForward |
( |
const Type * |
inputs, |
|
|
Type * |
outputs |
|
) |
| |
|
protected |
Definition at line 52 of file neural_net.cpp.
57 for (node_idx = 0; node_idx <
in_cnt_; node_idx++, node++) {
58 node->out = inputs[node_idx] - node->bias;
62 double activation = -node->bias;
63 for (
int fan_in_idx = 0; fan_in_idx < node->fan_in_cnt; fan_in_idx++) {
64 activation += (node->inputs[fan_in_idx].input_weight *
65 node->inputs[fan_in_idx].input_node->out);
71 for (node_idx = 0; node_idx <
out_cnt_; node_idx++, node++) {
72 outputs[node_idx] = node->out;
vector< Node > fast_nodes_
static float Sigmoid(float activation)
template<typename Type >
template bool tesseract::NeuralNet::FastGetNetOutput |
( |
const Type * |
inputs, |
|
|
int |
output_id, |
|
|
Type * |
output |
|
) |
| |
|
protected |
Definition at line 231 of file neural_net.cpp.
237 for (node_idx = 0; node_idx <
in_cnt_; node_idx++, node++) {
238 node->out = inputs[node_idx] - node->bias;
243 for (;node_idx < hidden_node_cnt; node_idx++, node++) {
244 double activation = -node->bias;
245 for (
int fan_in_idx = 0; fan_in_idx < node->fan_in_cnt; fan_in_idx++) {
246 activation += (node->inputs[fan_in_idx].input_weight *
247 node->inputs[fan_in_idx].input_node->out);
254 double activation = -node->bias;
255 for (
int fan_in_idx = 0; fan_in_idx < node->fan_in_cnt; fan_in_idx++) {
256 activation += (node->inputs[fan_in_idx].input_weight *
257 node->inputs[fan_in_idx].input_node->out);
vector< Node > fast_nodes_
static float Sigmoid(float activation)
template<typename Type >
template bool tesseract::NeuralNet::FeedForward |
( |
const Type * |
inputs, |
|
|
Type * |
outputs |
|
) |
| |
Definition at line 79 of file neural_net.cpp.
89 for (
int in = 0; in <
in_cnt_; in++) {
94 for (
int in = 0; in <
in_cnt_; in++) {
vector< float > inputs_min_
void set_output(float out_val)
bool FastFeedForward(const Type *inputs, Type *outputs)
vector< float > inputs_mean_
vector< float > inputs_std_dev_
vector< float > inputs_max_
NeuralNet * tesseract::NeuralNet::FromFile |
( |
const string |
file_name | ) |
|
|
static |
Definition at line 204 of file neural_net.cpp.
206 InputFileBuffer input_buff(file_name);
static NeuralNet * FromInputBuffer(InputFileBuffer *ib)
Definition at line 213 of file neural_net.cpp.
216 if (net_obj ==
NULL) {
220 if (!net_obj->ReadBinary(ib)) {
template<typename Type >
template bool tesseract::NeuralNet::GetNetOutput |
( |
const Type * |
inputs, |
|
|
int |
output_id, |
|
|
Type * |
output |
|
) |
| |
Definition at line 265 of file neural_net.cpp.
269 if (output_id < 0 || output_id >=
out_cnt_) {
284 (*output) = outputs[output_id];
bool FastGetNetOutput(const Type *inputs, int output_id, Type *output)
bool FeedForward(const Type *inputs, Type *outputs)
int tesseract::NeuralNet::in_cnt |
( |
| ) |
const |
|
inline |
void tesseract::NeuralNet::Init |
( |
| ) |
|
|
protected |
Definition at line 34 of file neural_net.cpp.
vector< float > inputs_min_
vector< float > inputs_mean_
vector< float > inputs_std_dev_
vector< float > inputs_max_
vector< vector< float > * > wts_vec_
int tesseract::NeuralNet::out_cnt |
( |
| ) |
const |
|
inline |
template<class ReadBuffType >
template bool tesseract::NeuralNet::ReadBinary |
( |
ReadBuffType * |
input_buff | ) |
|
|
inlineprotected |
Definition at line 106 of file neural_net.h.
110 unsigned int read_val;
111 unsigned int auto_encode;
113 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
119 if (input_buff->Read(&auto_encode,
sizeof(auto_encode)) !=
120 sizeof(auto_encode)) {
125 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
138 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
146 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
159 }
else if (idx >= (neuron_cnt_ -
out_cnt_)) {
166 for (
int node_idx = 0; node_idx <
neuron_cnt_; node_idx++) {
168 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
172 int fan_out_cnt = read_val;
173 for (
int fan_out_idx = 0; fan_out_idx < fan_out_cnt; fan_out_idx++) {
175 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
185 for (
int node_idx = 0; node_idx <
neuron_cnt_; node_idx++) {
vector< float > inputs_min_
bool ReadBinary(ReadBuffType *input_buff)
vector< float > inputs_mean_
vector< float > inputs_std_dev_
static const unsigned int kNetSignature
vector< float > inputs_max_
void set_node_type(NeuronTypes type)
bool SetConnection(int from, int to)
bool tesseract::NeuralNet::SetConnection |
( |
int |
from, |
|
|
int |
to |
|
) |
| |
|
protected |
Definition at line 112 of file neural_net.cpp.
void AddFromConnection(Neuron *neuron_vec, float *wts_offset, int from_cnt)
float * AllocWgt(int wgt_cnt)
int tesseract::NeuralNet::alloc_wgt_cnt_ |
|
protected |
bool tesseract::NeuralNet::auto_encoder_ |
|
protected |
vector<Node> tesseract::NeuralNet::fast_nodes_ |
|
protected |
int tesseract::NeuralNet::in_cnt_ |
|
protected |
vector<float> tesseract::NeuralNet::inputs_max_ |
|
protected |
vector<float> tesseract::NeuralNet::inputs_mean_ |
|
protected |
vector<float> tesseract::NeuralNet::inputs_min_ |
|
protected |
vector<float> tesseract::NeuralNet::inputs_std_dev_ |
|
protected |
const unsigned int tesseract::NeuralNet::kNetSignature = 0xFEFEABD0 |
|
staticprotected |
const int tesseract::NeuralNet::kWgtChunkSize = 0x10000 |
|
staticprotected |
int tesseract::NeuralNet::neuron_cnt_ |
|
protected |
Neuron* tesseract::NeuralNet::neurons_ |
|
protected |
int tesseract::NeuralNet::out_cnt_ |
|
protected |
bool tesseract::NeuralNet::read_only_ |
|
protected |
int tesseract::NeuralNet::wts_cnt_ |
|
protected |
vector<vector<float> *> tesseract::NeuralNet::wts_vec_ |
|
protected |
The documentation for this class was generated from the following files: