@@ -83,20 +83,12 @@ class OcropyRecognize(Processor):
8383
8484    def  __init__ (self , * args , ** kwargs ):
8585        self .ocrd_tool  =  get_ocrd_tool ()
86+         self .pad  =  16  # ocropus-rpred default 
87+         self .network  =  None  # set in process 
8688        kwargs ['ocrd_tool' ] =  self .ocrd_tool ['tools' ][TOOL ]
8789        kwargs ['version' ] =  self .ocrd_tool ['version' ]
8890        super (OcropyRecognize , self ).__init__ (* args , ** kwargs )
8991
90-         # from ocropus-rpred: 
91-         self .network  =  load_object (self .get_model (), verbose = 1 )
92-         for  x  in  self .network .walk ():
93-             x .postLoad ()
94-         for  x  in  self .network .walk ():
95-             if  isinstance (x , lstm .LSTM ):
96-                 x .allocate (5000 )
97- 
98-         self .pad  =  16  # ocropus-rpred default 
99- 
10092    def  get_model (self ):
10193        """Search for the model file.  First checks if 
10294        parameter['model'] is a valid readeable file and returns it. 
@@ -138,6 +130,14 @@ def process(self):
138130
139131        Produce a new output file by serialising the resulting hierarchy. 
140132        """ 
133+         # from ocropus-rpred: 
134+         self .network  =  load_object (self .get_model (), verbose = 1 )
135+         for  x  in  self .network .walk ():
136+             x .postLoad ()
137+         for  x  in  self .network .walk ():
138+             if  isinstance (x , lstm .LSTM ):
139+                 x .allocate (5000 )
140+ 
141141        maxlevel  =  self .parameter ['textequiv_level' ]
142142
143143        # LOG.info("Using model %s in %s for recognition", model) 
@@ -236,7 +236,7 @@ def process_lines(self, textlines, maxlevel, region_image, region_coords):
236236            # process ocropy: 
237237            try :
238238                linepred , clist , rlist , confidlist  =  recognize (
239-                     final_img , self . pad , self .network , check = True )
239+                     final_img , pad , self .network , check = True )
240240            except  Exception  as  err :
241241                LOG .debug ('ERROR: error processing line "%s": %s' , line .id , err )
242242                continue 
0 commit comments