Skip to content

Commit f39cbf2

Browse files
committed
Being nice to the linter
1 parent a79fe10 commit f39cbf2

File tree

11 files changed

+16
-31
lines changed

11 files changed

+16
-31
lines changed

calamari_ocr/ocr/dataset/datareader/abbyy/xml/data.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
class Rect:
2-
32
"""
43
Class defines the rectangle of an element in the Abbyy document
54
"""
65

76
def __init__(self, l: int, t: int, r: int, b: int):
8-
97
"""
108
Constructs a Rect class
119
:param l: length
@@ -36,7 +34,6 @@ def __str__(self):
3634

3735

3836
class Book:
39-
4037
"""
4138
Main class; contains all subelements: book -> page -> block -> par -> line -> format
4239
"""
@@ -64,7 +61,6 @@ def __str__(self):
6461
s += " " + format.__str__()
6562

6663
def getBlocks(self) -> []:
67-
6864
"""
6965
:return: All the blocks of this book
7066
"""
@@ -78,7 +74,6 @@ def getBlocks(self) -> []:
7874
return blocks
7975

8076
def getPars(self) -> []:
81-
8277
"""
8378
:return: All the paragraphs of this book
8479
"""
@@ -93,7 +88,6 @@ def getPars(self) -> []:
9388
return pars
9489

9590
def getLines(self) -> []:
96-
9791
"""
9892
:return: All the lines of this book
9993
"""
@@ -109,7 +103,6 @@ def getLines(self) -> []:
109103
return lines
110104

111105
def getFormats(self) -> []:
112-
113106
"""
114107
:return: All the chars of this book
115108
"""
@@ -127,7 +120,6 @@ def getFormats(self) -> []:
127120

128121

129122
class Page:
130-
131123
"""
132124
Subelement of the book class; contains a list with the subelement block
133125
"""
@@ -141,7 +133,6 @@ def __init__(
141133
imgFile: str,
142134
xmlFile: str,
143135
):
144-
145136
"""
146137
Construct a page class with an empty block list
147138
:param width: The width of the page (in pixel)
@@ -178,7 +169,6 @@ def __str__(self):
178169
)
179170

180171
def getPars(self) -> []:
181-
182172
"""
183173
:return: All the pars of this page
184174
"""
@@ -192,7 +182,6 @@ def getPars(self) -> []:
192182
return pars
193183

194184
def getLines(self) -> []:
195-
196185
"""
197186
:return: All the lines of this page
198187
"""
@@ -207,7 +196,6 @@ def getLines(self) -> []:
207196
return lines
208197

209198
def getFormats(self) -> []:
210-
211199
"""
212200
:return: All the Format Tags of this page
213201
"""
@@ -224,13 +212,11 @@ def getFormats(self) -> []:
224212

225213

226214
class Block:
227-
228215
"""
229216
Subelement of the page class; contains a list with the subelement par
230217
"""
231218

232219
def __init__(self, blockType: str, blockName: str, rect: Rect):
233-
234220
"""
235221
Construct a block class with an empty line list
236222
:param blockType: The type of a block (further information in the abbyy doc)
@@ -246,7 +232,6 @@ def __str__(self):
246232
return "Block:[BlockType={}, rect={}]".format(self.blockType, self.rect)
247233

248234
def getLines(self) -> []:
249-
250235
"""
251236
:return: All the lines of this block
252237
"""
@@ -260,7 +245,6 @@ def getLines(self) -> []:
260245
return lines
261246

262247
def getFormats(self) -> []:
263-
264248
"""
265249
:return: All the Format Tags of this block
266250
"""
@@ -281,7 +265,6 @@ class Par:
281265
"""
282266

283267
def __init__(self, align: str, startIndent: int, lineSpacing: int):
284-
285268
"""
286269
Construct a Paragraph Class with an empty line list
287270
:param align:
@@ -306,7 +289,6 @@ def __str__(self):
306289
)
307290

308291
def getFormats(self) -> []:
309-
310292
"""
311293
:return: All the Format Tags of the Paragraph
312294
"""
@@ -321,13 +303,11 @@ def getFormats(self) -> []:
321303

322304

323305
class Line:
324-
325306
""" "
326307
Subelement of the par class; contains a list with the subelement format
327308
"""
328309

329310
def __init__(self, baseline: int, rect: Rect):
330-
331311
"""
332312
Construct a line class with an empty char list
333313
:param baseline: ???

calamari_ocr/ocr/dataset/datareader/abbyy/xml/reader.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class XMLReader:
1515
"""
1616

1717
def __init__(self, imgfiles: [], abbyfiles: [], skip_invalid: bool):
18-
1918
"""
2019
Constructs an XMLReader class with the :param directory
2120
@@ -27,7 +26,6 @@ def __init__(self, imgfiles: [], abbyfiles: [], skip_invalid: bool):
2726
self.skip_invalid = skip_invalid
2827

