mirror of
				https://github.com/qurator-spk/eynollah.git
				synced 2025-10-31 01:34:17 +01:00 
			
		
		
		
	minor fixes to avoid frequent warnings
This commit is contained in:
		
							parent
							
								
									903c87aca0
								
							
						
					
					
						commit
						2919538382
					
				
					 5 changed files with 17 additions and 24 deletions
				
			
		|  | @ -32,7 +32,7 @@ from scipy.ndimage import gaussian_filter1d | |||
| from numba import cuda | ||||
| 
 | ||||
| from ocrd import OcrdPage | ||||
| from ocrd_utils import getLogger | ||||
| from ocrd_utils import getLogger, tf_disable_interactive_logs | ||||
| 
 | ||||
| try: | ||||
|     import torch | ||||
|  | @ -47,14 +47,11 @@ try: | |||
| except ImportError: | ||||
|     TrOCRProcessor = VisionEncoderDecoderModel = None | ||||
| 
 | ||||
| os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" | ||||
| #os.environ['CUDA_VISIBLE_DEVICES'] = '-1' | ||||
| stderr = sys.stderr | ||||
| sys.stderr = open(os.devnull, "w") | ||||
| tf_disable_interactive_logs() | ||||
| import tensorflow as tf | ||||
| from tensorflow.python.keras import backend as K | ||||
| from tensorflow.keras.models import load_model | ||||
| sys.stderr = stderr | ||||
| tf.get_logger().setLevel("ERROR") | ||||
| warnings.filterwarnings("ignore") | ||||
| # use tf1 compatibility for keras backend | ||||
|  | @ -3614,7 +3611,7 @@ class Eynollah: | |||
|             for ij in range(len(all_found_textline_polygons[j])): | ||||
|                 con_ind = all_found_textline_polygons[j][ij] | ||||
|                 area = cv2.contourArea(con_ind) | ||||
|                 con_ind = con_ind.astype(np.float) | ||||
|                 con_ind = con_ind.astype(float) | ||||
|                  | ||||
|                 x_differential = np.diff( con_ind[:,0,0]) | ||||
|                 y_differential = np.diff( con_ind[:,0,1]) | ||||
|  | @ -3718,7 +3715,7 @@ class Eynollah: | |||
|             con_ind = all_found_textline_polygons[j] | ||||
|             #print(len(con_ind[:,0,0]),'con_ind[:,0,0]') | ||||
|             area = cv2.contourArea(con_ind) | ||||
|             con_ind = con_ind.astype(np.float) | ||||
|             con_ind = con_ind.astype(float) | ||||
|              | ||||
|             x_differential = np.diff( con_ind[:,0,0]) | ||||
|             y_differential = np.diff( con_ind[:,0,1]) | ||||
|  | @ -3821,7 +3818,7 @@ class Eynollah: | |||
|                 con_ind = all_found_textline_polygons[j][ij] | ||||
|                 area = cv2.contourArea(con_ind) | ||||
|                  | ||||
|                 con_ind = con_ind.astype(np.float) | ||||
|                 con_ind = con_ind.astype(float) | ||||
|                  | ||||
|                 x_differential = np.diff( con_ind[:,0,0]) | ||||
|                 y_differential = np.diff( con_ind[:,0,1]) | ||||
|  | @ -4053,7 +4050,7 @@ class Eynollah: | |||
|         for j in range(len(all_found_textline_polygons)): | ||||
|             for i in range(len(all_found_textline_polygons[j])): | ||||
|                 con_ind = all_found_textline_polygons[j][i] | ||||
|                 con_ind = con_ind.astype(np.float) | ||||
|                 con_ind = con_ind.astype(float) | ||||
|                  | ||||
|                 x_differential = np.diff( con_ind[:,0,0]) | ||||
|                 y_differential = np.diff( con_ind[:,0,1]) | ||||
|  |  | |||
|  | @ -4,25 +4,19 @@ Tool to load model and binarize a given image. | |||
| 
 | ||||
