From 6c7c9d5fe8357c05f2f7376fdad3c1f8f6abef3f Mon Sep 17 00:00:00 2001 From: barrett Date: Thu, 16 May 2024 15:34:16 -0500 Subject: [PATCH 1/3] feat(WIP): add augmentation script this is incomplete! committing for better visibility --- training/pyproject.toml | 2 ++ training/src/training/augment.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 training/src/training/augment.py diff --git a/training/pyproject.toml b/training/pyproject.toml index 78e4d75..63bda3d 100644 --- a/training/pyproject.toml +++ b/training/pyproject.toml @@ -7,6 +7,8 @@ dependencies = [ "onnx>=1.15.0", "opencv-python>=4.9.0.80", "ultralytics>=8.1.10", + "albumentations>=1.4.4", + "datumaro>=1.6.1" ] readme = "README.md" requires-python = ">= 3.8" diff --git a/training/src/training/augment.py b/training/src/training/augment.py new file mode 100644 index 0000000..ef8e556 --- /dev/null +++ b/training/src/training/augment.py @@ -0,0 +1,32 @@ +from typing import List +import albumentations +import datumaro +import cv2 + +# load all the bounding boxes +boxes: List[List[float]] = [] + +# create the list of augmentations to perform +transform = albumentations.Compose( + [ + albumentations.RandomCrop(width=640, height=640, p=1), + albumentations.HorizontalFlip(p=0.5), + albumentations.VerticalFlip(p=0.5), + albumentations.RandomBrightnessContrast(p=0.5), + albumentations.ShiftScaleRotate(p=0.5), + albumentations.OneOf( + [ + albumentations.Blur(blur_limit=3, p=0.5), + albumentations.MedianBlur(blur_limit=3, p=0.5), + albumentations.GaussNoise(p=0.5), + albumentations.MotionBlur(blur_limit=3, p=0.5), + albumentations.OpticalDistortion(p=0.5), + albumentations.GridDistortion(p=0.5), + albumentations.ElasticTransform(p=0.5), + albumentations.CLAHE(p=0.5), + ], + p=0.5, + ), + ], + bbox_params=albumentations.BboxParams(format="yolo"), +) From 2c6d76adb890b2e270061c0e4780d4e2e9b33e5b Mon Sep 17 00:00:00 2001 From: Barrett Date: Wed, 22 May 2024 00:38:07 -0500 Subject: [PATCH 2/3] feat: add `loguru` library --- training/pyproject.toml | 3 +- training/requirements-dev.lock | 231 +++++++++++++++++++++++++++++++-- training/requirements.lock | 229 ++++++++++++++++++++++++++++++-- 3 files changed, 436 insertions(+), 27 deletions(-) diff --git a/training/pyproject.toml b/training/pyproject.toml index 63bda3d..70e6307 100644 --- a/training/pyproject.toml +++ b/training/pyproject.toml @@ -8,7 +8,8 @@ dependencies = [ "opencv-python>=4.9.0.80", "ultralytics>=8.1.10", "albumentations>=1.4.4", - "datumaro>=1.6.1" + "datumaro>=1.6.1", + "loguru>=0.7.2", ] readme = "README.md" requires-python = ">= 3.8" diff --git a/training/requirements-dev.lock b/training/requirements-dev.lock index b0a87c3..706fe31 100644 --- a/training/requirements-dev.lock +++ b/training/requirements-dev.lock @@ -5,61 +5,266 @@ # pre: false # features: [] # all-features: false +# with-sources: false -e file:. +albumentations==1.4.7 + # via training +annotated-types==0.7.0 + # via pydantic +attrs==23.2.0 + # via datumaro +brotli==1.1.0 + # via geventhttpclient certifi==2024.2.2 + # via geventhttpclient + # via requests +cffi==1.16.0 + # via cryptography charset-normalizer==3.3.2 + # via requests contourpy==1.2.0 + # via matplotlib +cryptography==42.0.7 + # via datumaro cycler==0.12.1 + # via matplotlib +datumaro==1.6.1 + # via training +defusedxml==0.7.1 + # via datumaro filelock==3.13.1 + # via huggingface-hub + # via torch fonttools==4.48.1 + # via matplotlib fsspec==2024.2.0 + # via huggingface-hub + # via torch +gevent==24.2.1 + # via geventhttpclient +geventhttpclient==2.3.1 + # via tritonclient +greenlet==3.0.3 + # via gevent +grpcio==1.64.0 + # via ovmsclient + # via tritonclient +h5py==3.11.0 + # via datumaro +huggingface-hub==0.23.1 + # via tokenizers idna==3.6 + # via requests +imageio==2.34.1 + # via scikit-image +imagesize==1.4.1 + # via datumaro jinja2==3.1.3 + # via torch +joblib==1.4.2 + # via scikit-learn +json-stream==2.3.2 + # via datumaro +json-stream-rs-tokenizer==0.4.26 + # via json-stream kiwisolver==1.4.5 + # via matplotlib +lazy-loader==0.4 + # via scikit-image +loguru==0.7.2 + # via training +lxml==5.2.2 + # via datumaro markupsafe==2.1.5 + # via jinja2 matplotlib==3.8.2 + # via datumaro + # via pycocotools + # via seaborn + # via ultralytics mpmath==1.3.0 + # via sympy mypy==1.8.0 mypy-extensions==1.0.0 + # via mypy networkx==3.2.1 + # via datumaro + # via scikit-image + # via torch +nibabel==5.2.1 + # via datumaro numpy==1.26.4 -nvidia-cublas-cu12==12.1.3.1 -nvidia-cuda-cupti-cu12==12.1.105 -nvidia-cuda-nvrtc-cu12==12.1.105 -nvidia-cuda-runtime-cu12==12.1.105 -nvidia-cudnn-cu12==8.9.2.26 -nvidia-cufft-cu12==11.0.2.54 -nvidia-curand-cu12==10.3.2.106 -nvidia-cusolver-cu12==11.4.5.107 -nvidia-cusparse-cu12==12.1.0.106 -nvidia-nccl-cu12==2.19.3 -nvidia-nvjitlink-cu12==12.3.101 -nvidia-nvtx-cu12==12.1.105 + # via albumentations + # via contourpy + # via datumaro + # via h5py + # via imageio + # via matplotlib + # via nibabel + # via onnx + # via opencv-python + # via opencv-python-headless + # via openvino + # via ovmsclient + # via pandas + # via pyarrow + # via pycocotools + # via pyemd + # via scikit-image + # via scikit-learn + # via scipy + # via seaborn + # via shapely + # via tensorboardx + # via tifffile + # via torchvision + # via tritonclient + # via ultralytics onnx==1.15.0 + # via training opencv-python==4.9.0.80 + # via datumaro + # via training + # via ultralytics +opencv-python-headless==4.9.0.80 + # via albumentations +openvino==2024.1.0 + # via datumaro +openvino-telemetry==2024.1.0 + # via openvino +orjson==3.10.0 + # via datumaro +ovmsclient==2023.1 + # via datumaro packaging==23.2 + # via huggingface-hub + # via lazy-loader + # via matplotlib + # via nibabel + # via openvino + # via scikit-image + # via tensorboardx pandas==2.2.0 + # via datumaro + # via seaborn + # via ultralytics pillow==10.2.0 + # via datumaro + # via imageio + # via matplotlib + # via scikit-image + # via torchvision + # via ultralytics protobuf==4.25.2 + # via datumaro + # via onnx + # via ovmsclient + # via tensorboardx + # via tritonclient psutil==5.9.8 + # via ultralytics py-cpuinfo==9.0.0 + # via ultralytics +pyarrow==16.1.0 + # via datumaro +pycocotools==2.0.7 + # via datumaro +pycparser==2.22 + # via cffi +pydantic==2.7.1 + # via albumentations +pydantic-core==2.18.2 + # via pydantic +pyemd==1.0.0 + # via datumaro pyparsing==3.1.1 + # via matplotlib python-dateutil==2.8.2 + # via matplotlib + # via pandas +python-rapidjson==1.17 + # via tritonclient pytz==2024.1 + # via pandas pyyaml==6.0.1 + # via albumentations + # via datumaro + # via huggingface-hub + # via ultralytics requests==2.31.0 + # via datumaro + # via huggingface-hub + # via ovmsclient + # via torchvision + # via ultralytics +ruamel-yaml==0.18.6 + # via datumaro +ruamel-yaml-clib==0.2.8 + # via ruamel-yaml ruff==0.2.1 +scikit-image==0.23.2 + # via albumentations +scikit-learn==1.5.0 + # via albumentations + # via datumaro scipy==1.12.0 + # via albumentations + # via datumaro + # via scikit-image + # via scikit-learn + # via ultralytics seaborn==0.13.2 + # via ultralytics +setuptools==70.0.0 + # via zope-event + # via zope-interface +shapely==2.0.4 + # via datumaro six==1.16.0 + # via python-dateutil sympy==1.12 + # via torch +tabulate==0.9.0 + # via datumaro +tensorboardx==2.6.2.2 + # via datumaro thop==0.1.1.post2209072238 + # via ultralytics +threadpoolctl==3.5.0 + # via scikit-learn +tifffile==2024.5.10 + # via scikit-image +tokenizers==0.19.1 + # via datumaro torch==2.2.0 + # via thop + # via torchvision + # via ultralytics torchvision==0.17.0 + # via ultralytics tqdm==4.66.1 -triton==2.2.0 + # via datumaro + # via huggingface-hub + # via ultralytics +tritonclient==2.17.0 + # via datumaro typing-extensions==4.9.0 + # via albumentations + # via datumaro + # via huggingface-hub + # via mypy + # via pydantic + # via pydantic-core + # via torch tzdata==2023.4 + # via pandas ultralytics==8.1.10 + # via training urllib3==2.2.0 + # via geventhttpclient + # via requests +zope-event==5.0 + # via gevent +zope-interface==6.4 + # via gevent diff --git a/training/requirements.lock b/training/requirements.lock index bb7146c..0c290ca 100644 --- a/training/requirements.lock +++ b/training/requirements.lock @@ -5,58 +5,261 @@ # pre: false # features: [] # all-features: false +# with-sources: false -e file:. +albumentations==1.4.7 + # via training +annotated-types==0.7.0 + # via pydantic +attrs==23.2.0 + # via datumaro +brotli==1.1.0 + # via geventhttpclient certifi==2024.2.2 + # via geventhttpclient + # via requests +cffi==1.16.0 + # via cryptography charset-normalizer==3.3.2 + # via requests contourpy==1.2.0 + # via matplotlib +cryptography==42.0.7 + # via datumaro cycler==0.12.1 + # via matplotlib +datumaro==1.6.1 + # via training +defusedxml==0.7.1 + # via datumaro filelock==3.13.1 + # via huggingface-hub + # via torch fonttools==4.48.1 + # via matplotlib fsspec==2024.2.0 + # via huggingface-hub + # via torch +gevent==24.2.1 + # via geventhttpclient +geventhttpclient==2.3.1 + # via tritonclient +greenlet==3.0.3 + # via gevent +grpcio==1.64.0 + # via ovmsclient + # via tritonclient +h5py==3.11.0 + # via datumaro +huggingface-hub==0.23.1 + # via tokenizers idna==3.6 + # via requests +imageio==2.34.1 + # via scikit-image +imagesize==1.4.1 + # via datumaro jinja2==3.1.3 + # via torch +joblib==1.4.2 + # via scikit-learn +json-stream==2.3.2 + # via datumaro +json-stream-rs-tokenizer==0.4.26 + # via json-stream kiwisolver==1.4.5 + # via matplotlib +lazy-loader==0.4 + # via scikit-image +loguru==0.7.2 + # via training +lxml==5.2.2 + # via datumaro markupsafe==2.1.5 + # via jinja2 matplotlib==3.8.2 + # via datumaro + # via pycocotools + # via seaborn + # via ultralytics mpmath==1.3.0 + # via sympy networkx==3.2.1 + # via datumaro + # via scikit-image + # via torch +nibabel==5.2.1 + # via datumaro numpy==1.26.4 -nvidia-cublas-cu12==12.1.3.1 -nvidia-cuda-cupti-cu12==12.1.105 -nvidia-cuda-nvrtc-cu12==12.1.105 -nvidia-cuda-runtime-cu12==12.1.105 -nvidia-cudnn-cu12==8.9.2.26 -nvidia-cufft-cu12==11.0.2.54 -nvidia-curand-cu12==10.3.2.106 -nvidia-cusolver-cu12==11.4.5.107 -nvidia-cusparse-cu12==12.1.0.106 -nvidia-nccl-cu12==2.19.3 -nvidia-nvjitlink-cu12==12.3.101 -nvidia-nvtx-cu12==12.1.105 + # via albumentations + # via contourpy + # via datumaro + # via h5py + # via imageio + # via matplotlib + # via nibabel + # via onnx + # via opencv-python + # via opencv-python-headless + # via openvino + # via ovmsclient + # via pandas + # via pyarrow + # via pycocotools + # via pyemd + # via scikit-image + # via scikit-learn + # via scipy + # via seaborn + # via shapely + # via tensorboardx + # via tifffile + # via torchvision + # via tritonclient + # via ultralytics onnx==1.15.0 + # via training opencv-python==4.9.0.80 + # via datumaro + # via training + # via ultralytics +opencv-python-headless==4.9.0.80 + # via albumentations +openvino==2024.1.0 + # via datumaro +openvino-telemetry==2024.1.0 + # via openvino +orjson==3.10.0 + # via datumaro +ovmsclient==2023.1 + # via datumaro packaging==23.2 + # via huggingface-hub + # via lazy-loader + # via matplotlib + # via nibabel + # via openvino + # via scikit-image + # via tensorboardx pandas==2.2.0 + # via datumaro + # via seaborn + # via ultralytics pillow==10.2.0 + # via datumaro + # via imageio + # via matplotlib + # via scikit-image + # via torchvision + # via ultralytics protobuf==4.25.2 + # via datumaro + # via onnx + # via ovmsclient + # via tensorboardx + # via tritonclient psutil==5.9.8 + # via ultralytics py-cpuinfo==9.0.0 + # via ultralytics +pyarrow==16.1.0 + # via datumaro +pycocotools==2.0.7 + # via datumaro +pycparser==2.22 + # via cffi +pydantic==2.7.1 + # via albumentations +pydantic-core==2.18.2 + # via pydantic +pyemd==1.0.0 + # via datumaro pyparsing==3.1.1 + # via matplotlib python-dateutil==2.8.2 + # via matplotlib + # via pandas +python-rapidjson==1.17 + # via tritonclient pytz==2024.1 + # via pandas pyyaml==6.0.1 + # via albumentations + # via datumaro + # via huggingface-hub + # via ultralytics requests==2.31.0 + # via datumaro + # via huggingface-hub + # via ovmsclient + # via torchvision + # via ultralytics +ruamel-yaml==0.18.6 + # via datumaro +ruamel-yaml-clib==0.2.8 + # via ruamel-yaml +scikit-image==0.23.2 + # via albumentations +scikit-learn==1.5.0 + # via albumentations + # via datumaro scipy==1.12.0 + # via albumentations + # via datumaro + # via scikit-image + # via scikit-learn + # via ultralytics seaborn==0.13.2 + # via ultralytics +setuptools==70.0.0 + # via zope-event + # via zope-interface +shapely==2.0.4 + # via datumaro six==1.16.0 + # via python-dateutil sympy==1.12 + # via torch +tabulate==0.9.0 + # via datumaro +tensorboardx==2.6.2.2 + # via datumaro thop==0.1.1.post2209072238 + # via ultralytics +threadpoolctl==3.5.0 + # via scikit-learn +tifffile==2024.5.10 + # via scikit-image +tokenizers==0.19.1 + # via datumaro torch==2.2.0 + # via thop + # via torchvision + # via ultralytics torchvision==0.17.0 + # via ultralytics tqdm==4.66.1 -triton==2.2.0 + # via datumaro + # via huggingface-hub + # via ultralytics +tritonclient==2.17.0 + # via datumaro typing-extensions==4.9.0 + # via albumentations + # via datumaro + # via huggingface-hub + # via pydantic + # via pydantic-core + # via torch tzdata==2023.4 + # via pandas ultralytics==8.1.10 + # via training urllib3==2.2.0 + # via geventhttpclient + # via requests +zope-event==5.0 + # via gevent +zope-interface==6.4 + # via gevent From f6766b6b922bf70dfe479db27751a97891bba8f7 Mon Sep 17 00:00:00 2001 From: Barrett Date: Wed, 22 May 2024 00:38:48 -0500 Subject: [PATCH 3/3] feat?(augment/WIP): this is messed up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit but might be on the right path. why is nothing typed? and nothing is documented? i do not know what i'm doing 😭 --- training/src/training/augment.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/training/src/training/augment.py b/training/src/training/augment.py index ef8e556..7c54e7c 100644 --- a/training/src/training/augment.py +++ b/training/src/training/augment.py @@ -1,10 +1,12 @@ from typing import List + import albumentations -import datumaro import cv2 +import datumaro +from loguru import logger # load all the bounding boxes -boxes: List[List[float]] = [] +data = datumaro.Dataset.import_from(path="data/export_dataset_feb_28_2024/data.yaml") # create the list of augmentations to perform transform = albumentations.Compose( @@ -28,5 +30,26 @@ p=0.5, ), ], - bbox_params=albumentations.BboxParams(format="yolo"), + bbox_params=albumentations.BboxParams(format="coco"), ) + +for image in data: + logger.info(f"Processing image {image.attributes.get('path')}") + + # load from disk + loaded_image = cv2.imread(image.attributes.get("path")) + loaded_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) + + # apply the augmentations + augmented = transform(image=image, bboxes=image.annotations) + augmented_image = augmented["image"] + augmented_bboxes = augmented["bboxes"] + + # save the augmented image + cv2.imwrite("augmented_aug.jpg", augmented) + + # push the bounding boxes to the dataset + data.put(augmented_bboxes) + +# write augmented dataset to disk +data.export("augmented_dataset.yaml", format="coco") \ No newline at end of file