Rework logging (#3358)

Unified all log files into one.

### What problem does this PR solve?

Unified all log files into one.

### Type of change

- [x] Refactoring
This commit is contained in:
Zhichang Yu
2024-11-12 17:35:13 +08:00
committed by GitHub
parent 567a7563e7
commit a2a5631da4
75 changed files with 481 additions and 853 deletions

View File

@ -20,6 +20,7 @@ import cv2
import numpy as np
import math
from PIL import Image
from api.utils.log_utils import logger
class DecodeImage(object):
@ -402,7 +403,7 @@ class DetResizeForTest(object):
return None, (None, None)
img = cv2.resize(img, (int(resize_w), int(resize_h)))
except BaseException:
print(img.shape, resize_w, resize_h)
logger.exception("{} {} {}".format(img.shape, resize_w, resize_h))
sys.exit(0)
ratio_h = resize_h / float(h)
ratio_w = resize_w / float(w)
@ -452,7 +453,6 @@ class E2EResizeForTest(object):
return data
def resize_image_for_totaltext(self, im, max_side_len=512):
h, w, _ = im.shape
resize_w = w
resize_h = h

View File

@ -19,6 +19,7 @@ from huggingface_hub import snapshot_download
from api.utils.file_utils import get_project_base_directory
from .operators import *
from api.utils.log_utils import logger
class Recognizer(object):
@ -439,7 +440,7 @@ class Recognizer(object):
end_index = min((i + 1) * batch_size, len(imgs))
batch_image_list = imgs[start_index:end_index]
inputs = self.preprocess(batch_image_list)
print("preprocess")
logger.info("preprocess")
for ins in inputs:
bb = self.postprocess(self.ort_sess.run(None, {k:v for k,v in ins.items() if k in self.input_names})[0], ins, thr)
res.append(bb)

View File

@ -14,6 +14,7 @@
import os
import PIL
from PIL import ImageDraw
from api.utils.log_utils import logger
def save_results(image_list, results, labels, output_dir='output/', threshold=0.5):
@ -24,7 +25,7 @@ def save_results(image_list, results, labels, output_dir='output/', threshold=0.
out_path = os.path.join(output_dir, f"{idx}.jpg")
im.save(out_path, quality=95)
print("save result to: " + out_path)
logger.info("save result to: " + out_path)
def draw_box(im, result, lables, threshold=0.5):

View File

@ -10,7 +10,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os, sys
import os
import sys
from api.utils.log_utils import logger
sys.path.insert(
0,
os.path.abspath(
@ -56,7 +59,7 @@ def main(args):
} for t in lyt]
img = draw_box(images[i], lyt, labels, float(args.threshold))
img.save(outputs[i], quality=95)
print("save result to: " + outputs[i])
logger.info("save result to: " + outputs[i])
def get_table_html(img, tb_cpns, ocr):