-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mindee:main' into main
- Loading branch information
Showing
27 changed files
with
241 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from doctr.file_utils import is_tf_available | ||
|
||
if is_tf_available(): | ||
from .tensorflow import * | ||
else: | ||
from .pytorch import * # type: ignore[misc] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright (C) 2021, Mindee. | ||
|
||
# This program is licensed under the Apache License version 2. | ||
# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details. | ||
|
||
from torch import Tensor | ||
from torch.nn.functional import max_pool2d | ||
|
||
__all__ = ['erode', 'dilate'] | ||
|
||
|
||
def erode(x: Tensor, kernel_size: int) -> Tensor: | ||
"""Performs erosion on a given tensor | ||
Args: | ||
x: boolean tensor of shape (N, C, H, W) | ||
kernel_size: the size of the kernel to use for erosion | ||
Returns: | ||
the eroded tensor | ||
""" | ||
_pad = (kernel_size - 1) // 2 | ||
|
||
return 1 - max_pool2d(1 - x, kernel_size, stride=1, padding=_pad) | ||
|
||
|
||
def dilate(x: Tensor, kernel_size: int) -> Tensor: | ||
"""Performs dilation on a given tensor | ||
Args: | ||
x: boolean tensor of shape (N, C, H, W) | ||
kernel_size: the size of the kernel to use for dilation | ||
Returns: | ||
the dilated tensor | ||
""" | ||
_pad = (kernel_size - 1) // 2 | ||
|
||
return max_pool2d(x, kernel_size, stride=1, padding=_pad) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (C) 2021, Mindee. | ||
|
||
# This program is licensed under the Apache License version 2. | ||
# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details. | ||
|
||
import tensorflow as tf | ||
|
||
__all__ = ['erode', 'dilate'] | ||
|
||
|
||
def erode(x: tf.Tensor, kernel_size: int) -> tf.Tensor: | ||
"""Performs erosion on a given tensor | ||
Args: | ||
x: boolean tensor of shape (N, H, W, C) | ||
kernel_size: the size of the kernel to use for erosion | ||
Returns: | ||
the eroded tensor | ||
""" | ||
|
||
return 1 - tf.nn.max_pool2d(1 - x, kernel_size, strides=1, padding="SAME") | ||
|
||
|
||
def dilate(x: tf.Tensor, kernel_size: int) -> tf.Tensor: | ||
"""Performs dilation on a given tensor | ||
Args: | ||
x: boolean tensor of shape (N, H, W, C) | ||
kernel_size: the size of the kernel to use for dilation | ||
Returns: | ||
the dilated tensor | ||
""" | ||
|
||
return tf.nn.max_pool2d(x, kernel_size, strides=1, padding="SAME") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.