Skip to content

Unofficial PyTorch implementation of "Composing Photos Like a Photographer"

License

Notifications You must be signed in to change notification settings

bo-zhang-cs/CACNet-Pytorch

Repository files navigation

CACNet-Pytorch

This is an unofficial PyTorch implementation of Composing Photos Like a Photographer, in which the anchor-point regressors is based on Anchor-to-Joint Regression Network and more details about this can be found in their paper & code.

Quick Start

  1. Download code and model.

    # Clone this repository
    git clone https://github.com/bo-zhang-cs/CACNet-Pytorch.git
    cd CACNet-Pytorch && mkdir pretrained_model

    Download the Image Cropping Model (~75MB) from [Google Drive] to the folder pretrained_model.

  2. Inference on a single image:

    python demo.py -i ${image_path} -o ${save_folder}
    # For example
    python demo.py -i tests/raw/302166.jpg -o tests/results/

    Or on an image folder:

    python demo.py -i ${image_folder} -o tests/results/
    # For example
    python demo.py -i tests/raw -o tests/results/

    After that, you can find the cropped images in tests/results. The raw and processed images are shown below:

Results

Test set FCDB FLMS KU-PCP
Original Paper IoU=0.718 BDE=0.069 IoU=0.854 BDE=0.033 Accuracy=88.2%
This code IoU=0.702 BDE=0.074 IoU=0.841 BDE=0.037 Accuracy=88.4%

Note that the accuracy is produced training composition classification branch alone.

Datasets Preparation

  1. Download these datasets and change the default dataset folder in config_*.py.
  2. There are some images that unable to open in KU-PCP dataset, and you can fix this by calling check_jpg_file function in KUPCP_dataset.py.

Requirements

  • PyTorch>=1.0
  • torchvision
  • tensorboardX
  • opencv-python
  • tqdm

You can also install packages using pip according to requirements.txt:

pip install -r requirements.txt

Train&Eval

Evaluation

  # clone this repository
  git clone https://github.com/bo-zhang-cs/CACNet-Pytorch.git
  cd CACNet-Pytorch && mkdir pretrained_model

Download pretrained models to the folder pretrained_model.

  • Image Cropping Model (~75MB) [Google Drive] (If you are only interested in the cropping results and not classification results, then only need to download this.)
  • Composition Classification Model (~63MB) [Google Drive] (Download this if you want the best accuracy (88.4%) of composition classification.)
python eval.py

This will produce a folder results where you can find the predicted best crops.

Training

Train composition classification model

python train_composition_classification.py

Train image cropping model (CACNet)

python train_image_cropping.py

Tracking training process

tensorboard --logdir=./experiments

The model performance for each epoch is also recorded in .csv file under the produced folder ./experiments.

Citation

@inproceedings{hong2021composing,
  title={Composing Photos Like a Photographer},
  author={Hong, Chaoyi and Du, Shuaiyuan and Xian, Ke and Lu, Hao and Cao, Zhiguo and Zhong, Weicai},
  booktitle={CVPR},
  year={2021}
}

More references about image cropping

Awesome Image Aesthetic Assessment and Cropping

Releases

No releases published

Packages

No packages published

Languages