tesseract
v5.3.3.20231005
generate_lut.py
Go to the documentation of this file.
1
#!/usr/bin/env python3
2
3
# Create C/C++ code for two lookup tables.
4
5
import
math
6
7
# kTableSize and kScaleFactor must match the values in functions.h.
8
9
# Size of static tables.
10
kTableSize = 4096
11
# Scale factor for float arg to int index.
12
kScaleFactor = 256.0
13
14
print(
"// Generated code with lookup tables (see generate_lut.py)"
)
15
print(
'#include "functions.h"'
)
16
print(
"namespace tesseract {"
)
17
18
print(
"const TFloat TanhTable[] = {"
)
19
for
i
in
range(kTableSize):
20
print(
" %a,"
% math.tanh(i / kScaleFactor))
21
print(
"};"
)
22
23
print(
"const TFloat LogisticTable[] = {"
)
24
for
i
in
range(kTableSize):
25
print(
" %a,"
% (1 / (1 + math.exp(-i / kScaleFactor))))
26
print(
"};"
)
27
print(
"} // namespace tesseract."
)
src
lstm
generate_lut.py
Generated on Thu Oct 5 2023 22:10:26 for tesseract by
1.9.4