tesseract v5.3.3.20231005
tesseract::NetworkBuilder Class Reference

#include <networkbuilder.h>

Public Member Functions

 NetworkBuilder (int num_softmax_outputs)
 
NetworkBuildFromString (const StaticShape &input_shape, const char **str)
 

Static Public Member Functions

static bool InitNetwork (int num_outputs, const char *network_spec, int append_index, int net_flags, float weight_range, TRand *randomizer, Network **network)
 

Detailed Description

Definition at line 35 of file networkbuilder.h.

Constructor & Destructor Documentation

◆ NetworkBuilder()

tesseract::NetworkBuilder::NetworkBuilder ( int  num_softmax_outputs)
inlineexplicit

Definition at line 37 of file networkbuilder.h.

37: num_softmax_outputs_(num_softmax_outputs) {}

Member Function Documentation

◆ BuildFromString()

Network * tesseract::NetworkBuilder::BuildFromString ( const StaticShape input_shape,
const char **  str 
)

Definition at line 88 of file networkbuilder.cpp.

88 {
89 SkipWhitespace(str);
90 char code_ch = **str;
91 if (code_ch == '[') {
92 return ParseSeries(input_shape, nullptr, str);
93 }
94 if (input_shape.depth() == 0) {
95 // There must be an input at this point.
96 return ParseInput(str);
97 }
98 switch (code_ch) {
99 case '(':
100 return ParseParallel(input_shape, str);
101 case 'R':
102 return ParseR(input_shape, str);
103 case 'S':
104 return ParseS(input_shape, str);
105 case 'C':
106 return ParseC(input_shape, str);
107 case 'M':
108 return ParseM(input_shape, str);
109 case 'L':
110 return ParseLSTM(input_shape, str);
111 case 'F':
112 return ParseFullyConnected(input_shape, str);
113 case 'O':
114 return ParseOutput(input_shape, str);
115 default:
116 tprintf("Invalid network spec:%s\n", *str);
117 return nullptr;
118 }
119 return nullptr;
120}
void tprintf(const char *format,...)
Definition: tprintf.cpp:41

◆ InitNetwork()

bool tesseract::NetworkBuilder::InitNetwork ( int  num_outputs,
const char *  network_spec,
int  append_index,
int  net_flags,
float  weight_range,
TRand randomizer,
Network **  network 
)
static

Definition at line 45 of file networkbuilder.cpp.

47 {
48 NetworkBuilder builder(num_outputs);
49 Series *bottom_series = nullptr;
50 StaticShape input_shape;
51 if (append_index >= 0) {
52 // Split the current network after the given append_index.
53 ASSERT_HOST(*network != nullptr && (*network)->type() == NT_SERIES);
54 auto *series = static_cast<Series *>(*network);
55 Series *top_series = nullptr;
56 series->SplitAt(append_index, &bottom_series, &top_series);
57 if (bottom_series == nullptr || top_series == nullptr) {
58 tprintf("Yikes! Splitting current network failed!!\n");
59 return false;
60 }
61 input_shape = bottom_series->OutputShape(input_shape);
62 delete top_series;
63 }
64 *network = builder.BuildFromString(input_shape, &network_spec);
65 if (*network == nullptr) {
66 return false;
67 }
68 (*network)->SetNetworkFlags(net_flags);
69 (*network)->InitWeights(weight_range, randomizer);
70 (*network)->SetupNeedsBackprop(false);
71 if (bottom_series != nullptr) {
72 bottom_series->AppendSeries(*network);
73 *network = bottom_series;
74 }
75 (*network)->CacheXScaleFactor((*network)->XScaleFactor());
76 return true;
77}
#define ASSERT_HOST(x)
Definition: errcode.h:54
@ NT_SERIES
Definition: network.h:52
NetworkBuilder(int num_softmax_outputs)

The documentation for this class was generated from the following files: