fix rabbit consumer

This commit is contained in:
Alex Bezdieniezhnykh
2025-03-07 14:33:02 +02:00
parent 4e8c67995a
commit edf685fabc
3 changed files with 101 additions and 58 deletions
+6 -4
View File
@@ -28,6 +28,7 @@ transform = A.Compose([
A.HueSaturationValue(p=0.3, hue_shift_limit=8, sat_shift_limit=8, val_shift_limit=8)
], bbox_params=A.BboxParams(format='yolo'))
def correct_bboxes(labels):
margin = 0.0005
min_size = 0.01
@@ -40,11 +41,11 @@ def correct_bboxes(labels):
# calc how much bboxes are outside borders ( +small margin ).
# value should be negative. If it's positive, then put 0, as no correction
w_diff = min( (1 - margin) - (x + half_width), (x - half_width) - margin, 0 )
w_diff = min((1 - margin) - (x + half_width), (x - half_width) - margin, 0)
w = bboxes[2] + 2*w_diff
if w < min_size:
continue
h_diff = min( (1 - margin) - (y + half_height), ((y - half_height) - margin), 0)
h_diff = min((1 - margin) - (y + half_height), ((y - half_height) - margin), 0)
h = bboxes[3] + 2 * h_diff
if h < min_size:
continue
@@ -125,10 +126,11 @@ def preprocess_annotations():
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(process_image_file, images)
def process_image_file(image_file): # this function will be executed in thread
def process_image_file(image_file):
try:
image_path = os.path.join(data_images_dir, image_file.name)
labels_path = os.path.join(data_labels_dir, f'{Path(image_path).stem}.txt')
labels_path = os.path.join(data_labels_dir, f'{Path(str(image_path)).stem}.txt')
image = cv2.imdecode(np.fromfile(image_path, dtype=np.uint8), cv2.IMREAD_UNCHANGED)
img_ann = ImageLabel(