Home

Awesome

Spatial-Separated Attention Module (S²AM)

Arxiv | Demo

This repo contains the PyTorch implement of the following paper:

    Improving the Harmony of the Composite Image by Spatial-Separated Attention Module<br>     Xiaodong Cun and Chi-Man Pun<br>     University of Macau<br>     Trans. on Image Processing, vol. 29, pp. 4759-4771, 2020.

News

Abstract

Image composition is one of the most important applications in image processing. However, the inharmonious appearance between the spliced region and background degrade the quality of image. Thus, we address the problem of Image Harmonization: Given a spliced image and the mask of the spliced region, we try to harmonize the ''style'' of the pasted region with the background (non-spliced region). Previous approaches have been focusing on learning directly by the neural network. In this work, we start from an empirical observation: the differences can only be found in the spliced region between the spliced image and the harmonized result while they share the same semantic information and the appearance in the non-spliced region. Thus, in order to learn the feature map in the masked region and the others individually, we propose a novel attention module named Spatial-Separated Attention Module (S²AM). Furthermore, we design a novel image harmonization framework by inserting the S²AM in the coarser low level features of the Unet structure by two different ways. Besides image harmonization, we make a big step for harmonizing the composite image without the specific mask under previous observation. The experiments show that the proposed S²AM performs better than other state-of-the-art attention modules in our task. Moreover, we demonstrate the advantages of our model against other state-of-the-art image harmonization methods via criteria from multiple points of view.

Some Results

results sample

Requirements

The code is tested on the python 3.6 and PyTorch v0.4+ under Ubuntu 18.04 OS.</br> You need to install all the requirements from pip.</br> Anaconda is highly recommendation for install the dependences.</br>

git clone https://github.com/vinthony/s2am.git
cd s2am
pip install -r requirements.txt

Datasets

We train the network under two different synthesized datasets.<br>

Train

All the options of the training can be found in options.py

# train the S2AD methods 
chmod +x ./example/train_harmorization_s2ad.sh && ./example/train_harmorization_s2ad.sh

# train the S2ASC methods .
chmod +x ./example/train_harmorization_s2asc.sh && ./example/train_harmorization_s2asc.sh

# train the image harmonization w/o mask task from our paper.
chmod +x ./example/train_harmorization_wo_mask.sh && ./example/train_harmorization_wo_mask.sh

you may also try our new code framework to train s2am. please refer to this link.

Visualization

We use TensorboardX to monitor the training process, just install it by the introduction of tensorboardX.

run the watching commond as :

tensorboard --logdir ./checkpoint

Demo

Local machine.

  1. clone this repo.

  2. download the pretrain models from google drive

  3. download some sample validation dataset from google drive

  4. configure the path to the dataset and pretrained model in visualize.ipynb

  5. run the notebook

Online demo

Just visit our google colab notebook.

The pretrained model and results on iHarmony5 Dataset.

We report the MAE and PSNR as shown in the original iHarmony5 paper. The pretrained model can be downloaded from here. These results are trained and evaluated using the newer version of our code framework with nothing changes to the algorithm(please refer to our new work here). All the results have been evaluated using a jupyter notebook in eval_s2am_iharmony4.ipynb, which is modified from the evaluation code in DoveNet(CVPR 2020). Notice that the original DoveNet use the total sub-datasets for training, the results report here are trained on each sub-dataset individually.

<table> <tr> <td></td> <td colspan="2">w/o global skip-connection </td> <td colspan="2">w global skip-connection </td> </tr> <tr> <td>dataset\method</td> <td>PSNR↑</td> <td>MAE↓</td> <td>PSNR↑</rd> <td>MAE↓</td> </tr> <tr> <td>HCOCO</td> <td>37.33</td> <td>25.59</td> <td>37.25</rd> <td>26.22</td> </tr> <tr> <td>HAdobe5K</td> <td>34.33</td> <td>47.49</td> <td>34.32</rd> <td>51.66</td> </tr> <tr> <td>HFlickr</td> <td>30.71</td> <td>112.92</td> <td>31.02</rd> <td>106.21</td> </tr> <tr> <td>HDay2night</td> <td>33.63</td> <td>70.03</td> <td>34.28</rd> <td>66.31</td> </tr> </table>

The Application of Spatial-Separated Attention Module (S²AM) w/o mask

Image Classification

We evaluate our method with the baseline attention module: CBAM and original ResNet in CIFAR-10 with the default setting of code in pytorch_resnet_cifar10

methodTest err (Orginal)Test err (w/ CBAM)Test err (w/ S²AM)
ResNet208.45%7.91%7.60%
ResNet327.40%7.07%7.06%
ResNet446.96%6.92%6.58%
ResNet566.47%6.43%6.41%

Interactive Wartmark Removal from a region.

By regard a region as mask, Our method can use to remove the visible wartmark from the image. We generate the datasets from VOC as image and 100 famous logo as watermark region. The network trains on 70 of them and testing on the rest of them, here are some random results: 1511 1582 1654 1728

Citation

If you find our work useful in your research, please consider citing:

@misc{cun2019improving,
    title={Improving the Harmony of the Composite Image by Spatial-Separated Attention Module},
    author={Xiaodong Cun and Chi-Man Pun},
    year={2019},
    eprint={1907.06406},
    archivePrefix={arXiv},
    primaryClass={cs.CV}
}