2928
def read(self) -> Book:
30-
3129
"""
3230
Start trying to read the data from the directory :var self.directory
3331

calamari_ocr/ocr/dataset/datareader/abbyy/xml/writer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def write(page: Page, filename: str):
7474

7575
@staticmethod
7676
def _addElement(element, key, value):
77-
7877
"""
7978
Only add attributes to an tag if the key is not None
8079

calamari_ocr/ocr/model/ctcdecoder/token_passing_ctc_decoder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ def get(self, w, s, t):
6767
return self.tokens[(w, s, t)]
6868

6969
def dump(self, s, t):
70-
for (k, v) in self.tokens.items():
70+
for k, v in self.tokens.items():
7171
if k[1] == s and k[2] == t:
7272
print(k, v)
7373

7474

7575
def outputIndices(toks, words, s, t):
7676
"""argmax_w tok(w,s,t)"""
7777
res = []
78-
for (wIdx, _) in enumerate(words):
78+
for wIdx, _ in enumerate(words):
7979
res.append(toks.get(wIdx, s, t))
8080

8181
idx = [i[0] for i in sorted(enumerate(res), key=lambda x: x[1].score)]
@@ -109,7 +109,7 @@ def ctcTokenPassing(mat, classes, charWords, blankIdx=-1, word_separator=" "):
109109
toks = TokenList()
110110

111111
# Initialisation: 1-9
112-
for (wIdx, w) in enumerate(words):
112+
for wIdx, w in enumerate(words):
113113
w = words[wIdx]
114114
wPrime = primeWords[wIdx]
115115

calamari_ocr/ocr/model/ensemblegraph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def gen_empty_output(bs):
112112
}
113113

114114
empty_output = gen_empty_output(1)
115+
115116
# Validation: Compute output for each graph but only for its own partition
116117
# Per sample this is one CER which is then used e. g. for early stopping
117118
def apply_single_model(batch):

calamari_ocr/ocr/model/ensemblemodel.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ def cer(decoded, targets, targets_length):
7878
# using the true codec size (the W/B-Matrix may change its shape however during loading/codec change
7979
# to match the true codec size
8080
sw = K.flatten(targets["gt_len"])
81-
return [self.cer_total(cer(outputs["decoded"], targets["gt"], targets["gt_len"]), sample_weight=sw,)] + [
81+
return [
82+
self.cer_total(
83+
cer(outputs["decoded"], targets["gt"], targets["gt_len"]),
84+
sample_weight=sw,
85+
)
86+
] + [
8287
self.sub_cer[i](
8388
cer(outputs[f"decoded_{i}"], targets["gt"], targets["gt_len"]),
8489
sample_weight=sw * tf.cast(tf.equal(K.flatten(targets["fold_id"]), i), tf.int32),

calamari_ocr/scripts/experiment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# path to the dir of this script to automatically detect the training script
1818
this_absdir = os.path.dirname(os.path.abspath(inspect.stack()[0][1]))
1919

20+
2021
# create necessary directories
2122
def run_for_single_line(args):
2223
# lines/network/pretraining as base dir

calamari_ocr/scripts/experiment_cross_fold.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# path to the dir of this script to automatically detect the training script
1616
this_absdir = os.path.dirname(os.path.abspath(inspect.stack()[0][1]))
1717

18+
1819
# create necessary directories
1920
def run_for_single_line(args):
2021
# lines/network/pretraining as base dir

calamari_ocr/thirdparty/ctcwordbeamsearch/Beam.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ def getBestBeams(self, num):
163163

164164
def deletePartialBeams(self, lm):
165165
"delete beams for which last word is not finished"
166-
for (k, v) in self.beams.items():
166+
for k, v in self.beams.items():
167167
lastWord = v.textual.wordDev
168168
if (lastWord != "") and (not lm.isWord(lastWord)):
169169
del self.beams[k]
170170

171171
def completeBeams(self, lm):
172172
"complete beams such that last word is complete word"
173-
for (_, v) in self.beams.items():
173+
for _, v in self.beams.items():
174174
lastPrefix = v.textual.wordDev
175175
if lastPrefix == "" or lm.isWord(lastPrefix):
176176
continue

calamari_ocr/thirdparty/ctcwordbeamsearch/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
csv = Utils.CSVWriter()
2929

3030
# decode each sample from dataset
31-
for (idx, data) in enumerate(loader):
31+
for idx, data in enumerate(loader):
3232
# decode matrix
3333
res = wordBeamSearch(data.mat, 10, loader.lm, useNGrams)
3434
print("Sample: " + str(idx + 1))

0 commit comments

Comments
 (0)