{
"info": {
"author": "Pavel Yakubovskiy",
"author_email": "qubvel@gmail.com",
"bugtrack_url": null,
"classifiers": [
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy"
],
"description": "\n# TTAch\nImage Test Time Augmentation with PyTorch!\n\nSimilar to what Data Augmentation is doing to the training set, the purpose of Test Time Augmentation is to perform random modifications to the test images. Thus, instead of showing the regular, \u201cclean\u201d images, only once to the trained model, we will show it the augmented images several times. We will then average the predictions of each corresponding image and take that as our final guess [[1](https://towardsdatascience.com/test-time-augmentation-tta-and-how-to-perform-it-with-keras-4ac19b67fb4d)]. \n```\n Input\n | # input batch of images \n / / /|\\ \\ \\ # apply augmentations (flips, rotation, scale, etc.)\n | | | | | | | # pass augmented batches through model\n | | | | | | | # reverse transformations for each batch of masks/labels\n \\ \\ \\ / / / # merge predictions (mean, max, gmean, etc.)\n | # output batch of masks/labels\n Output\n```\n\n\n## Quick start\n\n##### Segmentation model wrapping:\n```python\nimport ttach as tta\ntta_model = tta.SegmentationTTAWrapper(model, tta.aliases.d4_transform(), merge_mode='mean')\n```\n##### Classification model wrapping:\n```python\ntta_model = tta.ClassificationTTAWrapper(model, tta.aliases.five_crops_transform())\n```\n\n## Advanced Examples\n##### Custom transform:\n```python\n# defined 2 * 2 * 3 * 3 = 36 augmentations !\ntransforms = tta.Compose(\n [\n tta.HorizontalFlip(),\n tta.Rotate90(angles=[0, 180]),\n tta.Scale(scales=[1, 2, 4]),\n tta.Multiply(factors=[0.9, 1, 1.1]), \n ]\n)\n\ntta_model = tta.SegmentationTTAWrapper(model, transforms)\n```\n##### Custom model (multi-input / multi-output)\n```python\n# Example how to process ONE batch on images with TTA\n# Here `image`/`mask` are 4D tensors (B, C, H, W), `label` is 2D tensor (B, N)\n\nfor transformer in transforms: # custom transforms or e.g. tta.aliases.d4_transform() \n\n # augment image\n augmented_image = transformer.augment_image(image)\n\n # pass to model\n model_output = model(augmented_image, another_input_data)\n\n # reverse augmentation for mask and label\n deaug_mask = transformer.deaugment_mask(model_output['mask'])\n deaug_label = transformer.deaugment_label(model_output['label'])\n\n # save results\n labels.append(deaug_mask)\n masks.append(deaug_label)\n\n# reduce results as you want, e.g mean/max/min\nlabel = mean(labels)\nmask = mean(masks)\n```\n\n## Transforms\n\n| Transform | Parameters | Values |\n|----------------|:-------------------------:|:---------------------------------:|\n| HorizontalFlip | - | - |\n| VerticalFlip | - | - |\n| Rotate90 | angles | List\\[0, 90, 180, 270] |\n| Scale | scales
interpolation | List\\[float]
\"nearest\"/\"linear\"|\n| Add | values | List\\[float] |\n| Multiply | factors | List\\[float] |\n| FiveCrops | crop_height
crop_width | int
int |\n\n## Aliases\n\n - flip_transform (horizontal + vertical flips)\n - hflip_transform (horizontal flip)\n - d4_transform (flips + rotation 0, 90, 180, 270)\n - multiscale_transform (scale transform, take scales as input parameter)\n - five_crop_transform (corner crops + center crop)\n - ten_crop_transform (five crops + five crops on horizontal flip)\n\n## Merge modes\n - mean\n - gmean (geometric mean)\n - sum\n - max\n - min\n - tsharpen ([temperature sharpen](https://www.kaggle.com/c/severstal-steel-defect-detection/discussion/107716#latest-624046) with t=0.5)\n\n## Run tests\n\n```bash\ndocker build -f Dockerfile.dev -t ttach:dev . && docker run --rm ttach:dev pytest -p no:cacheprovider\n```\n\n\n",
"description_content_type": "text/markdown",
"docs_url": null,
"download_url": "",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "https://github.com/qubvel/ttach",
"keywords": "",
"license": "MIT",
"maintainer": "",
"maintainer_email": "",
"name": "ttach",
"package_url": "https://pypi.org/project/ttach/",
"platform": "",
"project_url": "https://pypi.org/project/ttach/",
"project_urls": {
"Homepage": "https://github.com/qubvel/ttach"
},
"release_url": "https://pypi.org/project/ttach/0.0.1/",
"requires_dist": [
"pytest ; extra == 'test'"
],
"requires_python": ">=3.0.0",
"summary": "Images test time augmentation with PyTorch.",
"version": "0.0.1"
},
"last_serial": 5917814,
"releases": {
"0.0.1": [
{
"comment_text": "",
"digests": {
"md5": "065c35c060cf0015cecfe5a1ed179741",
"sha256": "8c9f76bf4ec40b547299a660ab167ea746f71ace9cbd37e8581dfbd16da0fc98"
},
"downloads": -1,
"filename": "ttach-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "065c35c060cf0015cecfe5a1ed179741",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.0.0",
"size": 8655,
"upload_time": "2019-10-02T13:01:55",
"url": "https://files.pythonhosted.org/packages/2c/e0/115092bd2a827e4eb35a0c8445902737fe91754a9328b3901340fe086529/ttach-0.0.1-py3-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "b1d145b5ed94e2adf3bdad114f27a90f",
"sha256": "e06f5703133eebf7dc5bb05b9217fe4c6625af41b25279770d9a36166d986eab"
},
"downloads": -1,
"filename": "ttach-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "b1d145b5ed94e2adf3bdad114f27a90f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.0.0",
"size": 8444,
"upload_time": "2019-10-02T13:01:57",
"url": "https://files.pythonhosted.org/packages/27/87/f86ad00aaa4b7da0889a36677a7c0f004864ae8cb5cebe0e5888bb464ee1/ttach-0.0.1.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "065c35c060cf0015cecfe5a1ed179741",
"sha256": "8c9f76bf4ec40b547299a660ab167ea746f71ace9cbd37e8581dfbd16da0fc98"
},
"downloads": -1,
"filename": "ttach-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "065c35c060cf0015cecfe5a1ed179741",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.0.0",
"size": 8655,
"upload_time": "2019-10-02T13:01:55",
"url": "https://files.pythonhosted.org/packages/2c/e0/115092bd2a827e4eb35a0c8445902737fe91754a9328b3901340fe086529/ttach-0.0.1-py3-none-any.whl"
},
{
"comment_text": "",
"digests": {
"md5": "b1d145b5ed94e2adf3bdad114f27a90f",
"sha256": "e06f5703133eebf7dc5bb05b9217fe4c6625af41b25279770d9a36166d986eab"
},
"downloads": -1,
"filename": "ttach-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "b1d145b5ed94e2adf3bdad114f27a90f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.0.0",
"size": 8444,
"upload_time": "2019-10-02T13:01:57",
"url": "https://files.pythonhosted.org/packages/27/87/f86ad00aaa4b7da0889a36677a7c0f004864ae8cb5cebe0e5888bb464ee1/ttach-0.0.1.tar.gz"
}
]
}