Differentiable contour to mask and contour to distance map implementation with PyTorch
Project description
torch_contour
This library contains 2 pytorch layers for performing the diferentiable operations of :
- contour to mask
- 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.*.
The predicted polygon must be ordered in counter-clockwise.
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]])
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()
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
Built Distribution
Hashes for torch_contour-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f738a0d0d0ca9de31954126e6074bc42d3aec3bf48cc6ad45a3e2c803e2b21f |
|
MD5 | 159851685b84515d10369e0b227d8649 |
|
BLAKE2b-256 | cd38efa4844fa90a3af8a2713318eee8de97f3a32b65ef6c0b24ab0b3bc62085 |