Skip to main content

A Python package for copy-paste functionality. Torch only reimplementation of https://arxiv.org/abs/2012.07177

Project description

segpaste

A PyTorch implementation of "Simple Copy-Paste is a Strong Data Augmentation Method for Instance Segmentation" (arXiv:2012.07177).

This package also provides integration with torchvision ecosystem.

Installation

pip install segpaste

Or install from source:

git clone https://github.com/NoeFontana/segpaste.git
cd segpaste
pip install -e .

Usage

TorchVision Integration

Convenience types and wrappers are provided to ease integration with torchvision datasets and transforms.

  • PaddingMask: A TVTensor representing a padding mask.
  • CocoDetectionV2: A CocoDetection dataset that presents an interface compatible with torchvision.transforms.v2 and with support for padding masks.
  • SanitizeBoundingBoxes: A small wrapper around torchvision.transforms.v2.SanitizeBoundingBoxes that adds support for PaddingMask.

Collator

The recommended interface is through the CopyPasteCollator which can be used in lieu of a standard collate function in a PyTorch DataLoader as long as the batch_size is greater than 1.

from segpaste import CopyPasteAugmentation, CopyPasteCollator, CopyPasteConfig

config = CopyPasteConfig()
augmentation = CopyPasteAugmentation(config)
collate_fn = CopyPasteCollator(augmentation)
torch.utils.data.DataLoader(
        dataset, # Your dataset here
        batch_size=batch_size, # Must be > 1
        collate_fn=collate_fn,
    )

Examples of usage can be found in the test suite.

Transform (Unstable API)

A minimal working example with CopyPasteTransform can be found in the examples.

Further

The public API is exposed in the segpaste namespace. It is subject to breaking changes, without prior notice, until version 1.0.0.

Development

This project uses Ruff for linting/formatting and mypy for type checking.

# Install development dependencies
pip install -e ".[dev,coco]"

# Format, lint, and type-check
ruff format . && ruff check --fix . && mypy .

# Run tests
pytest

Contributing

Contributions are welcome. Please open an issue to discuss major changes or submit a pull request.

Citation

If you use this implementation in your research, please consider citing the original paper:

@article{ghiasi2020simple,
  title={Simple Copy-Paste is a Strong Data Augmentation Method for Instance Segmentation},
  author={Ghiasi, Golnaz and Cui, Yin and Srinivas, Aravind and Qian, Rui and Lin, Tsung-Yi and Cubuk, Ekin D and Le, Quoc V and Zoph, Barret},
  journal={arXiv preprint arXiv:2012.07177},
  year={2020}
}

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

segpaste-0.2.0.tar.gz (30.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

segpaste-0.2.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file segpaste-0.2.0.tar.gz.

File metadata

  • Download URL: segpaste-0.2.0.tar.gz
  • Upload date:
  • Size: 30.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.23

File hashes

Hashes for segpaste-0.2.0.tar.gz
Algorithm Hash digest
SHA256 52aa1087a16a7ef188ad30aff5e8af6a92c124b33cd9f1f951dc9b93aeb77570
MD5 e92ba4e25ec8eb213ac0c9c4806ff068
BLAKE2b-256 3007568b97cdb9752b197ac9fbe84fd195b37e01e44aa79f5fc5430d6ffc3600

See more details on using hashes here.

File details

Details for the file segpaste-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: segpaste-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.23

File hashes

Hashes for segpaste-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51d8154aca4687e1f0777a839538d71b8aa5e292fef2f26fcb55b5c3b95a32a8
MD5 4c2e1fc32774db5ffe71d95a08098c44
BLAKE2b-256 becec609a615424eb94517e2b1adfa14b808550b5b25bdd3774bee79102a111a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page