# WCN (Warped Convolution Networks for Homography Estimation)



## Dependencies
* Conda with Python 3.7
* Nvidia GPU
* PyTorch 1.11.0
* matplotlib
* OpenCV
* Kornia
* Torchvision 
* Numpy
* ...

## Step-by-step installation

#### Create environment and activate
```bash
conda create --name siamldes python=3.7
source activate siamldes
```

#### Install numpy/pytorch/opencv
```bash
conda install numpy==1.17.0
pip install torch
pip install opencv-python
```

#### Install other requirements
```bash
pip install pyyaml yacs tqdm colorama matplotlib cython tensorboard future  optuna graphviz scipy imageio kornia Pillow optuna psutil
```

## Training with evaluation 
### 1. MNIST-PROJ
- (1) python wcn_r18_e2e.py 

  The WCN codes with LeNet5

- (2) python wcn_le5_e2e.py 

  The WCN codes with ResNet18.

It may be slow to train with ResNet18, you can reduce the epochs number to quick view the results. 
The model is first trained with transformation loss and classification loss. then retrained with only classfication loss. If you try to achieve the best performance mentioned in the paper. Please modified the "wcn_r18_e2e.py", 
Train the model in 100 epochs, reload the checkpoint and remove the loss of transformation(in Line 325), and retrain the model for 100 epochs.



### 2. POT
- The codes for planar object tracking are complex and need to be orgnized. We will publish the codes soon.
- In folder "POT" we only provide the kernel codes for implementing the warp convolution network in hdn. 
```bash
fatal codes:
(1)hdn/tracker/hdn_tracker_proj_e2e.py: main tracker.
(2)hdn/models/model_builder_e2e_unconstrained.py: main training forward process.
(3)hdn/datasets/unconstrained_v2_dataset.py: modified datasets. /hdn/models/logpolar.py, sheer.py, dblog.py, perspective.py: warp sampler.
 ```

## License

This project is released under the Apache 2.0 license. 