Skip to content
Snippets Groups Projects

Remove unused utils functions

Merged Mélodie Boillet requested to merge clean-utils into main
1 file
+ 0
54
Compare changes
  • Side-by-side
  • Inline
+ 0
54
@@ -4,16 +4,6 @@ import numpy as np
import torch
from torch.distributions.uniform import Uniform
# Layout string to token
SEM_MATCHING_TOKENS_STR = {
"INTITULE": "",
"DATE": "",
"COTE_SERIE": "",
"ANALYSE_COMPL": "",
"PRECISIONS_SUR_COTE": "",
"COTE_ARTICLE": "",
}
# Layout begin-token to end-token
SEM_MATCHING_TOKENS = {"": "", "": "", "": "", "": "", "": "", "": ""}
@@ -57,20 +47,6 @@ def pad_sequences_1D(data, padding_value):
return padded_data
def resize_max(img, max_width=None, max_height=None):
if max_width is not None and img.shape[1] > max_width:
ratio = max_width / img.shape[1]
new_h = int(np.floor(ratio * img.shape[0]))
new_w = int(np.floor(ratio * img.shape[1]))
img = cv2.resize(img, (new_w, new_h), interpolation=cv2.INTER_LINEAR)
if max_height is not None and img.shape[0] > max_height:
ratio = max_height / img.shape[0]
new_h = int(np.floor(ratio * img.shape[0]))
new_w = int(np.floor(ratio * img.shape[1]))
img = cv2.resize(img, (new_w, new_h), interpolation=cv2.INTER_LINEAR)
return img
def pad_images(data, padding_value, padding_mode="br"):
"""
data: list of numpy array
@@ -157,36 +133,6 @@ def pad_image(
return output
def pad_image_width_right(img, new_width, padding_value):
"""
Pad img to right side with padding value to reach new_width as width
"""
h, w, c = img.shape
pad_width = max((new_width - w), 0)
pad_right = np.ones((h, pad_width, c), dtype=img.dtype) * padding_value
img = np.concatenate([img, pad_right], axis=1)
return img
def pad_image_width_random(img, new_width, padding_value, max_pad_left_ratio=1):
"""
Randomly pad img to left and right sides with padding value to reach new_width as width
"""
h, w, c = img.shape
pad_width = max((new_width - w), 0)
max_pad_left = int(max_pad_left_ratio * pad_width)
pad_left = (
randint(0, min(pad_width, max_pad_left))
if pad_width != 0 and max_pad_left > 0
else 0
)
pad_right = pad_width - pad_left
pad_left = np.ones((h, pad_left, c), dtype=img.dtype) * padding_value
pad_right = np.ones((h, pad_right, c), dtype=img.dtype) * padding_value
img = np.concatenate([pad_left, img, pad_right], axis=1)
return img
def read_image(filename, scale=1.0):
"""
Read image and rescale it
Loading