Replacing Mobile Camera ISP with a Single Deep Learning Model

Nov 30, 2023 | Data Science

As technology advances, even the smallest devices like mobile phones are taking stunning photos that rival professional cameras. In this article, we will explore how a deep learning model can efficiently replace the traditional Image Signal Processing (ISP) pipeline found in mobile cameras. This transformation allows RAW images captured by mobile sensors to be processed into high-quality photos comparable to those taken by DSLRs.

1. Overview

This implementation, inspired by the work presented in the paper Replacing Mobile Camera ISP with a Single Deep Learning Model, employs a convolutional neural network known as PyNET to convert RAW Bayer data from mobile camera sensors into stunning images. The pre-trained PyNET model is capable of producing full-resolution 12MP photos from RAW image files, specifically designed for the Sony Exmor IMX380 sensor. A demo showcasing the results using popular smartphone models like Huawei P20 and BlackBerry KeyOne can be found on the project webpage.

2. Prerequisites

3. First Steps

To get started, you’ll need to set up a few resources:

  • Download the pre-trained VGG-19 model and place it in the vgg_pretrained folder.
  • Fetch the pre-trained PyNET model for the models/original folder.
  • Download the Zurich RAW to RGB mapping dataset and extract its contents into raw_images folder, which should include three subfolders: train, test, and full_resolution.

Please note: Google Drive may limit downloads per day. To avoid this, add the file to your Google Drive instead of downloading directly.

4. Understanding the PyNET CNN Architecture

Imagine building a house starting from the foundation, laying each layer progressively until it reaches its full height. PyNET operates in a similar fashion: it has an inverted pyramid-shaped architecture that processes images at five different levels, beginning from the lowest level and progressing upwards. Each level learns from the previous one’s features, improving the reconstruction of missing low-level details as it moves to higher resolutions. The image is upsampled using transposed convolutional layers on the topmost level, achieving high-quality outputs at a target size.

5. Training the Model

The training process for the PyNET model involves incrementally training each layer, starting from the lowest:

python train_model.py level=level

Mandatory parameters include:

  • level: 5, 4, 3, 2, 1, 0

Optional parameters with default values:

  • batch_size: 50 (small values can lead to unstable training)
  • train_size: 30000 (number of training patches)
  • eval_step: 1000 (accuracy computed every eval_step)
  • learning_rate: 5e-5
  • restore_iter: None (specifies an iteration to restore)
  • num_train_iters: 5K for levels 5-1 and 100K for level 0
  • vgg_dir: path to VGG-19 network
  • dataset_dir: path to RAW images dataset

6. Testing the Pre-Trained Models

Once trained, the pre-trained models can be tested on full-resolution RAW images using the following command:

python test_model.py level=0 orig=true

Use optional parameters like:

  • use_gpu: true or false
  • dataset_dir: path to the dataset

7. Final Testing

To evaluate the model on full-resolution RAW files, the command is:

python test_model.py level=level

Similar parameters apply as above.

8. Folder Structure

Keep your files organized with the following structure:

  • models: contains logs and models from training
  • models/original: pre-trained PyNET model folder
  • raw_images: folder for Zurich dataset
  • results: contains visual results during training
  • results/full-resolution: results of full-resolution testing
  • vgg_pretrained: pre-trained VGG-19 network folder
  • load_dataset.py: script for loading training data
  • model.py: PyNET model implementation
  • train_model.py: training procedure implementation
  • test_model.py: apply the model to test images
  • utils.py: auxiliary functions
  • vgg.py: loads the pre-trained VGG-19 network

9. Bonus Files

To enhance your experiments with the model, consider using:

  • dng_to_png.py: converts DNG files to PyNET’s input format
  • evaluate_accuracy.py: calculates PSNR and MS-SSIM scores on the dataset

10. Troubleshooting

If you encounter any issues during setup or execution, consider the following:

  • Make sure all dependencies and packages are properly installed.
  • Verify the paths in your commands to ensure they correspond with where your files are located.
  • If there are memory issues during training, adjust the batch_size to a smaller number.
  • Consult the GitHub issue tracker for further assistance.

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

11. 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