DEV Community

Cover image for Run IC-Light on Google Colab Free Tier
0xkoji
0xkoji

Posted on

Run IC-Light on Google Colab Free Tier

What is IC-Light?

IC-Light is a project to manipulate the illumination of images.
The name “IC-Light” stands for “Imposing Consistent Light” (we will briefly describe this at the end of this page).

GitHub logo lllyasviel / IC-Light

More relighting!

IC-Light

IC-Light is a project to manipulate the illumination of images.

The name "IC-Light" stands for "Imposing Consistent Light" (we will briefly describe this at the end of this page).

Currently, we release two types of models: text-conditioned relighting model and background-conditioned model. Both types take foreground images as inputs.

Get Started

Below script will run the text-conditioned relighting model:

git clone https://github.com/lllyasviel/IC-Light.git
cd IC-Light
conda create -n iclight python=3.10
conda activate iclight
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
pip install -r requirements.txt
python gradio_demo.py

Or, to use background-conditioned demo:

python gradio_demo_bg.py

Model downloading is automatic.

Note that the "gradio_demo.py" has an official huggingFace Space here.

Screenshot

Text-Conditioned Model

(Note that the "Lighting Preference" are just initial latents - eg., if the Lighting Preference is "Left" then initial latent is left white right black.)


Prompt: beautiful woman, detailed face, warm atmosphere, at home, bedroom

Lighting Preference: Left

image


Prompt: beautiful

How to Run IC-Light on Google Colab?
The steps we need are very straightforward and not difficult.

Step1. Change Runtime on Google Colab

Go to https://colab.research.google.com/ and click Runtime -> Change Runtime -> T4 GPU

Step2. Clone the repo

!git clone https://github.com/lllyasviel/IC-Light.git
Enter fullscreen mode Exit fullscreen mode

Step3. Install dependencies

cd IC-Light
!pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
!pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

This step will take some time.

Step4. Modify gradio_demo_bg.py

We just need to change only 1 line.

before

block.launch(server_name='0.0.0.0')
Enter fullscreen mode Exit fullscreen mode

after

block.launch(server_name='127.0.0.1', share=True)
Enter fullscreen mode Exit fullscreen mode

Step5. Run gradio_demo_bg.py

!python gradio_demo_bg.py
Enter fullscreen mode Exit fullscreen mode

You will see something like this. This step also would take some time since need to download models.

/usr/local/lib/python3.10/dist-packages/transformers/utils/generic.py:441: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.
  _torch_pytree._register_pytree_node(
The cache for model files in Transformers v4.22.0 has been updated. Migrating your old cache. This is a one-time only operation. You can interrupt this and resume the migration later on by calling `transformers.utils.move_cache()`.
0it [00:00, ?it/s]
2024-05-11 01:08:16.363718: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2024-05-11 01:08:16.363780: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2024-05-11 01:08:16.493211: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2024-05-11 01:08:18.972938: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
/usr/local/lib/python3.10/dist-packages/transformers/utils/generic.py:309: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.
  _torch_pytree._register_pytree_node(
/usr/local/lib/python3.10/dist-packages/transformers/utils/generic.py:309: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.
  _torch_pytree._register_pytree_node(
tokenizer/tokenizer_config.json: 100% 704/704 [00:00<00:00, 2.61MB/s]
tokenizer/vocab.json: 100% 1.06M/1.06M [00:00<00:00, 3.22MB/s]
tokenizer/merges.txt: 100% 525k/525k [00:00<00:00, 2.15MB/s]
tokenizer/special_tokens_map.json: 100% 586/586 [00:00<00:00, 2.40MB/s]
text_encoder/config.json: 100% 560/560 [00:00<00:00, 2.23MB/s]
model.safetensors: 100% 246M/246M [00:01<00:00, 144MB/s]
vae/config.json: 100% 606/606 [00:00<00:00, 2.37MB/s]
diffusion_pytorch_model.safetensors: 100% 167M/167M [00:01<00:00, 163MB/s]
unet/config.json: 100% 1.78k/1.78k [00:00<00:00, 7.60MB/s]
diffusion_pytorch_model.safetensors: 100% 1.72G/1.72G [00:20<00:00, 83.9MB/s]
config.json: 100% 548/548 [00:00<00:00, 2.31MB/s]
pytorch_model.bin: 100% 177M/177M [00:02<00:00, 66.7MB/s]
100% 1.60G/1.60G [00:13<00:00, 126MB/s]
Running on local URL:  http://127.0.0.1:7860
IMPORTANT: You are using gradio version 3.41.2, however version 4.29.0 is available, please upgrade.
--------
Running on public URL: https://65a7c6684da105a45e.gradio.live
Enter fullscreen mode Exit fullscreen mode

Then you need to access Running on public URL.
When you access the public URL, you will see something like 👇

gradio

Enjoy IC-Light!

Top comments (0)