Skip to content

Commit

Permalink
make old-style classes inherit from object
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Jan 14, 2019
1 parent ac5f5f7 commit 21b1aa8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions ocrolib/common.py
Expand Up @@ -313,7 +313,7 @@ def pad_by(image,r,dtype=None):
result = zeros((w+2*r,h+2*r))
result[r:(w+r),r:(h+r)] = image
return result
class RegionExtractor:
class RegionExtractor(object):
"""A class facilitating iterating over the parts of a segmentation."""
def __init__(self):
self.cache = {}
Expand Down Expand Up @@ -454,7 +454,7 @@ def unpickle_stream(stream):
### Simple record object.
################################################################

class Record:
class Record(object):
"""A simple record datatype that allows initialization with
keyword arguments, as in Record(x=3,y=9)"""
def __init__(self,**kw):
Expand Down Expand Up @@ -867,7 +867,7 @@ def remove_noise(line,minsize=8):
good = minimum(bin,1-(sums>0)*(sums<minsize))
return good

class MovingStats:
class MovingStats(object):
def __init__(self,n=100):
self.data = []
self.n = n
Expand Down
2 changes: 1 addition & 1 deletion ocrolib/ligatures.py
Expand Up @@ -40,7 +40,7 @@ def common_ligatures(s):
if len(s)>=3 and s[:3] in common_ligature_table:
yield s[:3]

class LigatureTable:
class LigatureTable(object):
def __init__(self):
self.lig2code = {}
self.code2lig = {}
Expand Down
2 changes: 1 addition & 1 deletion ocrolib/lineest.py
Expand Up @@ -16,7 +16,7 @@ def scale_to_h(img,target_height,order=1,dtype=np.dtype('f'),cval=0):
output = np.array(output,dtype=dtype)
return output

class CenterNormalizer:
class CenterNormalizer(object):
def __init__(self,target_height=48,params=(4,1.0,0.3)):
self.debug = int(os.getenv("debug_center") or "0")
self.target_height = target_height
Expand Down
8 changes: 4 additions & 4 deletions ocrolib/lstm.py
Expand Up @@ -94,7 +94,7 @@ def sumouter(us,vs,lo=-1.0,hi=1.0,out=None):
result += np.outer(np.clip(u,lo,hi),v)
return result

class Network:
class Network():
"""General interface for networks. This mainly adds convenience
functions for `predict` and `train`.
Expand Down Expand Up @@ -847,9 +847,9 @@ def normalize_nfkc(s):
def add_training_info(network):
return network

class SeqRecognizer:
class SeqRecognizer():
"""Perform sequence recognition using BIDILSTM and alignment."""
def __init__(self,ninput,nstates,noutput=-1,codec=None,normalize=normalize_nfkc):
def __init__(self, ninput=None, nstates=None, noutput=-1, codec=None, normalize=normalize_nfkc):
self.Ni = ninput
if codec: noutput = codec.size()
assert noutput>0
Expand Down Expand Up @@ -937,7 +937,7 @@ def predictString(self,xs):
cs = self.predictSequence(xs)
return self.l2s(cs)

class Codec:
class Codec(object):
"""Translate between integer codes and characters."""
def init(self,charset):
charset = sorted(list(set(charset)))
Expand Down
5 changes: 3 additions & 2 deletions ocrolib/psegutils.py
Expand Up @@ -19,8 +19,9 @@ def B(a):
if a.dtype==np.dtype('B'): return a
return np.array(a,'B')

class record:
def __init__(self,**kw): self.__dict__.update(kw)
class record(object):
def __init__(self,**kw):
self.__dict__.update(kw)

@obsolete
def blackout_images(image,ticlass):
Expand Down
2 changes: 1 addition & 1 deletion run-test-ci
Expand Up @@ -76,7 +76,7 @@ test_rtrain_files() {
tar -zxf $BASE/tests/uw3-500.tgz
find 'book' -name '*.bin.png' > INPUT_FILES
$RUNNER $BASE/ocropus-rtrain -f INPUT_FILES -F $TRAIN_ITERATIONS -N $TRAIN_ITERATIONS -o ci-test-model
rm INPUT_FILES
rm INPUT_FILES ci-test-model-00000005.pyrnn.gz
}

test_nlbin() {
Expand Down

0 comments on commit 21b1aa8

Please sign in to comment.