Skip to content

Commit e4494bc

Browse files
Refine Readme for image2image and image2video. (#1890)
* Refine Readme for image2image and image2video. --------- Signed-off-by: Yao, Qing <qing.yao@intel.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d181899 commit e4494bc

4 files changed

Lines changed: 319 additions & 148 deletions

File tree

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Deploying Image-to-Image Service
2+
3+
This document provides a comprehensive guide to deploying the Image-to-Image microservice pipeline on Intel platforms.
4+
5+
This guide covers two deployment methods:
6+
7+
- [🚀 1. Quick Start with Docker Compose](#-1-quick-start-with-docker-compose): The recommended method for a fast and easy setup.
8+
- [🚀 2. Manual Step-by-Step Deployment (Advanced)](#-2-manual-step-by-step-deployment-advanced): For users who want to build and run the container individually.
9+
10+
## 🚀 1. Quick Start with Docker Compose
11+
12+
This method uses Docker Compose to start the service with a single command. It is the fastest and easiest way to get the service running.
13+
14+
### 1.1. Access the Code
15+
16+
Clone the repository and navigate to the deployment directory:
17+
18+
```bash
19+
git clone https://github.com/opea-project/GenAIComps.git
20+
cd GenAIComps/comps/image2image/deployment/docker_compose
21+
```
22+
23+
### 1.2. Set Hugging Face Token
24+
25+
Set your Hugging Face token as an environment variable. This is required to download the Stable Diffusion model.
26+
27+
```bash
28+
export HF_TOKEN=<your huggingface token>
29+
```
30+
31+
### 1.3. Deploy the Service
32+
33+
Choose the command corresponding to your target platform.
34+
35+
- **For Intel® Xeon® CPU:**
36+
37+
```bash
38+
docker compose -f compose.yaml up image2image -d
39+
```
40+
41+
- **For Intel® Gaudi® 2 HPU:**
42+
```bash
43+
docker compose -f compose.yaml up image2image-gaudi -d
44+
```
45+
46+
### 1.4. Validate the Service
47+
48+
Once the container is running, you can validate the service. **Note:** Run this command from the root of the `GenAIComps` repository.
49+
50+
```bash
51+
export ip_address=$(hostname -I | awk '{print $1}')
52+
curl http://${ip_address}:9389/v1/image2image -XPOST \
53+
-d '{"image": "https://huggingface.co/datasets/patrickvonplaten/images/resolve/main/aa_xl/000000009.png", "prompt":"a photo of an astronaut riding a horse on mars", "num_images_per_prompt":1}' \
54+
-H 'Content-Type: application/json'
55+
```
56+
57+
The expected output will be a JSON object containing the generated image data.
58+
59+
### 1.5. Clean Up the Deployment
60+
61+
To stop and remove the containers, run the following command from the `comps/image2image/deployment/docker_compose` directory:
62+
63+
```bash
64+
docker compose down
65+
```
66+
67+
---
68+
69+
## 🚀 2. Manual Step-by-Step Deployment (Advanced)
70+
71+
This section provides detailed instructions for building the Docker image and running the microservice container individually.
72+
73+
### 2.1. Clone the Repository
74+
75+
If you haven't already, clone the repository and navigate to the root directory:
76+
77+
```bash
78+
git clone https://github.com/opea-project/GenAIComps.git
79+
cd GenAIComps
80+
```
81+
82+
### 2.2. Build the Docker Image
83+
84+
- **For Intel® Xeon® CPU:**
85+
```bash
86+
docker build -t opea/image2image:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/image2image/src/Dockerfile .
87+
```
88+
- **For Intel® Gaudi® 2 HPU:**
89+
```bash
90+
docker build -t opea/image2image-gaudi:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/image2image/src/Dockerfile.intel_hpu .
91+
```
92+
93+
### 2.3. Configure Environment Variables
94+
95+
Set the necessary environment variables for the container.
96+
97+
- **For both Intel® Xeon® and Intel® Gaudi® 2 HPU:**
98+
99+
```bash
100+
export ip_address=$(hostname -I | awk '{print $1}')
101+
export HF_TOKEN=<your huggingface token>
102+
# SDXL is an example, you can use other compatible models.
103+
export MODEL=stabilityai/stable-diffusion-xl-refiner-1.0
104+
```
105+
106+
### 2.4. Run the Microservice Container
107+
108+
#### 2.4.1. Run Image-to-Image Microservice on Xeon
109+
110+
```bash
111+
docker run -d --name "image2image-service" --ipc=host -p 9389:9389 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e HF_TOKEN=$HF_TOKEN -e MODEL=$MODEL opea/image2image:latest
112+
```
113+
114+
#### 2.4.2. Run Image-to-Image Microservice on Gaudi
115+
116+
```bash
117+
docker run -d --name "image2image-gaudi-service" -p 9389:9389 --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e HF_TOKEN=$HF_TOKEN -e MODEL=$MODEL opea/image2image-gaudi:latest
118+
```
119+
120+
### 2.5. Validate the Service
121+
122+
After starting the container, test the service endpoint. Make sure you are in the root directory of the `GenAIComps` repository.
123+
124+
```bash
125+
# The ip_address variable should be set from step 2.3
126+
curl http://${ip_address}:9389/v1/image2image -XPOST \
127+
-d '{"image": "https://huggingface.co/datasets/patrickvonplaten/images/resolve/main/aa_xl/000000009.png", "prompt":"a photo of an astronaut riding a horse on mars", "num_images_per_prompt":1}' \
128+
-H 'Content-Type: application/json'
129+
```
130+
131+
You should see a successful response containing the generated image data.
132+
133+
### 2.6. Clean Up the Deployment
134+
135+
To stop and remove the container you started manually, use the `docker stop` and `docker rm` commands.
136+
137+
- **For Intel® Xeon® CPU:**
138+
139+
```bash
140+
docker stop image2image-service
141+
docker rm image2image-service
142+
```
143+
144+
- **For Intel® Gaudi® 2 HPU:**
145+
```bash
146+
docker stop image2image-gaudi-service
147+
docker rm image2image-gaudi-service
148+
```

comps/image2image/src/README.md

Lines changed: 18 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,31 @@
11
# Image-to-Image Microservice
22

3-
Image-to-Image is a task that generate image conditioning on the provided image and text. This microservice supports image-to-image task by using Stable Diffusion (SD) model.
3+
The Image-to-Image microservice generates an image based on a provided source image and a descriptive text prompt. This service utilizes a Stable Diffusion (SD) model to perform the image generation task. It takes a source image and text as input and produces a new, modified image as output.
44

5-
# 🚀1. Start Microservice with Python (Option 1)
5+
## Table of contents
66

7-
## 1.1 Install Requirements
7+
1. [Architecture](#architecture)
8+
2. [Deployment Options](#deployment-options)
9+
3. [Validated Configurations](#validated-configurations)
810

9-
```bash
10-
pip install -r requirements.txt
11-
```
11+
## Architecture
1212

13-
## 1.2 Start Image-to-Image Microservice
13+
The Image-to-Image service is a single microservice that exposes an API endpoint. It receives a request containing a source image URL and a text prompt, processes it using the Stable Diffusion model, and returns the generated image.
1414

15-
Select Stable Diffusion (SD) model and assign its name to a environment variable as below:
15+
- **Image-to-Image Server**: This microservice is the core engine for the image generation task. It can be deployed on both CPU and HPU.
1616

17-
```bash
18-
# SDXL
19-
export MODEL=stabilityai/stable-diffusion-xl-refiner-1.0
20-
```
17+
## Deployment Options
2118

22-
Set huggingface token:
19+
For detailed, step-by-step instructions on how to deploy the Image-to-Image microservice using Docker Compose on different Intel platforms, please refer to the deployment guide. The guide contains all necessary steps, including building images, configuring the environment, and running the service.
2320

24-
```bash
25-
export HF_TOKEN=<your huggingface token>
26-
```
21+
| Platform | Deployment Method | Link |
22+
| ----------------- | ----------------- | ---------------------------------------------------------- |
23+
| Intel Xeon/Gaudi2 | Docker Compose | [Deployment Guide](../deployment/docker_compose/README.md) |
2724

28-
Start the OPEA Microservice:
25+
## Validated Configurations
2926

30-
```bash
31-
python opea_image2image_microservice.py --bf16 --model_name_or_path $MODEL --token $HF_TOKEN
32-
```
27+
The following configurations have been validated for the Image-to-Image microservice.
3328

34-
# 🚀2. Start Microservice with Docker (Option 2)
35-
36-
## 2.1 Build Images
37-
38-
Select Stable Diffusion (SD) model and assign its name to a environment variable as below:
39-
40-
```bash
41-
# SDXL
42-
export MODEL=stabilityai/stable-diffusion-xl-refiner-1.0
43-
```
44-
45-
### 2.1.1 Image-to-Image Service Image on Xeon
46-
47-
Build image-to-image service image on Xeon with below command:
48-
49-
```bash
50-
cd ../..
51-
docker build -t opea/image2image:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/image2image/src/Dockerfile .
52-
```
53-
54-
### 2.1.2 Image-to-Image Service Image on Gaudi
55-
56-
Build image-to-image service image on Gaudi with below command:
57-
58-
```bash
59-
cd ../..
60-
docker build -t opea/image2image-gaudi:latest --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy -f comps/image2image/src/Dockerfile.intel_hpu .
61-
```
62-
63-
## 2.2 Start Image-to-Image Service with Docker
64-
65-
### 2.2.1 Start Image-to-Image Service on Xeon
66-
67-
Start image-to-image service on Xeon with below command:
68-
69-
```bash
70-
docker run --ipc=host -p 9389:9389 -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e HF_TOKEN=$HF_TOKEN -e MODEL=$MODEL opea/image2image:latest
71-
```
72-
73-
### 2.2.2 Start Image-to-Image Service on Gaudi
74-
75-
Start image-to-image service on Gaudi with below command:
76-
77-
```bash
78-
docker run -p 9389:9389 --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host -e http_proxy=$http_proxy -e https_proxy=$https_proxy -e HF_TOKEN=$HF_TOKEN -e MODEL=$MODEL opea/image2image-gaudi:latest
79-
```
80-
81-
# 🚀3. Start Image-to-Image with Docker Compose
82-
83-
Alternatively, you can also start the Image-to-Image microservice with Docker Compose.
84-
85-
- Xeon CPU
86-
87-
```bash
88-
cd comps/image2image/deployment/docker_compose
89-
docker compose -f compose.yaml up image2image -d
90-
```
91-
92-
- Gaudi2 HPU
93-
94-
```bash
95-
cd comps/image2image/deployment/docker_compose
96-
docker compose -f compose.yaml up image2image-gaudi -d
97-
```
98-
99-
# 4 Test Image-to-Image Service
100-
101-
```bash
102-
http_proxy="" curl http://localhost:9389/v1/image2image -XPOST -d '{"image": "https://huggingface.co/datasets/patrickvonplaten/images/resolve/main/aa_xl/000000009.png", "prompt":"a photo of an astronaut riding a horse on mars", "num_images_per_prompt":1}' -H 'Content-Type: application/json'
103-
```
29+
| **Deploy Method** | **Core Models** | **Platform** |
30+
| ----------------- | ---------------- | ----------------- |
31+
| Docker Compose | Stable Diffusion | Intel Xeon/Gaudi2 |

0 commit comments

Comments
 (0)