Instructions to use kevinwang676/MuseTalk1.5 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use kevinwang676/MuseTalk1.5 with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("kevinwang676/MuseTalk1.5", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +11 -0
- assets/BBOX_SHIFT.md +26 -0
- assets/demo/man/man.png +3 -0
- assets/demo/monalisa/monalisa.png +3 -0
- assets/demo/musk/musk.png +3 -0
- assets/demo/sit/sit.jpeg +0 -0
- assets/demo/sun1/sun.png +3 -0
- assets/demo/sun2/sun.png +3 -0
- assets/demo/video1/video1.png +3 -0
- assets/demo/yongen/yongen.jpeg +0 -0
- assets/figs/landmark_ref.png +0 -0
- assets/figs/musetalk_arc.jpg +3 -0
- configs/inference/realtime.yaml +10 -0
- configs/inference/test.yaml +10 -0
- data/audio/sun.wav +3 -0
- data/audio/yongen.wav +3 -0
- data/video/sun.mp4 +3 -0
- data/video/yongen.mp4 +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_4k_rb_v0.6.2/vmaf_4k_rb_v0.6.2.pkl +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_4k_rb_v0.6.2/vmaf_4k_rb_v0.6.2.pkl.0002.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0001.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0002.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0003.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0006.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0007.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0008.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0009.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0010.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0011.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0012.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0013.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0014.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0015.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0016.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0017.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0018.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0019.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0020.model +3 -0
- ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.model +3 -0
- models/dwpose/dw-ll_ucoco_384.pth +3 -0
- models/face-parse-bisent/79999_iter.pth +3 -0
- models/face-parse-bisent/resnet18-5c106cde.pth +3 -0
- models/musetalkV15/musetalk.json +36 -0
- models/sd-vae-ft-mse/diffusion_pytorch_model.bin +3 -0
- models/whisper/pytorch_model.bin +3 -0
- musetalk/models/unet.py +51 -0
- musetalk/models/vae.py +148 -0
- musetalk/utils/__init__.py +5 -0
- musetalk/utils/audio_processor.py +99 -0
.gitattributes
CHANGED
|
@@ -36,3 +36,14 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 36 |
ffmpeg-6.1-amd64-static/qt-faststart filter=lfs diff=lfs merge=lfs -text
|
| 37 |
ffmpeg-6.1-amd64-static/ffmpeg filter=lfs diff=lfs merge=lfs -text
|
| 38 |
ffmpeg-6.1-amd64-static/ffprobe filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
ffmpeg-6.1-amd64-static/qt-faststart filter=lfs diff=lfs merge=lfs -text
|
| 37 |
ffmpeg-6.1-amd64-static/ffmpeg filter=lfs diff=lfs merge=lfs -text
|
| 38 |
ffmpeg-6.1-amd64-static/ffprobe filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
assets/demo/musk/musk.png filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
assets/demo/monalisa/monalisa.png filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
assets/demo/video1/video1.png filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
assets/figs/musetalk_arc.jpg filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
assets/demo/sun1/sun.png filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
assets/demo/man/man.png filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
data/video/sun.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
assets/demo/sun2/sun.png filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
data/audio/yongen.wav filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
data/video/yongen.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
data/audio/sun.wav filter=lfs diff=lfs merge=lfs -text
|
assets/BBOX_SHIFT.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Why is there a "bbox_shift" parameter?
|
| 2 |
+
When processing training data, we utilize the combination of face detection results (bbox) and facial landmarks to determine the region of the head segmentation box. Specifically, we use the upper bound of the bbox as the upper boundary of the segmentation box, the maximum y value of the facial landmarks coordinates as the lower boundary of the segmentation box, and the minimum and maximum x values of the landmarks coordinates as the left and right boundaries of the segmentation box. By processing the dataset in this way, we can ensure the integrity of the face.
|
| 3 |
+
|
| 4 |
+
However, we have observed that the masked ratio on the face varies across different images due to the varying face shapes of subjects. Furthermore, we found that the upper-bound of the mask mainly lies close to the landmark28, landmark29 and landmark30 landmark points (as shown in Fig.1), which correspond to proportions of 15%, 63%, and 22% in the dataset, respectively.
|
| 5 |
+
|
| 6 |
+
During the inference process, we discover that as the upper-bound of the mask gets closer to the mouth (near landmark30), the audio features contribute more to lip movements. Conversely, as the upper-bound of the mask moves away from the mouth (near landmark28), the audio features contribute more to generating details of facial appearance. Hence, we define this characteristic as a parameter that can adjust the contribution of audio features to generating lip movements, which users can modify according to their specific needs in practical scenarios.
|
| 7 |
+
|
| 8 |
+

|
| 9 |
+
|
| 10 |
+
Fig.1. Facial landmarks
|
| 11 |
+
### Step 0.
|
| 12 |
+
Running with the default configuration to obtain the adjustable value range.
|
| 13 |
+
```
|
| 14 |
+
python -m scripts.inference --inference_config configs/inference/test.yaml
|
| 15 |
+
```
|
| 16 |
+
```
|
| 17 |
+
********************************************bbox_shift parameter adjustment**********************************************************
|
| 18 |
+
Total frame:「838」 Manually adjust range : [ -9~9 ] , the current value: 0
|
| 19 |
+
*************************************************************************************************************************************
|
| 20 |
+
```
|
| 21 |
+
### Step 1.
|
| 22 |
+
Re-run the script within the above range.
|
| 23 |
+
```
|
| 24 |
+
python -m scripts.inference --inference_config configs/inference/test.yaml --bbox_shift xx # where xx is in [-9, 9].
|
| 25 |
+
```
|
| 26 |
+
In our experimental observations, we found that positive values (moving towards the lower half) generally increase mouth openness, while negative values (moving towards the upper half) generally decrease mouth openness. However, it's important to note that this is not an absolute rule, and users may need to adjust the parameter according to their specific needs and the desired effect.
|
assets/demo/man/man.png
ADDED
|
Git LFS Details
|
assets/demo/monalisa/monalisa.png
ADDED
|
Git LFS Details
|
assets/demo/musk/musk.png
ADDED
|
Git LFS Details
|
assets/demo/sit/sit.jpeg
ADDED
|
assets/demo/sun1/sun.png
ADDED
|
Git LFS Details
|
assets/demo/sun2/sun.png
ADDED
|
Git LFS Details
|
assets/demo/video1/video1.png
ADDED
|
Git LFS Details
|
assets/demo/yongen/yongen.jpeg
ADDED
|
assets/figs/landmark_ref.png
ADDED
|
assets/figs/musetalk_arc.jpg
ADDED
|
Git LFS Details
|
configs/inference/realtime.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
avator_1:
|
| 2 |
+
preparation: False
|
| 3 |
+
bbox_shift: 5
|
| 4 |
+
video_path: "data/video/sun.mp4"
|
| 5 |
+
audio_clips:
|
| 6 |
+
audio_0: "data/audio/yongen.wav"
|
| 7 |
+
audio_1: "data/audio/sun.wav"
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
configs/inference/test.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
task_0:
|
| 2 |
+
video_path: "data/video/yongen.mp4"
|
| 3 |
+
audio_path: "data/audio/yongen.wav"
|
| 4 |
+
|
| 5 |
+
task_1:
|
| 6 |
+
video_path: "data/video/sun.mp4"
|
| 7 |
+
audio_path: "data/audio/sun.wav"
|
| 8 |
+
bbox_shift: -7
|
| 9 |
+
|
| 10 |
+
|
data/audio/sun.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3f163b0fe2f278504c15cab74cd37b879652749e2a8a69f7848ad32c847d8007
|
| 3 |
+
size 1983572
|
data/audio/yongen.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2b775c363c968428d1d6df4456495e4c11f00e3204d3082e51caff415ec0e2ba
|
| 3 |
+
size 1536078
|
data/video/sun.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9f240982090f4255a7589e3cd67b4219be7820f9eb9a7461fc915eb5f0c8e075
|
| 3 |
+
size 2217973
|
data/video/yongen.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1effa976d410571cd185554779d6d43a6ba636e0e3401385db1d607daa46441f
|
| 3 |
+
size 1870923
|
ffmpeg-6.1-amd64-static/model/vmaf_4k_rb_v0.6.2/vmaf_4k_rb_v0.6.2.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b367c22ef4d3369e6d609d81c96187cb6a7c23cf2b1203d580a072955487705b
|
| 3 |
+
size 1058
|
ffmpeg-6.1-amd64-static/model/vmaf_4k_rb_v0.6.2/vmaf_4k_rb_v0.6.2.pkl.0002.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3ede915cf8718a16cd85264fdd2f3bd8e6ff258c1d400eca95465a0af3602cba
|
| 3 |
+
size 21001
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:250e31405a914bd2c493a77d5aaa6046d2841f5d2b458f61debc5b380b18dd5a
|
| 3 |
+
size 1192
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0001.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3e7db1834c62e48e0da04e6c2671e7f19af77f3fd2afdd150cb59dd7083358aa
|
| 3 |
+
size 17041
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0002.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:03021ce7009424a7ae9e654baa8bf2cfe0b2dfd51051c13261c953c5cbe46f4d
|
| 3 |
+
size 17066
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0003.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fe82afada783967633870677ca367fb1e4564e46b25368254462abd1f277b1e4
|
| 3 |
+
size 16968
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0006.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0839e94f1d9c66125a4ee9481d6b8d2bff40979bd766637ab8db5fdba64a61ed
|
| 3 |
+
size 17260
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0007.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1f268b0f5eb5c1b3353c1821a1ad568c09ce07e40759a64a40db33363b8c96e5
|
| 3 |
+
size 17009
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0008.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:18542324d8dc41a3d16db980afae11944cae845a735f9527f5f0492f9ab760f0
|
| 3 |
+
size 16947
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0009.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3f090d7f6aa26b1a1065339e8441d24f4f7d310a201682b18369fe704e9386e6
|
| 3 |
+
size 17209
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0010.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:def124ee54e7367c1d6bced55456f3e48df5dab624446b06a07b912a8d8fd742
|
| 3 |
+
size 17128
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0011.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3268f5503e5a0e438642da8eb8c3cb0fca8848a1065e81381697448098c7e5f1
|
| 3 |
+
size 16977
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0012.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a911555c138a9d05c46b1196de0279b6aaa4dc910bafe0a7ab6eb469fdd26bbf
|
| 3 |
+
size 16910
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0013.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:691b42e87b4a7be454e2a2349b1894409c4c3c6d74d91f8d768c88e16a184f5a
|
| 3 |
+
size 16835
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0014.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b878982625f4149a8b15fba8fd79b5a8968a9334ccc9dc1a2b83f998ab761e0f
|
| 3 |
+
size 17169
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0015.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:19f39504d4b2f1309b4c76716a2cb701c4b1179f944ff272ce2b2c3c4c27e226
|
| 3 |
+
size 17039
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0016.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9762de7f3ad0b44acd8ff7cc89a762c5b700cfd0059ae303be2ae13d1180df1c
|
| 3 |
+
size 17276
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0017.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:df0b7fbce0a3a1f078b91d9a12295a1e33ff80d91ff3e0b4de2bdfc960370625
|
| 3 |
+
size 17077
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0018.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:15d6d809353a65f9d57b7962ebd73a68dba650b490f8a38c6d48d7bd26b97dbb
|
| 3 |
+
size 17371
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0019.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c54f2746647d4bd53acc49813ad6f519d7fafdd18820cbb81f8a1072cb840b1b
|
| 3 |
+
size 16947
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.0020.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cd5743c771d863fcb639512e64730e5b2c6ebc89e04766cbebe0c9201a0ce604
|
| 3 |
+
size 17065
|
ffmpeg-6.1-amd64-static/model/vmaf_rb_v0.6.3/vmaf_rb_v0.6.3.pkl.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0c82d6c3881936b9babddb0ecd6b1f6b012a1008a3023f4ffe6ea42e7792eab1
|
| 3 |
+
size 17004
|
models/dwpose/dw-ll_ucoco_384.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0d9408b13cd863c4e95a149dd31232f88f2a12aa6cf8964ed74d7d97748c7a07
|
| 3 |
+
size 406878486
|
models/face-parse-bisent/79999_iter.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:468e13ca13a9b43cc0881a9f99083a430e9c0a38abd935431d1c28ee94b26567
|
| 3 |
+
size 53289463
|
models/face-parse-bisent/resnet18-5c106cde.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5c106cde386e87d4033832f2996f5493238eda96ccf559d1d62760c4de0613f8
|
| 3 |
+
size 46827520
|
models/musetalkV15/musetalk.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_class_name": "UNet2DConditionModel",
|
| 3 |
+
"_diffusers_version": "0.6.0.dev0",
|
| 4 |
+
"act_fn": "silu",
|
| 5 |
+
"attention_head_dim": 8,
|
| 6 |
+
"block_out_channels": [
|
| 7 |
+
320,
|
| 8 |
+
640,
|
| 9 |
+
1280,
|
| 10 |
+
1280
|
| 11 |
+
],
|
| 12 |
+
"center_input_sample": false,
|
| 13 |
+
"cross_attention_dim": 384,
|
| 14 |
+
"down_block_types": [
|
| 15 |
+
"CrossAttnDownBlock2D",
|
| 16 |
+
"CrossAttnDownBlock2D",
|
| 17 |
+
"CrossAttnDownBlock2D",
|
| 18 |
+
"DownBlock2D"
|
| 19 |
+
],
|
| 20 |
+
"downsample_padding": 1,
|
| 21 |
+
"flip_sin_to_cos": true,
|
| 22 |
+
"freq_shift": 0,
|
| 23 |
+
"in_channels": 8,
|
| 24 |
+
"layers_per_block": 2,
|
| 25 |
+
"mid_block_scale_factor": 1,
|
| 26 |
+
"norm_eps": 1e-05,
|
| 27 |
+
"norm_num_groups": 32,
|
| 28 |
+
"out_channels": 4,
|
| 29 |
+
"sample_size": 64,
|
| 30 |
+
"up_block_types": [
|
| 31 |
+
"UpBlock2D",
|
| 32 |
+
"CrossAttnUpBlock2D",
|
| 33 |
+
"CrossAttnUpBlock2D",
|
| 34 |
+
"CrossAttnUpBlock2D"
|
| 35 |
+
]
|
| 36 |
+
}
|
models/sd-vae-ft-mse/diffusion_pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1b4889b6b1d4ce7ae320a02dedaeff1780ad77d415ea0d744b476155c6377ddc
|
| 3 |
+
size 334707217
|
models/whisper/pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9607f98a2b22d9e229ae43c52ecea79dcede9e0c5cfae67e8da6eda86d8aac1d
|
| 3 |
+
size 151095027
|
musetalk/models/unet.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
import math
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
from diffusers import UNet2DConditionModel
|
| 7 |
+
import sys
|
| 8 |
+
import time
|
| 9 |
+
import numpy as np
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
class PositionalEncoding(nn.Module):
|
| 13 |
+
def __init__(self, d_model=384, max_len=5000):
|
| 14 |
+
super(PositionalEncoding, self).__init__()
|
| 15 |
+
pe = torch.zeros(max_len, d_model)
|
| 16 |
+
position = torch.arange(0, max_len, dtype=torch.float).unsqueeze(1)
|
| 17 |
+
div_term = torch.exp(torch.arange(0, d_model, 2).float() * (-math.log(10000.0) / d_model))
|
| 18 |
+
pe[:, 0::2] = torch.sin(position * div_term)
|
| 19 |
+
pe[:, 1::2] = torch.cos(position * div_term)
|
| 20 |
+
pe = pe.unsqueeze(0)
|
| 21 |
+
self.register_buffer('pe', pe)
|
| 22 |
+
|
| 23 |
+
def forward(self, x):
|
| 24 |
+
b, seq_len, d_model = x.size()
|
| 25 |
+
pe = self.pe[:, :seq_len, :]
|
| 26 |
+
x = x + pe.to(x.device)
|
| 27 |
+
return x
|
| 28 |
+
|
| 29 |
+
class UNet():
|
| 30 |
+
def __init__(self,
|
| 31 |
+
unet_config,
|
| 32 |
+
model_path,
|
| 33 |
+
use_float16=False,
|
| 34 |
+
device=None
|
| 35 |
+
):
|
| 36 |
+
with open(unet_config, 'r') as f:
|
| 37 |
+
unet_config = json.load(f)
|
| 38 |
+
self.model = UNet2DConditionModel(**unet_config)
|
| 39 |
+
self.pe = PositionalEncoding(d_model=384)
|
| 40 |
+
if device != None:
|
| 41 |
+
self.device = device
|
| 42 |
+
else:
|
| 43 |
+
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 44 |
+
weights = torch.load(model_path) if torch.cuda.is_available() else torch.load(model_path, map_location=self.device)
|
| 45 |
+
self.model.load_state_dict(weights)
|
| 46 |
+
if use_float16:
|
| 47 |
+
self.model = self.model.half()
|
| 48 |
+
self.model.to(self.device)
|
| 49 |
+
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
unet = UNet()
|
musetalk/models/vae.py
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffusers import AutoencoderKL
|
| 2 |
+
import torch
|
| 3 |
+
import torchvision.transforms as transforms
|
| 4 |
+
import torch.nn.functional as F
|
| 5 |
+
import cv2
|
| 6 |
+
import numpy as np
|
| 7 |
+
from PIL import Image
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
class VAE():
|
| 11 |
+
"""
|
| 12 |
+
VAE (Variational Autoencoder) class for image processing.
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
def __init__(self, model_path="./models/sd-vae-ft-mse/", resized_img=256, use_float16=False):
|
| 16 |
+
"""
|
| 17 |
+
Initialize the VAE instance.
|
| 18 |
+
|
| 19 |
+
:param model_path: Path to the trained model.
|
| 20 |
+
:param resized_img: The size to which images are resized.
|
| 21 |
+
:param use_float16: Whether to use float16 precision.
|
| 22 |
+
"""
|
| 23 |
+
self.model_path = model_path
|
| 24 |
+
self.vae = AutoencoderKL.from_pretrained(self.model_path)
|
| 25 |
+
|
| 26 |
+
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 27 |
+
self.vae.to(self.device)
|
| 28 |
+
|
| 29 |
+
if use_float16:
|
| 30 |
+
self.vae = self.vae.half()
|
| 31 |
+
self._use_float16 = True
|
| 32 |
+
else:
|
| 33 |
+
self._use_float16 = False
|
| 34 |
+
|
| 35 |
+
self.scaling_factor = self.vae.config.scaling_factor
|
| 36 |
+
self.transform = transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
|
| 37 |
+
self._resized_img = resized_img
|
| 38 |
+
self._mask_tensor = self.get_mask_tensor()
|
| 39 |
+
|
| 40 |
+
def get_mask_tensor(self):
|
| 41 |
+
"""
|
| 42 |
+
Creates a mask tensor for image processing.
|
| 43 |
+
:return: A mask tensor.
|
| 44 |
+
"""
|
| 45 |
+
mask_tensor = torch.zeros((self._resized_img,self._resized_img))
|
| 46 |
+
mask_tensor[:self._resized_img//2,:] = 1
|
| 47 |
+
mask_tensor[mask_tensor< 0.5] = 0
|
| 48 |
+
mask_tensor[mask_tensor>= 0.5] = 1
|
| 49 |
+
return mask_tensor
|
| 50 |
+
|
| 51 |
+
def preprocess_img(self,img_name,half_mask=False):
|
| 52 |
+
"""
|
| 53 |
+
Preprocess an image for the VAE.
|
| 54 |
+
|
| 55 |
+
:param img_name: The image file path or a list of image file paths.
|
| 56 |
+
:param half_mask: Whether to apply a half mask to the image.
|
| 57 |
+
:return: A preprocessed image tensor.
|
| 58 |
+
"""
|
| 59 |
+
window = []
|
| 60 |
+
if isinstance(img_name, str):
|
| 61 |
+
window_fnames = [img_name]
|
| 62 |
+
for fname in window_fnames:
|
| 63 |
+
img = cv2.imread(fname)
|
| 64 |
+
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 65 |
+
img = cv2.resize(img, (self._resized_img, self._resized_img),
|
| 66 |
+
interpolation=cv2.INTER_LANCZOS4)
|
| 67 |
+
window.append(img)
|
| 68 |
+
else:
|
| 69 |
+
img = cv2.cvtColor(img_name, cv2.COLOR_BGR2RGB)
|
| 70 |
+
window.append(img)
|
| 71 |
+
|
| 72 |
+
x = np.asarray(window) / 255.
|
| 73 |
+
x = np.transpose(x, (3, 0, 1, 2))
|
| 74 |
+
x = torch.squeeze(torch.FloatTensor(x))
|
| 75 |
+
if half_mask:
|
| 76 |
+
x = x * (self._mask_tensor>0.5)
|
| 77 |
+
x = self.transform(x)
|
| 78 |
+
|
| 79 |
+
x = x.unsqueeze(0) # [1, 3, 256, 256] torch tensor
|
| 80 |
+
x = x.to(self.vae.device)
|
| 81 |
+
|
| 82 |
+
return x
|
| 83 |
+
|
| 84 |
+
def encode_latents(self,image):
|
| 85 |
+
"""
|
| 86 |
+
Encode an image into latent variables.
|
| 87 |
+
|
| 88 |
+
:param image: The image tensor to encode.
|
| 89 |
+
:return: The encoded latent variables.
|
| 90 |
+
"""
|
| 91 |
+
with torch.no_grad():
|
| 92 |
+
init_latent_dist = self.vae.encode(image.to(self.vae.dtype)).latent_dist
|
| 93 |
+
init_latents = self.scaling_factor * init_latent_dist.sample()
|
| 94 |
+
return init_latents
|
| 95 |
+
|
| 96 |
+
def decode_latents(self, latents):
|
| 97 |
+
"""
|
| 98 |
+
Decode latent variables back into an image.
|
| 99 |
+
:param latents: The latent variables to decode.
|
| 100 |
+
:return: A NumPy array representing the decoded image.
|
| 101 |
+
"""
|
| 102 |
+
latents = (1/ self.scaling_factor) * latents
|
| 103 |
+
image = self.vae.decode(latents.to(self.vae.dtype)).sample
|
| 104 |
+
image = (image / 2 + 0.5).clamp(0, 1)
|
| 105 |
+
image = image.detach().cpu().permute(0, 2, 3, 1).float().numpy()
|
| 106 |
+
image = (image * 255).round().astype("uint8")
|
| 107 |
+
image = image[...,::-1] # RGB to BGR
|
| 108 |
+
return image
|
| 109 |
+
|
| 110 |
+
def get_latents_for_unet(self,img):
|
| 111 |
+
"""
|
| 112 |
+
Prepare latent variables for a U-Net model.
|
| 113 |
+
:param img: The image to process.
|
| 114 |
+
:return: A concatenated tensor of latents for U-Net input.
|
| 115 |
+
"""
|
| 116 |
+
|
| 117 |
+
ref_image = self.preprocess_img(img,half_mask=True) # [1, 3, 256, 256] RGB, torch tensor
|
| 118 |
+
masked_latents = self.encode_latents(ref_image) # [1, 4, 32, 32], torch tensor
|
| 119 |
+
ref_image = self.preprocess_img(img,half_mask=False) # [1, 3, 256, 256] RGB, torch tensor
|
| 120 |
+
ref_latents = self.encode_latents(ref_image) # [1, 4, 32, 32], torch tensor
|
| 121 |
+
latent_model_input = torch.cat([masked_latents, ref_latents], dim=1)
|
| 122 |
+
return latent_model_input
|
| 123 |
+
|
| 124 |
+
if __name__ == "__main__":
|
| 125 |
+
vae_mode_path = "./models/sd-vae-ft-mse/"
|
| 126 |
+
vae = VAE(model_path = vae_mode_path,use_float16=False)
|
| 127 |
+
img_path = "./results/sun001_crop/00000.png"
|
| 128 |
+
|
| 129 |
+
crop_imgs_path = "./results/sun001_crop/"
|
| 130 |
+
latents_out_path = "./results/latents/"
|
| 131 |
+
if not os.path.exists(latents_out_path):
|
| 132 |
+
os.mkdir(latents_out_path)
|
| 133 |
+
|
| 134 |
+
files = os.listdir(crop_imgs_path)
|
| 135 |
+
files.sort()
|
| 136 |
+
files = [file for file in files if file.split(".")[-1] == "png"]
|
| 137 |
+
|
| 138 |
+
for file in files:
|
| 139 |
+
index = file.split(".")[0]
|
| 140 |
+
img_path = crop_imgs_path + file
|
| 141 |
+
latents = vae.get_latents_for_unet(img_path)
|
| 142 |
+
print(img_path,"latents",latents.size())
|
| 143 |
+
#torch.save(latents,os.path.join(latents_out_path,index+".pt"))
|
| 144 |
+
#reload_tensor = torch.load('tensor.pt')
|
| 145 |
+
#print(reload_tensor.size())
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
|
musetalk/utils/__init__.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from os.path import abspath, dirname
|
| 3 |
+
current_dir = dirname(abspath(__file__))
|
| 4 |
+
parent_dir = dirname(current_dir)
|
| 5 |
+
sys.path.append(parent_dir+'/utils')
|
musetalk/utils/audio_processor.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import math
|
| 3 |
+
import librosa
|
| 4 |
+
import numpy as np
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from einops import rearrange
|
| 8 |
+
from transformers import AutoFeatureExtractor
|
| 9 |
+
|
| 10 |
+
class AudioProcessor:
|
| 11 |
+
def __init__(self, feature_extractor_path="openai/whisper-tiny/"):
|
| 12 |
+
self.feature_extractor = AutoFeatureExtractor.from_pretrained(feature_extractor_path)
|
| 13 |
+
|
| 14 |
+
def get_audio_feature(self, wav_path, start_index=0):
|
| 15 |
+
if not os.path.exists(wav_path):
|
| 16 |
+
return None
|
| 17 |
+
librosa_output, sampling_rate = librosa.load(wav_path, sr=16000)
|
| 18 |
+
assert sampling_rate == 16000
|
| 19 |
+
# Split audio into 30s segments
|
| 20 |
+
segment_length = 30 * sampling_rate
|
| 21 |
+
segments = [librosa_output[i:i + segment_length] for i in range(0, len(librosa_output), segment_length)]
|
| 22 |
+
|
| 23 |
+
features = []
|
| 24 |
+
for segment in segments:
|
| 25 |
+
audio_feature = self.feature_extractor(
|
| 26 |
+
segment,
|
| 27 |
+
return_tensors="pt",
|
| 28 |
+
sampling_rate=sampling_rate
|
| 29 |
+
).input_features
|
| 30 |
+
features.append(audio_feature)
|
| 31 |
+
|
| 32 |
+
return features, len(librosa_output)
|
| 33 |
+
|
| 34 |
+
def get_whisper_chunk(
|
| 35 |
+
self,
|
| 36 |
+
whisper_input_features,
|
| 37 |
+
device,
|
| 38 |
+
weight_dtype,
|
| 39 |
+
whisper,
|
| 40 |
+
librosa_length,
|
| 41 |
+
fps=25,
|
| 42 |
+
audio_padding_length_left=2,
|
| 43 |
+
audio_padding_length_right=2,
|
| 44 |
+
):
|
| 45 |
+
audio_feature_length_per_frame = 2 * (audio_padding_length_left + audio_padding_length_right + 1)
|
| 46 |
+
whisper_feature = []
|
| 47 |
+
# Process multiple 30s mel input features
|
| 48 |
+
for input_feature in whisper_input_features:
|
| 49 |
+
audio_feats = whisper.encoder(input_feature.to(device), output_hidden_states=True).hidden_states
|
| 50 |
+
audio_feats = torch.stack(audio_feats, dim=2).to(weight_dtype)
|
| 51 |
+
whisper_feature.append(audio_feats)
|
| 52 |
+
|
| 53 |
+
whisper_feature = torch.cat(whisper_feature, dim=1)
|
| 54 |
+
# Trim the last segment to remove padding
|
| 55 |
+
sr = 16000
|
| 56 |
+
audio_fps = 50
|
| 57 |
+
fps = int(fps)
|
| 58 |
+
whisper_idx_multiplier = audio_fps / fps
|
| 59 |
+
num_frames = math.floor((librosa_length / sr)) * fps
|
| 60 |
+
actual_length = math.floor((librosa_length / sr)) * audio_fps
|
| 61 |
+
whisper_feature = whisper_feature[:,:actual_length,...]
|
| 62 |
+
|
| 63 |
+
# Calculate padding amount
|
| 64 |
+
padding_nums = math.floor(whisper_idx_multiplier)
|
| 65 |
+
# Add padding at start and end
|
| 66 |
+
whisper_feature = torch.cat([
|
| 67 |
+
torch.zeros_like(whisper_feature[:, :padding_nums * audio_padding_length_left]),
|
| 68 |
+
whisper_feature,
|
| 69 |
+
# Add extra padding to prevent out of bounds
|
| 70 |
+
torch.zeros_like(whisper_feature[:, :padding_nums * 3 * audio_padding_length_right])
|
| 71 |
+
], 1)
|
| 72 |
+
|
| 73 |
+
audio_prompts = []
|
| 74 |
+
for frame_index in range(num_frames):
|
| 75 |
+
try:
|
| 76 |
+
audio_index = math.floor(frame_index * whisper_idx_multiplier)
|
| 77 |
+
audio_clip = whisper_feature[:, audio_index: audio_index + audio_feature_length_per_frame]
|
| 78 |
+
assert audio_clip.shape[1] == audio_feature_length_per_frame
|
| 79 |
+
audio_prompts.append(audio_clip)
|
| 80 |
+
except Exception as e:
|
| 81 |
+
print(f"Error occurred: {e}")
|
| 82 |
+
print(f"whisper_feature.shape: {whisper_feature.shape}")
|
| 83 |
+
print(f"audio_clip.shape: {audio_clip.shape}")
|
| 84 |
+
print(f"num frames: {num_frames}, fps: {fps}, whisper_idx_multiplier: {whisper_idx_multiplier}")
|
| 85 |
+
print(f"frame_index: {frame_index}, audio_index: {audio_index}-{audio_index + audio_feature_length_per_frame}")
|
| 86 |
+
exit()
|
| 87 |
+
|
| 88 |
+
audio_prompts = torch.cat(audio_prompts, dim=0) # T, 10, 5, 384
|
| 89 |
+
audio_prompts = rearrange(audio_prompts, 'b c h w -> b (c h) w')
|
| 90 |
+
return audio_prompts
|
| 91 |
+
|
| 92 |
+
if __name__ == "__main__":
|
| 93 |
+
audio_processor = AudioProcessor()
|
| 94 |
+
wav_path = "./2.wav"
|
| 95 |
+
audio_feature, librosa_feature_length = audio_processor.get_audio_feature(wav_path)
|
| 96 |
+
print("Audio Feature shape:", audio_feature.shape)
|
| 97 |
+
print("librosa_feature_length:", librosa_feature_length)
|
| 98 |
+
|
| 99 |
+
|