| import sys | ||||
| from glob import glob | ||||
| from os import environ, devnull | ||||
| from os.path import join | ||||
| from warnings import catch_warnings, simplefilter | ||||
| import os | ||||
| import logging | ||||
| 
 | ||||
| import numpy as np | ||||
| from PIL import Image | ||||
| import cv2 | ||||
| environ['TF_CPP_MIN_LOG_LEVEL'] = '3' | ||||
| stderr = sys.stderr | ||||
| sys.stderr = open(devnull, 'w') | ||||
| from ocrd_utils import tf_disable_interactive_logs | ||||
| tf_disable_interactive_logs() | ||||
| import tensorflow as tf | ||||
| from tensorflow.keras.models import load_model | ||||
| from tensorflow.python.keras import backend as tensorflow_backend | ||||
| sys.stderr = stderr | ||||
| 
 | ||||
| 
 | ||||
| import logging | ||||
| 
 | ||||
| def resize_image(img_in, input_height, input_width): | ||||
|     return cv2.resize(img_in, (input_width, input_height), interpolation=cv2.INTER_NEAREST) | ||||
| 
 | ||||
|  | @ -53,7 +47,7 @@ class SbbBinarizer: | |||
|         del self.session | ||||
| 
 | ||||
|     def load_model(self, model_name): | ||||
|         model = load_model(join(self.model_dir, model_name), compile=False) | ||||
|         model = load_model(os.path.join(self.model_dir, model_name), compile=False) | ||||
|         model_height = model.layers[len(model.layers)-1].output_shape[1] | ||||
|         model_width = model.layers[len(model.layers)-1].output_shape[2] | ||||
|         n_classes = model.layers[len(model.layers)-1].output_shape[3] | ||||
|  |  | |||
|  | @ -247,7 +247,7 @@ def get_textregion_contours_in_org_image_light(cnts, img, slope_first, map=map): | |||
|     img = cv2.resize(img, (int(img.shape[1]/6), int(img.shape[0]/6)), interpolation=cv2.INTER_NEAREST) | ||||
|     ##cnts = list( (np.array(cnts)/2).astype(np.int16) ) | ||||
|     #cnts = cnts/2 | ||||
|     cnts = [(i/6).astype(np.int) for i in cnts] | ||||
|     cnts = [(i/6).astype(int) for i in cnts] | ||||
|     results = map(partial(do_back_rotation_and_get_cnt_back, | ||||
|                           img=img, | ||||
|                           slope_first=slope_first, | ||||
|  |  | |||
|  | @ -1,3 +1,4 @@ | |||
| from contextlib import nullcontext | ||||
| from PIL import Image | ||||
| import numpy as np | ||||
| from ocrd_models import OcrdExif | ||||
|  | @ -17,12 +18,13 @@ def pil2cv(img): | |||
| def check_dpi(img): | ||||
|     try: | ||||
|         if isinstance(img, Image.Image): | ||||
|             pil_image = img | ||||
|             pil_image = nullcontext(img) | ||||
|         elif isinstance(img, str): | ||||
|             pil_image = Image.open(img) | ||||
|         else: | ||||
|             pil_image = cv2pil(img) | ||||
|         exif = OcrdExif(pil_image) | ||||
|             pil_image = nullcontext(cv2pil(img)) | ||||
|         with pil_image: | ||||
|             exif = OcrdExif(pil_image) | ||||
|         resolution = exif.resolution | ||||
|         if resolution == 1: | ||||
|             raise Exception() | ||||
|  |  | |||
|  | @ -1616,7 +1616,7 @@ def do_work_of_slopes_new( | |||
|             textline_con_fil = filter_contours_area_of_image(img_int_p, textline_con, | ||||
|                                                              hierarchy, | ||||
|                                                              max_area=1, min_area=0.00008) | ||||
|             y_diff_mean = find_contours_mean_y_diff(textline_con_fil) | ||||
|             y_diff_mean = find_contours_mean_y_diff(textline_con_fil) if len(textline_con_fil) > 1 else np.NaN | ||||
|             if np.isnan(y_diff_mean): | ||||
|                 slope_for_all = MAX_SLOPE | ||||
|             else: | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue