Skip to main content

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.

Metadata

Release files for segpaste 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for segpaste 0.2.0
File Size Uploaded Provenance Actions
segpaste-0.2.0.tar.gz 30.8 kB Without provenance Details for segpaste-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for segpaste 0.2.0
File Interpreter ABI Platform Actions
segpaste-0.2.0-py3-none-any.whl Python 3 none any Details for segpaste-0.2.0-py3-none-any.whl

Total release size: 54.4 kB

Release files / segpaste-0.2.0.tar.gz

Download URL segpaste-0.2.0.tar.gz
Size 30.8 kB
Tags Source
SHA-256 checksum
How to use checksums
52aa1087a16a7ef188ad30aff5e8af6a92c124b33cd9f1f951dc9b93aeb77570
BLAKE2b-256 checksum
How to use checksums
3007568b97cdb9752b197ac9fbe84fd195b37e01e44aa79f5fc5430d6ffc3600
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.23

Release files / segpaste-0.2.0-py3-none-any.whl

Download URL segpaste-0.2.0-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
51d8154aca4687e1f0777a839538d71b8aa5e292fef2f26fcb55b5c3b95a32a8
BLAKE2b-256 checksum
How to use checksums
becec609a615424eb94517e2b1adfa14b808550b5b25bdd3774bee79102a111a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.23

Security for segpaste 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page