From 830c3a05713d46d00cb15acc74eb20490ef8d082 Mon Sep 17 00:00:00 2001 From: hasslesstech Date: Wed, 3 Dec 2025 12:20:19 +0200 Subject: [PATCH] aug batchable --- aug.py | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/aug.py b/aug.py index 3cc4571..444c0fd 100644 --- a/aug.py +++ b/aug.py @@ -1,11 +1,7 @@ import albumentations as a import numpy as np -#from ultralytics import YOLO from os import listdir as ls import cv2 as cv -#from pybboxes import BoundingBox as bb - -#import torch def b_c(b, s = (1920, 1080)): return [ @@ -24,6 +20,8 @@ def sq(img, bbox): base_path = '../videos/total' tagt_path = '../videos/total-exp' +p = 1 + t = a.Compose([ a.BBoxSafeRandomCrop(), a.HorizontalFlip(p=0.5), @@ -36,29 +34,23 @@ for i in list(fs)[:1]: img = cv.cvtColor(cv.imread(f"{base_path}/{i}.jpg"), cv.COLOR_BGR2RGB) box = [tuple(map(float, j.split()[1:])) for j in open(f"{base_path}/{i}.txt").read().split("\n") if j] - #for j in open(f"{base_path}/{i}.txt").read().split("\n"): - # box.append(tuple(map(float, j.split()[1:]))) - - print(box) - lbl = np.array(['ch'] * len(box)) box = np.array(box) - #sq(img, box) + for k in range(10): + r = t(image = img, bboxes = box, class_labels = lbl) - r = t(image = img, bboxes = box, class_labels = lbl) + out_img = r['image'] + out_box = r['bboxes'] + out_lbl = r['class_labels'] - out_img = r['image'] - out_box = r['bboxes'] - out_lbl = r['class_labels'] + #print(f"open({tagt_path}/{p}-{i}-{k}.xml)") + #print("\n".join([" ".join(list(map(str, ['0'] + list(y)))) for y in out_box]) + "\n") + open(f"{tagt_path}/{p}-{i}-{k}.xml", 'w').write("\n".join([" ".join(list(map(str, ['0'] + list(y)))) for y in out_box]) + "\n") + cv.imwrite(f"{tagt_path}/{p}-{i}-{k}.jpg", cv.cvtColor(out_img, cv.COLOR_RGB2BGR)) - sq(out_img, out_box) + #sq(out_img, out_box) - from matplotlib import pyplot as plt - plt.imshow(out_img) - plt.show() - -#y = YOLO("m.yaml") -#y.info() - -#o = y.model(torch.randn(1, 3, 640, 640)) + #from matplotlib import pyplot as plt + #plt.imshow(out_img) + #plt.show()