Skip to content

Commit 14baf2f

Browse files
fix logger
1 parent f0b3b1d commit 14baf2f

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

fastlabel/__init__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import json
33
import os
44
import re
5-
from logging import getLogger
5+
import logging
66
from typing import List
77
from concurrent.futures import ThreadPoolExecutor
88
import cv2
@@ -11,6 +11,7 @@
1111
from PIL import Image, ImageColor, ImageDraw
1212
from fastlabel import const, converters, utils
1313
from fastlabel.const import (
14+
EXPORT_IMAGE_WITH_ANNOTATIONS_SUPPORTED_IMAGE_TYPES,
1415
KEYPOINT_MIN_STROKE_WIDTH,
1516
OPACITY_DARK,
1617
OPACITY_THIN,
@@ -22,7 +23,11 @@
2223
from .api import Api
2324
from .exceptions import FastLabelInvalidException
2425

25-
logger = getLogger(__name__)
26+
logger = logging.getLogger(__name__)
27+
logging.basicConfig(
28+
level=logging.INFO,
29+
format="%(levelname)s: %(message)s",
30+
)
2631

2732

2833
class Client:
@@ -2263,7 +2268,7 @@ def __create_image_with_annotation(self, img_file_path_task):
22632268
try:
22642269
rgb = ImageColor.getcolor(task_annotation["color"], "RGB")
22652270
except Exception as e:
2266-
print(e)
2271+
logger.info(e)
22672272
if not rgb:
22682273
continue
22692274
rgba_dark = rgb + (OPACITY_DARK,)
@@ -2379,7 +2384,7 @@ def __create_image_with_annotation(self, img_file_path_task):
23792384
task_annotation_keypoint_keypoint_color, "RGB"
23802385
)
23812386
except Exception as e:
2382-
print(
2387+
logger.info(
23832388
f"Invalid color: {task_annotation_keypoint_keypoint_color}, "
23842389
f"content_name: {task_annotation_keypoint_name}, {e}"
23852390
)
@@ -2476,8 +2481,8 @@ def export_image_with_annotations(
24762481
for target_file_candidate_path in target_file_candidate_paths:
24772482
if not os.path.isfile(target_file_candidate_path):
24782483
continue
2479-
if not target_file_candidate_path.endswith(
2480-
(".jpeg", ".jpg", ".png", ".JPEG", ".JPG", ".PNG", ".tif", ".TIF")
2484+
if not target_file_candidate_path.lower().endswith(
2485+
EXPORT_IMAGE_WITH_ANNOTATIONS_SUPPORTED_IMAGE_TYPES
24812486
):
24822487
continue
24832488
img_file_paths.append(target_file_candidate_path)
@@ -2496,7 +2501,7 @@ def export_image_with_annotations(
24962501
None,
24972502
)
24982503
if not task:
2499-
print(f"not find task. filepath: {task_name}")
2504+
logger.info(f"Not find task. filepath: {task_name}")
25002505
continue
25012506
img_file_path_task_list.append([img_file_path, task, output_dir])
25022507

fastlabel/const.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@
185185
POSE_ESTIMATION_MIN_STROKE_WIDTH = 7
186186
SEPARATOER = "@@@@@"
187187

188+
EXPORT_IMAGE_WITH_ANNOTATIONS_SUPPORTED_IMAGE_TYPES = (
189+
".jpeg",
190+
".jpg",
191+
".png",
192+
".tif",
193+
".tiff",
194+
".bmp",
195+
)
196+
188197
# under 512 MB. Actual size is 536870888 bytes, but to consider other attributes,
189198
# minus 888 bytes.
190199
# Because of V8's limitation, API only can accept the JSON string that length is

0 commit comments

Comments
 (0)