How to use from the
Use from the
Diffusers library
pip install -U diffusers transformers accelerate
import torch
from diffusers import AutoPipelineForInpainting
from diffusers.utils import load_image

# switch to "mps" for apple devices
pipe = AutoPipelineForInpainting.from_pretrained("BiliSakura/RS-Painter-Diffusers", dtype=torch.float16, variant="fp16", device_map="cuda")

img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"

image = load_image(img_url).resize((1024, 1024))
mask_image = load_image(mask_url).resize((1024, 1024))

prompt = "a tiger sitting on a park bench"
generator = torch.Generator(device="cuda").manual_seed(0)

image = pipe(
  prompt=prompt,
  image=image,
  mask_image=mask_image,
  guidance_scale=8.0,
  num_inference_steps=20,  # steps between 15 and 30 work well for us
  strength=0.99,  # make sure to use `strength` below 1.0
  generator=generator,
).images[0]

RS-Painter-Diffusers

Tackling Few-Shot Segmentation in Remote Sensing via Inpainting Diffusion Model

Paper License

ICLR Machine Learning for Remote Sensing Workshop, 2025 (Best Paper Award)

Model Description

RS-Painter is an image-conditioned diffusion-based approach for creating diverse sets of novel-class samples for semantic segmentation in few-shot settings in the remote sensing domain. By ensuring semantic consistency using cosine similarity between the generated samples and the conditioning image, and using the Segment Anything Model (SAM) to obtain precise segmentation, this method can train off-the-shelf segmentation models with high-quality synthetic data, significantly improving performance in low-data scenarios.

This model is compatible with the Hugging Face diffusers library and can be used with StableDiffusionInpaintPipeline.

Quick Start

from diffusers import StableDiffusionInpaintPipeline
from PIL import Image

# Load pipeline
pipeline = StableDiffusionInpaintPipeline.from_pretrained(
    "BiliSakura/RS-Painter-Diffusers",
    safety_checker=None,
    requires_safety_checker=False,
)

# Load image and mask
image = Image.open("input_image.png").convert("RGB")
mask = Image.open("mask.png").convert("L")

# Generate
result = pipeline(
    prompt="a beautiful landscape",
    image=image,
    mask_image=mask,
    num_inference_steps=50,
)

# Save result
result.images[0].save("output.png")

Citation

If you use this model in your research, please cite:

@article{2025rspaint,
  title={Tackling Few-Shot Segmentation in Remote Sensing via Inpainting Diffusion Model},
  author={Immanuel, Steve Andreas and Cho, Woojin and Heo, Junhyuk and Kwon, Darongsae},
  journal={arXiv preprint arXiv:2503.03785},
  year={2025}
}
Downloads last month
1
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collection including BiliSakura/RS-Painter-Diffusers

Paper for BiliSakura/RS-Painter-Diffusers