jmanhype commited on
Commit
9bb0e80
·
1 Parent(s): 5ece241

Add complete implementation

Browse files
Files changed (4) hide show
  1. Dockerfile +45 -25
  2. README.md +8 -490
  3. app.py +92 -20
  4. requirements.txt +18 -3
Dockerfile CHANGED
@@ -1,49 +1,69 @@
1
  FROM nvidia/cuda:11.7.1-cudnn8-devel-ubuntu20.04
2
 
3
  ENV DEBIAN_FRONTEND=noninteractive
 
 
4
 
5
- # Add retry logic for apt-get
6
- RUN echo 'Acquire::Retries "3";' > /etc/apt/apt.conf.d/80-retries
7
-
8
- # Clean and update package lists
9
- RUN rm -rf /var/lib/apt/lists/* && \
10
- apt-get clean && \
11
- apt-get update --fix-missing
12
-
13
- # Install system dependencies with retry logic
14
- RUN apt-get install -y --no-install-recommends --fix-missing \
15
  git \
16
  python3-pip \
17
  python3-dev \
18
  ffmpeg \
19
  libsm6 \
20
  libxext6 \
 
21
  && rm -rf /var/lib/apt/lists/*
22
 
23
- # Set up a new user named "user" with user ID 1000
24
  RUN useradd -m -u 1000 user
 
 
 
 
 
 
25
  USER user
26
 
27
- # Set home to the user's home directory
28
- ENV HOME=/home/user \
29
- PATH=/home/user/.local/bin:$PATH
30
 
31
- # Set the working directory
32
  WORKDIR $HOME/app
33
 
34
- # Install dependencies
 
35
  RUN pip install --no-cache-dir -r requirements.txt
36
 
37
- # Copy the application code
38
- COPY --chown=user . .
 
 
 
 
39
 
40
- # Create data directory with correct permissions
41
- USER root
42
- RUN mkdir -p /data && chown -R user:user /data
43
- USER user
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
- # Expose the port
46
  EXPOSE 7860
47
 
48
- # Start the Gradio app
49
- CMD ["python", "app.py"]
 
1
  FROM nvidia/cuda:11.7.1-cudnn8-devel-ubuntu20.04
2
 
3
  ENV DEBIAN_FRONTEND=noninteractive
4
+ ENV HF_HUB_ENABLE_HF_TRANSFER=0
5
+ ENV HUGGINGFACE_HUB_CACHE=/data/huggingface
6
 
7
+ # Install system dependencies
8
+ RUN apt-get update && apt-get install -y --no-install-recommends \
 
 
 
 
 
 
 
 
9
  git \
10
  python3-pip \
11
  python3-dev \
12
  ffmpeg \
13
  libsm6 \
14
  libxext6 \
15
+ wget \
16
  && rm -rf /var/lib/apt/lists/*
17
 
18
+ # Set up a new user
19
  RUN useradd -m -u 1000 user
20
+
21
+ # Create directories and set permissions
22
+ RUN mkdir -p /data/huggingface /data/models && \
23
+ chown -R user:user /data
24
+
25
+ # Switch to user
26
  USER user
27
 
28
+ # Set environment variables
29
+ ENV HOME=/home/user
30
+ ENV PATH=/home/user/.local/bin:$PATH
31
 
32
+ # Set up workspace
33
  WORKDIR $HOME/app
34
 
35
+ # Install Python packages
36
+ COPY --chown=user:user requirements.txt .
37
  RUN pip install --no-cache-dir -r requirements.txt
38
 
39
+ # Install additional dependencies
40
+ RUN pip install --no-cache-dir openmim && \
41
+ mim install mmengine && \
42
+ mim install "mmcv>=2.0.1" && \
43
+ mim install "mmdet>=3.1.0" && \
44
+ mim install "mmpose>=1.1.0"
45
 
46
+ # Clone and set up MuseV
47
+ RUN git clone https://github.com/TMElyralab/MuseV.git && \
48
+ cd MuseV && \
49
+ git clone https://github.com/huggingface/diffusers.git && \
50
+ git clone https://github.com/patrickvonplaten/controlnet_aux.git && \
51
+ cd diffusers && pip install -e . && \
52
+ cd ../controlnet_aux && pip install -e .
53
+
54
+ # Set up Python path
55
+ ENV PYTHONPATH="${HOME}/app:${HOME}/app/MuseV:${HOME}/app/MuseV/MMCM:${HOME}/app/MuseV/diffusers/src:${HOME}/app/MuseV/controlnet_aux/src:${HOME}/app/MuseV/scripts/gradio"
56
+
57
+ # Copy application code
58
+ COPY --chown=user:user . .
59
+
60
+ # Debug information
61
+ RUN echo "Current directory:" && pwd && \
62
+ echo "Directory contents:" && ls -la && \
63
+ echo "MuseV directory contents:" && ls -la MuseV && \
64
+ echo "Gradio scripts directory contents:" && ls -la MuseV/scripts/gradio && \
65
+ echo "Python path:" && echo $PYTHONPATH
66
 
 
67
  EXPOSE 7860
68
 
69
+ CMD ["python", "-u", "app.py"]
 
README.md CHANGED
@@ -1,496 +1,14 @@
1
  ---
2
- title: MuseV
3
- emoji: 🎨
4
  colorFrom: blue
5
- colorTo: purple
6
- sdk: docker
7
- app_port: 7860
 
8
  pinned: false
9
  ---
10
 
11
- # MuseV [English](README.md) [中文](README-zh.md)
12
 
13
- <font size=5>MuseV: Infinite-length and High Fidelity Virtual Human Video Generation with Visual Conditioned Parallel Denoising
14
- </br>
15
- Zhiqiang Xia <sup>\*</sup>,
16
- Zhaokang Chen<sup>\*</sup>,
17
- Bin Wu<sup>†</sup>,
18
- Chao Li,
19
- Kwok-Wai Hung,
20
- Chao Zhan,
21
- Yingjie He,
22
- Wenjiang Zhou
23
- (<sup>*</sup>co-first author, <sup>†</sup>Corresponding Author, [email protected])
24
- </font>
25
-
26
- **[github](https://github.com/TMElyralab/MuseV)** **[huggingface](https://huggingface.co/TMElyralab/MuseV)** **[HuggingfaceSpace](https://huggingface.co/spaces/AnchorFake/MuseVDemo)** **[project](https://tmelyralab.github.io/MuseV_Page/)** **Technical report (comming soon)**
27
-
28
-
29
- We have setup **the world simulator vision since March 2023, believing diffusion models can simulate the world**. `MuseV` was a milestone achieved around **July 2023**. Amazed by the progress of Sora, we decided to opensource `MuseV`, hopefully it will benefit the community. Next we will move on to the promising diffusion+transformer scheme.
30
-
31
-
32
- Update: We have released <a href="https://github.com/TMElyralab/MuseTalk" style="font-size:24px; color:red;">MuseTalk</a>, a real-time high quality lip sync model, which can be applied with MuseV as a complete virtual human generation solution.
33
-
34
- # Overview
35
- `MuseV` is a diffusion-based virtual human video generation framework, which
36
- 1. supports **infinite length** generation using a novel **Visual Conditioned Parallel Denoising scheme**.
37
- 2. checkpoint available for virtual human video generation trained on human dataset.
38
- 3. supports Image2Video, Text2Image2Video, Video2Video.
39
- 4. compatible with the **Stable Diffusion ecosystem**, including `base_model`, `lora`, `controlnet`, etc.
40
- 5. supports multi reference image technology, including `IPAdapter`, `ReferenceOnly`, `ReferenceNet`, `IPAdapterFaceID`.
41
- 6. training codes (comming very soon).
42
-
43
- # Important bug fixes
44
- 1. `musev_referencenet_pose`: model_name of `unet`, `ip_adapter` of Command is not correct, please use `musev_referencenet_pose` instead of `musev_referencenet`.
45
-
46
- # News
47
- - [03/27/2024] release `MuseV` project and trained model `musev`, `muse_referencenet`.
48
- - [03/30/2024] add huggingface space gradio to generate video in gui
49
-
50
- ## Model
51
- ### Overview of model structure
52
- ![model_structure](./data/models/musev_structure.png)
53
- ### Parallel denoising
54
- ![parallel_denoise](./data//models/parallel_denoise.png)
55
-
56
- ## Cases
57
- All frames were generated directly from text2video model, without any post process.
58
- MoreCase is in **[project](https://tmelyralab.github.io/MuseV_Page/)**, including **1-2 minute video**.
59
-
60
- <!-- # TODO: // use youtu video link? -->
61
- Examples bellow can be accessed at `configs/tasks/example.yaml`
62
-
63
-
64
- ### Text/Image2Video
65
-
66
- #### Human
67
-
68
- <table class="center">
69
- <tr style="font-weight: bolder;text-align:center;">
70
- <td width="50%">image</td>
71
- <td width="45%">video </td>
72
- <td width="5%">prompt</td>
73
- </tr>
74
-
75
- <tr>
76
- <td>
77
- <img src=./data/images/yongen.jpeg width="400">
78
- </td>
79
- <td >
80
- <video src="https://github.com/TMElyralab/MuseV/assets/163980830/732cf1fd-25e7-494e-b462-969c9425d277" width="100" controls preload></video>
81
- </td>
82
- <td>(masterpiece, best quality, highres:1),(1boy, solo:1),(eye blinks:1.8),(head wave:1.3)
83
- </td>
84
- </tr>
85
-
86
- <tr>
87
- <td>
88
- <img src=./data/images/seaside4.jpeg width="400">
89
- </td>
90
- <td>
91
- <video src="https://github.com/TMElyralab/MuseV/assets/163980830/9b75a46c-f4e6-45ef-ad02-05729f091c8f" width="100" controls preload></video>
92
- </td>
93
- <td>
94
- (masterpiece, best quality, highres:1), peaceful beautiful sea scene
95
- </td>
96
- </tr>
97
- <tr>
98
- <td>
99
- <img src=./data/images/seaside_girl.jpeg width="400">
100
- </td>
101
- <td>
102
- <video src="https://github.com/TMElyralab/MuseV/assets/163980830/d0f3b401-09bf-4018-81c3-569ec24a4de9" width="100" controls preload></video>
103
- </td>
104
- <td>
105
- (masterpiece, best quality, highres:1), peaceful beautiful sea scene
106
- </td>
107
- </tr>
108
- <!-- guitar -->
109
- <tr>
110
- <td>
111
- <img src=./data/images/boy_play_guitar.jpeg width="400">
112
- </td>
113
- <td>
114
- <video src="https://github.com/TMElyralab/MuseV/assets/163980830/61bf955e-7161-44c8-a498-8811c4f4eb4f" width="100" controls preload></video>
115
- </td>
116
- <td>
117
- (masterpiece, best quality, highres:1), playing guitar
118
- </td>
119
- </tr>
120
- <tr>
121
- <td>
122
- <img src=./data/images/girl_play_guitar2.jpeg width="400">
123
- </td>
124
- <td>
125
- <video src="https://github.com/TMElyralab/MuseV/assets/163980830/40982aa7-9f6a-4e44-8ef6-3f185d284e6a" width="100" controls preload></video>
126
- </td>
127
- <td>
128
- (masterpiece, best quality, highres:1), playing guitar
129
- </td>
130
- </tr>
131
- <!-- famous people -->
132
- <tr>
133
- <td>
134
- <img src=./data/images/dufu.jpeg width="400">
135
- </td>
136
- <td>
137
- <video src="https://github.com/TMElyralab/MuseV/assets/163980830/28294baa-b996-420f-b1fb-046542adf87d" width="100" controls preload></video>
138
- </td>
139
- <td>
140
- (masterpiece, best quality, highres:1),(1man, solo:1),(eye blinks:1.8),(head wave:1.3),Chinese ink painting style
141
- </td>
142
- </tr>
143
-
144
- <tr>
145
- <td>
146
- <img src=./data/images/Mona_Lisa.jpg width="400">
147
- </td>
148
- <td>
149
- <video src="https://github.com/TMElyralab/MuseV/assets/163980830/1ce11da6-14c6-4dcd-b7f9-7a5f060d71fb" width="100" controls preload></video>
150
- </td>
151
- <td>
152
- (masterpiece, best quality, highres:1),(1girl, solo:1),(beautiful face,
153
- soft skin, costume:1),(eye blinks:{eye_blinks_factor}),(head wave:1.3)
154
- </td>
155
- </tr>
156
- </table >
157
-
158
- #### Scene
159
-
160
- <table class="center">
161
- <tr style="font-weight: bolder;text-align:center;">
162
- <td width="35%">image</td>
163
- <td width="50%">video</td>
164
- <td width="15%">prompt</td>
165
- </tr>
166
-
167
- <tr>
168
- <td>
169
- <img src=./data/images/waterfall4.jpeg width="400">
170
- </td>
171
- <td>
172
- <video src="https://github.com/TMElyralab/MuseV/assets/163980830/852daeb6-6b58-4931-81f9-0dddfa1b4ea5" width="100" controls preload></video>
173
- </td>
174
- <td>
175
- (masterpiece, best quality, highres:1), peaceful beautiful waterfall, an
176
- endless waterfall
177
- </td>
178
- </tr>
179
-
180
- <tr>
181
- <td>
182
- <img src=./data/images/seaside2.jpeg width="400">
183
- </td>
184
- <td>
185
- <video src="https://github.com/TMElyralab/MuseV/assets/163980830/4a4d527a-6203-411f-afe9-31c992d26816" width="100" controls preload></video>
186
- </td>
187
- <td>(masterpiece, best quality, highres:1), peaceful beautiful sea scene
188
- </td>
189
- </tr>
190
- </table >
191
-
192
- ### VideoMiddle2Video
193
-
194
- **pose2video**
195
- In `duffy` mode, pose of the vision condition frame is not aligned with the first frame of control video. `posealign` will solve the problem.
196
-
197
- <table class="center">
198
- <tr style="font-weight: bolder;text-align:center;">
199
- <td width="25%">image</td>
200
- <td width="65%">video</td>
201
- <td width="10%">prompt</td>
202
- </tr>
203
- <tr>
204
- <td>
205
- <img src=./data/images/spark_girl.png width="200">
206
- <img src=./data/images/cyber_girl.png width="200">
207
- </td>
208
- <td>
209
- <video src="https://github.com/TMElyralab/MuseV/assets/163980830/484cc69d-c316-4464-a55b-3df929780a8e" width="400" controls preload></video>
210
- </td>
211
- <td>
212
- (masterpiece, best quality, highres:1) , a girl is dancing, animation
213
- </td>
214
- </tr>
215
- <tr>
216
- <td>
217
- <img src=./data/images/duffy.png width="400">
218
- </td>
219
- <td>
220
- <video src="https://github.com/TMElyralab/MuseV/assets/163980830/c44682e6-aafc-4730-8fc1-72825c1bacf2" width="400" controls preload></video>
221
- </td>
222
- <td>
223
- (masterpiece, best quality, highres:1), is dancing, animation
224
- </td>
225
- </tr>
226
- </table >
227
-
228
- ### MuseTalk
229
- The character of talk, `Sun Xinying` is a supermodel KOL. You can follow her on [douyin](https://www.douyin.com/user/MS4wLjABAAAAWDThbMPN_6Xmm_JgXexbOii1K-httbu2APdG8DvDyM8).
230
-
231
- <table class="center">
232
- <tr style="font-weight: bolder;">
233
- <td width="35%">name</td>
234
- <td width="50%">video</td>
235
- </tr>
236
-
237
- <tr>
238
- <td>
239
- talk
240
- </td>
241
- <td>
242
- <video src="https://github.com/TMElyralab/MuseV/assets/163980830/951188d1-4731-4e7f-bf40-03cacba17f2f" width="100" controls preload></video>
243
- </td>
244
- <tr>
245
- <td>
246
- sing
247
- </td>
248
- <td>
249
- <video src="https://github.com/TMElyralab/MuseV/assets/163980830/50b8ffab-9307-4836-99e5-947e6ce7d112" width="100" controls preload></video>
250
- </td>
251
- </tr>
252
- </table >
253
-
254
-
255
- # TODO:
256
- - [ ] technical report (comming soon).
257
- - [ ] training codes.
258
- - [ ] release pretrained unet model, which is trained with controlnet、referencenet、IPAdapter, which is better on pose2video.
259
- - [ ] support diffusion transformer generation framework.
260
- - [ ] release `posealign` module
261
-
262
- # Quickstart
263
- Prepare python environment and install extra package like `diffusers`, `controlnet_aux`, `mmcm`.
264
-
265
- ## Third party integration
266
- Thanks for the third-party integration, which makes installation and use more convenient for everyone.
267
- We also hope you note that we have not verified, maintained, or updated third-party. Please refer to this project for specific results.
268
-
269
- ### [ComfyUI](https://github.com/chaojie/ComfyUI-MuseV)
270
- ### [One click integration package in windows](https://www.bilibili.com/video/BV1ux4y1v7pF/?vd_source=fe03b064abab17b79e22a692551405c3)
271
- netdisk:https://www.123pan.com/s/Pf5Yjv-Bb9W3.html
272
-
273
- code: glut
274
-
275
- ## Prepare environment
276
- You are recommended to use `docker` primarily to prepare python environment.
277
- ### prepare python env
278
- **Attention**: we only test with docker, there are maybe trouble with conda, or requirement. We will try to fix it. Use `docker` Please.
279
-
280
- #### Method 1: docker
281
- 1. pull docker image
282
- ```bash
283
- docker pull anchorxia/musev:latest
284
- ```
285
- 2. run docker
286
- ```bash
287
- docker run --gpus all -it --entrypoint /bin/bash anchorxia/musev:latest
288
- ```
289
- The default conda env is `musev`.
290
-
291
- #### Method 2: conda
292
- create conda environment from environment.yaml
293
- ```
294
- conda env create --name musev --file ./environment.yml
295
- ```
296
- #### Method 3: pip requirements
297
- ```
298
- pip install -r requirements.txt
299
- ```
300
- #### Prepare mmlab package
301
- if not use docker, should install mmlab package additionally.
302
- ```bash
303
- pip install --no-cache-dir -U openmim
304
- mim install mmengine
305
- mim install "mmcv>=2.0.1"
306
- mim install "mmdet>=3.1.0"
307
- mim install "mmpose>=1.1.0"
308
- ```
309
-
310
- ### Prepare custom package / modified package
311
- #### clone
312
- ```bash
313
- git clone --recursive https://github.com/TMElyralab/MuseV.git
314
- ```
315
- #### prepare PYTHONPATH
316
- ```bash
317
- current_dir=$(pwd)
318
- export PYTHONPATH=${PYTHONPATH}:${current_dir}/MuseV
319
- export PYTHONPATH=${PYTHONPATH}:${current_dir}/MuseV/MMCM
320
- export PYTHONPATH=${PYTHONPATH}:${current_dir}/MuseV/diffusers/src
321
- export PYTHONPATH=${PYTHONPATH}:${current_dir}/MuseV/controlnet_aux/src
322
- cd MuseV
323
- ```
324
-
325
- 1. `MMCM`: multi media, cross modal process package。
326
- 1. `diffusers`: modified diffusers package based on [diffusers](https://github.com/huggingface/diffusers)
327
- 1. `controlnet_aux`: modified based on [controlnet_aux](https://github.com/TMElyralab/controlnet_aux)
328
-
329
-
330
- ## Download models
331
- ```bash
332
- git clone https://huggingface.co/TMElyralab/MuseV ./checkpoints
333
- ```
334
- - `motion`: text2video model, trained on tiny `ucf101` and tiny `webvid` dataset, approximately 60K videos text pairs. GPU memory consumption testing on `resolution`$=512*512$, `time_size=12`.
335
- - `musev/unet`: only has and train `unet` motion module. `GPU memory consumption` $\approx 8G$.
336
- - `musev_referencenet`: train `unet` module, `referencenet`, `IPAdapter`. `GPU memory consumption` $\approx 12G$.
337
- - `unet`: `motion` module, which has `to_k`, `to_v` in `Attention` layer refer to `IPAdapter`
338
- - `referencenet`: similar to `AnimateAnyone`
339
- - `ip_adapter_image_proj.bin`: images clip emb project layer, refer to `IPAdapter`
340
- - `musev_referencenet_pose`: based on `musev_referencenet`, fix `referencenet`and `controlnet_pose`, train `unet motion` and `IPAdapter`. `GPU memory consumption` $\approx 12G$
341
- - `t2i/sd1.5`: text2image model, parameter are frozen when training motion module. Different `t2i` base_model has a significant impact.could be replaced with other t2i base.
342
- - `majicmixRealv6Fp16`: example, download from [majicmixRealv6Fp16](https://civitai.com/models/43331?modelVersionId=94640)
343
- - `fantasticmix_v10`: example, download from [fantasticmix_v10](https://civitai.com/models/22402?modelVersionId=26744)
344
- - `IP-Adapter/models`: download from [IPAdapter](https://huggingface.co/h94/IP-Adapter/tree/main)
345
- - `image_encoder`: vision clip model.
346
- - `ip-adapter_sd15.bin`: original IPAdapter model checkpoint.
347
- - `ip-adapter-faceid_sd15.bin`: original IPAdapter model checkpoint.
348
-
349
- ## Inference
350
-
351
- ### Prepare model_path
352
- Skip this step when run example task with example inference command.
353
- Set model path and abbreviation in config, to use abbreviation in inference script.
354
- - T2I SD:ref to `musev/configs/model/T2I_all_model.py`
355
- - Motion Unet: refer to `musev/configs/model/motion_model.py`
356
- - Task: refer to `musev/configs/tasks/example.yaml`
357
-
358
- ### musev_referencenet
359
- #### text2video
360
- ```bash
361
- python scripts/inference/text2video.py --sd_model_name majicmixRealv6Fp16 --unet_model_name musev_referencenet --referencenet_model_name musev_referencenet --ip_adapter_model_name musev_referencenet -test_data_path ./configs/tasks/example.yaml --output_dir ./output --n_batch 1 --target_datas yongen --vision_clip_extractor_class_name ImageClipVisionFeatureExtractor --vision_clip_model_path ./checkpoints/IP-Adapter/models/image_encoder --time_size 12 --fps 12
362
- ```
363
- **common parameters**:
364
- - `test_data_path`: task_path in yaml extention
365
- - `target_datas`: sep is `,`, sample subtasks if `name` in `test_data_path` is in `target_datas`.
366
- - `sd_model_cfg_path`: T2I sd models path, model config path or model path.
367
- - `sd_model_name`: sd model name, which use to choose full model path in sd_model_cfg_path. multi model names with sep =`,`, or `all`
368
- - `unet_model_cfg_path`: motion unet model config path or model path。
369
- - `unet_model_name`: unet model name, use to get model path in `unet_model_cfg_path`, and init unet class instance in `musev/models/unet_loader.py`. multi model names with sep=`,`, or `all`. If `unet_model_cfg_path` is model path, `unet_name` must be supported in `musev/models/unet_loader.py`
370
- - `time_size`: num_frames per diffusion denoise generation。default=`12`.
371
- - `n_batch`: generation numbers of shot, $total\_frames=n\_batch * time\_size + n\_viscond$, default=`1`。
372
- - `context_frames`: context_frames num. If `time_size` > `context_frame`,`time_size` window is split into many sub-windows for parallel denoising"。 default=`12`。
373
-
374
- **To generate long videos**, there two ways:
375
- 1. `visual conditioned parallel denoise`: set `n_batch=1`, `time_size` = all frames you want.
376
- 1. `traditional end-to-end`: set `time_size` = `context_frames` = frames of a shot (`12`), `context_overlap` = 0;
377
-
378
-
379
- **model parameters**:
380
- supports `referencenet`, `IPAdapter`, `IPAdapterFaceID`, `Facein`.
381
- - referencenet_model_name: `referencenet` model name.
382
- - ImageClipVisionFeatureExtractor: `ImageEmbExtractor` name, extractor vision clip emb used in `IPAdapter`.
383
- - vision_clip_model_path: `ImageClipVisionFeatureExtractor` model path.
384
- - ip_adapter_model_name: from `IPAdapter`, it's `ImagePromptEmbProj`, used with `ImageEmbExtractor`。
385
- - ip_adapter_face_model_name: `IPAdapterFaceID`, from `IPAdapter` to keep faceid,should set `face_image_path`。
386
-
387
- **Some parameters that affect the motion range and generation results**:
388
- - `video_guidance_scale`: Similar to text2image, control influence between cond and uncond,default=`3.5`
389
- - `use_condition_image`: Whether to use the given first frame for video generation, if not generate vision condition frames first. Default=`True`.
390
- - `redraw_condition_image`: Whether to redraw the given first frame image.
391
- - `video_negative_prompt`: Abbreviation of full `negative_prompt` in config path. default=`V2`.
392
-
393
-
394
- #### video2video
395
- `t2i` base_model has a significant impact. In this case, `fantasticmix_v10` performs better than `majicmixRealv6Fp16`.
396
- ```bash
397
- python scripts/inference/video2video.py --sd_model_name fantasticmix_v10 --unet_model_name musev_referencenet --referencenet_model_name musev_referencenet --ip_adapter_model_name musev_referencenet -test_data_path ./configs/tasks/example.yaml --vision_clip_extractor_class_name ImageClipVisionFeatureExtractor --vision_clip_model_path ./checkpoints/IP-Adapter/models/image_encoder --output_dir ./output --n_batch 1 --controlnet_name dwpose_body_hand --which2video "video_middle" --target_datas dance1 --fps 12 --time_size 12
398
- ```
399
- **import parameters**
400
-
401
- Most of the parameters are same as `musev_text2video`. Special parameters of `video2video` are:
402
- 1. need to set `video_path` as reference video in `test_data`. Now reference video supports `rgb video` and `controlnet_middle_video`。
403
- - `which2video`: whether `rgb` video influences initial noise, influence of `rgb` is stronger than of controlnet condition.
404
- - `controlnet_name`:whether to use `controlnet condition`, such as `dwpose,depth`.
405
- - `video_is_middle`: `video_path` is `rgb video` or `controlnet_middle_video`. Can be set for every `test_data` in test_data_path.
406
- - `video_has_condition`: whether condtion_images is aligned with the first frame of video_path. If Not, exrtact condition of `condition_images` firstly generate, and then align with concatation. set in `test_data`。
407
-
408
- all controlnet_names refer to [mmcm](https://github.com/TMElyralab/MMCM/blob/main/mmcm/vision/feature_extractor/controlnet.py#L513)
409
- ```python
410
- ['pose', 'pose_body', 'pose_hand', 'pose_face', 'pose_hand_body', 'pose_hand_face', 'dwpose', 'dwpose_face', 'dwpose_hand', 'dwpose_body', 'dwpose_body_hand', 'canny', 'tile', 'hed', 'hed_scribble', 'depth', 'pidi', 'normal_bae', 'lineart', 'lineart_anime', 'zoe', 'sam', 'mobile_sam', 'leres', 'content', 'face_detector']
411
- ```
412
-
413
- ### musev_referencenet_pose
414
- Only used for `pose2video`
415
- train based on `musev_referencenet`, fix `referencenet`, `pose-controlnet`, and `T2I`, train `motion` module and `IPAdapter`.
416
-
417
- `t2i` base_model has a significant impact. In this case, `fantasticmix_v10` performs better than `majicmixRealv6Fp16`.
418
-
419
- ```bash
420
- python scripts/inference/video2video.py --sd_model_name fantasticmix_v10 --unet_model_name musev_referencenet_pose --referencenet_model_name musev_referencenet --ip_adapter_model_name musev_referencenet_pose -test_data_path ./configs/tasks/example.yaml --vision_clip_extractor_class_name ImageClipVisionFeatureExtractor --vision_clip_model_path ./checkpoints/IP-Adapter/models/image_encoder --output_dir ./output --n_batch 1 --controlnet_name dwpose_body_hand --which2video "video_middle" --target_datas dance1 --fps 12 --time_size 12
421
- ```
422
-
423
- ### musev
424
- Only has motion module, no referencenet, requiring less gpu memory.
425
- #### text2video
426
- ```bash
427
- python scripts/inference/text2video.py --sd_model_name majicmixRealv6Fp16 --unet_model_name musev -test_data_path ./configs/tasks/example.yaml --output_dir ./output --n_batch 1 --target_datas yongen --time_size 12 --fps 12
428
- ```
429
- #### video2video
430
- ##### pose align
431
- ```bash
432
- python ./pose_align/pose_align.py --max_frame 200 --vidfn ./data/source_video/dance.mp4 --imgfn_refer ./data/images/man.jpg --outfn_ref_img_pose ./data/pose_align_results/ref_img_pose.jpg --outfn_align_pose_video ./data/pose_align_results/align_pose_video.mp4 --outfn ./data/pose_align_results/align_demo.mp4
433
- ```
434
- - `max_frame`: how many frames to align (count from the first frame)
435
- - `vidfn`:real dance video in rgb
436
- - `imgfn_refer`: refer image path
437
- - `outfn_ref_img_pose`: output path of the pose of the refer img
438
- - `outfn_align_pose_video`: output path of the aligned video of the refer img
439
- - `outfn`: output path of the alignment visualization
440
-
441
-
442
-
443
- https://github.com/TMElyralab/MuseV/assets/47803475/787d7193-ec69-43f4-a0e5-73986a808f51
444
-
445
-
446
-
447
-
448
- then you can use the aligned pose `outfn_align_pose_video` for pose guided generation. You may need to modify the example in the config file `./configs/tasks/example.yaml`
449
- ##### generation
450
- ```bash
451
- python scripts/inference/video2video.py --sd_model_name fantasticmix_v10 --unet_model_name musev -test_data_path ./configs/tasks/example.yaml --output_dir ./output --n_batch 1 --controlnet_name dwpose_body_hand --which2video "video_middle" --target_datas dance1 --fps 12 --time_size 12
452
- ```
453
-
454
- ### Gradio demo
455
- MuseV provides gradio script to generate a GUI in a local machine to generate video conveniently.
456
-
457
- ```bash
458
- cd scripts/gradio
459
- python app.py
460
- ```
461
-
462
-
463
- # Acknowledgements
464
-
465
- 1. MuseV has referred much to [TuneAVideo](https://github.com/showlab/Tune-A-Video), [diffusers](https://github.com/huggingface/diffusers), [Moore-AnimateAnyone](https://github.com/MooreThreads/Moore-AnimateAnyone/tree/master/src/pipelines), [animatediff](https://github.com/guoyww/AnimateDiff), [IP-Adapter](https://github.com/tencent-ailab/IP-Adapter), [AnimateAnyone](https://arxiv.org/abs/2311.17117), [VideoFusion](https://arxiv.org/abs/2303.08320), [insightface](https://github.com/deepinsight/insightface).
466
- 2. MuseV has been built on `ucf101` and `webvid` datasets.
467
-
468
- Thanks for open-sourcing!
469
-
470
- # Limitation
471
- There are still many limitations, including
472
-
473
- 1. Lack of generalization ability. Some visual condition image perform well, some perform bad. Some t2i pretraied model perform well, some perform bad.
474
- 1. Limited types of video generation and limited motion range, partly because of limited types of training data. The released `MuseV` has been trained on approximately 60K human text-video pairs with resolution `512*320`. `MuseV` has greater motion range while lower video quality at lower resolution. `MuseV` tends to generate less motion range with high video quality. Trained on larger, higher resolution, higher quality text-video dataset may make `MuseV` better.
475
- 1. Watermarks may appear because of `webvid`. A cleaner dataset without watermarks may solve this issue.
476
- 1. Limited types of long video generation. Visual Conditioned Parallel Denoise can solve accumulated error of video generation, but the current method is only suitable for relatively fixed camera scenes.
477
- 1. Undertrained referencenet and IP-Adapter, beacause of limited time and limited resources.
478
- 1. Understructured code. `MuseV` supports rich and dynamic features, but with complex and unrefacted codes. It takes time to familiarize.
479
-
480
-
481
- <!-- # Contribution 暂时不需要组织开源共建 -->
482
- # Citation
483
- ```bib
484
- @article{musev,
485
- title={MuseV: Infinite-length and High Fidelity Virtual Human Video Generation with Visual Conditioned Parallel Denoising},
486
- author={Xia, Zhiqiang and Chen, Zhaokang and Wu, Bin and Li, Chao and Hung, Kwok-Wai and Zhan, Chao and He, Yingjie and Zhou, Wenjiang},
487
- journal={arxiv},
488
- year={2024}
489
- }
490
- ```
491
- # Disclaimer/License
492
- 1. `code`: The code of MuseV is released under the MIT License. There is no limitation for both academic and commercial usage.
493
- 1. `model`: The trained model are available for non-commercial research purposes only.
494
- 1. `other opensource model`: Other open-source models used must comply with their license, such as `insightface`, `IP-Adapter`, `ft-mse-vae`, etc.
495
- 1. The testdata are collected from internet, which are available for non-commercial research purposes only.
496
- 1. `AIGC`: This project strives to impact the domain of AI-driven video generation positively. Users are granted the freedom to create videos using this tool, but they are expected to comply with local laws and utilize it responsibly. The developers do not assume any responsibility for potential misuse by users.
 
1
  ---
2
+ title: MuseV Demo
3
+ emoji: 🎬
4
  colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: gradio
7
+ sdk_version: "4.16.0"
8
+ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
+ # MuseV: Infinite-length and High Fidelity Virtual Human Video Generation
13
 
14
+ A Hugging Face Space for the MuseV project, which enables infinite-length and high fidelity virtual human video generation with visual conditioned parallel denoising.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py CHANGED
@@ -1,24 +1,96 @@
 
 
 
 
 
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- def process_video(video_path):
4
- # Initialize the pipeline
5
- # pipeline = MuseVPipeline()
6
-
7
- # Process the video
8
- # result = pipeline.process(video_path)
9
-
10
- # For now, just return the input video
11
- return video_path
12
-
13
- # Create the Gradio interface
14
- iface = gr.Interface(
15
- fn=process_video,
16
- inputs=gr.Video(label="Upload Video"),
17
- outputs=gr.Video(label="Processed Video"),
18
- title="MuseV - Video Processing",
19
- description="Upload a video to process with MuseV"
20
  )
21
 
22
- # Launch the interface
23
- if __name__ == "__main__":
24
- iface.launch(server_name="0.0.0.0", server_port=7860)
 
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import time
5
+ import sys
6
+ import PIL.Image
7
+ import numpy as np
8
  import gradio as gr
9
+ import spaces
10
+ import cuid
11
+
12
+ from huggingface_hub import snapshot_download
13
+
14
+ # Set up paths
15
+ ProjectDir = os.path.dirname(os.path.abspath(__file__))
16
+ CheckpointsDir = os.path.join(ProjectDir, "checkpoints")
17
+ MuseVDir = os.path.join(ProjectDir, "MuseV")
18
+ GradioScriptsDir = os.path.join(MuseVDir, "scripts", "gradio")
19
+
20
+ # Add the MuseV paths to sys.path
21
+ paths_to_add = [
22
+ GradioScriptsDir,
23
+ MuseVDir,
24
+ os.path.join(MuseVDir, "MMCM"),
25
+ os.path.join(MuseVDir, "diffusers", "src"),
26
+ os.path.join(MuseVDir, "controlnet_aux", "src"),
27
+ os.path.dirname(os.path.abspath(__file__))
28
+ ]
29
+
30
+ for path in paths_to_add:
31
+ if os.path.exists(path) and path not in sys.path:
32
+ sys.path.insert(0, path)
33
+ print(f"Added {path} to PYTHONPATH")
34
+
35
+ def download_model():
36
+ if not os.path.exists(CheckpointsDir):
37
+ print("Checkpoint Not Downloaded, start downloading...")
38
+ tic = time.time()
39
+ snapshot_download(
40
+ repo_id="TMElyralab/MuseV",
41
+ local_dir=CheckpointsDir,
42
+ max_workers=8,
43
+ )
44
+ toc = time.time()
45
+ print(f"download cost {toc-tic} seconds")
46
+ else:
47
+ print("Already download the model.")
48
+
49
+ print("Starting model download...")
50
+ download_model()
51
+ print("Model download complete.")
52
+
53
+ print("Setting up paths...")
54
+ for path in sys.path:
55
+ print(f"Path: {path}")
56
+
57
+ print("Attempting to import gradio modules...")
58
+ try:
59
+ from gradio_video2video import online_v2v_inference
60
+ print("Successfully imported video2video")
61
+ except Exception as e:
62
+ print(f"Error importing video2video: {str(e)}")
63
+ print(f"Current directory: {os.getcwd()}")
64
+ print(f"Directory contents: {os.listdir('.')}")
65
+ if os.path.exists(GradioScriptsDir):
66
+ print(f"Gradio scripts directory contents: {os.listdir(GradioScriptsDir)}")
67
+
68
+ try:
69
+ from gradio_text2video import online_t2v_inference
70
+ print("Successfully imported text2video")
71
+ except Exception as e:
72
+ print(f"Error importing text2video: {str(e)}")
73
+
74
+ ignore_video2video = False
75
+ max_image_edge = 1280
76
 
77
+ print("Setting up Gradio interface...")
78
+ demo = gr.Interface(
79
+ fn=online_t2v_inference,
80
+ inputs=[
81
+ gr.Textbox(label="Prompt"),
82
+ gr.Image(label="Reference Image"),
83
+ gr.Number(label="Seed", value=-1),
84
+ gr.Number(label="FPS", value=6),
85
+ gr.Number(label="Width", value=-1),
86
+ gr.Number(label="Height", value=-1),
87
+ gr.Number(label="Video Length", value=12),
88
+ gr.Number(label="Image Edge Ratio", value=1.0),
89
+ ],
90
+ outputs=gr.Video(),
91
+ title="MuseV Demo",
92
+ description="Generate videos from text and reference images"
 
93
  )
94
 
95
+ print("Launching Gradio interface...")
96
+ demo.queue().launch(server_name="0.0.0.0", server_port=7860)
 
requirements.txt CHANGED
@@ -1,4 +1,19 @@
1
- gradio==4.12
2
- spaces
3
  cuid
4
- huggingface_hub
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ gradio>=4.16.0
2
+ numpy
3
  cuid
4
+ spaces
5
+ huggingface_hub
6
+ openmim
7
+ mmengine
8
+ mmcv>=2.0.1
9
+ mmdet>=3.1.0
10
+ mmpose>=1.1.0
11
+ Pillow
12
+ torch
13
+ torchvision
14
+ diffusers
15
+ transformers
16
+ accelerate
17
+ safetensors
18
+ opencv-python-headless
19
+ moviepy