Skip to content
Snippets Groups Projects
Commit 50a4c6e7 authored by Harald Scheidl's avatar Harald Scheidl
Browse files

py2 compatibility (print, div) via __future__

parent a5336fea
No related branches found
No related tags found
No related merge requests found
...@@ -4,3 +4,4 @@ src/__pycache__/ ...@@ -4,3 +4,4 @@ src/__pycache__/
model/checkpoint model/checkpoint
model/snapshot-* model/snapshot-*
*.so *.so
*.pyc
from __future__ import division
from __future__ import print_function
import os import os
import random import random
import numpy as np import numpy as np
...@@ -57,8 +60,11 @@ class DataLoader: ...@@ -57,8 +60,11 @@ class DataLoader:
if not os.path.getsize(fileName): if not os.path.getsize(fileName):
bad_samples.append(lineSplit[0] + '.png') bad_samples.append(lineSplit[0] + '.png')
continue continue
# put sample into list # put sample into list
self.samples.append(Sample(gtText, fileName)) self.samples.append(Sample(gtText, fileName))
# some images in the IAM dataset are known to be damaged, don't show warning for them
if set(bad_samples) != set(bad_samples_reference): if set(bad_samples) != set(bad_samples_reference):
print("Warning, damaged images found:", bad_samples) print("Warning, damaged images found:", bad_samples)
print("Damaged images expected:", bad_samples_reference) print("Damaged images expected:", bad_samples_reference)
......
from __future__ import division
from __future__ import print_function
import sys import sys
import tensorflow as tf import tensorflow as tf
......
from __future__ import division
from __future__ import print_function
import random import random
import numpy as np import numpy as np
import cv2 import cv2
...@@ -19,8 +22,8 @@ def preprocess(img, imgSize, dataAugmentation=False): ...@@ -19,8 +22,8 @@ def preprocess(img, imgSize, dataAugmentation=False):
# create target image and copy sample image into it # create target image and copy sample image into it
(wt, ht) = imgSize (wt, ht) = imgSize
(h, w) = img.shape (h, w) = img.shape
fx = float(w) / wt fx = w / wt
fy = float(h) / ht fy = h / ht
f = max(fx, fy) f = max(fx, fy)
newSize = (max(min(wt, int(w / f)), 1), max(min(ht, int(h / f)), 1)) # scale according to f (result at least 1 and at most wt or ht) newSize = (max(min(wt, int(w / f)), 1), max(min(ht, int(h / f)), 1)) # scale according to f (result at least 1 and at most wt or ht)
img = cv2.resize(img, newSize) img = cv2.resize(img, newSize)
......
from __future__ import division
from __future__ import print_function
import sys import sys
import argparse import argparse
import cv2 import cv2
...@@ -79,8 +82,8 @@ def validate(model, loader): ...@@ -79,8 +82,8 @@ def validate(model, loader):
print('[OK]' if dist==0 else '[ERR:%d]' % dist,'"' + batch.gtTexts[i] + '"', '->', '"' + recognized[i] + '"') print('[OK]' if dist==0 else '[ERR:%d]' % dist,'"' + batch.gtTexts[i] + '"', '->', '"' + recognized[i] + '"')
# print validation result # print validation result
charErrorRate = float(numCharErr) / numCharTotal charErrorRate = numCharErr / numCharTotal
wordAccuracy = float(numWordOK) / numWordTotal wordAccuracy = numWordOK / numWordTotal
print('Character error rate: %f%%. Word accuracy: %f%%.' % (charErrorRate*100.0, wordAccuracy*100.0)) print('Character error rate: %f%%. Word accuracy: %f%%.' % (charErrorRate*100.0, wordAccuracy*100.0))
return charErrorRate return charErrorRate
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment