{"id":13717323,"url":"https://github.com/jbohnslav/opencv_transforms","last_synced_at":"2025-04-12T23:30:10.708Z","repository":{"id":38291020,"uuid":"146785061","full_name":"jbohnslav/opencv_transforms","owner":"jbohnslav","description":"OpenCV implementation of Torchvision's image augmentations","archived":false,"fork":false,"pushed_at":"2021-05-03T14:25:06.000Z","size":1778,"stargazers_count":377,"open_issues_count":7,"forks_count":46,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-04T02:07:54.735Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jbohnslav.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-30T17:43:11.000Z","updated_at":"2024-11-14T07:35:11.000Z","dependencies_parsed_at":"2022-09-02T19:12:23.610Z","dependency_job_id":null,"html_url":"https://github.com/jbohnslav/opencv_transforms","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbohnslav%2Fopencv_transforms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbohnslav%2Fopencv_transforms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbohnslav%2Fopencv_transforms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbohnslav%2Fopencv_transforms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jbohnslav","download_url":"https://codeload.github.com/jbohnslav/opencv_transforms/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647249,"owners_count":21139081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T00:01:20.799Z","updated_at":"2025-04-12T23:30:10.687Z","avatar_url":"https://github.com/jbohnslav.png","language":"Python","readme":"# opencv_transforms\r\n\r\nThis repository is intended as a faster drop-in replacement for [Pytorch's Torchvision augmentations](https://github.com/pytorch/vision/). This repo uses OpenCV for fast image augmentation for PyTorch computer vision pipelines. I wrote this code because the Pillow-based Torchvision transforms was starving my GPU due to slow image augmentation.\r\n\r\n## Requirements\r\n* A working installation of OpenCV. **Tested with OpenCV version 3.4.1, 4.1.0**\r\n* Tested on Windows 10 and Ubuntu 18.04. There is evidence that OpenCV doesn't work well with multithreading on Linux / MacOS, for example `num_workers \u003e0` in a pytorch `DataLoader`. I haven't run into this issue yet. \r\n\r\n## Installation\r\nopencv_transforms is now a pip package! Simply use\r\n* `pip install opencv_transforms`\r\n\r\n## Usage\r\n**Breaking change! Please note the import syntax!** \r\n* `from opencv_transforms import transforms`\r\n* From here, almost everything should work exactly as the original `transforms`.\r\n#### Example: Image resizing \r\n```python\r\nimport numpy as np\r\nimage = np.random.randint(low=0, high=255, size=(1024, 2048, 3))\r\nresize = transforms.Resize(size=(256,256))\r\nimage = resize(image)\r\n```\r\nShould be 1.5 to 10 times faster than PIL. See benchmarks\r\n\r\n## Performance\r\n* Most transformations are between 1.5X and ~4X faster in OpenCV. Large image resizes are up to 10 times faster in OpenCV.\r\n* To reproduce the following benchmarks, download the [Cityscapes dataset](https://www.cityscapes-dataset.com/). \r\n* An example benchmarking file can be found in the notebook **bencharming_v2.ipynb** I wrapped the Cityscapes default directories with a HDF5 file for even faster reading. \r\n\r\n![resize](benchmarks/benchmarking_Resize.png)\r\n![random crop](benchmarks/benchmarking_Random_crop_quarter_size.png)\r\n![change brightness](benchmarks/benchmarking_Color_brightness_only.png)\r\n![change brightness and contrast](benchmarks/benchmarking_Color_constrast_and_brightness.png)\r\n![change contrast only](benchmarks/benchmarking_Color_contrast_only.png)\r\n![random horizontal flips](benchmarks/benchmarking_Random_horizontal_flip.png)\r\n\r\nThe changes start to add up when you compose multiple transformations together.\r\n![composed transformations](benchmarks/benchmarking_Resize_flip_brightness_contrast_rotate.png)\r\n\r\n## TODO\r\n- [x] Initial commit with all currently implemented torchvision transforms\r\n- [x] Cityscapes benchmarks\r\n- [ ] Make the `resample` flag on `RandomRotation`, `RandomAffine` actually do something\r\n- [ ] Speed up augmentation in saturation and hue. Currently, fastest way is to convert to a PIL image, perform same augmentation as Torchvision, then convert back to np.ndarray\r\n","funding_links":[],"categories":["Pytorch \u0026 related libraries｜Pytorch \u0026 相关库","Python","Pytorch \u0026 related libraries"],"sub_categories":["Other libraries｜其他库:","Other libraries:"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbohnslav%2Fopencv_transforms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjbohnslav%2Fopencv_transforms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbohnslav%2Fopencv_transforms/lists"}