Skip to playerSkip to main content
Don't have a powerful local GPU? You can still use the advanced "Image-to-Image" (img2img) capabilities of Stable Diffusion for free using Google Colab.

In this tutorial, I show you how to set up an img2img workflow in Colab, from connecting to a T4 GPU instance to uploading your source images and applying changes via prompts. Whether you want to turn sketches into realistic art, change clothing colors, or alter expressions, this guide walks you through the settings—including the critical "denoising strength"—to help you get the best results without needing high-end hardware.

Google Colab: https://colab.research.google.com/
Script Code1:
!pip install diffusers["torch"] transformers
!pip install accelerate
!pip install git+https://github.com/huggingface/diffusers

Script Code2:
import torch
from diffusers import AutoPipelineForImage2Image
from diffusers.utils import load_image, make_image_grid


init_image = load_image("/content/9.png")
mymodel = "digiplay/Realisian_v5"
myprompt="Cat Head, male"
mynegative_prompt = ""
myheight=512
mywidth=768
mysteps=25
myguidance_scale = 7.5
mystrength=0.7

pipeline = AutoPipelineForImage2Image.from_pretrained(
mymodel, torch_dtype=torch.float16, variant="fp16", use_safetensors=True
).to("cuda")
pipeline.safety_checker = None

image1 = pipeline(
prompt=myprompt,
image=init_image,
negative_prompt=mynegative_prompt,
height=myheight, width=mywidth,
num_inference_step=mysteps,
guidance_scale = myguidance_scale,
strength=mystrength,
).images[0]
image1
make_image_grid([init_image, image1], rows=1, cols=2)

How to do text 2 image stable diffusion in Google Colab: https://www.dailymotion.com/video/xa7wtw2

Original YouTube Tutorial: https://youtu.be/tWdYwuFryFs

Video Details:
* Original Publish Date: March 27, 2024
* Focus: Image-to-Image / Google Colab / Stable Diffusion Workflow
* Test using RTX 4060 TI 16 GB of VRAM

Follow lordcaocao2025 on Dailymotion for more technical AI research and generative workflow guides!

---
Connect with me:
📺 YouTube: https://www.youtube.com/@CaoCao2025
📱 TikTok: https://www.tiktok.com/@caocao20250
💎 Patreon: https://www.patreon.com/cw/Caocao2025

#StableDiffusion #GoogleColab #img2img #AIArt #FreeTools #AITutorial #lordcaocao2025
Transcript
00:05Hello guys welcome back with me Chowchow2025. Today we're going to learn
00:10about using image to image in Google Colab for free. First you need to connect
00:18this T4 so you click this change run type T4 GPU this is the free tier and then you
00:30go here and you play this. Let me paste this. I already explained to you on the
00:37last episode of the XT2 image in Google Colab so I'm not going to explain it again
00:43and this is the model for the XT2 image. Here auto pipeline XT2 image here. I add
00:51fire in FP16 and use self dancer to increase the speed and this is the image
00:57to image. Load image and auto pipeline for image to image this is what you need to
01:05upload. Load image this is you need to decide where the image is. Could use
01:12Hitler portrait you know you could just access anywhere in the website or you
01:17could upload the file here so you could click here and then just take and
01:25roll picture into here and simply right click and copy paste here. So I'll try to
01:33run the Hitler here I say I used the realism version 5 model masterpiece cat hat.
01:41Without negative from this I don't think it's work my head my width and you know copy paste this
01:48run it and this is the result. So we change his head into a cat hat. Remember there's a
01:56strange here this is like denoising straight. The larger is this the the more image gonna be changed.
02:06So we have a sample here this is one of my images on Takamaki. Let's see copy paste here for
02:22example we could make her picture realistic
02:28simply write it like this. Realistic and negative we could add anime cartoon drawing paint render.
02:40Let's try play it again. Like usually if this is your first time playing it it kind of
02:46load something but if not it's going to progress directly.
02:56And here are the results.
03:00Okay that's really bad.
03:04Maybe we could edit the strings to 0.4
03:09So let's see here.
03:10Because it's nowhere look like end.
03:14Of course you don't use any LoRa here so it's hard to maintain end faces.
03:20But with denoising strings or the string here are these we could just add in the face like ugly the
03:31form and stuff maybe.
03:33So it's look better.
03:34Cool quality here.
03:38Cool quality.
03:41And add masterpiece here.
03:45It actually look better.
03:51Yeah okay.
03:53Yeah I take it.
03:54That's quite good.
03:57Let's see our image that I upload.
03:59It's Futaba.
04:00Okay.
04:01That's right Futaba.
04:02We're going to try to change her color of her jacket maybe.
04:07To blue jacket.
04:10Let's see if it's work.
04:14Yeah it's working.
04:16Blue jacket.
04:19Her glasses is ruined though.
04:22Whatever.
04:23This is an example.
04:24So what we're trying to do next.
04:27What's the string name?
04:28Okay.
04:29Kawakami.
04:30Maybe we're not going to change anything here.
04:35But we're going to change her hair.
04:39Black hair.
04:39Simply changing her hair.
04:42Maybe we reduce the strings to two so nothing is really changed.
04:47Simply changing her hair.
04:49She doesn't have like.
04:52Yeah it's black hair.
04:53Her face is a little bit changing.
04:55But it's black hair alright.
04:57But yeah.
04:58It's also changing.
05:00So you need to add a Navi skirt or something if you don't want it to change.
05:06But overall it's working.
05:09And you know it's free.
05:12You can use your weakest GPU to do this.
05:15And.
05:16Because you use Google Collab GPU.
05:18It's.
05:19Not a problem actually.
05:21So.
05:21Okay.
05:22This is Haru-chan.
05:24Maybe add the glasses.
05:25Right.
05:26Add glasses.
05:27Maybe we don't add to add Masterpiece.
05:29So her face not changing much.
05:32Of course.
05:33It's way better to use in painting for.
05:35So.
05:35This kind of thing.
05:39Yeah.
05:40That's bad.
05:42It actually will.
05:43But maybe.
05:44If.
05:44I can reduce the changing.
05:48And it forces itself to be realistic too.
05:51Which I don't want to.
05:52Maybe I should.
05:53Use some models that are cartoon.
05:55But this is for example.
05:57Yeah.
05:57Realism is for.
05:58Really.
06:00Real.
06:01Models.
06:02So it's.
06:02It forces itself.
06:03If you're not giving a problem.
06:05To realistic models.
06:06Yeah.
06:07It is what it is.
06:09What we're going to use here.
06:11Okay.
06:12It's just a face.
06:14Okay.
06:14Let's.
06:16Change it.
06:17Into.
06:17Angry face.
06:19Yeah.
06:20Let's.
06:20Skip it.
06:21Oh.
06:22Sorry.
06:23Done.
06:23It's not that bad.
06:26The face is changing.
06:30Anyway guys.
06:31Yeah.
06:32That's it.
06:32And.
06:33Hope it helps.
06:35It's free.
06:36If you want.
06:37To know.
06:38Stable diffusion.
06:39About what it is.
06:40And you want to try around.
06:42Better use this.
06:43Instead of buying a new GPU.
06:45Or.
06:45Renting.
06:46A high-end.
06:48A GPU.
06:49In some.
06:50Website.
06:51This is free.
06:53Because if you want.
06:54Just to know.
06:55What a stable diffusion is.
06:57No need to do that.
06:58Anyway.
06:59Hope you have.
07:01And have a nice day.
Comments

Recommended