Giter VIP home page Giter VIP logo

duconet-image-harmonization's Introduction

[ACM MM-23] Deep image harmonization in Dual Color Space [ACM MM-23]

PWC

This is the official repository for the following paper:

Deep Image Harmonization in Dual Color Spaces [arXiv]

Linfeng Tan, Jiangtong Li, Li Niu, Liqing Zhang
Accepted by ACMMM2023.

Image harmonization is an essential step in image composition that adjusts the appearance of composite foreground to address the inconsistency between foreground and background. Existing methods primarily operate in correlated $RGB$ color space, leading to entangled features and limited representation ability. In contrast, decorrelated color space ($Lab$) has decorrelated channels that provide disentangled color and illumination statistics. In this paper, we explore image harmonization in dual color spaces, which supplements entangled $RGB$ features with disentangled $L$, $a$, $b$ features to alleviate the workload in harmonization process. The network comprises a $RGB$ harmonization backbone, an $Lab$ encoding module, and an $Lab$ control module. The backbone is a U-Net network translating composite image to harmonized image. Three encoders in $Lab$ encoding module extract three control codes independently from $L$, $a$, $b$ channels, which are used to manipulate the decoder features in harmonization backbone via $Lab$ control module.

Getting Started

Prerequisites

Please refer to iSSAM for guidance on setting up the environment.

Installation

  • Clone this repo:
git clone https://github.com/bcmi/DucoNet-Image-Harmonization.git
cd ./DucoNet-Image-Harmonization
pip install -r requirements.txt

Training

If you want to train DucoNet on dataset iHarmony4, you can run this command:

## for low-resolution 

python train.py models/DucoNet_256.py --workers=8 --gpus=0,1 --exp-name=DucoNet_256 --batch-size=64

## for high-resolution 

python train.py models/DucoNet_1024.py --workers=8 --gpus=2,3 --exp-name=DucoNet_1024 --batch-size=4

We have also provided some commands in the "train.sh" for your convenience.

Testing

You can run the following command to test the pretrained model, and you can download the pre-trained model we released from Google Drive or Baidu Cloud:

python scripts/evaluate_model.py DucoNet ./checkpoints/last_model/DucoNet256.pth \
--resize-strategy Fixed256 \
--gpu 0 

#python scripts/evaluate_model.py DucoNet ./checkpoints/last_model/DucoNet1024.pth \
#--resize-strategy Fixed1024 \
#--gpu 1 \
#--datasets HAdobe5k1 

We have also provided some commands in the "test.sh" for your convenience.

Results and Pretrained model

We test our DucoNet on iHarmony4 dataset with image size 256×256 and on HAdobe5k dataset with image size 1024×1024. We report our results on evaluation metrics, including MSE, fMSE, and PSNR. We also released the pretrained model corresponding to our results, you can download it from the corresponding link.

Image Size fMSE MSE PSNR Google Drive Baidu Cloud
256 $\times$ 256 212.53 18.47 39.17 Google Drive Baidu Cloud
1024 $\times$ 1024 80.69 10.94 41.37 Google Drive Baidu Cloud

Other Resources

Acknowledgement

Our code is heavily borrowed from iSSAM and PyTorch implementation of styleGANv2 .

Bibtex:

If you are interested in our work, please consider citing the following:

@article{tan2023deep,
  title={Deep Image Harmonization in Dual Color Spaces},
  author={Tan, Linfeng and Li, Jiangtong and Niu, Li and Zhang, Liqing},
  journal={arXiv preprint arXiv:2308.02813},
  year={2023}
}

duconet-image-harmonization's People

Contributors

ustcnewly avatar zeroflt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

cv-ip someone45

duconet-image-harmonization's Issues

why image_lab is <class 'NoneType'> ?

def predict(self, image, mask, image_lab = None,return_numpy=True):
with torch.no_grad():
for transform in self.transforms:
image, mask = transform.transform(image, mask)

        transform = transforms.Compose([
            transforms.ToTensor(),
         ])
        print(type(image_lab))
        comp_image_lab = transform(image_lab).unsqueeze(0).to(self.device)
        predicted_output = self.net(image, mask,image_lab = comp_image_lab)
        predicted_image = predicted_output['images']


        for transform in reversed(self.transforms):
            predicted_image = transform.inv_transform(predicted_image)

        predicted_image = torch.clamp(predicted_image, 0, 255)

    if return_numpy:
        return predicted_image.cpu().numpy()
    else:
        return predicted_image

why image_lab is <class 'NoneType'> ?
getting error:

File "/home/rnd/miniconda3/envs/e4s/lib/python3.8/site-packages/torchvision/transforms/functional.py", line 138, in to_tensor
raise TypeError(f"pic should be PIL Image or ndarray. Got {type(pic)}")
TypeError: pic should be PIL Image or ndarray. Got <class 'NoneType'>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.