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
智启未来,您的人工智能解决方案智库
简体中文