Image Colorization Application
This application provides a web-based interface for colorizing black and white images using DeOldify technology. It consists of a FastAPI backend for processing images and a Streamlit frontend for a user-friendly interface.
Features
- Colorize black and white images using DeOldify
- Choose between Artistic (more vibrant) and Stable (more realistic) models
- Adjust render factor to control quality and processing time
- Generate multiple renders with different factors to find the optimal result
- Download colorized images
Installation
Prerequisites
- Python 3.7 or higher
- CUDA-capable GPU (recommended for faster processing)
- Git
Setup Instructions
- Clone the DeOldify repository inside your project directory:
git clone https://github.com/jantic/DeOldify.git
- Install the requirements:
pip install -r requirements.txt
This installs both the dependencies for our application and most of the dependencies needed for DeOldify.
- Download the pre-trained model weights:
- Artistic model: ColorizeArtistic_gen.pth
- Stable model: ColorizeStable_gen.pth
- Create a models directory and place the downloaded weights:
mkdir -p DeOldify/models
# Move the downloaded .pth files to the DeOldify/models directory
IMPORTANT: The application expects the DeOldify directory to be in the same directory as the app.py and streamlit_app.py files.
Running the Application
- Start the FastAPI server:
python app.py
This will start the API server on http://localhost:8000
- In a new terminal window, start the Streamlit web application:
streamlit run streamlit_app.py
This will open the web interface in your browser, typically at http://localhost:8501
Troubleshooting
Common Issues
ModuleNotFoundError: No module named 'deoldify'
This error indicates that the application cannot find the DeOldify module. Make sure:
- The DeOldify repository is cloned in the same directory as app.py
- You're running the commands from the root directory of the project, not from inside the DeOldify directory
CUDA/GPU-related errors
If you encounter CUDA errors:
- Make sure your GPU drivers are up to date
- Try running with a lower render factor
- Edit app.py to change
DeviceId.GPU0toDeviceId.CPUif you don't have a GPU
API Documentation
Once the FastAPI server is running, you can access the API documentation at:
- http://localhost:8000/docs (Swagger UI)
- http://localhost:8000/redoc (ReDoc)
API Endpoints
POST /colorize: Colorize a single image with specified parametersPOST /colorize_multiple: Generate multiple colorizations with different render factorsGET /image/{image_path}: Retrieve a colorized image by its path
Streamlit Web App
The web application provides an intuitive interface for:
- Uploading images
- Selecting colorization model (Artistic or Stable)
- Adjusting render factor
- Generating and comparing multiple renders
- Downloading colorized images
Technical Details
- The application uses DeOldify's image colorization models
- Default render factor is 10, but can be adjusted between 5-50
- The artistic model is used by default, but can be switched to stable
- For multiple renders, you can specify the minimum and maximum render factors and step size
Performance Tips
- If you encounter CUDA out-of-memory errors, try lowering the render factor
- For best results with the artistic model, a render factor of 35-40 is recommended
- For the stable model, a render factor of 20-25 typically works well
License
This project uses DeOldify, which is licensed under MIT License.