模型:
import base64
import requests
HF_TOKEN = 'hf_xxxxxxxxxxxxx'
API_ENDPOINT = 'https://xxxxxxxxxxx.us-east-1.aws.endpoints.huggingface.cloud'
def load_image(path):
try:
with open(path, 'rb') as file:
return file.read()
except FileNotFoundError as error:
print('Error reading image:', error)
def get_b64_image(path):
image_buffer = load_image(path)
if image_buffer:
return base64.b64encode(image_buffer).decode('utf-8')
def process_images(original_image_path, mask_image_path, result_path, prompt, width, height):
original_b64 = get_b64_image(original_image_path)
mask_b64 = get_b64_image(mask_image_path)
if not original_b64 or not mask_b64:
return
body = {
'inputs': prompt,
'image': original_b64,
'mask_image': mask_b64,
'width': width,
'height': height
}
headers = {
'Authorization': f'Bearer {HF_TOKEN}',
'Content-Type': 'application/json',
'Accept': 'image/png'
}
response = requests.post(
API_ENDPOINT,
json=body,
headers=headers
)
blob = response.content
save_image(blob, result_path)
def save_image(blob, file_path):
with open(file_path, 'wb') as file:
file.write(blob)
print('File saved successfully!')
if __name__ == '__main__':
original_image_path = 'images/original.png'
mask_image_path = 'images/mask.png'
result_path = 'images/result.png'
process_images(original_image_path, mask_image_path, result_path, 'cyberpunk mona lisa', 512, 768)
Controlnet v1.1于 lllyasviel/ControlNet-v1-1 由 Lvmin Zhang 发布。
该检查点是将 the original checkpoint 转换为漫射器的格式。它可以与稳定扩散(例如 runwayml/stable-diffusion-v1-5 )结合使用。
更多详细信息,请参阅 🧨 Diffusers docs 。
ControlNet是一种神经网络结构,用于通过添加额外的条件来控制扩散模型。
此检查点对应于在填充图像上调整的ControlNet。
开发者:Lvmin Zhang,Maneesh Agrawala
模型类型:基于扩散的文本到图像生成模型
语言:英语
许可证: The CreativeML OpenRAIL M license 是一个 Open RAIL M license ,根据 BigScience 和 the RAIL Initiative 在负责任的AI许可领域共同开展工作而改编的。另请参阅我们的许可证 the article about the BLOOM Open RAIL license 。
了解更多信息的资源: GitHub Repository , Paper 。
引用为:
@misc{zhang2023adding, title={Adding Conditional Control to Text-to-Image Diffusion Models}, author={Lvmin Zhang and Maneesh Agrawala}, year={2023}, eprint={2302.05543}, archivePrefix={arXiv}, primaryClass={cs.CV}}
Controlnet于 Adding Conditional Control to Text-to-Image Diffusion Models 由Lvmin Zhang,Maneesh Agrawala提出。
摘要如下:
我们提出了一种神经网络结构ControlNet,用于控制预训练的大规模扩散模型以支持附加输入条件。 ControlNet以端到端的方式学习任务特定条件,并且即使训练数据集很小(