Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Deepseek ai Janus Image Post Processing Flow

From Leeroopedia


Knowledge Sources
Domains Computer_Vision, Image_Generation
Last Updated 2026-02-10 09:30 GMT

Overview

Pattern for converting VAE-decoded tensors to displayable images with Lanczos upscaling in the JanusFlow pipeline.

Description

This user-defined pattern converts the SDXL VAE decoder output to uint8 images and upscales them from 384×384 to 1024×1024 using PIL's Lanczos filter.

Usage

Implement this pattern after AutoencoderKL.decode() to produce final output images.

Code Reference

Source Location

  • Repository: Janus
  • File: demo/app_janusflow.py
  • Lines: L136-138 (tensor conversion), L175 (resize to 1024)

Pattern Implementation

import numpy as np
from PIL import Image

# decoded_image: [B, 3, 384, 384] from VAE decode
images = decoded_image.float().clip_(-1., 1.).permute(0, 2, 3, 1).cpu().numpy()
images = ((images + 1) / 2. * 255).astype(np.uint8)

# Upscale to 1024x1024 with Lanczos filter
output_images = [
    Image.fromarray(images[i]).resize((1024, 1024), Image.LANCZOS)
    for i in range(images.shape[0])
]

Import

import numpy as np
from PIL import Image

I/O Contract

Inputs

Name Type Required Description
decoded_image torch.Tensor [B, 3, 384, 384] Yes VAE-decoded images, range [-1, 1]

Outputs

Name Type Description
output_images List[PIL.Image.Image] 1024×1024 RGB images ready for display or saving

Usage Examples

Full Post-Processing

decoded_image = vae.decode(z / vae.config.scaling_factor).sample

images = decoded_image.float().clip_(-1., 1.).permute(0, 2, 3, 1).cpu().numpy()
images = ((images + 1) / 2. * 255).astype(np.uint8)

output = [
    Image.fromarray(images[i]).resize((1024, 1024), Image.LANCZOS)
    for i in range(images.shape[0])
]
# output: list of 5 PIL Images at 1024x1024 resolution

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment