# Guide to Huggingface InstantID

## Introduction
InstantID is a cutting-edge tuning-free method for achieving ID-Preserving generation using only a single image. It supports various downstream tasks and is a state-of-the-art solution.

![Applications](https://huggingface.co/InstantX/InstantID/resolve/main/examples/applications.png)

## Usage
To use InstantID, you can either directly download the model from the repository or download it using a Python script.

Python Script:
“`python
from huggingface_hub import hf_hub_download

hf_hub_download(repo_id=”InstantX/InstantID”, filename=”ControlNetModel/config.json”, local_dir=”./checkpoints”)
hf_hub_download(repo_id=”InstantX/InstantID”, filename=”ControlNetModel/diffusion_pytorch_model.safetensors”, local_dir=”./checkpoints”)
hf_hub_download(repo_id=”InstantX/InstantID”, filename=”ip-adapter.bin”, local_dir=”./checkpoints”)
“`

For the face encoder, manual download is required via this [URL](https://github.com/deepinsight/insightface/issues/1896#issuecomment-1023867304) to `models/antelopev2`.

For further details and customization, you can refer to the GitHub repository.

## Usage Tips
Here are some tips for using InstantID effectively:
1. If you’re not satisfied with the similarity, try to increase the weight of “IdentityNet Strength” and “Adapter Strength”.
2. If you feel that the saturation is too high, first decrease the Adapter strength. If it is still too high, then decrease the IdentityNet strength.
3. If you find that text control is not as expected, decrease Adapter strength.
4. If you find that realistic style is not good enough, go for our Github repo and use a more realistic base model.

## Demos
Check out these demos of InstantID in action:

![Demo 1](https://huggingface.co/InstantX/InstantID/resolve/main/examples/0.png)

![Demo 2](https://huggingface.co/InstantX/InstantID/resolve/main/examples/1.png)

## Disclaimer
This project is released under the Apache License and aims to positively impact the field of AI-driven image generation. Users are granted the freedom to create images using this tool, but they are obligated to comply with local laws and utilize it responsibly. The developers will not assume any responsibility for potential misuse by users.

## Citation
If you use InstantID in your research, please cite the following:
“`bibtex
@article{wang2024instantid,
title={InstantID: Zero-shot Identity-Preserving Generation in Seconds},
author={Wang, Qixun and Bai, Xu and Wang, Haofan and Qin, Zekui and Chen, Anthony},
journal={arXiv preprint arXiv:2401.07519},
year={2024}
}
“`

For more details and updates, please refer to the official [GitHub repository](https://github.com/InstantID/InstantID).

Source link
# HuggingFace InstantID Tutorial

## Introduction

InstantID is a state-of-the-art tuning-free method for achieving ID-Preserving generation with just a single image. It supports various downstream tasks. The purpose of this tutorial is to provide guidance on the usage of InstantID.

![InstantID Image](https://huggingface.co/InstantX/InstantID/resolve/main/examples/applications.png)

## Usage

### Download the Model

You can directly download the model from the repository. Additionally, you can download the model using a Python script:

“`python
from huggingface_hub import hf_hub_download
hf_hub_download(repo_id=”InstantX/InstantID”, filename=”ControlNetModel/config.json”, local_dir=”./checkpoints”)
hf_hub_download(repo_id=”InstantX/InstantID”, filename=”ControlNetModel/diffusion_pytorch_model.safetensors”, local_dir=”./checkpoints”)
hf_hub_download(repo_id=”InstantX/InstantID”, filename=”ip-adapter.bin”, local_dir=”./checkpoints”)
“`

For the face encoder, you need to manually download it from [this URL](https://github.com/deepinsight/insightface/issues/1896#issuecomment-1023867304) to `models/antelopev2`.

### Customized Face Images

“`python
# Import necessary modules and libraries

# Load the image
image = load_image(“your-example.jpg”)

# Get face info
face_info = app.get(cv2.cvtColor(np.array(face_image), cv2.COLOR_RGB2BGR))
face_info = sorted(face_info, key=lambda x:(x[‘bbox’][2]-x[‘bbox’][0])*x[‘bbox’][3]-x[‘bbox’][1])[-1]
face_emb = face_info[’embedding’]
face_kps = draw_kps(face_image, face_info[‘kps’])

# Set custom parameters and generate the image
prompt = “analog film photo of a man. faded film, desaturated, 35mm photo, grainy, vignette, vintage, Kodachrome, Lomography, stained, highly detailed, found footage, masterpiece, best quality”
negative_prompt = “(lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured (lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch,deformed, mutated, cross-eyed, ugly, disfigured”

image = pipe(
prompt,
image_embeds=face_emb,
image=face_kps,
controlnet_conditioning_scale=0.8
).images[0]
“`

For more details, please refer to our [GitHub repository](https://github.com/InstantID/InstantID).

## Usage Tips
1. If you’re not satisfied with the similarity, try to increase the weight of “IdentityNet Strength” and “Adapter Strength”.
2. If you feel that the saturation is too high, first decrease the Adapter strength. If it is still too high, then decrease the IdentityNet strength.
3. If you find that text control is not as expected, decrease Adapter strength.
4. If you find that realistic style is not good enough, go to our GitHub repo and use a more realistic base model.

## Demos

![Demo Image 1](https://huggingface.co/InstantX/InstantID/resolve/main/examples/0.png)

![Demo Image 2](https://huggingface.co/InstantX/InstantID/resolve/main/examples/1.png)

## Disclaimer

This project is released under the Apache License and aims to positively impact the field of AI-driven image generation. Users are granted the freedom to create images using this tool, but they are obligated to comply with local laws and utilize it responsibly. The developers will not assume any responsibility for potential misuse by users.

## Citation

“`
@article{wang2024instantid,
title={InstantID: Zero-shot Identity-Preserving Generation in Seconds},
author={Wang, Qixun and Bai, Xu and Wang, Haofan and Qin, Zekui and Chen, Anthony},
journal={arXiv preprint arXiv:2401.07519},
year={2024}
}
“`

We hope you find this tutorial helpful in utilizing HuggingFace InstantID for your image generation needs. If you have any further questions, please refer to the official documentation or reach out to the HuggingFace community.



Introduction

InstantID is a new state-of-the-art tuning-free method to achieve ID-Preserving generation with only single image, supporting various downstream tasks.



Usage

You can directly download the model in this repository.
You also can download the model in python script:

from huggingface_hub import hf_hub_download
hf_hub_download(repo_id="InstantX/InstantID", filename="ControlNetModel/config.json", local_dir="./checkpoints")
hf_hub_download(repo_id="InstantX/InstantID", filename="ControlNetModel/diffusion_pytorch_model.safetensors", local_dir="./checkpoints")
hf_hub_download(repo_id="InstantX/InstantID", filename="ip-adapter.bin", local_dir="./checkpoints")

For face encoder, you need to manutally download via this URL to models/antelopev2.


import diffusers
from diffusers.utils import load_image
from diffusers.models import ControlNetModel

import cv2
import torch
import numpy as np
from PIL import Image

from insightface.app import FaceAnalysis
from pipeline_stable_diffusion_xl_instantid import StableDiffusionXLInstantIDPipeline, draw_kps


app = FaceAnalysis(name='antelopev2', root='./', providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
app.prepare(ctx_id=0, det_size=(640, 640))


face_adapter = f'./checkpoints/ip-adapter.bin'
controlnet_path = f'./checkpoints/ControlNetModel'


controlnet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=torch.float16)

pipe = StableDiffusionXLInstantIDPipeline.from_pretrained(
...     "stabilityai/stable-diffusion-xl-base-1.0", controlnet=controlnet, torch_dtype=torch.float16
... )
pipe.cuda()


pipe.load_ip_adapter_instantid(face_adapter)

Then, you can customized your own face images


image = load_image("your-example.jpg")


face_info = app.get(cv2.cvtColor(np.array(face_image), cv2.COLOR_RGB2BGR))
face_info = sorted(face_info, key=lambda x:(x['bbox'][2]-x['bbox'][0])*x['bbox'][3]-x['bbox'][1])[-1] 
face_emb = face_info['embedding']
face_kps = draw_kps(face_image, face_info['kps'])

pipe.set_ip_adapter_scale(0.8)

prompt = "analog film photo of a man. faded film, desaturated, 35mm photo, grainy, vignette, vintage, Kodachrome, Lomography, stained, highly detailed, found footage, masterpiece, best quality"
negative_prompt = "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured (lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch,deformed, mutated, cross-eyed, ugly, disfigured"


image = pipe(
...     prompt, image_embeds=face_emb, image=face_kps, controlnet_conditioning_scale=0.8
... ).images[0]

For more details, please follow the instructions in our GitHub repository.



Usage Tips

  1. If you’re not satisfied with the similarity, try to increase the weight of “IdentityNet Strength” and “Adapter Strength”.
  2. If you feel that the saturation is too high, first decrease the Adapter strength. If it is still too high, then decrease the IdentityNet strength.
  3. If you find that text control is not as expected, decrease Adapter strength.
  4. If you find that realistic style is not good enough, go for our Github repo and use a more realistic base model.



Demos



Disclaimer

This project is released under Apache License and aims to positively impact the field of AI-driven image generation. Users are granted the freedom to create images using this tool, but they are obligated to comply with local laws and utilize it responsibly. The developers will not assume any responsibility for potential misuse by users.



Citation

@article{wang2024instantid,
  title={InstantID: Zero-shot Identity-Preserving Generation in Seconds},
  author={Wang, Qixun and Bai, Xu and Wang, Haofan and Qin, Zekui and Chen, Anthony},
  journal={arXiv preprint arXiv:2401.07519},
  year={2024}
}

The

tag in HTML is a versatile element that can be used to group various content together and apply styling and behavior to that content as a unit. When used in combination with other HTML and CSS code, the

tag is a powerful tool for creating dynamic and interactive web interfaces. In the example provided, the

tag is used in conjunction with other HTML elements to structure and present information about a project called InstantID, which is a state-of-the-art identity-preserving image generation method.

One use case of the

tag is to align and display images in a centered position on a web page. In the example, the

is used to wrap around an image tag, causing the image to be centered on the page. This is a common use case for the

tag, as it allows for the creation of visually appealing layouts and designs.

Another use case for the

tag is to group and style related content together. In the given example, the

tag is used to group multiple images together under the “Demos” section. This allows the images to be treated as a single unit for styling and layout purposes, making it easier to manage and style multiple elements at once.

The

tag can also be used to define sections or containers within a web page. In the example, each section of content, such as “Introduction,” “Usage,” “Usage Tips,” etc., is wrapped in a

tag with a unique ID. This allows for easy navigation and styling of these content sections using CSS or JavaScript.

Furthermore, the

tag can be leveraged to create columns and grids on a web page. By using multiple

elements with appropriate styling, developers can create complex layouts that adapt to different screen sizes and devices.

In addition, the

tag can be used as a target for JavaScript events to create interactive behavior. By adding event listeners to

elements, developers can create interactive components such as buttons, sliders, or pop-up modals.

Overall, the

tag in HTML is a fundamental building block for structuring and designing web pages. It enables developers to create organized and visually appealing layouts, define sections of content, and implement interactive features, contributing to a rich and dynamic user experience on the web.

2024-01-23T11:49:16+01:00