Are you an enormous fan of the dreamy artwork model of Studio Ghibli? What if we stated you may make Ghibli art work totally free out of your individual photographs? And with Python and AI — it’s not as laborious because it sounds!
I’ll present you the way we will generate our photographs to seem like it got here from a Ghibli film through the use of Python.
Not a member? Get free entry now — click here!
- A photograph you need to rework
- Python put in in your laptop
- A free AI mannequin for model switch
First, open your Python setting and set up these:
pip set up torch torchvision pillow requests
These assist with AI and picture processing.
We’ll use a free Ghibli AI generator mannequin. You will discover pre-trained fashions on-line (seek for “Ghibli artwork model switch mannequin”).
from PIL import Picture
import torch
from torchvision import transforms
import requests# Obtain a Ghibli-style mannequin (instance)
model_url = "https://huggingface.co/some-ghibli-model/resolve/foremost/mannequin.pth"
response = requests.get(model_url)
with open("ghibli_model.pth", "wb") as f:
f.write(response.content material)
# Load mannequin
mannequin = torch.load("ghibli_model.pth")
mannequin.eval()
Now, let’s flip your picture into Ghibli artwork drawing model:
# Load and course of your picture
input_image = Picture.open("your_photo.jpg")
preprocess = transforms.Compose([
transforms.Resize(512),
transforms.ToTensor(),
])
input_tensor = preprocess(input_image).unsqueeze(0)# Apply model switch
with torch.no_grad():
output = mannequin(input_tensor)
# Save consequence
output_image = transforms.ToPILImage()(output.squeeze(0))
output_image.save("ghibli_output.jpg")
Now verify your folder — it’s best to see a Ghibli-style model of your picture!
Be aware: The simplest approach is to make use of Google Colab: