donkeycar
donkeycar copied to clipboard
Remove albumentations
Albumentations still has the problem on jetson nano that it causes a crash because underneath it still uses a dependency that installs opencv-headless.
The reality is that we only use two augmentations from it; a brightness augmentation and a guassian blur. These are both easily implemented with opencv.
Replace the brightness augmentation and the guassian blur augmentation in https://github.com/autorope/donkeycar/blob/1398eec8309499c4d54fc45d510348bcb819daff/donkeycar/pipeline/augmentations.py#L13. with ones based on opencv so we can remove albumentations.
Yes, in the current setup that would work. But there are other augmentations, like CoarseDropout for example, which might be quite useful (one can play with them here: https://demo.albumentations.ai/). However, they might be easy to generate with cv
too.
Hello I am trying to train in a Nvidia Jetson AGX Xavier, I am having problems with albumentations. When I pip install albumentations, it seems to uninstall my current version of opencv-python. ( The problem is that I have to use a custom version of this library to be able to do gpu accelation in my platform). I get this error after installing albumentations: pip install albumentations
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 181, in <module>
bootstrap()
File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 175, in bootstrap
if __load_extra_py_code_for_module("cv2", submodule, DEBUG):
File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 28, in __load_extra_py_code_for_module
py_module = importlib.import_module(module_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/local/lib/python3.8/dist-packages/cv2/mat_wrapper/__init__.py", line 39, in <module>
cv._registerMatType(Mat)
AttributeError: partially initialized module 'cv2' has no attribute '_registerMatType' (most likely due to a circular import)
Is there a reason why albumentations is needed? I need guidance to know if I can to try to use opencv version. Would you like me to send a pull request if it does work with opencv implementation?
import cv2
import logging
from cv2 import GaussianBlur
from cv2 import addWeighted
import numpy as np
from donkeycar.config import Config
logger = logging.getLogger(__name__)
class ImageAugmentation:
def __init__(self, cfg, key, prob=0.5, always_apply=False):
aug_list = getattr(cfg, key, [])
self.augmentations = [ImageAugmentation.create(a, cfg, prob, always_apply) for a in aug_list]
@classmethod
def create(cls, aug_type: str, config: Config, prob, always) -> callable:
""" Augmentation factory."""
if aug_type == 'BRIGHTNESS':
b_limit = getattr(config, 'AUG_BRIGHTNESS_RANGE', 0.2)
logger.info(f'Creating augmentation {aug_type} {b_limit}')
bightness = np.random.uniform(-b_limit, b_limit)
return lambda img_arr: addWeighted(img_arr, 1.0 + bightness, img_arr, 0, 0)
elif aug_type == 'BLUR':
b_range = getattr(config, 'AUG_BLUR_RANGE', (0,3))
logger.info(f'Creating augmentation {aug_type} {b_range}')
bur_intensity = np.random.uniform(b_range[0], b_range[1])
return lambda img_arr: GaussianBlur(img_arr, (13,13), bur_intensity)
# Parts interface
def run(self, img_arr):
for augmentation in self.augmentations:
img_arr = augmentation(img_arr)
return img_arr
Little update, I was able to train. After committing the above update on my Jetson. Will test on real data soon and send a little clip within the next few days.
https://youtu.be/rgLV-9JGVLM?si=X8n_8SM7aP7GspVT
@Ezward @DocGarbanzo