{"id":22111718,"url":"https://github.com/agentmaker/patta","last_synced_at":"2025-07-25T07:32:09.074Z","repository":{"id":46197511,"uuid":"346014957","full_name":"AgentMaker/PaTTA","owner":"AgentMaker","description":"A test times augmentation toolkit based on paddle2.0.","archived":false,"fork":false,"pushed_at":"2022-05-23T13:13:10.000Z","size":43,"stargazers_count":105,"open_issues_count":3,"forks_count":15,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-20T07:41:18.506Z","etag":null,"topics":["paddlepaddle","tta"],"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/AgentMaker.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":"2021-03-09T13:26:19.000Z","updated_at":"2025-01-17T16:07:10.000Z","dependencies_parsed_at":"2022-09-04T21:01:00.031Z","dependency_job_id":null,"html_url":"https://github.com/AgentMaker/PaTTA","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/AgentMaker/PaTTA","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgentMaker%2FPaTTA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgentMaker%2FPaTTA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgentMaker%2FPaTTA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgentMaker%2FPaTTA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AgentMaker","download_url":"https://codeload.github.com/AgentMaker/PaTTA/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgentMaker%2FPaTTA/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266972956,"owners_count":24014609,"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","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["paddlepaddle","tta"],"created_at":"2024-12-01T10:51:27.244Z","updated_at":"2025-07-25T07:32:08.806Z","avatar_url":"https://github.com/AgentMaker.png","language":"Python","readme":"# Patta\r\n![GitHub forks](https://img.shields.io/github/forks/AgentMaker/PaTTA)\r\n![GitHub Repo stars](https://img.shields.io/github/stars/AgentMaker/PaTTA)\r\n![GitHub](https://img.shields.io/github/license/AgentMaker/PaTTA)\r\n[![Upload Python Package](https://github.com/AgentMaker/PaTTA/actions/workflows/python-publish.yml/badge.svg)](https://github.com/AgentMaker/PaTTA/actions/workflows/python-publish.yml)\r\n[![PaTTA Tests](https://github.com/AgentMaker/PaTTA/actions/workflows/tests.yml/badge.svg)](https://github.com/AgentMaker/PaTTA/actions/workflows/tests.yml)\r\n\r\nImage Test Time Augmentation with Paddle2.0!\r\n\r\n```\r\n           Input\r\n             |           # input batch of images \r\n        / / /|\\ \\ \\      # apply augmentations (flips, rotation, scale, etc.)\r\n       | | | | | | |     # pass augmented batches through model\r\n       | | | | | | |     # reverse transformations for each batch of masks/labels\r\n        \\ \\ \\|/ / /      # merge predictions (mean, max, gmean, etc.)\r\n             |           # output batch of masks/labels\r\n           Output\r\n```\r\n## Table of Contents\r\n1. [Quick Start](#quick-start)\r\n- [Test](#Test)\r\n- [Predict](#Predict)\r\n- [Use Tools](#Use-Tools)\r\n2. [Transforms](#Advanced-Examples (DIY Transforms))\r\n3. [Aliases](#Aliases (Combos))\r\n4. [Merge modes](#Merge-modes)\r\n5. [Installation](#installation)\r\n\r\n## Quick start (Default Transforms)\r\n\r\n#### Test\r\nWe support that you can use the following to test after defining the network.\r\n\r\n#####  Segmentation model wrapping [[docstring](patta/wrappers.py#L8)]:\r\n```python\r\nimport patta as tta\r\ntta_model = tta.SegmentationTTAWrapper(model, tta.aliases.d4_transform(), merge_mode='mean')\r\n```\r\n#####  Classification model wrapping [[docstring](patta/wrappers.py#L52)]:\r\n```python\r\ntta_model = tta.ClassificationTTAWrapper(model, tta.aliases.five_crop_transform())\r\n```\r\n#####  Keypoints model wrapping [[docstring](patta/wrappers.py#L96)]:\r\n```python\r\ntta_model = tta.KeypointsTTAWrapper(model, tta.aliases.flip_transform(), scaled=True)\r\n```\r\n**Note**: the model must return keypoints in the format `Tensor([x1, y1, ..., xn, yn])`\r\n\r\n#### Predict\r\nWe support that you can use the following to test when you have the static model: `*.pdmodel`、`*.pdiparams`、`*.pdiparams.info`.\r\n\r\n#####  Load model [[docstring](patta/load_model.py#L3)]:\r\n```python\r\nimport patta as tta\r\nmodel = tta.load_model(path='output/model')\r\n```\r\n#####  Segmentation model wrapping [[docstring](patta/wrappers.py#L8)]:\r\n```python\r\ntta_model = tta.SegmentationTTAWrapper(model, tta.aliases.d4_transform(), merge_mode='mean')\r\n```\r\n#####  Classification model wrapping [[docstring](patta/wrappers.py#L52)]:\r\n```python\r\ntta_model = tta.ClassificationTTAWrapper(model, tta.aliases.five_crop_transform())\r\n```\r\n#####  Keypoints model wrapping [[docstring](patta/wrappers.py#L96)]:\r\n```python\r\ntta_model = tta.KeypointsTTAWrapper(model, tta.aliases.flip_transform(), scaled=True)\r\n```\r\n\r\n#### Use-Tools\r\n#####  Segmentation model [[docstring](tools/seg.py)]:\r\n**Note**: Usually, we recommend that the picture's shape is [**, **, 3].\r\n\r\nWe recommend modifying the file `seg.py` according to your own model.\r\n```python\r\npython seg.py --model_path='output/model' \\\r\n                 --batch_size=16 \\\r\n                 --test_dataset='test.txt'\r\n```\r\n**Note**: Related to [paddleseg](https://github.com/PaddlePaddle/Paddleseg)\r\n\r\n## Advanced-Examples (DIY Transforms)\r\n#####  Custom transform:\r\n```python\r\n# defined 2 * 2 * 3 * 3 = 36 augmentations !\r\ntransforms = tta.Compose(\r\n    [\r\n        tta.HorizontalFlip(),\r\n        tta.Rotate90(angles=[0, 180]),\r\n        tta.Scale(scales=[1, 2, 4]),\r\n        tta.Multiply(factors=[0.9, 1, 1.1]),        \r\n    ]\r\n)\r\n\r\ntta_model = tta.SegmentationTTAWrapper(model, transforms)\r\n```\r\n##### Custom model (multi-input / multi-output)\r\n```python\r\n# Example how to process ONE batch on images with TTA\r\n# Here `image`/`mask` are 4D tensors (B, C, H, W), `label` is 2D tensor (B, N)\r\n\r\nfor transformer in transforms: # custom transforms or e.g. tta.aliases.d4_transform() \r\n    \r\n    # augment image\r\n    augmented_image = transformer.augment_image(image)\r\n    \r\n    # pass to model\r\n    model_output = model(augmented_image, another_input_data)\r\n    \r\n    # reverse augmentation for mask and label\r\n    deaug_mask = transformer.deaugment_mask(model_output['mask'])\r\n    deaug_label = transformer.deaugment_label(model_output['label'])\r\n    \r\n    # save results\r\n    labels.append(deaug_mask)\r\n    masks.append(deaug_label)\r\n    \r\n# reduce results as you want, e.g mean/max/min\r\nlabel = mean(labels)\r\nmask = mean(masks)\r\n```\r\n \r\n## Optional Transforms\r\n  \r\n| Transform      | Parameters                | Values                            |\r\n|----------------|:-------------------------:|:---------------------------------:|\r\n| HorizontalFlip | -                         | -                                 |\r\n| VerticalFlip   | -                         | -                                 |\r\n| HorizontalShift| shifts                    | List\\[float]                      |\r\n| VerticalShift  | shifts                    | List\\[float]                      |\r\n| Rotate90       | angles                    | List\\[0, 90, 180, 270]            |\r\n| Scale          | scales\u003cbr\u003einterpolation   | List\\[float]\u003cbr\u003e\"nearest\"/\"linear\"|\r\n| Resize         | sizes\u003cbr\u003eoriginal_size\u003cbr\u003einterpolation   | List\\[Tuple\\[int, int]]\u003cbr\u003eTuple\\[int,int]\u003cbr\u003e\"nearest\"/\"linear\"|\r\n| Add            | values                    | List\\[float]                      |\r\n| Multiply       | factors                   | List\\[float]                      |\r\n| FiveCrops      | crop_height\u003cbr\u003ecrop_width | int\u003cbr\u003eint                        |\r\n| AdjustContrast | factors                   | List\\[float]                      |\r\n| AdjustBrightness|factors                   | List\\[float]                      |\r\n| AverageBlur    | kernel_sizes              | List\\[Union\\[Tuple\\[int, int], int]] |\r\n| GaussianBlur   | kernel_sizes\u003cbr\u003esigma     | List\\[Union\\[Tuple\\[int, int], int]]\u003cbr\u003eOptional\\[Union\\[Tuple\\[float, float], float]]|\r\n| Sharpen        | kernel_sizes              | List[int]                         |\r\n \r\n## Aliases (Combos)\r\n\r\n  - flip_transform (horizontal + vertical flips)\r\n  - hflip_transform (horizontal flip)\r\n  - d4_transform (flips + rotation 0, 90, 180, 270)\r\n  - multiscale_transform (scale transform, take scales as input parameter)\r\n  - five_crop_transform (corner crops + center crop)\r\n  - ten_crop_transform (five crops + five crops on horizontal flip)\r\n  \r\n## Merge-modes\r\n - mean\r\n - gmean (geometric mean)\r\n - sum\r\n - max\r\n - min\r\n - tsharpen ([temperature sharpen](https://www.kaggle.com/c/severstal-steel-defect-detection/discussion/107716#latest-624046) with t=0.5)\r\n \r\n## Installation\r\nPyPI:\r\n```bash\r\n# Use pip install PaTTA\r\n$ pip install patta\r\n```\r\nor\r\n```bash\r\n# After downloading the whole dir\r\n$ git clone https://github.com/AgentMaker/PaTTA.git\r\n$ pip install PaTTA/\r\n\r\n```\r\n\r\n## Run tests\r\n\r\n```bash\r\npython -m pytest\r\n```\r\n\r\n## Contact us\r\nEmail : [agentmaker@163.com]()\u003cbr\u003e\r\nQQ Group : 1005109853\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagentmaker%2Fpatta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagentmaker%2Fpatta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagentmaker%2Fpatta/lists"}