DSLR-Quality Photos on Mobile Devices with Deep Convolutional Networks

May 30, 2023 | Data Science

Welcome to a thrilling exploration of enhancing your smartphone photography to DSLR-quality images utilizing the power of deep learning! In this article, we will guide you step by step through the process of setting up an environment and executing the code that allows this transformation. Ready to elevate your mobile photography skills? Let’s dive in!

1. Overview

This project showcases an end-to-end deep learning approach that translates ordinary photos taken with smartphones into photos that boast DSLR-quality. The model can be applied to photos of varying resolutions and is generalized for any digital camera. For detailed reading, refer to the Paper. Additional resources are available on the Project webpage. To enhance RAW photos, check out Enhancing RAW photos, and for rendering bokeh effects, explore Rendering Bokeh Effect.

2. Prerequisites

3. First Steps

Before we delve into training, let’s get the essentials in place:

  1. Download the pre-trained VGG-19 model and place it in the vgg_pretrained folder.
  2. Download the DPED dataset, which includes patches for CNN training, and extract it into the dped folder. This folder should have three subfolders: sony, iphone, and blackberry.

4. Train the Model

To kickstart the training process, open your terminal and run the following command while specifying the model and other parameters:

bash
python train_model.py model=model

Here are the obligatory and optional parameters:

  • model: Choose from iphone, blackberry, or sony
  • Optional Parameters:
    • batch_size: 50 (smaller values can lead to unstable training)
    • train_size: 30000 (number of training patches randomly loaded each eval_step iterations)
    • eval_step: 1000 (model saving iterations)
    • num_train_iters: 20000 (total training iterations)
    • learning_rate: 5e-4
    • w_content: 10 (weight of the content loss)
    • w_color: 0.5 (weight of the color loss)
    • w_texture: 1 (weight of the texture loss)
    • w_tv: 2000 (weight of the total variation loss)
    • dped_dir: Path to the dped dataset folder
    • vgg_dir: Path to the pre-trained VGG-19 network

Example command:

bash
python train_model.py model=iphone batch_size=50 dped_dir=dped w_color=0.7

5. Testing the Pre-Trained Models

After training, it’s time to test the acquired models. Execute the command:

bash
python test_model.py model=model

Parameters:

  • model: Options include iphone_orig, blackberry_orig, or sony_orig
  • Optional Parameters:
    • test_subset: Choose between full or small
    • resolution: Options are orig, high, medium, small, or tiny
    • use_gpu: Set to true or false
    • dped_dir: Path to the dped dataset

Example command:

bash
python test_model.py model=iphone_orig test_subset=full resolution=orig use_gpu=true

6. Testing the Obtained Models

Continue testing with different configurations:

bash
python test_model.py model=model

Parameters similar to the prior step continue to apply. Here are additional options:

  • iteration: Specify all or a specific number (must be a multiple of eval_step)

Example command:

bash
python test_model.py model=iphone iteration=13000 test_subset=full resolution=orig use_gpu=true

7. Folder Structure

It is essential to maintain the following folder structure for smooth operation:

  • dped: Contains the dataset.
  • models: Stores logs and saved models during training.
  • models_orig: Houses the provided pre-trained models for iphone, sony, and blackberry.
  • results: Will hold visual results for image patches during training.
  • vgg-pretrained: Directory for the pre-trained VGG-19 network.
  • visual_results: Contains enhanced processed test images.
  • load_dataset.py: Python script for loading training data.
  • models.py: Architecture of the image enhancement networks.
  • ssim.py: Implementation of the SSIM score.
  • train_model.py: Script for the training procedure.
  • test_model.py: Used for applying the pre-trained models to test images.
  • utils.py: Contains auxiliary functions.
  • vgg.py: Responsible for loading the pre-trained VGG-19 network.

8. Problems and Errors

If you encounter the error “OOM when allocating tensor with shape […]”, it often signifies that your GPU lacks sufficient memory. Here’s how you can troubleshoot:

  • During training, decrease the size of the training batch_size. However, be cautious as lower values might lead to unstable training.
  • During testing, consider running the model on the CPU by setting use_gpu to false. Note that this may extend processing time to up to 5 minutes per image.
  • You can also use cropped images by adjusting the resolution to: high, medium, small, or tiny, which process smaller sections of your images.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

9. Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox