Practical overview
When it fits
Use it when a PyTorch CNN needs a DCNv2 layer or when you want to examine the repository's offset visualization and scaled-MNIST example.
Who it is for
- PyTorch developers adding deformable convolution to CNNs.
- Computer-vision practitioners exploring spatially adaptive sampling or inspecting learned offsets.
- Developers reviewing the included scaled-MNIST classification example.
Documented uses
- Add a DeformableConv2d layer to a CNN using configurable channel counts, kernel size, stride and padding.
- Visualize learned offsets with the repository's offset-visualization script.
- Review or reproduce the notebook's scaled-MNIST classification experiment in Google Colab.
Requirements & limits
The repository specifies the MIT license and points to Google Colab for reproducing the included experiment.
- The implementation is provided as a PyTorch module named DeformableConv2d.
- An offset-visualization script is included for viewing learned offsets.
- The notebook describes a five-convolution-layer scaled-MNIST experiment and reports 92.90% top-1 accuracy with DCNv2 versus 90.03% without it on a scale-augmented test set.
- The README demonstrates layer usage but does not provide a full installation procedure.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Use DeformableConv2d in a PyTorch model
Add a deformable convolution layer to a model using the documented Python interface.
Before you start
- A PyTorch model that uses nn.Module; the README does not specify installation or dependency requirements.
Steps
Import DeformableConv2d with
from dcn import DeformableConv2d.Define the layer in the model, for example
DeformableConv2d(in_channels=32, out_channels=32, kernel_size=3, stride=1, padding=1).Use the layer as part of the model, as shown for
self.conv.
Expected outcome
The model definition includes a DeformableConv2d layer with the specified channels and convolution parameters.
Configure the documented Scaled-MNIST experiment
Set up the README's five-convolution classifier and training configuration for Scaled-MNIST classification.
Before you start
- The DeformableConv2d import shown in the README.
- The Scaled-MNIST task and five-convolution classifier structure shown in the README.
Steps
Define three initial Conv2d layers and select
nn.Conv2dorDeformableConv2dfor the fourth and fifth layers using thedeformableflag.Complete the classifier with ReLU activations, two MaxPool2d operations, AdaptiveAvgPool2d((1, 1)), flattening, and a 10-output linear layer, as shown.
Configure training with Adam, learning rate 1e-3, StepLR(step_size=1, gamma=0.7), batch size 64, 14 epochs, and no augmentation.
For the reported scale-augmentation test, augment MNIST test images at scales x0.5 through x1.5 in increments of x0.1.
Expected outcome
A classifier and training configuration matching the described Scaled-MNIST experiment are specified; the README reports 90.03% top-1 accuracy without DCNv2 and 92.90% with DCNv2 on its scale-augmented test.
Guide limitations
- The README points to experiment.ipynb for reproducing the experiment but does not provide its full execution procedure here.
- The reported results do not establish performance on other datasets, architectures, or training setups.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 17 November 2026
- Original website title
- developer0hye/PyTorch-Deformable-Convolution-v2 · Official homepage title · retained in its source language

