{"id":13737249,"url":"https://github.com/yu4u/cutout-random-erasing","last_synced_at":"2025-03-25T19:32:06.306Z","repository":{"id":55138284,"uuid":"108452896","full_name":"yu4u/cutout-random-erasing","owner":"yu4u","description":"Cutout / Random Erasing implementation, especially for ImageDataGenerator in Keras","archived":false,"fork":false,"pushed_at":"2020-08-26T14:20:33.000Z","size":120,"stargazers_count":166,"open_issues_count":5,"forks_count":37,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-08-04T03:08:28.539Z","etag":null,"topics":["cutout","deep-learning","deeplearning","keras","random-erasing"],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","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/yu4u.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":"2017-10-26T18:53:25.000Z","updated_at":"2024-05-21T12:49:34.000Z","dependencies_parsed_at":"2022-08-14T13:10:30.018Z","dependency_job_id":null,"html_url":"https://github.com/yu4u/cutout-random-erasing","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/yu4u%2Fcutout-random-erasing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yu4u%2Fcutout-random-erasing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yu4u%2Fcutout-random-erasing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yu4u%2Fcutout-random-erasing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yu4u","download_url":"https://codeload.github.com/yu4u/cutout-random-erasing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222090823,"owners_count":16929472,"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":["cutout","deep-learning","deeplearning","keras","random-erasing"],"created_at":"2024-08-03T03:01:38.547Z","updated_at":"2024-10-29T18:16:43.132Z","avatar_url":"https://github.com/yu4u.png","language":"Jupyter Notebook","readme":"# Cutout / Random Erasing\nThis is a Cutout [1] / Random Erasing [2] implementation.\nIn particular, it is easily used with ImageDataGenerator in Keras.\nPlease check [random_eraser.py](random_eraser.py) for implementation details.\n\n## About Cutout / Random Erasing\nCutout or Random Erasing is a kind of image augmentation methods\nfor convolutional neural networks (CNN).\nThey are very similar methods and were proposed almost at the same time.\n\nThey try to regularize models using training images\nthat are randomly masked with random values.\n\n\u003cimg src=\"example.png\" width=\"480px\"\u003e\n\n\u003cimg src=\"example2.png\" width=\"480px\"\u003e\n\n## Usage\n### With ImageDataGenerator in Keras\nIt is very easy to use if you are using ImageDataGenerator in Keras;\nget `eraser` function by `get_random_eraser()`,\nand then pass it to `ImageDataGenerator` as `preprocessing_function`.\nBy doing so, all images are randomly erased *before* standard augmentation\ndone by ImageDataGenerator.\n\nPlease check [cifar10_resnet.py](cifar10_resnet.py),\nwhich is imported from [official Keras examples](https://github.com/fchollet/keras/tree/master/examples).\n\nWhat I did is adding only two lines:\n\n```python\n...\nfrom random_eraser import get_random_eraser  # added\n...\n\n    datagen = ImageDataGenerator(\n    ...\n        preprocessing_function=get_random_eraser(v_l=0, v_h=1))  # added\n```\n\n### Erase a single image\nOf cause, you can erase a single image using `eraser` function.\nPlease note that `eraser` function works in inplace mode;\nthe input image itself will be modified (therefore, `img = eraser(img)` can be replaced by `eraser(img)` in the following example).\n\n```python\nfrom random_eraser import get_random_eraser\neraser = get_random_eraser()\n\n# load image to img\nimg = eraser(img)\n```\n\nPleae check [example.ipynb](example.ipynb) for complete example.\n\n### Parameters\nParameters are fully configurable as:\n\n```\nget_random_eraser(p=0.5, s_l=0.02, s_h=0.4, r_1=0.3, r_2=1/0.3,\n                  v_l=0, v_h=255, pixel_level=False)\n```\n\n- `p` : the probability that random erasing is performed\n- `s_l`, `s_h` : minimum / maximum proportion of erased area against input image\n- `r_1`, `r_2` : minimum / maximum aspect ratio of erased area\n- `v_l`, `v_h` : minimum / maximum value for erased area\n- `pixel_level` : pixel-level randomization for erased area\n\n\n## Results\nThe original `cifar10_resnet.py` result (w/o cutout / random erasing):\n\n```\nTest loss: 0.539187009859\nTest accuracy: 0.9077\n```\n\nWith cutout / random erasing:\n\n```\nTest loss: 0.445597583055\nTest accuracy: 0.9182\n```\n\nWith cutout / random erasing (pixel-level):\n\n```\nTest loss: 0.446407950497\nTest accuracy: 0.9213\n```\n\n\n## References\n[1] T. DeVries and G. W. Taylor, \"Improved Regularization of Convolutional Neural Networks with Cutout,\" in arXiv:1708.04552, 2017.\n\n[2] Z. Zhong, L. Zheng, G. Kang, S. Li, and Y. Yang, \"Random Erasing Data Augmentation,\" in arXiv:1708.04896, 2017.\n","funding_links":[],"categories":["Jupyter Notebook"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyu4u%2Fcutout-random-erasing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyu4u%2Fcutout-random-erasing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyu4u%2Fcutout-random-erasing/lists"}