Facial-Style-Transfer-for-Realistic-Artwork-Generation

Stylize Script

This script allows you to stylize images using a pre-trained model. It takes command-line arguments to specify the input image, the checkpoint file containing the pre-trained model, and the path to save the stylized image.

Requirements

  • Python 3.x
  • torch
  • opencv-python
  • torchvision

Usage

  1. Clone the repository:

    $ git clone https://github.com/mahdid-lilia/Facial-Style-Transfer-for-Realistic-Artwork-Generation.git
    $ cd Facial-Style-Transfer-for-Realistic-Artwork-Generation
  2. Run the script with the following command:

    python setup.py <option> <arguments>

    Replace <option> and <arguments> with the appropriate values:

    • <option>: Specify the option for stylizing the image. Currently, options supported are single_image and folder.
    • <arguments>:
      • --content: Path to the content image (for single image stylization) or folder path containing images (for batch stylization).
      • --checkpoint: Path to the checkpoint file containing the pre-trained model.
      • --save: Path to save the stylized image or folder path to save stylized images.
      • --model: Specify the model name for stylization.
      • Additional arguments specific to the chosen model (e.g., alpha for TransformerResNextNetwork_Pruned model).

Example

Stylize a single image:

content_path="/workspaces/Facial-Style-Transfer-for-Realistic-Artwork-Generation/data/test/test_1.jpeg"
checkpoint_path="/workspaces/Facial-Style-Transfer-for-Realistic-Artwork-Generation/models/3. TransformerResNextNetwork_Pruned03/checkpoints/checkpoint_d1500.pth"
output_path="image.png"
model_name="TransformerResNextNetwork_Pruned"
alpha=0.3

python setup.py single_image --content "$content_path" --checkpoint "$checkpoint_path" --save "$output_path" --model "$model_name" "$alpha"

Stylize images in a folder:

folder_path="/workspaces/Facial-Style-Transfer-for-Realistic-Artwork-Generation/data/test/"
checkpoint_path="models/3. TransformerResNextNetwork_Pruned03/checkpoints/checkpoint_d1500.pth"
output_path="data/output/3. TransformerResNextNetwork_Pruned03/"
model_name="TransformerResNextNetwork_Pruned"
alpha=0.3

python setup.py folder --folder "$folder_path" --checkpoint "$checkpoint_path" --save "$output_path" --model "$model_name" "$alpha"

Test Results

Stylized Images

TransformerResNextNetwork-Pruned (alpha=0.3)

test_5 test_7 test_8 test_9

TransformerResNextNetwork-Pruned (alpha=1.0)

test_5 test_7 test_8 test_9

TransformerNetworkV2

test_5 test_7 test_8 test_9