mirror of
https://github.com/qurator-spk/eynollah.git
synced 2025-10-06 14:39:55 +02:00
remove redundant parentheses
This commit is contained in:
parent
f2f93e0251
commit
91d2a74ac9
10 changed files with 29 additions and 29 deletions
|
@ -4886,9 +4886,9 @@ class Eynollah:
|
|||
textline_mask_tot_ea_org[img_revised_tab==drop_label_in_full_layout] = 0
|
||||
|
||||
|
||||
text_only = ((img_revised_tab[:, :] == 1)) * 1
|
||||
text_only = (img_revised_tab[:, :] == 1) * 1
|
||||
if np.abs(slope_deskew) >= SLOPE_THRESHOLD:
|
||||
text_only_d = ((text_regions_p_1_n[:, :] == 1)) * 1
|
||||
text_only_d = (text_regions_p_1_n[:, :] == 1) * 1
|
||||
|
||||
#print("text region early 2 in %.1fs", time.time() - t0)
|
||||
###min_con_area = 0.000005
|
||||
|
|
|
@ -12,7 +12,7 @@ from .utils import crop_image_inside_box
|
|||
from .utils.rotate import rotate_image_different
|
||||
from .utils.resize import resize_image
|
||||
|
||||
class EynollahPlotter():
|
||||
class EynollahPlotter:
|
||||
"""
|
||||
Class collecting all the plotting and image writing methods
|
||||
"""
|
||||
|
|
|
@ -1267,11 +1267,11 @@ def order_of_regions(textline_mask, contours_main, contours_header, y_ref):
|
|||
top = peaks_neg_new[i]
|
||||
down = peaks_neg_new[i + 1]
|
||||
indexes_in = matrix_of_orders[:, 0][(matrix_of_orders[:, 3] >= top) &
|
||||
((matrix_of_orders[:, 3] < down))]
|
||||
(matrix_of_orders[:, 3] < down)]
|
||||
cxs_in = matrix_of_orders[:, 2][(matrix_of_orders[:, 3] >= top) &
|
||||
((matrix_of_orders[:, 3] < down))]
|
||||
(matrix_of_orders[:, 3] < down)]
|
||||
cys_in = matrix_of_orders[:, 3][(matrix_of_orders[:, 3] >= top) &
|
||||
((matrix_of_orders[:, 3] < down))]
|
||||
(matrix_of_orders[:, 3] < down)]
|
||||
types_of_text = matrix_of_orders[:, 1][(matrix_of_orders[:, 3] >= top) &
|
||||
(matrix_of_orders[:, 3] < down)]
|
||||
index_types_of_text = matrix_of_orders[:, 4][(matrix_of_orders[:, 3] >= top) &
|
||||
|
@ -1408,7 +1408,7 @@ def return_points_with_boundies(peaks_neg_fin, first_point, last_point):
|
|||
|
||||
def find_number_of_columns_in_document(region_pre_p, num_col_classifier, tables, pixel_lines, contours_h=None):
|
||||
t_ins_c0 = time.time()
|
||||
separators_closeup=( (region_pre_p[:,:,:]==pixel_lines))*1
|
||||
separators_closeup= (region_pre_p[:, :, :] == pixel_lines) * 1
|
||||
separators_closeup[0:110,:,:]=0
|
||||
separators_closeup[separators_closeup.shape[0]-150:,:,:]=0
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from collections import Counter
|
|||
REGION_ID_TEMPLATE = 'region_%04d'
|
||||
LINE_ID_TEMPLATE = 'region_%04d_line_%04d'
|
||||
|
||||
class EynollahIdCounter():
|
||||
class EynollahIdCounter:
|
||||
|
||||
def __init__(self, region_idx=0, line_idx=0):
|
||||
self._counter = Counter()
|
||||
|
|
|
@ -76,7 +76,7 @@ def get_marginals(text_with_lines, text_regions, num_col, slope_deskew, light_ve
|
|||
|
||||
peaks, _ = find_peaks(text_with_lines_y_rev, height=0)
|
||||
peaks=np.array(peaks)
|
||||
peaks=peaks[(peaks>first_nonzero) & ((peaks<last_nonzero))]
|
||||
peaks=peaks[(peaks>first_nonzero) & (peaks < last_nonzero)]
|
||||
peaks=peaks[region_sum_0[peaks]<min_textline_thickness ]
|
||||
|
||||
|
||||
|
|
|
@ -1428,9 +1428,9 @@ def separate_lines_new2(img_path, thetha, num_col, slope_region, logger=None, pl
|
|||
img_int = np.zeros((img_xline.shape[0], img_xline.shape[1]))
|
||||
img_int[:, :] = img_xline[:, :] # img_patch_org[:,:,0]
|
||||
|
||||
img_resized = np.zeros((int(img_int.shape[0] * (1.2)), int(img_int.shape[1] * (3))))
|
||||
img_resized[int(img_int.shape[0] * (0.1)) : int(img_int.shape[0] * (0.1)) + img_int.shape[0],
|
||||
int(img_int.shape[1] * (1.0)) : int(img_int.shape[1] * (1.0)) + img_int.shape[1]] = img_int[:, :]
|
||||
img_resized = np.zeros((int(img_int.shape[0] * 1.2), int(img_int.shape[1] * 3)))
|
||||
img_resized[int(img_int.shape[0] * 0.1): int(img_int.shape[0] * 0.1) + img_int.shape[0],
|
||||
int(img_int.shape[1] * 1.0): int(img_int.shape[1] * 1.0) + img_int.shape[1]] = img_int[:, :]
|
||||
# plt.imshow(img_xline)
|
||||
# plt.show()
|
||||
img_line_rotated = rotate_image(img_resized, slopes_tile_wise[i])
|
||||
|
@ -1442,8 +1442,8 @@ def separate_lines_new2(img_path, thetha, num_col, slope_region, logger=None, pl
|
|||
img_patch_separated_returned[:, :][img_patch_separated_returned[:, :] != 0] = 1
|
||||
|
||||
img_patch_separated_returned_true_size = img_patch_separated_returned[
|
||||
int(img_int.shape[0] * (0.1)) : int(img_int.shape[0] * (0.1)) + img_int.shape[0],
|
||||
int(img_int.shape[1] * (1.0)) : int(img_int.shape[1] * (1.0)) + img_int.shape[1]]
|
||||
int(img_int.shape[0] * 0.1): int(img_int.shape[0] * 0.1) + img_int.shape[0],
|
||||
int(img_int.shape[1] * 1.0): int(img_int.shape[1] * 1.0) + img_int.shape[1]]
|
||||
|
||||
img_patch_separated_returned_true_size = img_patch_separated_returned_true_size[:, margin : length_x - margin]
|
||||
img_patch_ineterst_revised[:, index_x_d + margin : index_x_u - margin] = img_patch_separated_returned_true_size
|
||||
|
@ -1471,7 +1471,7 @@ def return_deskew_slop(img_patch_org, sigma_des,n_tot_angles=100,
|
|||
img_int[:,:]=img_patch_org[:,:]#img_patch_org[:,:,0]
|
||||
|
||||
max_shape=np.max(img_int.shape)
|
||||
img_resized=np.zeros((int( max_shape*(1.1) ) , int( max_shape*(1.1) ) ))
|
||||
img_resized=np.zeros((int(max_shape * 1.1) , int(max_shape * 1.1)))
|
||||
|
||||
onset_x=int((img_resized.shape[1]-img_int.shape[1])/2.)
|
||||
onset_y=int((img_resized.shape[0]-img_int.shape[0])/2.)
|
||||
|
@ -1536,7 +1536,7 @@ def return_deskew_slop_old_mp(img_patch_org, sigma_des,n_tot_angles=100,
|
|||
img_int[:,:]=img_patch_org[:,:]#img_patch_org[:,:,0]
|
||||
|
||||
max_shape=np.max(img_int.shape)
|
||||
img_resized=np.zeros((int( max_shape*(1.1) ) , int( max_shape*(1.1) ) ))
|
||||
img_resized=np.zeros((int(max_shape * 1.1) , int(max_shape * 1.1)))
|
||||
|
||||
onset_x=int((img_resized.shape[1]-img_int.shape[1])/2.)
|
||||
onset_y=int((img_resized.shape[0]-img_int.shape[0])/2.)
|
||||
|
|
|
@ -21,7 +21,7 @@ from ocrd_models.ocrd_page import (
|
|||
)
|
||||
import numpy as np
|
||||
|
||||
class EynollahXmlWriter():
|
||||
class EynollahXmlWriter:
|
||||
|
||||
def __init__(self, *, dir_out, image_filename, curved_line,textline_light, pcgts=None):
|
||||
self.logger = getLogger('eynollah.writer')
|
||||
|
|
|
@ -173,7 +173,7 @@ class sbb_predict:
|
|||
##if self.weights_dir!=None:
|
||||
##self.model.load_weights(self.weights_dir)
|
||||
|
||||
if (self.task != 'classification' and self.task != 'reading_order'):
|
||||
if self.task != 'classification' and self.task != 'reading_order':
|
||||
self.img_height=self.model.layers[len(self.model.layers)-1].output_shape[1]
|
||||
self.img_width=self.model.layers[len(self.model.layers)-1].output_shape[2]
|
||||
self.n_classes=self.model.layers[len(self.model.layers)-1].output_shape[3]
|
||||
|
@ -560,7 +560,7 @@ class sbb_predict:
|
|||
if self.image:
|
||||
res=self.predict(image_dir = self.image)
|
||||
|
||||
if (self.task == 'classification' or self.task == 'reading_order'):
|
||||
if self.task == 'classification' or self.task == 'reading_order':
|
||||
pass
|
||||
elif self.task == 'enhancement':
|
||||
if self.save:
|
||||
|
@ -583,7 +583,7 @@ class sbb_predict:
|
|||
image_dir = os.path.join(self.dir_in, ind_image)
|
||||
res=self.predict(image_dir)
|
||||
|
||||
if (self.task == 'classification' or self.task == 'reading_order'):
|
||||
if self.task == 'classification' or self.task == 'reading_order':
|
||||
pass
|
||||
elif self.task == 'enhancement':
|
||||
self.save = os.path.join(self.out, f_name+'.png')
|
||||
|
@ -664,7 +664,7 @@ def main(image, dir_in, model, patches, save, save_layout, ground_truth, xml_fil
|
|||
with open(os.path.join(model,'config.json')) as f:
|
||||
config_params_model = json.load(f)
|
||||
task = config_params_model['task']
|
||||
if (task != 'classification' and task != 'reading_order'):
|
||||
if task != 'classification' and task != 'reading_order':
|
||||
if image and not save:
|
||||
print("Error: You used one of segmentation or binarization task with image input but not set -s, you need a filename to save visualized output with -s")
|
||||
sys.exit(1)
|
||||
|
|
|
@ -269,10 +269,10 @@ def run(_config, n_classes, n_epochs, input_height,
|
|||
num_patches = num_patches_x * num_patches_y
|
||||
|
||||
if transformer_cnn_first:
|
||||
if (input_height != (num_patches_y * transformer_patchsize_y * 32) ):
|
||||
if input_height != (num_patches_y * transformer_patchsize_y * 32):
|
||||
print("Error: transformer_patchsize_y or transformer_num_patches_xy height value error . input_height should be equal to ( transformer_num_patches_xy height value * transformer_patchsize_y * 32)")
|
||||
sys.exit(1)
|
||||
if (input_width != (num_patches_x * transformer_patchsize_x * 32) ):
|
||||
if input_width != (num_patches_x * transformer_patchsize_x * 32):
|
||||
print("Error: transformer_patchsize_x or transformer_num_patches_xy width value error . input_width should be equal to ( transformer_num_patches_xy width value * transformer_patchsize_x * 32)")
|
||||
sys.exit(1)
|
||||
if (transformer_projection_dim % (transformer_patchsize_y * transformer_patchsize_x)) != 0:
|
||||
|
@ -282,10 +282,10 @@ def run(_config, n_classes, n_epochs, input_height,
|
|||
|
||||
model = vit_resnet50_unet(n_classes, transformer_patchsize_x, transformer_patchsize_y, num_patches, transformer_mlp_head_units, transformer_layers, transformer_num_heads, transformer_projection_dim, input_height, input_width, task, weight_decay, pretraining)
|
||||
else:
|
||||
if (input_height != (num_patches_y * transformer_patchsize_y) ):
|
||||
if input_height != (num_patches_y * transformer_patchsize_y):
|
||||
print("Error: transformer_patchsize_y or transformer_num_patches_xy height value error . input_height should be equal to ( transformer_num_patches_xy height value * transformer_patchsize_y)")
|
||||
sys.exit(1)
|
||||
if (input_width != (num_patches_x * transformer_patchsize_x) ):
|
||||
if input_width != (num_patches_x * transformer_patchsize_x):
|
||||
print("Error: transformer_patchsize_x or transformer_num_patches_xy width value error . input_width should be equal to ( transformer_num_patches_xy width value * transformer_patchsize_x)")
|
||||
sys.exit(1)
|
||||
if (transformer_projection_dim % (transformer_patchsize_y * transformer_patchsize_x)) != 0:
|
||||
|
@ -297,7 +297,7 @@ def run(_config, n_classes, n_epochs, input_height,
|
|||
model.summary()
|
||||
|
||||
|
||||
if (task == "segmentation" or task == "binarization"):
|
||||
if task == "segmentation" or task == "binarization":
|
||||
if not is_loss_soft_dice and not weighted_loss:
|
||||
model.compile(loss='categorical_crossentropy',
|
||||
optimizer=Adam(learning_rate=learning_rate), metrics=['accuracy'])
|
||||
|
|
|
@ -260,7 +260,7 @@ def generate_data_from_folder_training(path_classes, batchsize, height, width, n
|
|||
|
||||
if batchcount>=batchsize:
|
||||
ret_x = ret_x/255.
|
||||
yield (ret_x, ret_y)
|
||||
yield ret_x, ret_y
|
||||
ret_x= np.zeros((batchsize, height,width, 3)).astype(np.int16)
|
||||
ret_y= np.zeros((batchsize, n_classes)).astype(np.int16)
|
||||
batchcount = 0
|
||||
|
@ -446,7 +446,7 @@ def generate_arrays_from_folder_reading_order(classes_file_dir, modal_dir, batch
|
|||
ret_y[batchcount, :] = label_class
|
||||
batchcount+=1
|
||||
if batchcount>=batchsize:
|
||||
yield (ret_x, ret_y)
|
||||
yield ret_x, ret_y
|
||||
ret_x= np.zeros((batchsize, height, width, 3))#.astype(np.int16)
|
||||
ret_y= np.zeros((batchsize, n_classes)).astype(np.int16)
|
||||
batchcount = 0
|
||||
|
@ -464,7 +464,7 @@ def generate_arrays_from_folder_reading_order(classes_file_dir, modal_dir, batch
|
|||
ret_y[batchcount, :] = label_class
|
||||
batchcount+=1
|
||||
if batchcount>=batchsize:
|
||||
yield (ret_x, ret_y)
|
||||
yield ret_x, ret_y
|
||||
ret_x= np.zeros((batchsize, height, width, 3))#.astype(np.int16)
|
||||
ret_y= np.zeros((batchsize, n_classes)).astype(np.int16)
|
||||
batchcount = 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue