torch-contour


Nametorch-contour JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/antoinehabis/torch_contour
SummaryDifferentiable contour to mask and contour to distance map implementation with PyTorch
upload_time2024-05-17 14:35:05
maintainerNone
docs_urlNone
authorAntoine Habis
requires_python>=3.7
licenseMIT
keywords differentiable contour processing pytorch machine learning
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # torch_contour
<figure>
<p align="center">
  <img 
  src="vary_nodes.jpg"
  alt="Example of torch contour on a circle when varying the number of nodes"
  width="500">
  <figcaption>Example of torch contour on a circle when varying the number of nodes</figcaption>
</p>
</figure>

This library contains 2 pytorch layers for performing the diferentiable operations of :

1. contour to mask
2. contour to distance map. 

It can therefore be used to transform a polygon into a binary mask or distance map in a completely differentiable way.
In particular, it can be used to transform the detection task into a segmentation task.
The two layers have no learnable weight, so all it does is apply a function in a derivative way.



## Input (Float):

A polygon of size $2 \times n$ with \
with $n$ the number of nodes


## Output (Float):

A mask or distance map of size $1 \times H \times W$.\
with $H$ and $W$ respectively the Heigh and Width of the distance map or mask.

## Important: 

The polygon must have values between 0 and 1. It is therefore important to apply a sigmoid function before the layer.*.

## Example:

 ```
from torch_contour.torch_contour import Contour_to_distance_map, Contour_to_mask
import torch
import matplotlib.pyplot as plt

x = torch.tensor([[0.1,0.1],
                  [0.1,0.9],
                  [0.9,0.9],
                  [0.9,0.1]])[None]

Dmap = Contour_to_distance_map(200)
Mask = Contour_to_mask(200)

plt.imshow(Dmap(x).cpu().detach().numpy()[0,0])
plt.show()
plt.imshow(Mask(x).cpu().detach().numpy()[0,0])
plt.show()
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/antoinehabis/torch_contour",
    "name": "torch-contour",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "differentiable contour processing, pytorch, machine learning",
    "author": "Antoine Habis",
    "author_email": "antoine.habis.tlcm@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/1c/15/d62b4908e6521b3ec36f63dd46d20f10755410f9c1964be30ee5b8642e43/torch_contour-1.0.0.tar.gz",
    "platform": null,
    "description": "# torch_contour\n<figure>\n<p align=\"center\">\n  <img \n  src=\"vary_nodes.jpg\"\n  alt=\"Example of torch contour on a circle when varying the number of nodes\"\n  width=\"500\">\n  <figcaption>Example of torch contour on a circle when varying the number of nodes</figcaption>\n</p>\n</figure>\n\nThis library contains 2 pytorch layers for performing the diferentiable operations of :\n\n1. contour to mask\n2. contour to distance map. \n\nIt can therefore be used to transform a polygon into a binary mask or distance map in a completely differentiable way.\nIn particular, it can be used to transform the detection task into a segmentation task.\nThe two layers have no learnable weight, so all it does is apply a function in a derivative way.\n\n\n\n## Input (Float):\n\nA polygon of size $2 \\times n$ with \\\nwith $n$ the number of nodes\n\n\n## Output (Float):\n\nA mask or distance map of size $1 \\times H \\times W$.\\\nwith $H$ and $W$ respectively the Heigh and Width of the distance map or mask.\n\n## Important: \n\nThe polygon must have values between 0 and 1. It is therefore important to apply a sigmoid function before the layer.*.\n\n## Example:\n\n ```\nfrom torch_contour.torch_contour import Contour_to_distance_map, Contour_to_mask\nimport torch\nimport matplotlib.pyplot as plt\n\nx = torch.tensor([[0.1,0.1],\n                  [0.1,0.9],\n                  [0.9,0.9],\n                  [0.9,0.1]])[None]\n\nDmap = Contour_to_distance_map(200)\nMask = Contour_to_mask(200)\n\nplt.imshow(Dmap(x).cpu().detach().numpy()[0,0])\nplt.show()\nplt.imshow(Mask(x).cpu().detach().numpy()[0,0])\nplt.show()\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Differentiable contour to mask and contour to distance map implementation with PyTorch",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/antoinehabis/torch_contour"
    },
    "split_keywords": [
        "differentiable contour processing",
        " pytorch",
        " machine learning"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "76aa5fc4012094c5d4014cbeefde0b9c8c4c12d55cff90470db73f761ca5e10c",
                "md5": "cf9cbb0a911a4a989cda1aa6945a7c64",
                "sha256": "c83f4e72d333dc78299a2cf3bfe48fcb021a18f6f5b593e9bfd3776ebdef9fc7"
            },
            "downloads": -1,
            "filename": "torch_contour-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cf9cbb0a911a4a989cda1aa6945a7c64",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 4539,
            "upload_time": "2024-05-17T14:35:03",
            "upload_time_iso_8601": "2024-05-17T14:35:03.694151Z",
            "url": "https://files.pythonhosted.org/packages/76/aa/5fc4012094c5d4014cbeefde0b9c8c4c12d55cff90470db73f761ca5e10c/torch_contour-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1c15d62b4908e6521b3ec36f63dd46d20f10755410f9c1964be30ee5b8642e43",
                "md5": "fe789762ba1e73780d965bd24d789d9e",
                "sha256": "396596547374fee2d3ccc1c82d978e24e1143f5b514920c51040e0d6d0bae4ca"
            },
            "downloads": -1,
            "filename": "torch_contour-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fe789762ba1e73780d965bd24d789d9e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 4150,
            "upload_time": "2024-05-17T14:35:05",
            "upload_time_iso_8601": "2024-05-17T14:35:05.371477Z",
            "url": "https://files.pythonhosted.org/packages/1c/15/d62b4908e6521b3ec36f63dd46d20f10755410f9c1964be30ee5b8642e43/torch_contour-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-17 14:35:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "antoinehabis",
    "github_project": "torch_contour",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "torch-contour"
}
        
Elapsed time: 0.36950s