Downloads · 30 days
0
hajar001/fast-neural-style-transfer
fast-neural-style-transfer is a machine learning model from hajar001. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
Apply a Picasso art style to any content image in under a second. Try it live in the browser →
Downloads · 30 days
0
Access
Public
Updated Aug 25, 2026
Parameters
6.2M
50.1 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors25 MB · 100%
From the Hugging Face model README
Apply a Picasso art style to any content image in under a second. Try it live in the browser →
This is a PyTorch implementation of "Perceptual Losses for Real-Time Style Transfer and Super-Resolution" (Johnson et al., 2016), trained as a feed-forward network for a single fixed style. Inference takes ~1 second on CPU and under a second on GPU.
Pushed to the Hub using the PytorchModelHubMixin integration.
import torch
from huggingface_hub import hf_hub_download
import sys, os
import torchvision.transforms as transforms
from PIL import Image
# Download model file
model_file = hf_hub_download(
repo_id="hajar001/fast-neural-style-transfer",
filename="style_transfer_model.py"
)
sys.path.insert(0, os.path.dirname(model_file))
from style_transfer_model import StyleTransferNet
transform = transforms.Compose([
transforms.Resize((256, 256)),
transforms.ToTensor(),
])
# Load model
model = StyleTransferNet.from_pretrained("hajar001/fast-neural-style-transfer")
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)
model.eval()
with torch.no_grad():
# Load and preprocess content image
test_image = Image.open("content_image.jpg").convert("RGB")
test_tensor = transform(test_image).unsqueeze(0).to(device)
# Generate stylized image
stylized_tensor = model(test_tensor)
# Denormalize and convert to PIL
denorm = transforms.Normalize(
mean=[-0.485/0.229, -0.456/0.224, -0.406/0.225],
std=[1/0.229, 1/0.224, 1/0.225]
)
stylized_tensor = denorm(stylized_tensor[0])
stylized_tensor = torch.clamp(stylized_tensor, 0, 1)
stylized_img = transforms.ToPILImage()(stylized_tensor.cpu())
stylized_img.save("stylized_image.jpg")