BRIA 2.3 ControlNet Inpainting
基於商業級授權數據集訓練的智能圖像修復模型,提供法律責任保障
下載量 25
發布時間 : 6/13/2024
模型概述
BRIA 2.3是一款基於用戶文本提示對圖像遮蔽區域進行智能填充的修復模型,支持對象移除、替換、添加、修改及圖像擴展功能
模型特點
商業法律保障
訓練數據完全合規,提供版權侵權、隱私侵犯及有害內容的完整法律責任覆蓋
極速修復
結合FAST-LORA技術,在A10 GPU上僅需1.6秒完成修復
多場景應用
支持對象移除、替換、添加、修改及圖像擴展等多種編輯需求
模型能力
圖像修復
對象移除
內容替換
圖像擴展
使用案例
圖像編輯
移除不需要的對象
從照片中移除不需要的人物或物體
生成自然無痕的修復效果
內容替換
替換圖像中的特定元素
保持圖像整體風格一致
創意設計
圖像擴展
擴展圖像邊界或填充缺失區域
生成符合原始圖像風格的擴展內容
🚀 BRIA 2.3 ControlNet Inpainting Fast
BRIA 2.3是一款專為商業用途打造的圖像修復模型,它基於大規模多源商業級許可數據集進行訓練,在保證圖像質量的同時,為商業使用提供了安全保障。該模型能有效避免版權和隱私侵權問題,以及有害內容的產生。它可以根據用戶提供的文本提示,填充圖像中的掩碼區域,適用於圖像中物體的移除、替換、添加和修改等多種場景,還具備圖像擴展能力。
🚀 快速開始
加入我們的 Discord社區,獲取更多信息、教程和工具,還能與其他用戶交流!
✨ 主要特性
- 全新特性:BRIA 2.3 ControlNet Inpainting 可以基於 BRIA 2.3 Text-to-Image 使用 Fast-LORA,實現極快的圖像修復,在 A10 GPU 上僅需 1.6 秒。
- 高質量與安全性:僅在最大的多源商業級許可數據集上進行訓練,保證最佳質量,同時確保商業使用安全。
- 法律責任保障:為版權和隱私侵權以及有害內容緩解提供全面的法律責任覆蓋。
- 廣泛應用場景:可用於圖像中物體的移除、替換、添加、修改以及圖像擴展等。
📦 安裝指南
下載
from huggingface_hub import hf_hub_download
import os
try:
local_dir = os.path.dirname(__file__)
except:
local_dir = '.'
hf_hub_download(repo_id="briaai/BRIA-2.3-ControlNet-Inpainting", filename='controlnet.py', local_dir=local_dir)
hf_hub_download(repo_id="briaai/BRIA-2.3-ControlNet-Inpainting", filename='config.json', local_dir=local_dir)
hf_hub_download(repo_id="briaai/BRIA-2.3-ControlNet-Inpainting", filename='image_processor.py', local_dir=local_dir)
hf_hub_download(repo_id="briaai/BRIA-2.3-ControlNet-Inpainting", filename='pipeline_controlnet_sd_xl.py', local_dir=local_dir)
💻 使用示例
基礎用法
from diffusers import (
AutoencoderKL,
LCMScheduler,
)
from pipeline_controlnet_sd_xl import StableDiffusionXLControlNetPipeline
from controlnet import ControlNetModel
import torch
import numpy as np
from PIL import Image
import requests
import PIL
from io import BytesIO
from torchvision import transforms
import os
def resize_image_to_retain_ratio(image):
pixel_number = 1024*1024
granularity_val = 8
ratio = image.size[0] / image.size[1]
width = int((pixel_number * ratio) ** 0.5)
width = width - (width % granularity_val)
height = int(pixel_number / width)
height = height - (height % granularity_val)
image = image.resize((width, height))
return image
def download_image(url):
response = requests.get(url)
return PIL.Image.open(BytesIO(response.content)).convert("RGB")
def get_masked_image(image, image_mask, width, height):
image_mask = image_mask # inpaint area is white
image_mask = image_mask.resize((width, height)) # object to remove is white (1)
image_mask_pil = image_mask
image = np.array(image.convert("RGB")).astype(np.float32) / 255.0
image_mask = np.array(image_mask_pil.convert("L")).astype(np.float32) / 255.0
assert image.shape[0:1] == image_mask.shape[0:1], "image and image_mask must have the same image size"
masked_image_to_present = image.copy()
masked_image_to_present[image_mask > 0.5] = (0.5,0.5,0.5) # set as masked pixel
image[image_mask > 0.5] = 0.5 # set as masked pixel - s.t. will be grey
image = Image.fromarray((image * 255.0).astype(np.uint8))
masked_image_to_present = Image.fromarray((masked_image_to_present * 255.0).astype(np.uint8))
return image, image_mask_pil, masked_image_to_present
image_transforms = transforms.Compose(
[
transforms.ToTensor(),
]
)
default_negative_prompt = "Logo,Watermark,Text,Ugly,Morbid,Extra fingers,Poorly drawn hands,Mutation,Blurry,Extra limbs,Gross proportions,Missing arms,Mutated hands,Long neck,Duplicate,Mutilated,Mutilated hands,Poorly drawn face,Deformed,Bad anatomy,Cloned face,Malformed limbs,Missing legs,Too many fingers"
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"
init_image = download_image(img_url).resize((1024, 1024))
mask_image = download_image(mask_url).resize((1024, 1024))
init_image = resize_image_to_retain_ratio(init_image)
width, height = init_image.size
mask_image = mask_image.convert("L").resize(init_image.size)
width, height = init_image.size
# Load, init model
controlnet = ControlNetModel().from_pretrained("briaai/BRIA-2.3-ControlNet-Inpainting", torch_dtype=torch.float16)
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
pipe = StableDiffusionXLControlNetPipeline.from_pretrained("briaai/BRIA-2.3", controlnet=controlnet.to(dtype=torch.float16), torch_dtype=torch.float16, vae=vae) #force_zeros_for_empty_prompt=False, # vae=vae)
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
pipe.load_lora_weights("briaai/BRIA-2.3-FAST-LORA")
pipe.fuse_lora()
pipe = pipe.to(device="cuda")
# pipe.enable_xformers_memory_efficient_attention()
generator = torch.Generator(device="cuda").manual_seed(123456)
vae = pipe.vae
masked_image, image_mask, masked_image_to_present = get_masked_image(init_image, mask_image, width, height)
masked_image_tensor = image_transforms(masked_image)
masked_image_tensor = (masked_image_tensor - 0.5) / 0.5
masked_image_tensor = masked_image_tensor.unsqueeze(0).to(device="cuda")
control_latents = vae.encode(
masked_image_tensor[:, :3, :, :].to(vae.dtype)
).latent_dist.sample()
control_latents = control_latents * vae.config.scaling_factor
image_mask = np.array(image_mask)[:,:]
mask_tensor = torch.tensor(image_mask, dtype=torch.float32)[None, ...]
# binarize the mask
mask_tensor = torch.where(mask_tensor > 128.0, 255.0, 0)
mask_tensor = mask_tensor / 255.0
mask_tensor = mask_tensor.to(device="cuda")
mask_resized = torch.nn.functional.interpolate(mask_tensor[None, ...], size=(control_latents.shape[2], control_latents.shape[3]), mode='nearest')
masked_image = torch.cat([control_latents, mask_resized], dim=1)
prompt = ""
gen_img = pipe(negative_prompt=default_negative_prompt, prompt=prompt,
controlnet_conditioning_scale=1.0,
num_inference_steps=12,
height=height, width=width,
image = masked_image, # control image
init_image = init_image,
mask_image = mask_tensor,
guidance_scale = 1.2,
generator=generator).images[0]
display(gen_img)
📚 詳細文檔
模型描述
屬性 | 詳情 |
---|---|
開發者 | BRIA AI |
模型類型 | 潛在擴散圖像到圖像模型 |
許可證 | bria-2.3 修復許可條款和條件,使用和訪問該模型需要購買許可證。 |
模型描述 | BRIA 2.3 修復模型僅在專業級許可數據集上進行訓練,專為商業用途設計,並提供全面的法律責任覆蓋。 |
更多信息資源 | BRIA AI |
獲取源代碼和預訓練模型
如果您對 BRIA 2.3 修復模型感興趣,可以購買使用許可。購買 BRIA 2.3 修復模型的訪問權限可確保版稅管理和商業使用的完全責任。
如果您是初創企業或學生,我們鼓勵您申請我們的專業學術和 初創企業計劃 以獲取訪問權限。這些計劃旨在通過我們的前沿技術支持新興企業和學術研究。
通過提交上述表格,您同意 BRIA 的 隱私政策 和 條款與條件。
📄 許可證
本模型使用 bria-2.3 inpainting Licensing terms & conditions 許可證。模型權重需購買商業許可證才能獲取。請填寫以下表格,我們會與您聯繫。
Stable Diffusion V1 5
Openrail
穩定擴散是一種潛在的文本到圖像擴散模型,能夠根據任何文本輸入生成逼真的圖像。
圖像生成
S
stable-diffusion-v1-5
3.7M
518
Stable Diffusion Inpainting
Openrail
基於穩定擴散的文本到圖像生成模型,具備圖像修復能力
圖像生成
S
stable-diffusion-v1-5
3.3M
56
Stable Diffusion Xl Base 1.0
SDXL 1.0是基於擴散的文本生成圖像模型,採用專家集成的潛在擴散流程,支持高分辨率圖像生成
圖像生成
S
stabilityai
2.4M
6,545
Stable Diffusion V1 4
Openrail
穩定擴散是一種潛在文本到圖像擴散模型,能夠根據任意文本輸入生成逼真圖像。
圖像生成
S
CompVis
1.7M
6,778
Stable Diffusion Xl Refiner 1.0
SD-XL 1.0優化器模型是Stability AI開發的圖像生成模型,專為提升SDXL基礎模型生成的圖像質量而設計,特別擅長最終去噪步驟處理。
圖像生成
S
stabilityai
1.1M
1,882
Stable Diffusion 2 1
基於擴散的文本生成圖像模型,支持通過文本提示生成和修改圖像
圖像生成
S
stabilityai
948.75k
3,966
Stable Diffusion Xl 1.0 Inpainting 0.1
基於Stable Diffusion XL的潛在文本到圖像擴散模型,具備通過遮罩進行圖像修復的功能
圖像生成
S
diffusers
673.14k
334
Stable Diffusion 2 Base
基於擴散的文生圖模型,可根據文本提示生成高質量圖像
圖像生成
S
stabilityai
613.60k
349
Playground V2.5 1024px Aesthetic
其他
開源文生圖模型,能生成1024x1024分辨率及多種縱橫比的美學圖像,在美學質量上處於開源領域領先地位。
圖像生成
P
playgroundai
554.94k
723
Sd Turbo
SD-Turbo是一款高速文本生成圖像模型,僅需單次網絡推理即可根據文本提示生成逼真圖像。該模型作為研究原型發佈,旨在探索小型蒸餾文本生成圖像模型。
圖像生成
S
stabilityai
502.82k
380
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98