Skip to content

Fix Deformable Convolutional Op Support #179 #1129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
eca80f5
Update BUILD
seanpmorgan Jan 14, 2019
1ad0309
Merge branch 'master' of https://github.com/tensorflow/addons
smallsunsun1 Mar 26, 2020
8d46b24
Merge branch 'master' of https://github.com/tensorflow/addons
smallsunsun1 Mar 26, 2020
350d26c
Add DeformableConv2D and DeformablePSROIAlign operator with cpu and gpu
smallsunsun1 Feb 9, 2020
bec6e34
fixed a problem
smallsunsun1 Feb 9, 2020
a84a1f0
fix problem
smallsunsun1 Feb 9, 2020
30a5434
reformat
smallsunsun1 Feb 9, 2020
948f8ef
reformat
smallsunsun1 Feb 9, 2020
176fcb1
fixed problem
smallsunsun1 Feb 9, 2020
603ffa7
fix problem
smallsunsun1 Feb 9, 2020
1c7b33a
fixed cpu don't support NCHW format in nn.conv2d
smallsunsun1 Feb 9, 2020
527dc81
fixed cpu don't support NCHW format in nn.conv2d
smallsunsun1 Feb 9, 2020
b13201e
use WIN32 to support windows
smallsunsun1 Feb 9, 2020
e60191b
use conditional compile to support windows
smallsunsun1 Feb 9, 2020
d1fc3ca
use conditional compile to support windows
smallsunsun1 Feb 9, 2020
84d1d05
fix syntax problem in windows
smallsunsun1 Feb 9, 2020
52ae901
remove some redudant code
smallsunsun1 Feb 10, 2020
27aa599
add EquiConv according to https://arxiv.org/pdf/1903.08094.pdf
smallsunsun1 Feb 22, 2020
057d927
fix timeout problem
smallsunsun1 Feb 22, 2020
663622a
fix test problem
smallsunsun1 Feb 22, 2020
6a72bcc
fix problem
smallsunsun1 Mar 27, 2020
dc3e3ab
format code
smallsunsun1 Mar 27, 2020
4aad322
manully format code
smallsunsun1 Mar 27, 2020
430cc6a
Update deformable_conv2d.py
liborvaneksw Jun 8, 2020
72c19cf
Merge pull request #1 from liborvaneksw/feature/deformable_ops
smallsunsun1 Jul 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions change.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

git filter-branch -f --env-filter '

OLD_EMAIL="sunjiahe@sss-2.local"
CORRECT_NAME="public"
CORRECT_EMAIL="975759105@qq.com"

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' -- --all
148 changes: 148 additions & 0 deletions docs/tutorials/deformable_conv2d_ops.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"cells": [
{
"cell_type": "markdown",
"source": [
"Setup\n"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"try:\n",
" %tensorflow_version 2.x\n",
"except:\n",
" pass\n",
"\n",
"import tensorflow as tf\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"!pip install -q --no-deps tensorflow-addons~=0.9"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"import numpy as np\n",
"import tensorflow_addons as tfa\n",
"import matplotlib.pyplot as plt\n"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "markdown",
"source": [
"Usage example\n",
"\n",
"(DeformableConv2D is just like normal tf.keras.layers.Conv2D)\n",
"\n",
"(DeformablePSROIAlign is something like tf.image.crop_and_resize)\n",
"\n",
"(EquiConv is proposed by https://arxiv.org/pdf/1903.08094.pdf, which is a special case\n",
"of DeformableConv2D)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"filters = 64\n",
"batch_size = 4\n",
"channels = 3\n",
"kernel_size = (3, 3)\n",
"padding = \"same\"\n",
"featuremap = tf.random.uniform(shape=[batch_size, 20, 20, channels], dtype=tf.float32)\n",
"\n",
"deformable_layer = tfa.layers.DeformableConv2D(filters, kernel_size, padding=padding)\n",
"equi_conv_layer = tfa.layers.EquiConv(64, (3, 3), 1, 1, (1, 1),\n",
" 1, False, \"same\", \"channels_last\")\n",
"result = deformable_layer(featuremap)\n",
"equi_result = equi_conv_layer(featuremap)\n",
"\n",
"image_featuremap = tf.random.normal(shape=[2, 64, 100, 100])\n",
"rois = tf.convert_to_tensor([[0, 1, 1, 800, 800], [1, 2, 2, 400, 400]], dtype=tf.float32)\n",
"out_dim = 64\n",
"spatial_scale = 1 / 16\n",
"group_size = 1\n",
"pooled_size = 7\n",
"sample_per_part = 4\n",
"part_size = 7\n",
"trans_std = 1\n",
"data_format = \"channels_first\"\n",
"psroi_align_layer = tfa.layers.DeformablePSROIAlign(out_dim, spatial_scale, group_size,\n",
" pooled_size, sample_per_part, part_size,\n",
" trans_std, data_format)\n",
"features = psroi_align_layer([image_featuremap, rois])"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
},
"pycharm": {
"stem_cell": {
"cell_type": "raw",
"source": [],
"metadata": {
"collapsed": false
}
}
}
},
"nbformat": 4,
"nbformat_minor": 0
}
18 changes: 18 additions & 0 deletions tensorflow_addons/custom_ops/layers/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,21 @@ custom_op_library(
"cc/kernels/correlation_cost_op_gpu.cu.cc",
],
)

custom_op_library(
name = "_deformable_conv2d_ops.so",
srcs = [
"cc/kernels/deformable_conv2d_utils.h",
"cc/kernels/deformable_conv_op.cc",
"cc/kernels/deformable_conv_op.h",
"cc/ops/deformable_conv2d.cc",
],
cuda_deps = [
"@cub_archive//:cub",
],
cuda_srcs = [
"cc/kernels/deformable_conv2d_utils.h",
"cc/kernels/deformable_conv_op.h",
"cc/kernels/deformable_conv_op_gpu.cu.cc",
],
)
Loading