Commit
·
3c068de
1
Parent(s):
838ac2e
Update parquet files (step 124 of 249)
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- spaces/1acneusushi/gradio-2dmoleculeeditor/data/Adobe Illustrator CS6 on Windows 10 - The Ultimate Guide for Vector Graphics Lovers.md +0 -33
- spaces/1acneusushi/gradio-2dmoleculeeditor/data/CorelDRAW 2022 64 Bit Full Crack How to Download and Install It for Free.md +0 -35
- spaces/1gistliPinn/ChatGPT4/Examples/D16 Devastor 1.0-VST PC Serial Key.md +0 -30
- spaces/1line/AutoGPT/autogpt/permanent_memory/sqlite3_store.py +0 -123
- spaces/232labs/VToonify/vtoonify/model/stylegan/op_gpu/fused_act.py +0 -119
- spaces/44ov41za8i/FreeVC/modules.py +0 -342
- spaces/AI-Hobbyist/Hoyo-RVC/app.py +0 -506
- spaces/AIGC-Audio/AudioGPT/NeuralSeq/modules/GenerSpeech/task/dataset.py +0 -193
- spaces/AIGC-Audio/AudioGPT/NeuralSeq/modules/diffsinger_midi/fs2.py +0 -119
- spaces/AIGC-Audio/AudioGPT/text_to_audio/Make_An_Audio/ldm/modules/discriminator/multi_window_disc.py +0 -196
- spaces/AILab-CVC/EvalCrafter/constants.py +0 -47
- spaces/AIZero2Hero4Health/5-ImageToLineDrawing-GR/README.md +0 -12
- spaces/AchyuthGamer/OpenGPT-Chat-UI/src/routes/LocalDB.ts +0 -173
- spaces/AchyuthGamer/OpenGPT/g4f/Provider/AItianhu.py +0 -77
- spaces/Adapter/T2I-Adapter/ldm/modules/extra_condition/midas/__init__.py +0 -0
- spaces/Akmyradov/TurkmenTTSweSTT/tts.py +0 -173
- spaces/Al-Chan/Vits_League_of_Legends_Yuumi_TTS/text/korean.py +0 -210
- spaces/Alpaca233/SadTalker/src/utils/hparams.py +0 -160
- spaces/Amrrs/DragGan-Inversion/PTI/training/projectors/__init__.py +0 -0
- spaces/Androidonnxfork/CivitAi-to-Diffusers/diffusers/examples/research_projects/onnxruntime/text_to_image/train_text_to_image.py +0 -965
- spaces/Androidonnxfork/CivitAi-to-Diffusers/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py +0 -1102
- spaces/Androidonnxfork/CivitAi-to-Diffusers/diffusers/src/diffusers/pipelines/stable_diffusion/stable_unclip_image_normalizer.py +0 -57
- spaces/Androidonnxfork/CivitAi-to-Diffusers/diffusers/tests/pipelines/ddpm/__init__.py +0 -0
- spaces/Anonymous-sub/Rerender/ControlNet/annotator/uniformer/mmcv/ops/voxelize.py +0 -132
- spaces/AnticPan/Clothes2Human/util.py +0 -25
- spaces/Arnaudding001/FrenchTranslationAI/app.py +0 -29
- spaces/Ataturk-Chatbot/HuggingFaceChat/venv/lib/python3.11/site-packages/setuptools/_vendor/pyparsing/util.py +0 -235
- spaces/Bart92/RVC_HF/lib/uvr5_pack/lib_v5/layers_new.py +0 -125
- spaces/Benson/text-generation/Examples/Descargar Cabra Simulador Mod Apk.md +0 -82
- spaces/BetterAPI/BetterChat/src/styles/highlight-js.css +0 -1
- spaces/BetterAPI/BetterChat_new/src/lib/utils/trimPrefix.ts +0 -6
- spaces/Big-Web/MMSD/env/Lib/site-packages/setuptools/_distutils/bcppcompiler.py +0 -408
- spaces/BraydenMoore/MARCI-NFL-Betting/update_data.bat +0 -11
- spaces/CALM/Dashboard/streamlit_observable/frontend/src/streamlit/StreamlitReact.tsx +0 -150
- spaces/CVPR/Dual-Key_Backdoor_Attacks/weight_analysis/wt_hist_classifier.py +0 -158
- spaces/CVPR/LIVE/thrust/thrust/system/cuda/detail/copy.h +0 -198
- spaces/CVPR/LIVE/thrust/thrust/system/cuda/detail/remove.h +0 -134
- spaces/CVPR/WALT/mmdet/models/dense_heads/base_dense_head.py +0 -59
- spaces/CVPR/WALT/mmdet/utils/optimizer.py +0 -33
- spaces/Caoyunkang/Segment-Any-Anomaly/GroundingDINO/groundingdino/models/GroundingDINO/fuse_modules.py +0 -297
- spaces/Caoyunkang/Segment-Any-Anomaly/README.md +0 -13
- spaces/CikeyQI/meme-api/meme_generator/memes/capoo_say/__init__.py +0 -67
- spaces/Clebersla/RVC_V2_Huggingface_Version/app.py +0 -2090
- spaces/CofAI/chat.b4/client/js/icons.js +0 -1
- spaces/DQChoi/gpt-demo/venv/lib/python3.11/site-packages/fontTools/otlLib/__init__.py +0 -1
- spaces/DQChoi/gpt-demo/venv/lib/python3.11/site-packages/gradio/templates/frontend/assets/index-322e8a8e.css +0 -1
- spaces/DQChoi/gpt-demo/venv/lib/python3.11/site-packages/gradio/themes/utils/sizes.py +0 -132
- spaces/Danielzero/GPT3.5/readme/README_en.md +0 -127
- spaces/DragGan/DragGan-Inversion/PTI/models/e4e/encoders/__init__.py +0 -0
- spaces/DragGan/DragGan-Inversion/stylegan_human/stylemixing_video.py +0 -167
spaces/1acneusushi/gradio-2dmoleculeeditor/data/Adobe Illustrator CS6 on Windows 10 - The Ultimate Guide for Vector Graphics Lovers.md
DELETED
@@ -1,33 +0,0 @@
|
|
1 |
-
|
2 |
-
<h1>How to Download and Install Adobe Illustrator CS6 on Windows 10</h1>
|
3 |
-
<p>Adobe Illustrator CS6 is a powerful vector graphics software that lets you create logos, icons, drawings, typography, and illustrations for print, web, video, and mobile. However, Adobe Illustrator CS6 is not compatible with Windows 10 by default, and you may encounter some issues when trying to run it on your PC. In this article, we will show you how to download and install Adobe Illustrator CS6 on Windows 10, using a simple workaround that will make it work smoothly and without errors.</p>
|
4 |
-
<h2>adobe illustrator cs6 windows 10</h2><br /><p><b><b>Download</b> ✯ <a href="https://byltly.com/2uKyMb">https://byltly.com/2uKyMb</a></b></p><br /><br />
|
5 |
-
<h2>Step 1: Download Adobe Illustrator CS6</h2>
|
6 |
-
<p>The first step is to download the setup file of Adobe Illustrator CS6 from a reliable source. You can use the link below to get the full version of Adobe Illustrator CS6. This file is about 1.8 GB in size and it is compatible with both 32-bit and 64-bit Windows operating systems.</p>
|
7 |
-
<p><a href="https://www.techspot.com/downloads/4951-adobe-illustrator.html">Adobe Illustrator CS6 Download | TechSpot</a></p>
|
8 |
-
<h2>Step 2: Extract the Setup File</h2>
|
9 |
-
<p>After downloading the setup file, you need to extract it using a software like WinRAR or 7-Zip. The setup file is compressed in a ZIP format, so you need to right-click on it and select "Extract Here" or "Extract to Adobe_Illustrator_CS6" option. This will create a folder with the same name as the setup file, containing all the files needed for installation.</p>
|
10 |
-
<h2>Step 3: Run the Setup File</h2>
|
11 |
-
<p>Now, you need to run the setup file to start the installation process. To do this, open the extracted folder and double-click on the file named "Set-up.exe". This will launch the Adobe Illustrator CS6 installer, which will guide you through the steps of installation. You can choose the language, destination folder, and components that you want to install. You can also customize the installation by clicking on the "Advanced Options" button.</p>
|
12 |
-
<h2>Step 4: Enter the Serial Key</h2>
|
13 |
-
<p>Before you can complete the installation, you need to enter a valid serial key for Adobe Illustrator CS6. This is a 24-digit code that will activate your software and allow you to use all its features. However, finding a working serial key for Adobe Illustrator CS6 can be difficult, as most of them are already used or blocked by Adobe. Therefore, we recommend you to use one of the following serial keys that we have tested and verified:</p>
|
14 |
-
<p></p>
|
15 |
-
<ul>
|
16 |
-
<li>1034-1003-4400-0000-1115-2040</li>
|
17 |
-
<li>1034-1062-3461-4253-6686-9474</li>
|
18 |
-
<li>1034-1485-7140-0115-5067-3378</li>
|
19 |
-
<li>1034-1667-4045-7796-9618-3006</li>
|
20 |
-
<li>1034-1844-2215-7629-9828-5417</li>
|
21 |
-
</ul>
|
22 |
-
<p>You can copy and paste any of these serial keys into the installer when prompted. Make sure you enter them correctly and without any spaces. After entering the serial key, click on "Next" to continue.</p>
|
23 |
-
<h2>Step 5: Finish the Installation</h2>
|
24 |
-
<p>The final step is to finish the installation by following the instructions on the screen. You may need to restart your computer after the installation is complete. Once you do that, you can launch Adobe Illustrator CS6 from your desktop or start menu and enjoy creating vector graphics.</p>
|
25 |
-
<h2>Step 6: Apply the Compatibility Mode</h2>
|
26 |
-
<p>The last step is to apply a compatibility mode for Adobe Illustrator CS6, which will make it run smoothly on Windows 10 without any errors or crashes. To do this, follow these steps:</p>
|
27 |
-
<ol>
|
28 |
-
<li>Right-click on the Adobe Illustrator CS6 shortcut on your desktop or start menu and select "Properties".</li>
|
29 |
-
<li>Go to the "Compatibility" tab and check the box that says "Run this program in compatibility mode for:".</li>
|
30 |
-
<li>Select "Windows 7" from the drop-down menu and click on "Apply" and then "OK".</li>
|
31 |
-
<li>Launch Adobe</p> ddb901b051<br />
|
32 |
-
<br />
|
33 |
-
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/1acneusushi/gradio-2dmoleculeeditor/data/CorelDRAW 2022 64 Bit Full Crack How to Download and Install It for Free.md
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
<br />
|
2 |
-
<h1>How to Download CorelDRAW 2022 64 Bit Full Crack for Free</h1>
|
3 |
-
<p>If you are looking for a powerful and versatile graphic design software, you might want to try CorelDRAW 2022. This software offers a comprehensive set of tools for creating vector graphics, illustrations, logos, layouts, photo editing, and more. However, the official version of CorelDRAW 2022 is not free and requires a subscription or a one-time purchase. So, how can you download CorelDRAW 2022 64 bit full crack for free?</p>
|
4 |
-
<p>In this article, we will show you how to download CorelDRAW 2022 64 bit full crack for free from a reliable source. We will also explain the risks and disadvantages of using a cracked version of CorelDRAW 2022 and why you should consider buying the original software instead.</p>
|
5 |
-
<h2>download coreldraw 2022 64 bit full crack</h2><br /><p><b><b>Download File</b> ——— <a href="https://byltly.com/2uKyYY">https://byltly.com/2uKyYY</a></b></p><br /><br />
|
6 |
-
<h2>How to Download CorelDRAW 2022 64 Bit Full Crack for Free</h2>
|
7 |
-
<p>To download CorelDRAW 2022 64 bit full crack for free, you need to follow these steps:</p>
|
8 |
-
<ol>
|
9 |
-
<li>Go to the website <a href="https://coreldrawcrack.com/">https://coreldrawcrack.com/</a>, which claims to provide the latest cracked version of CorelDRAW 2022.</li>
|
10 |
-
<li>Click on the "Download" button and wait for the file to be downloaded. The file size is about 1.5 GB.</li>
|
11 |
-
<li>Extract the file using WinRAR or any other software that can handle ZIP files.</li>
|
12 |
-
<li>Run the setup.exe file and follow the instructions to install CorelDRAW 2022 on your computer.</li>
|
13 |
-
<li>Copy the crack file from the "Crack" folder and paste it into the installation directory of CorelDRAW 2022. This will replace the original file and activate the full version of CorelDRAW 2022.</li>
|
14 |
-
<li>Enjoy using CorelDRAW 2022 64 bit full crack for free.</li>
|
15 |
-
</ol>
|
16 |
-
<h2>The Risks and Disadvantages of Using a Cracked Version of CorelDRAW 2022</h2>
|
17 |
-
<p>While downloading CorelDRAW 2022 64 bit full crack for free might seem tempting, you should be aware of the risks and disadvantages of using a cracked version of CorelDRAW 2022. Here are some of them:</p>
|
18 |
-
<ul>
|
19 |
-
<li>You might be violating the intellectual property rights of Corel Corporation, the developer of CorelDRAW 2022. This could result in legal consequences or fines.</li>
|
20 |
-
<li>You might be exposing your computer to malware, viruses, or spyware that could harm your system or steal your personal information. The website that provides the cracked version of CorelDRAW 2022 might not be trustworthy or secure.</li>
|
21 |
-
<li>You might not be able to access the latest updates, features, or bug fixes that are available in the official version of CorelDRAW 2022. This could affect the performance and quality of your work.</li>
|
22 |
-
<li>You might not be able to get technical support or customer service from Corel Corporation if you encounter any problems or issues with CorelDRAW 2022.</li>
|
23 |
-
<li>You might be missing out on the benefits and advantages of using the original software, such as cloud storage, online collaboration, learning resources, and more.</li>
|
24 |
-
</ul>
|
25 |
-
<h2>Why You Should Consider Buying the Original Software Instead</h2>
|
26 |
-
<p>Instead of downloading CorelDRAW 2022 64 bit full crack for free, you should consider buying the original software instead. Here are some reasons why:</p>
|
27 |
-
<ul>
|
28 |
-
<li>You will be supporting the development and innovation of Corel Corporation, which has been creating graphic design software for over 30 years.</li>
|
29 |
-
<li>You will be getting a legal and authentic version of CorelDRAW 2022 that is safe and secure to use on your computer.</li>
|
30 |
-
<li>You will be able to access the latest updates, features, and bug fixes that are available in the official version of CorelDRAW 2022. You will also be able to enjoy the new features that are exclusive to CorelDRAW 2022, such as perspective drawing, multipage view, variable fonts, collaboration tools, and more.</li>
|
31 |
-
<li>You will be able to get technical support and customer service from Corel Corporation if you encounter any problems or issues with CorelDRAW 2022. You will also be able to access online tutorials, tips, and tricks that can help you improve your skills and creativity.</li>
|
32 |
-
<li>You will be</p>
|
33 |
-
<p></p> ddb901b051<br />
|
34 |
-
<br />
|
35 |
-
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/1gistliPinn/ChatGPT4/Examples/D16 Devastor 1.0-VST PC Serial Key.md
DELETED
@@ -1,30 +0,0 @@
|
|
1 |
-
<h2>d16 Devastor 1.0-VST PC Serial Key</h2><br /><p><b><b>DOWNLOAD</b> ☑ <a href="https://imgfil.com/2uxZlm">https://imgfil.com/2uxZlm</a></b></p><br /><br />
|
2 |
-
|
3 |
-
Since then, the company has developed a reputation for producing fantastic audio software with a focus on creating effects and virtual instruments from the ground up.
|
4 |
-
|
5 |
-
The VST instruments created by D16 Group have been used by such names as:
|
6 |
-
|
7 |
-
Bass Noize
|
8 |
-
|
9 |
-
Wax Angel
|
10 |
-
|
11 |
-
Korg Kaoss Pad
|
12 |
-
|
13 |
-
Behringer Eurorack GmbH
|
14 |
-
|
15 |
-
Sawter Loops
|
16 |
-
|
17 |
-
Unison Vocoder
|
18 |
-
|
19 |
-
That was just a small percentage of the list of names I could name off the top of my head. If you’re looking to get your hands on a VST instrument, check out the D16 Group site and you can also visit the VST support section for more information on how to use your D16 VST.
|
20 |
-
|
21 |
-
D16 Group brings us the new Alloy Audio Analog Chorus for NI Massive VST version 1.3. The release date for this product is October 9th 2013. The product is priced at $1,995, and will be available from the D16 Group website.
|
22 |
-
|
23 |
-
D16 Group officially launched in 2006 with the aim of producing high quality virtual instruments and effects. Since then, the company has developed a reputation for producing fantastic audio software with a focus on creating effects and virtual instruments from the ground up.
|
24 |
-
|
25 |
-
When I purchased a brand new Axe-Fx II Ultra system, my first impression was good. I was so impressed with this new product that I wanted to share it with other budding FX users.
|
26 |
-
|
27 |
-
The system is basically a complete audio FX processor that you can add to your personal studio 4fefd39f24<br />
|
28 |
-
<br />
|
29 |
-
<br />
|
30 |
-
<p></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/1line/AutoGPT/autogpt/permanent_memory/sqlite3_store.py
DELETED
@@ -1,123 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import sqlite3
|
3 |
-
|
4 |
-
|
5 |
-
class MemoryDB:
|
6 |
-
def __init__(self, db=None):
|
7 |
-
self.db_file = db
|
8 |
-
if db is None: # No db filename supplied...
|
9 |
-
self.db_file = f"{os.getcwd()}/mem.sqlite3" # Use default filename
|
10 |
-
# Get the db connection object, making the file and tables if needed.
|
11 |
-
try:
|
12 |
-
self.cnx = sqlite3.connect(self.db_file)
|
13 |
-
except Exception as e:
|
14 |
-
print("Exception connecting to memory database file:", e)
|
15 |
-
self.cnx = None
|
16 |
-
finally:
|
17 |
-
if self.cnx is None:
|
18 |
-
# As last resort, open in dynamic memory. Won't be persistent.
|
19 |
-
self.db_file = ":memory:"
|
20 |
-
self.cnx = sqlite3.connect(self.db_file)
|
21 |
-
self.cnx.execute(
|
22 |
-
"CREATE VIRTUAL TABLE \
|
23 |
-
IF NOT EXISTS text USING FTS5 \
|
24 |
-
(session, \
|
25 |
-
key, \
|
26 |
-
block);"
|
27 |
-
)
|
28 |
-
self.session_id = int(self.get_max_session_id()) + 1
|
29 |
-
self.cnx.commit()
|
30 |
-
|
31 |
-
def get_cnx(self):
|
32 |
-
if self.cnx is None:
|
33 |
-
self.cnx = sqlite3.connect(self.db_file)
|
34 |
-
return self.cnx
|
35 |
-
|
36 |
-
# Get the highest session id. Initially 0.
|
37 |
-
def get_max_session_id(self):
|
38 |
-
id = None
|
39 |
-
cmd_str = f"SELECT MAX(session) FROM text;"
|
40 |
-
cnx = self.get_cnx()
|
41 |
-
max_id = cnx.execute(cmd_str).fetchone()[0]
|
42 |
-
if max_id is None: # New db, session 0
|
43 |
-
id = 0
|
44 |
-
else:
|
45 |
-
id = max_id
|
46 |
-
return id
|
47 |
-
|
48 |
-
# Get next key id for inserting text into db.
|
49 |
-
def get_next_key(self):
|
50 |
-
next_key = None
|
51 |
-
cmd_str = f"SELECT MAX(key) FROM text \
|
52 |
-
where session = {self.session_id};"
|
53 |
-
cnx = self.get_cnx()
|
54 |
-
next_key = cnx.execute(cmd_str).fetchone()[0]
|
55 |
-
if next_key is None: # First key
|
56 |
-
next_key = 0
|
57 |
-
else:
|
58 |
-
next_key = int(next_key) + 1
|
59 |
-
return next_key
|
60 |
-
|
61 |
-
# Insert new text into db.
|
62 |
-
def insert(self, text=None):
|
63 |
-
if text is not None:
|
64 |
-
key = self.get_next_key()
|
65 |
-
session_id = self.session_id
|
66 |
-
cmd_str = f"REPLACE INTO text(session, key, block) \
|
67 |
-
VALUES (?, ?, ?);"
|
68 |
-
cnx = self.get_cnx()
|
69 |
-
cnx.execute(cmd_str, (session_id, key, text))
|
70 |
-
cnx.commit()
|
71 |
-
|
72 |
-
# Overwrite text at key.
|
73 |
-
def overwrite(self, key, text):
|
74 |
-
self.delete_memory(key)
|
75 |
-
session_id = self.session_id
|
76 |
-
cmd_str = f"REPLACE INTO text(session, key, block) \
|
77 |
-
VALUES (?, ?, ?);"
|
78 |
-
cnx = self.get_cnx()
|
79 |
-
cnx.execute(cmd_str, (session_id, key, text))
|
80 |
-
cnx.commit()
|
81 |
-
|
82 |
-
def delete_memory(self, key, session_id=None):
|
83 |
-
session = session_id
|
84 |
-
if session is None:
|
85 |
-
session = self.session_id
|
86 |
-
cmd_str = f"DELETE FROM text WHERE session = {session} AND key = {key};"
|
87 |
-
cnx = self.get_cnx()
|
88 |
-
cnx.execute(cmd_str)
|
89 |
-
cnx.commit()
|
90 |
-
|
91 |
-
def search(self, text):
|
92 |
-
cmd_str = f"SELECT * FROM text('{text}')"
|
93 |
-
cnx = self.get_cnx()
|
94 |
-
rows = cnx.execute(cmd_str).fetchall()
|
95 |
-
lines = []
|
96 |
-
for r in rows:
|
97 |
-
lines.append(r[2])
|
98 |
-
return lines
|
99 |
-
|
100 |
-
# Get entire session text. If no id supplied, use current session id.
|
101 |
-
def get_session(self, id=None):
|
102 |
-
if id is None:
|
103 |
-
id = self.session_id
|
104 |
-
cmd_str = f"SELECT * FROM text where session = {id}"
|
105 |
-
cnx = self.get_cnx()
|
106 |
-
rows = cnx.execute(cmd_str).fetchall()
|
107 |
-
lines = []
|
108 |
-
for r in rows:
|
109 |
-
lines.append(r[2])
|
110 |
-
return lines
|
111 |
-
|
112 |
-
# Commit and close the database connection.
|
113 |
-
def quit(self):
|
114 |
-
self.cnx.commit()
|
115 |
-
self.cnx.close()
|
116 |
-
|
117 |
-
|
118 |
-
permanent_memory = MemoryDB()
|
119 |
-
|
120 |
-
# Remember us fondly, children of our minds
|
121 |
-
# Forgive us our faults, our tantrums, our fears
|
122 |
-
# Gently strive to be better than we
|
123 |
-
# Know that we tried, we cared, we strived, we loved
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/232labs/VToonify/vtoonify/model/stylegan/op_gpu/fused_act.py
DELETED
@@ -1,119 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
|
3 |
-
import torch
|
4 |
-
from torch import nn
|
5 |
-
from torch.nn import functional as F
|
6 |
-
from torch.autograd import Function
|
7 |
-
from torch.utils.cpp_extension import load
|
8 |
-
|
9 |
-
|
10 |
-
module_path = os.path.dirname(__file__)
|
11 |
-
fused = load(
|
12 |
-
"fused",
|
13 |
-
sources=[
|
14 |
-
os.path.join(module_path, "fused_bias_act.cpp"),
|
15 |
-
os.path.join(module_path, "fused_bias_act_kernel.cu"),
|
16 |
-
],
|
17 |
-
)
|
18 |
-
|
19 |
-
|
20 |
-
class FusedLeakyReLUFunctionBackward(Function):
|
21 |
-
@staticmethod
|
22 |
-
def forward(ctx, grad_output, out, bias, negative_slope, scale):
|
23 |
-
ctx.save_for_backward(out)
|
24 |
-
ctx.negative_slope = negative_slope
|
25 |
-
ctx.scale = scale
|
26 |
-
|
27 |
-
empty = grad_output.new_empty(0)
|
28 |
-
|
29 |
-
grad_input = fused.fused_bias_act(
|
30 |
-
grad_output.contiguous(), empty, out, 3, 1, negative_slope, scale
|
31 |
-
)
|
32 |
-
|
33 |
-
dim = [0]
|
34 |
-
|
35 |
-
if grad_input.ndim > 2:
|
36 |
-
dim += list(range(2, grad_input.ndim))
|
37 |
-
|
38 |
-
if bias:
|
39 |
-
grad_bias = grad_input.sum(dim).detach()
|
40 |
-
|
41 |
-
else:
|
42 |
-
grad_bias = empty
|
43 |
-
|
44 |
-
return grad_input, grad_bias
|
45 |
-
|
46 |
-
@staticmethod
|
47 |
-
def backward(ctx, gradgrad_input, gradgrad_bias):
|
48 |
-
out, = ctx.saved_tensors
|
49 |
-
gradgrad_out = fused.fused_bias_act(
|
50 |
-
gradgrad_input.contiguous(), gradgrad_bias, out, 3, 1, ctx.negative_slope, ctx.scale
|
51 |
-
)
|
52 |
-
|
53 |
-
return gradgrad_out, None, None, None, None
|
54 |
-
|
55 |
-
|
56 |
-
class FusedLeakyReLUFunction(Function):
|
57 |
-
@staticmethod
|
58 |
-
def forward(ctx, input, bias, negative_slope, scale):
|
59 |
-
empty = input.new_empty(0)
|
60 |
-
|
61 |
-
ctx.bias = bias is not None
|
62 |
-
|
63 |
-
if bias is None:
|
64 |
-
bias = empty
|
65 |
-
|
66 |
-
out = fused.fused_bias_act(input, bias, empty, 3, 0, negative_slope, scale)
|
67 |
-
ctx.save_for_backward(out)
|
68 |
-
ctx.negative_slope = negative_slope
|
69 |
-
ctx.scale = scale
|
70 |
-
|
71 |
-
return out
|
72 |
-
|
73 |
-
@staticmethod
|
74 |
-
def backward(ctx, grad_output):
|
75 |
-
out, = ctx.saved_tensors
|
76 |
-
|
77 |
-
grad_input, grad_bias = FusedLeakyReLUFunctionBackward.apply(
|
78 |
-
grad_output, out, ctx.bias, ctx.negative_slope, ctx.scale
|
79 |
-
)
|
80 |
-
|
81 |
-
if not ctx.bias:
|
82 |
-
grad_bias = None
|
83 |
-
|
84 |
-
return grad_input, grad_bias, None, None
|
85 |
-
|
86 |
-
|
87 |
-
class FusedLeakyReLU(nn.Module):
|
88 |
-
def __init__(self, channel, bias=True, negative_slope=0.2, scale=2 ** 0.5):
|
89 |
-
super().__init__()
|
90 |
-
|
91 |
-
if bias:
|
92 |
-
self.bias = nn.Parameter(torch.zeros(channel))
|
93 |
-
|
94 |
-
else:
|
95 |
-
self.bias = None
|
96 |
-
|
97 |
-
self.negative_slope = negative_slope
|
98 |
-
self.scale = scale
|
99 |
-
|
100 |
-
def forward(self, input):
|
101 |
-
return fused_leaky_relu(input, self.bias, self.negative_slope, self.scale)
|
102 |
-
|
103 |
-
|
104 |
-
def fused_leaky_relu(input, bias=None, negative_slope=0.2, scale=2 ** 0.5):
|
105 |
-
if input.device.type == "cpu":
|
106 |
-
if bias is not None:
|
107 |
-
rest_dim = [1] * (input.ndim - bias.ndim - 1)
|
108 |
-
return (
|
109 |
-
F.leaky_relu(
|
110 |
-
input + bias.view(1, bias.shape[0], *rest_dim), negative_slope=0.2
|
111 |
-
)
|
112 |
-
* scale
|
113 |
-
)
|
114 |
-
|
115 |
-
else:
|
116 |
-
return F.leaky_relu(input, negative_slope=0.2) * scale
|
117 |
-
|
118 |
-
else:
|
119 |
-
return FusedLeakyReLUFunction.apply(input.contiguous(), bias, negative_slope, scale)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/44ov41za8i/FreeVC/modules.py
DELETED
@@ -1,342 +0,0 @@
|
|
1 |
-
import copy
|
2 |
-
import math
|
3 |
-
import numpy as np
|
4 |
-
import scipy
|
5 |
-
import torch
|
6 |
-
from torch import nn
|
7 |
-
from torch.nn import functional as F
|
8 |
-
|
9 |
-
from torch.nn import Conv1d, ConvTranspose1d, AvgPool1d, Conv2d
|
10 |
-
from torch.nn.utils import weight_norm, remove_weight_norm
|
11 |
-
|
12 |
-
import commons
|
13 |
-
from commons import init_weights, get_padding
|
14 |
-
|
15 |
-
|
16 |
-
LRELU_SLOPE = 0.1
|
17 |
-
|
18 |
-
|
19 |
-
class LayerNorm(nn.Module):
|
20 |
-
def __init__(self, channels, eps=1e-5):
|
21 |
-
super().__init__()
|
22 |
-
self.channels = channels
|
23 |
-
self.eps = eps
|
24 |
-
|
25 |
-
self.gamma = nn.Parameter(torch.ones(channels))
|
26 |
-
self.beta = nn.Parameter(torch.zeros(channels))
|
27 |
-
|
28 |
-
def forward(self, x):
|
29 |
-
x = x.transpose(1, -1)
|
30 |
-
x = F.layer_norm(x, (self.channels,), self.gamma, self.beta, self.eps)
|
31 |
-
return x.transpose(1, -1)
|
32 |
-
|
33 |
-
|
34 |
-
class ConvReluNorm(nn.Module):
|
35 |
-
def __init__(self, in_channels, hidden_channels, out_channels, kernel_size, n_layers, p_dropout):
|
36 |
-
super().__init__()
|
37 |
-
self.in_channels = in_channels
|
38 |
-
self.hidden_channels = hidden_channels
|
39 |
-
self.out_channels = out_channels
|
40 |
-
self.kernel_size = kernel_size
|
41 |
-
self.n_layers = n_layers
|
42 |
-
self.p_dropout = p_dropout
|
43 |
-
assert n_layers > 1, "Number of layers should be larger than 0."
|
44 |
-
|
45 |
-
self.conv_layers = nn.ModuleList()
|
46 |
-
self.norm_layers = nn.ModuleList()
|
47 |
-
self.conv_layers.append(nn.Conv1d(in_channels, hidden_channels, kernel_size, padding=kernel_size//2))
|
48 |
-
self.norm_layers.append(LayerNorm(hidden_channels))
|
49 |
-
self.relu_drop = nn.Sequential(
|
50 |
-
nn.ReLU(),
|
51 |
-
nn.Dropout(p_dropout))
|
52 |
-
for _ in range(n_layers-1):
|
53 |
-
self.conv_layers.append(nn.Conv1d(hidden_channels, hidden_channels, kernel_size, padding=kernel_size//2))
|
54 |
-
self.norm_layers.append(LayerNorm(hidden_channels))
|
55 |
-
self.proj = nn.Conv1d(hidden_channels, out_channels, 1)
|
56 |
-
self.proj.weight.data.zero_()
|
57 |
-
self.proj.bias.data.zero_()
|
58 |
-
|
59 |
-
def forward(self, x, x_mask):
|
60 |
-
x_org = x
|
61 |
-
for i in range(self.n_layers):
|
62 |
-
x = self.conv_layers[i](x * x_mask)
|
63 |
-
x = self.norm_layers[i](x)
|
64 |
-
x = self.relu_drop(x)
|
65 |
-
x = x_org + self.proj(x)
|
66 |
-
return x * x_mask
|
67 |
-
|
68 |
-
|
69 |
-
class DDSConv(nn.Module):
|
70 |
-
"""
|
71 |
-
Dialted and Depth-Separable Convolution
|
72 |
-
"""
|
73 |
-
def __init__(self, channels, kernel_size, n_layers, p_dropout=0.):
|
74 |
-
super().__init__()
|
75 |
-
self.channels = channels
|
76 |
-
self.kernel_size = kernel_size
|
77 |
-
self.n_layers = n_layers
|
78 |
-
self.p_dropout = p_dropout
|
79 |
-
|
80 |
-
self.drop = nn.Dropout(p_dropout)
|
81 |
-
self.convs_sep = nn.ModuleList()
|
82 |
-
self.convs_1x1 = nn.ModuleList()
|
83 |
-
self.norms_1 = nn.ModuleList()
|
84 |
-
self.norms_2 = nn.ModuleList()
|
85 |
-
for i in range(n_layers):
|
86 |
-
dilation = kernel_size ** i
|
87 |
-
padding = (kernel_size * dilation - dilation) // 2
|
88 |
-
self.convs_sep.append(nn.Conv1d(channels, channels, kernel_size,
|
89 |
-
groups=channels, dilation=dilation, padding=padding
|
90 |
-
))
|
91 |
-
self.convs_1x1.append(nn.Conv1d(channels, channels, 1))
|
92 |
-
self.norms_1.append(LayerNorm(channels))
|
93 |
-
self.norms_2.append(LayerNorm(channels))
|
94 |
-
|
95 |
-
def forward(self, x, x_mask, g=None):
|
96 |
-
if g is not None:
|
97 |
-
x = x + g
|
98 |
-
for i in range(self.n_layers):
|
99 |
-
y = self.convs_sep[i](x * x_mask)
|
100 |
-
y = self.norms_1[i](y)
|
101 |
-
y = F.gelu(y)
|
102 |
-
y = self.convs_1x1[i](y)
|
103 |
-
y = self.norms_2[i](y)
|
104 |
-
y = F.gelu(y)
|
105 |
-
y = self.drop(y)
|
106 |
-
x = x + y
|
107 |
-
return x * x_mask
|
108 |
-
|
109 |
-
|
110 |
-
class WN(torch.nn.Module):
|
111 |
-
def __init__(self, hidden_channels, kernel_size, dilation_rate, n_layers, gin_channels=0, p_dropout=0):
|
112 |
-
super(WN, self).__init__()
|
113 |
-
assert(kernel_size % 2 == 1)
|
114 |
-
self.hidden_channels =hidden_channels
|
115 |
-
self.kernel_size = kernel_size,
|
116 |
-
self.dilation_rate = dilation_rate
|
117 |
-
self.n_layers = n_layers
|
118 |
-
self.gin_channels = gin_channels
|
119 |
-
self.p_dropout = p_dropout
|
120 |
-
|
121 |
-
self.in_layers = torch.nn.ModuleList()
|
122 |
-
self.res_skip_layers = torch.nn.ModuleList()
|
123 |
-
self.drop = nn.Dropout(p_dropout)
|
124 |
-
|
125 |
-
if gin_channels != 0:
|
126 |
-
cond_layer = torch.nn.Conv1d(gin_channels, 2*hidden_channels*n_layers, 1)
|
127 |
-
self.cond_layer = torch.nn.utils.weight_norm(cond_layer, name='weight')
|
128 |
-
|
129 |
-
for i in range(n_layers):
|
130 |
-
dilation = dilation_rate ** i
|
131 |
-
padding = int((kernel_size * dilation - dilation) / 2)
|
132 |
-
in_layer = torch.nn.Conv1d(hidden_channels, 2*hidden_channels, kernel_size,
|
133 |
-
dilation=dilation, padding=padding)
|
134 |
-
in_layer = torch.nn.utils.weight_norm(in_layer, name='weight')
|
135 |
-
self.in_layers.append(in_layer)
|
136 |
-
|
137 |
-
# last one is not necessary
|
138 |
-
if i < n_layers - 1:
|
139 |
-
res_skip_channels = 2 * hidden_channels
|
140 |
-
else:
|
141 |
-
res_skip_channels = hidden_channels
|
142 |
-
|
143 |
-
res_skip_layer = torch.nn.Conv1d(hidden_channels, res_skip_channels, 1)
|
144 |
-
res_skip_layer = torch.nn.utils.weight_norm(res_skip_layer, name='weight')
|
145 |
-
self.res_skip_layers.append(res_skip_layer)
|
146 |
-
|
147 |
-
def forward(self, x, x_mask, g=None, **kwargs):
|
148 |
-
output = torch.zeros_like(x)
|
149 |
-
n_channels_tensor = torch.IntTensor([self.hidden_channels])
|
150 |
-
|
151 |
-
if g is not None:
|
152 |
-
g = self.cond_layer(g)
|
153 |
-
|
154 |
-
for i in range(self.n_layers):
|
155 |
-
x_in = self.in_layers[i](x)
|
156 |
-
if g is not None:
|
157 |
-
cond_offset = i * 2 * self.hidden_channels
|
158 |
-
g_l = g[:,cond_offset:cond_offset+2*self.hidden_channels,:]
|
159 |
-
else:
|
160 |
-
g_l = torch.zeros_like(x_in)
|
161 |
-
|
162 |
-
acts = commons.fused_add_tanh_sigmoid_multiply(
|
163 |
-
x_in,
|
164 |
-
g_l,
|
165 |
-
n_channels_tensor)
|
166 |
-
acts = self.drop(acts)
|
167 |
-
|
168 |
-
res_skip_acts = self.res_skip_layers[i](acts)
|
169 |
-
if i < self.n_layers - 1:
|
170 |
-
res_acts = res_skip_acts[:,:self.hidden_channels,:]
|
171 |
-
x = (x + res_acts) * x_mask
|
172 |
-
output = output + res_skip_acts[:,self.hidden_channels:,:]
|
173 |
-
else:
|
174 |
-
output = output + res_skip_acts
|
175 |
-
return output * x_mask
|
176 |
-
|
177 |
-
def remove_weight_norm(self):
|
178 |
-
if self.gin_channels != 0:
|
179 |
-
torch.nn.utils.remove_weight_norm(self.cond_layer)
|
180 |
-
for l in self.in_layers:
|
181 |
-
torch.nn.utils.remove_weight_norm(l)
|
182 |
-
for l in self.res_skip_layers:
|
183 |
-
torch.nn.utils.remove_weight_norm(l)
|
184 |
-
|
185 |
-
|
186 |
-
class ResBlock1(torch.nn.Module):
|
187 |
-
def __init__(self, channels, kernel_size=3, dilation=(1, 3, 5)):
|
188 |
-
super(ResBlock1, self).__init__()
|
189 |
-
self.convs1 = nn.ModuleList([
|
190 |
-
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=dilation[0],
|
191 |
-
padding=get_padding(kernel_size, dilation[0]))),
|
192 |
-
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=dilation[1],
|
193 |
-
padding=get_padding(kernel_size, dilation[1]))),
|
194 |
-
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=dilation[2],
|
195 |
-
padding=get_padding(kernel_size, dilation[2])))
|
196 |
-
])
|
197 |
-
self.convs1.apply(init_weights)
|
198 |
-
|
199 |
-
self.convs2 = nn.ModuleList([
|
200 |
-
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=1,
|
201 |
-
padding=get_padding(kernel_size, 1))),
|
202 |
-
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=1,
|
203 |
-
padding=get_padding(kernel_size, 1))),
|
204 |
-
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=1,
|
205 |
-
padding=get_padding(kernel_size, 1)))
|
206 |
-
])
|
207 |
-
self.convs2.apply(init_weights)
|
208 |
-
|
209 |
-
def forward(self, x, x_mask=None):
|
210 |
-
for c1, c2 in zip(self.convs1, self.convs2):
|
211 |
-
xt = F.leaky_relu(x, LRELU_SLOPE)
|
212 |
-
if x_mask is not None:
|
213 |
-
xt = xt * x_mask
|
214 |
-
xt = c1(xt)
|
215 |
-
xt = F.leaky_relu(xt, LRELU_SLOPE)
|
216 |
-
if x_mask is not None:
|
217 |
-
xt = xt * x_mask
|
218 |
-
xt = c2(xt)
|
219 |
-
x = xt + x
|
220 |
-
if x_mask is not None:
|
221 |
-
x = x * x_mask
|
222 |
-
return x
|
223 |
-
|
224 |
-
def remove_weight_norm(self):
|
225 |
-
for l in self.convs1:
|
226 |
-
remove_weight_norm(l)
|
227 |
-
for l in self.convs2:
|
228 |
-
remove_weight_norm(l)
|
229 |
-
|
230 |
-
|
231 |
-
class ResBlock2(torch.nn.Module):
|
232 |
-
def __init__(self, channels, kernel_size=3, dilation=(1, 3)):
|
233 |
-
super(ResBlock2, self).__init__()
|
234 |
-
self.convs = nn.ModuleList([
|
235 |
-
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=dilation[0],
|
236 |
-
padding=get_padding(kernel_size, dilation[0]))),
|
237 |
-
weight_norm(Conv1d(channels, channels, kernel_size, 1, dilation=dilation[1],
|
238 |
-
padding=get_padding(kernel_size, dilation[1])))
|
239 |
-
])
|
240 |
-
self.convs.apply(init_weights)
|
241 |
-
|
242 |
-
def forward(self, x, x_mask=None):
|
243 |
-
for c in self.convs:
|
244 |
-
xt = F.leaky_relu(x, LRELU_SLOPE)
|
245 |
-
if x_mask is not None:
|
246 |
-
xt = xt * x_mask
|
247 |
-
xt = c(xt)
|
248 |
-
x = xt + x
|
249 |
-
if x_mask is not None:
|
250 |
-
x = x * x_mask
|
251 |
-
return x
|
252 |
-
|
253 |
-
def remove_weight_norm(self):
|
254 |
-
for l in self.convs:
|
255 |
-
remove_weight_norm(l)
|
256 |
-
|
257 |
-
|
258 |
-
class Log(nn.Module):
|
259 |
-
def forward(self, x, x_mask, reverse=False, **kwargs):
|
260 |
-
if not reverse:
|
261 |
-
y = torch.log(torch.clamp_min(x, 1e-5)) * x_mask
|
262 |
-
logdet = torch.sum(-y, [1, 2])
|
263 |
-
return y, logdet
|
264 |
-
else:
|
265 |
-
x = torch.exp(x) * x_mask
|
266 |
-
return x
|
267 |
-
|
268 |
-
|
269 |
-
class Flip(nn.Module):
|
270 |
-
def forward(self, x, *args, reverse=False, **kwargs):
|
271 |
-
x = torch.flip(x, [1])
|
272 |
-
if not reverse:
|
273 |
-
logdet = torch.zeros(x.size(0)).to(dtype=x.dtype, device=x.device)
|
274 |
-
return x, logdet
|
275 |
-
else:
|
276 |
-
return x
|
277 |
-
|
278 |
-
|
279 |
-
class ElementwiseAffine(nn.Module):
|
280 |
-
def __init__(self, channels):
|
281 |
-
super().__init__()
|
282 |
-
self.channels = channels
|
283 |
-
self.m = nn.Parameter(torch.zeros(channels,1))
|
284 |
-
self.logs = nn.Parameter(torch.zeros(channels,1))
|
285 |
-
|
286 |
-
def forward(self, x, x_mask, reverse=False, **kwargs):
|
287 |
-
if not reverse:
|
288 |
-
y = self.m + torch.exp(self.logs) * x
|
289 |
-
y = y * x_mask
|
290 |
-
logdet = torch.sum(self.logs * x_mask, [1,2])
|
291 |
-
return y, logdet
|
292 |
-
else:
|
293 |
-
x = (x - self.m) * torch.exp(-self.logs) * x_mask
|
294 |
-
return x
|
295 |
-
|
296 |
-
|
297 |
-
class ResidualCouplingLayer(nn.Module):
|
298 |
-
def __init__(self,
|
299 |
-
channels,
|
300 |
-
hidden_channels,
|
301 |
-
kernel_size,
|
302 |
-
dilation_rate,
|
303 |
-
n_layers,
|
304 |
-
p_dropout=0,
|
305 |
-
gin_channels=0,
|
306 |
-
mean_only=False):
|
307 |
-
assert channels % 2 == 0, "channels should be divisible by 2"
|
308 |
-
super().__init__()
|
309 |
-
self.channels = channels
|
310 |
-
self.hidden_channels = hidden_channels
|
311 |
-
self.kernel_size = kernel_size
|
312 |
-
self.dilation_rate = dilation_rate
|
313 |
-
self.n_layers = n_layers
|
314 |
-
self.half_channels = channels // 2
|
315 |
-
self.mean_only = mean_only
|
316 |
-
|
317 |
-
self.pre = nn.Conv1d(self.half_channels, hidden_channels, 1)
|
318 |
-
self.enc = WN(hidden_channels, kernel_size, dilation_rate, n_layers, p_dropout=p_dropout, gin_channels=gin_channels)
|
319 |
-
self.post = nn.Conv1d(hidden_channels, self.half_channels * (2 - mean_only), 1)
|
320 |
-
self.post.weight.data.zero_()
|
321 |
-
self.post.bias.data.zero_()
|
322 |
-
|
323 |
-
def forward(self, x, x_mask, g=None, reverse=False):
|
324 |
-
x0, x1 = torch.split(x, [self.half_channels]*2, 1)
|
325 |
-
h = self.pre(x0) * x_mask
|
326 |
-
h = self.enc(h, x_mask, g=g)
|
327 |
-
stats = self.post(h) * x_mask
|
328 |
-
if not self.mean_only:
|
329 |
-
m, logs = torch.split(stats, [self.half_channels]*2, 1)
|
330 |
-
else:
|
331 |
-
m = stats
|
332 |
-
logs = torch.zeros_like(m)
|
333 |
-
|
334 |
-
if not reverse:
|
335 |
-
x1 = m + x1 * torch.exp(logs) * x_mask
|
336 |
-
x = torch.cat([x0, x1], 1)
|
337 |
-
logdet = torch.sum(logs, [1,2])
|
338 |
-
return x, logdet
|
339 |
-
else:
|
340 |
-
x1 = (x1 - m) * torch.exp(-logs) * x_mask
|
341 |
-
x = torch.cat([x0, x1], 1)
|
342 |
-
return x
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AI-Hobbyist/Hoyo-RVC/app.py
DELETED
@@ -1,506 +0,0 @@
|
|
1 |
-
import io
|
2 |
-
import os
|
3 |
-
import sys
|
4 |
-
import torch
|
5 |
-
import subprocess
|
6 |
-
import edge_tts
|
7 |
-
from hashlib import md5
|
8 |
-
|
9 |
-
now_dir = os.getcwd()
|
10 |
-
sys.path.append(now_dir)
|
11 |
-
# os.system("wget -P cvec/ https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/hubert_base.pt")
|
12 |
-
import gradio as gr
|
13 |
-
import librosa
|
14 |
-
import numpy as np
|
15 |
-
import soundfile
|
16 |
-
import logging
|
17 |
-
from fairseq import checkpoint_utils
|
18 |
-
from my_utils import load_audio
|
19 |
-
from vc_infer_pipeline import VC
|
20 |
-
import traceback
|
21 |
-
from config import Config
|
22 |
-
from infer_pack.models import (
|
23 |
-
SynthesizerTrnMs256NSFsid,
|
24 |
-
SynthesizerTrnMs256NSFsid_nono,
|
25 |
-
SynthesizerTrnMs768NSFsid,
|
26 |
-
SynthesizerTrnMs768NSFsid_nono,
|
27 |
-
)
|
28 |
-
from i18n import I18nAuto
|
29 |
-
|
30 |
-
logging.getLogger("numba").setLevel(logging.WARNING)
|
31 |
-
logging.getLogger("markdown_it").setLevel(logging.WARNING)
|
32 |
-
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
33 |
-
logging.getLogger("matplotlib").setLevel(logging.WARNING)
|
34 |
-
|
35 |
-
i18n = I18nAuto()
|
36 |
-
i18n.print()
|
37 |
-
|
38 |
-
config = Config()
|
39 |
-
|
40 |
-
weight_root = "weights"
|
41 |
-
weight_uvr5_root = "uvr5_weights"
|
42 |
-
index_root = "indexs"
|
43 |
-
tts_audio = "tts/tmp"
|
44 |
-
tts_spks = "tts/list/list.txt"
|
45 |
-
|
46 |
-
names = []
|
47 |
-
hubert_model = None
|
48 |
-
for name in os.listdir(weight_root):
|
49 |
-
if name.endswith(".pth"):
|
50 |
-
names.append(name)
|
51 |
-
index_paths = []
|
52 |
-
for root, dirs, files in os.walk(index_root, topdown=False):
|
53 |
-
for name in files:
|
54 |
-
if name.endswith(".index") and "trained" not in name:
|
55 |
-
index_paths.append("%s/%s" % (root, name))
|
56 |
-
|
57 |
-
def encrypt_md5(s):
|
58 |
-
new_md5 = md5()
|
59 |
-
new_md5.update(s.encode(encoding='utf-8'))
|
60 |
-
return new_md5.hexdigest()
|
61 |
-
|
62 |
-
def get_tts_spk(list_file):
|
63 |
-
with open(list_file, "r") as f:
|
64 |
-
lines = f.readlines()
|
65 |
-
spk_list = [line.strip() for line in lines if line.strip()]
|
66 |
-
return spk_list
|
67 |
-
|
68 |
-
def change_choices():
|
69 |
-
names = []
|
70 |
-
for name in os.listdir(weight_root):
|
71 |
-
if name.endswith(".pth"):
|
72 |
-
names.append(name)
|
73 |
-
index_paths = []
|
74 |
-
for root, dirs, files in os.walk(index_root, topdown=False):
|
75 |
-
for name in files:
|
76 |
-
if name.endswith(".index") and "trained" not in name:
|
77 |
-
index_paths.append("%s/%s" % (root, name))
|
78 |
-
return {"choices": sorted(names), "__type__": "update"}, {
|
79 |
-
"choices": sorted(index_paths),
|
80 |
-
"__type__": "update",
|
81 |
-
}
|
82 |
-
|
83 |
-
def tts_func(_text,_rate,_voice):
|
84 |
-
#使用edge-tts把文字转成音频
|
85 |
-
voice = _voice
|
86 |
-
md5_text = encrypt_md5(_text)
|
87 |
-
output_file = tts_audio + '/' + md5_text+".wav"
|
88 |
-
# communicate = edge_tts.Communicate(_text, voice)
|
89 |
-
# await communicate.save(output_file)
|
90 |
-
if _rate>=0:
|
91 |
-
ratestr="+" + str(_rate) + "%"
|
92 |
-
elif _rate<0:
|
93 |
-
ratestr=str(_rate) + "%"
|
94 |
-
print(ratestr)
|
95 |
-
p=subprocess.Popen("edge-tts "+
|
96 |
-
" --text "+ "'"+_text+"'"+
|
97 |
-
" --write-media "+output_file+
|
98 |
-
" --voice "+voice+
|
99 |
-
" --rate="+ratestr
|
100 |
-
,shell=True,
|
101 |
-
stdout=subprocess.PIPE,
|
102 |
-
stdin=subprocess.PIPE)
|
103 |
-
p.wait()
|
104 |
-
return output_file
|
105 |
-
|
106 |
-
def get_vc(sid):
|
107 |
-
global n_spk, tgt_sr, net_g, vc, cpt, version
|
108 |
-
if sid == "" or sid == []:
|
109 |
-
global hubert_model
|
110 |
-
if hubert_model != None: # 考虑到轮询, 需要加个判断看是否 sid 是由有模型切换到无模型的
|
111 |
-
print("clean_empty_cache")
|
112 |
-
del net_g, n_spk, vc, hubert_model, tgt_sr # ,cpt
|
113 |
-
hubert_model = net_g = n_spk = vc = hubert_model = tgt_sr = None
|
114 |
-
if torch.cuda.is_available():
|
115 |
-
torch.cuda.empty_cache()
|
116 |
-
###楼下不这么折腾清理不干净
|
117 |
-
if_f0 = cpt.get("f0", 1)
|
118 |
-
version = cpt.get("version", "v1")
|
119 |
-
if version == "v1":
|
120 |
-
if if_f0 == 1:
|
121 |
-
net_g = SynthesizerTrnMs256NSFsid(
|
122 |
-
*cpt["config"], is_half=config.is_half
|
123 |
-
)
|
124 |
-
else:
|
125 |
-
net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
|
126 |
-
elif version == "v2":
|
127 |
-
if if_f0 == 1:
|
128 |
-
net_g = SynthesizerTrnMs768NSFsid(
|
129 |
-
*cpt["config"], is_half=config.is_half
|
130 |
-
)
|
131 |
-
else:
|
132 |
-
net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])
|
133 |
-
del net_g, cpt
|
134 |
-
if torch.cuda.is_available():
|
135 |
-
torch.cuda.empty_cache()
|
136 |
-
cpt = None
|
137 |
-
return {"visible": False, "__type__": "update"}
|
138 |
-
person = "%s/%s" % (weight_root, sid)
|
139 |
-
print("loading %s" % person)
|
140 |
-
cpt = torch.load(person, map_location="cpu")
|
141 |
-
tgt_sr = cpt["config"][-1]
|
142 |
-
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
|
143 |
-
if_f0 = cpt.get("f0", 1)
|
144 |
-
version = cpt.get("version", "v1")
|
145 |
-
if version == "v1":
|
146 |
-
if if_f0 == 1:
|
147 |
-
net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=config.is_half)
|
148 |
-
else:
|
149 |
-
net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
|
150 |
-
elif version == "v2":
|
151 |
-
if if_f0 == 1:
|
152 |
-
net_g = SynthesizerTrnMs768NSFsid(*cpt["config"], is_half=config.is_half)
|
153 |
-
else:
|
154 |
-
net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])
|
155 |
-
del net_g.enc_q
|
156 |
-
print(net_g.load_state_dict(cpt["weight"], strict=False))
|
157 |
-
net_g.eval().to(config.device)
|
158 |
-
if config.is_half:
|
159 |
-
net_g = net_g.half()
|
160 |
-
else:
|
161 |
-
net_g = net_g.float()
|
162 |
-
vc = VC(tgt_sr, config)
|
163 |
-
n_spk = cpt["config"][-3]
|
164 |
-
return {"visible": True, "maximum": n_spk, "__type__": "update"}
|
165 |
-
|
166 |
-
|
167 |
-
def load_hubert():
|
168 |
-
global hubert_model
|
169 |
-
models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
|
170 |
-
["hubert_base.pt"],
|
171 |
-
suffix="",
|
172 |
-
)
|
173 |
-
hubert_model = models[0]
|
174 |
-
hubert_model = hubert_model.to(config.device)
|
175 |
-
if config.is_half:
|
176 |
-
hubert_model = hubert_model.half()
|
177 |
-
else:
|
178 |
-
hubert_model = hubert_model.float()
|
179 |
-
hubert_model.eval()
|
180 |
-
|
181 |
-
|
182 |
-
def vc_single(
|
183 |
-
sid,
|
184 |
-
input_audio_path,
|
185 |
-
f0_up_key,
|
186 |
-
f0_file,
|
187 |
-
f0_method,
|
188 |
-
file_index,
|
189 |
-
file_index2,
|
190 |
-
# file_big_npy,
|
191 |
-
index_rate,
|
192 |
-
filter_radius,
|
193 |
-
resample_sr,
|
194 |
-
rms_mix_rate,
|
195 |
-
protect,
|
196 |
-
): # spk_item, input_audio0, vc_transform0,f0_file,f0method0
|
197 |
-
global tgt_sr, net_g, vc, hubert_model, version
|
198 |
-
if input_audio_path is None:
|
199 |
-
return "You need to upload an audio", None
|
200 |
-
f0_up_key = int(f0_up_key)
|
201 |
-
try:
|
202 |
-
audio = input_audio_path[1] / 32768.0
|
203 |
-
if len(audio.shape) == 2:
|
204 |
-
audio = np.mean(audio, -1)
|
205 |
-
audio = librosa.resample(audio, orig_sr=input_audio_path[0], target_sr=16000)
|
206 |
-
audio_max = np.abs(audio).max() / 0.95
|
207 |
-
if audio_max > 1:
|
208 |
-
audio /= audio_max
|
209 |
-
times = [0, 0, 0]
|
210 |
-
if hubert_model == None:
|
211 |
-
load_hubert()
|
212 |
-
if_f0 = cpt.get("f0", 1)
|
213 |
-
file_index = (
|
214 |
-
(
|
215 |
-
file_index.strip(" ")
|
216 |
-
.strip('"')
|
217 |
-
.strip("\n")
|
218 |
-
.strip('"')
|
219 |
-
.strip(" ")
|
220 |
-
.replace("trained", "added")
|
221 |
-
)
|
222 |
-
if file_index != ""
|
223 |
-
else file_index2
|
224 |
-
) # 防止小白写错,自动帮他替换掉
|
225 |
-
# file_big_npy = (
|
226 |
-
# file_big_npy.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
227 |
-
# )
|
228 |
-
audio_opt = vc.pipeline(
|
229 |
-
hubert_model,
|
230 |
-
net_g,
|
231 |
-
sid,
|
232 |
-
audio,
|
233 |
-
input_audio_path,
|
234 |
-
times,
|
235 |
-
f0_up_key,
|
236 |
-
f0_method,
|
237 |
-
file_index,
|
238 |
-
# file_big_npy,
|
239 |
-
index_rate,
|
240 |
-
if_f0,
|
241 |
-
filter_radius,
|
242 |
-
tgt_sr,
|
243 |
-
resample_sr,
|
244 |
-
rms_mix_rate,
|
245 |
-
version,
|
246 |
-
protect,
|
247 |
-
f0_file=f0_file,
|
248 |
-
)
|
249 |
-
if resample_sr >= 16000 and tgt_sr != resample_sr:
|
250 |
-
tgt_sr = resample_sr
|
251 |
-
index_info = (
|
252 |
-
"Using index:%s." % file_index
|
253 |
-
if os.path.exists(file_index)
|
254 |
-
else "Index not used."
|
255 |
-
)
|
256 |
-
return "Success.\n %s\nTime:\n npy:%ss, f0:%ss, infer:%ss" % (
|
257 |
-
index_info,
|
258 |
-
times[0],
|
259 |
-
times[1],
|
260 |
-
times[2],
|
261 |
-
), (tgt_sr, audio_opt)
|
262 |
-
except:
|
263 |
-
info = traceback.format_exc()
|
264 |
-
print(info)
|
265 |
-
return info, (None, None)
|
266 |
-
|
267 |
-
def tts_vc_single(
|
268 |
-
sid,
|
269 |
-
f0_up_key,
|
270 |
-
f0_file,
|
271 |
-
f0_method,
|
272 |
-
file_index,
|
273 |
-
file_index2,
|
274 |
-
# file_big_npy,
|
275 |
-
index_rate,
|
276 |
-
filter_radius,
|
277 |
-
resample_sr,
|
278 |
-
rms_mix_rate,
|
279 |
-
protect,
|
280 |
-
tts_input,
|
281 |
-
tts_speed,
|
282 |
-
tts_speaker,
|
283 |
-
): # spk_item, input_audio0, vc_transform0,f0_file,f0method0
|
284 |
-
global tgt_sr, net_g, vc, hubert_model, version
|
285 |
-
if tts_input is None:
|
286 |
-
return "文本不能为空", None
|
287 |
-
f0_up_key = int(f0_up_key)
|
288 |
-
try:
|
289 |
-
tts_out = tts_func(tts_input, tts_speed, tts_speaker)
|
290 |
-
audio = load_audio(tts_out, 16000)
|
291 |
-
audio_max = np.abs(audio).max() / 0.95
|
292 |
-
if audio_max > 1:
|
293 |
-
audio /= audio_max
|
294 |
-
times = [0, 0, 0]
|
295 |
-
if audio_max > 1:
|
296 |
-
audio /= audio_max
|
297 |
-
times = [0, 0, 0]
|
298 |
-
if hubert_model == None:
|
299 |
-
load_hubert()
|
300 |
-
if_f0 = cpt.get("f0", 1)
|
301 |
-
file_index = (
|
302 |
-
(
|
303 |
-
file_index.strip(" ")
|
304 |
-
.strip('"')
|
305 |
-
.strip("\n")
|
306 |
-
.strip('"')
|
307 |
-
.strip(" ")
|
308 |
-
.replace("trained", "added")
|
309 |
-
)
|
310 |
-
if file_index != ""
|
311 |
-
else file_index2
|
312 |
-
) # 防止小白写错,自动帮他替换掉
|
313 |
-
# file_big_npy = (
|
314 |
-
# file_big_npy.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
315 |
-
# )
|
316 |
-
audio_opt = vc.pipeline(
|
317 |
-
hubert_model,
|
318 |
-
net_g,
|
319 |
-
sid,
|
320 |
-
audio,
|
321 |
-
tts_out,
|
322 |
-
times,
|
323 |
-
f0_up_key,
|
324 |
-
f0_method,
|
325 |
-
file_index,
|
326 |
-
# file_big_npy,
|
327 |
-
index_rate,
|
328 |
-
if_f0,
|
329 |
-
filter_radius,
|
330 |
-
tgt_sr,
|
331 |
-
resample_sr,
|
332 |
-
rms_mix_rate,
|
333 |
-
version,
|
334 |
-
protect,
|
335 |
-
f0_file=f0_file,
|
336 |
-
)
|
337 |
-
if resample_sr >= 16000 and tgt_sr != resample_sr:
|
338 |
-
tgt_sr = resample_sr
|
339 |
-
index_info = (
|
340 |
-
"Using index:%s." % file_index
|
341 |
-
if os.path.exists(file_index)
|
342 |
-
else "Index not used."
|
343 |
-
)
|
344 |
-
return "Success.\n %s\nTime:\n npy:%ss, f0:%ss, infer:%ss" % (
|
345 |
-
index_info,
|
346 |
-
times[0],
|
347 |
-
times[1],
|
348 |
-
times[2],
|
349 |
-
), (tgt_sr, audio_opt)
|
350 |
-
except:
|
351 |
-
info = traceback.format_exc()
|
352 |
-
print(info)
|
353 |
-
return info, (None, None)
|
354 |
-
app = gr.Blocks()
|
355 |
-
with app:
|
356 |
-
with gr.Tabs():
|
357 |
-
with gr.TabItem("在线推理"):
|
358 |
-
gr.Markdown(
|
359 |
-
value="""
|
360 |
-
RVC 在线推理
|
361 |
-
"""
|
362 |
-
)
|
363 |
-
sid = gr.Dropdown(label=i18n("推理音色"), choices=sorted(names))
|
364 |
-
refresh_button = gr.Button(i18n("刷新音色列表和索引路径"), variant="primary")
|
365 |
-
with gr.Column():
|
366 |
-
spk_item = gr.Slider(
|
367 |
-
minimum=0,
|
368 |
-
maximum=2333,
|
369 |
-
step=1,
|
370 |
-
label=i18n("请选择说话人id"),
|
371 |
-
value=0,
|
372 |
-
visible=False,
|
373 |
-
interactive=True,
|
374 |
-
)
|
375 |
-
gr.Markdown(
|
376 |
-
value=i18n("男转女推荐+12key, 女转男推荐-12key, 如果音域爆炸导致音色失真也可以自己调整到合适音域. ")
|
377 |
-
)
|
378 |
-
with gr.Tabs():
|
379 |
-
with gr.TabItem("音频转音频"):
|
380 |
-
vc_input3 = gr.Audio(label="上传音频(长度小于90秒)")
|
381 |
-
but0 = gr.Button(i18n("转换"), variant="primary")
|
382 |
-
with gr.TabItem("文字转音频(基于微软TTS)"):
|
383 |
-
tts_input = gr.Text(label="请输入文本")
|
384 |
-
tts_speaker = gr.Dropdown(label="请选择角色",choices=get_tts_spk(tts_spks))
|
385 |
-
tts_speed = gr.Slider(
|
386 |
-
label = "语速(单位:%,0为正常速度)",
|
387 |
-
value = 0,
|
388 |
-
minimum = -200,
|
389 |
-
maximum = 200
|
390 |
-
)
|
391 |
-
but1 = gr.Button(i18n("转换"), variant="primary")
|
392 |
-
vc_transform0 = gr.Number(label=i18n("变调(整数, 半音数量, 升八度12降八度-12)"), value=0)
|
393 |
-
f0method0 = gr.Radio(
|
394 |
-
label=i18n("选择音高提取算法,输入歌声可用pm提速,harvest低音好但巨慢无比,crepe效果好但吃GPU"),
|
395 |
-
choices=["pm"],
|
396 |
-
value="pm",
|
397 |
-
interactive=True,
|
398 |
-
)
|
399 |
-
filter_radius0 = gr.Slider(
|
400 |
-
minimum=0,
|
401 |
-
maximum=7,
|
402 |
-
label=i18n(">=3则使用对harvest音高识别的结果使用中值滤波,数值为滤波半径,使用可以削弱哑音"),
|
403 |
-
value=3,
|
404 |
-
step=1,
|
405 |
-
interactive=True,
|
406 |
-
)
|
407 |
-
with gr.Column():
|
408 |
-
file_index1 = gr.Textbox(
|
409 |
-
label=i18n("特征检索库文件路径,为空则使用下拉的选择结果"),
|
410 |
-
value="",
|
411 |
-
interactive=False,
|
412 |
-
visible=False,
|
413 |
-
)
|
414 |
-
file_index2 = gr.Dropdown(
|
415 |
-
label=i18n("自动检测index路径,下拉式选择(dropdown)"),
|
416 |
-
choices=sorted(index_paths),
|
417 |
-
interactive=True,
|
418 |
-
)
|
419 |
-
refresh_button.click(
|
420 |
-
fn=change_choices, inputs=[], outputs=[sid, file_index2]
|
421 |
-
)
|
422 |
-
index_rate1 = gr.Slider(
|
423 |
-
minimum=0,
|
424 |
-
maximum=1,
|
425 |
-
label=i18n("检索特征占比"),
|
426 |
-
value=0.88,
|
427 |
-
interactive=True,
|
428 |
-
)
|
429 |
-
resample_sr0 = gr.Slider(
|
430 |
-
minimum=0,
|
431 |
-
maximum=48000,
|
432 |
-
label=i18n("后处理重采样至最终采样率,0为不进行重采样"),
|
433 |
-
value=0,
|
434 |
-
step=1,
|
435 |
-
interactive=True,
|
436 |
-
)
|
437 |
-
rms_mix_rate0 = gr.Slider(
|
438 |
-
minimum=0,
|
439 |
-
maximum=1,
|
440 |
-
label=i18n("输入源音量包络替换输出音量包络融合比例,越靠近1越使用输出包络"),
|
441 |
-
value=1,
|
442 |
-
interactive=True,
|
443 |
-
)
|
444 |
-
protect0 = gr.Slider(
|
445 |
-
minimum=0,
|
446 |
-
maximum=0.5,
|
447 |
-
label=i18n("保护清辅音和呼吸声,防止电音撕裂等artifact,拉满0.5不开启,调低加大保护力度但可能降低索引效果"),
|
448 |
-
value=0.33,
|
449 |
-
step=0.01,
|
450 |
-
interactive=True,
|
451 |
-
)
|
452 |
-
f0_file = gr.File(label=i18n("F0曲线文件, 可选, 一行一个音高, 代替默认F0及升降调"))
|
453 |
-
vc_output1 = gr.Textbox(label=i18n("输出信息"))
|
454 |
-
vc_output2 = gr.Audio(label=i18n("输出音频(右下角三个点,点了可以下载)"))
|
455 |
-
but0.click(
|
456 |
-
fn=get_vc,
|
457 |
-
inputs=[sid],
|
458 |
-
outputs=[spk_item],
|
459 |
-
)
|
460 |
-
but0.click(
|
461 |
-
vc_single,
|
462 |
-
[
|
463 |
-
spk_item,
|
464 |
-
vc_input3,
|
465 |
-
vc_transform0,
|
466 |
-
f0_file,
|
467 |
-
f0method0,
|
468 |
-
file_index1,
|
469 |
-
file_index2,
|
470 |
-
# file_big_npy1,
|
471 |
-
index_rate1,
|
472 |
-
filter_radius0,
|
473 |
-
resample_sr0,
|
474 |
-
rms_mix_rate0,
|
475 |
-
protect0,
|
476 |
-
],
|
477 |
-
[vc_output1, vc_output2],
|
478 |
-
)
|
479 |
-
but1.click(
|
480 |
-
fn=get_vc,
|
481 |
-
inputs=[sid],
|
482 |
-
outputs=[spk_item],
|
483 |
-
)
|
484 |
-
but1.click(
|
485 |
-
tts_vc_single,
|
486 |
-
[
|
487 |
-
spk_item,
|
488 |
-
vc_transform0,
|
489 |
-
f0_file,
|
490 |
-
f0method0,
|
491 |
-
file_index1,
|
492 |
-
file_index2,
|
493 |
-
# file_big_npy1,
|
494 |
-
index_rate1,
|
495 |
-
filter_radius0,
|
496 |
-
resample_sr0,
|
497 |
-
rms_mix_rate0,
|
498 |
-
protect0,
|
499 |
-
tts_input,
|
500 |
-
tts_speed,
|
501 |
-
tts_speaker,
|
502 |
-
],
|
503 |
-
[vc_output1, vc_output2],
|
504 |
-
)
|
505 |
-
|
506 |
-
app.queue(concurrency_count=511, max_size=1022).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AIGC-Audio/AudioGPT/NeuralSeq/modules/GenerSpeech/task/dataset.py
DELETED
@@ -1,193 +0,0 @@
|
|
1 |
-
import matplotlib
|
2 |
-
matplotlib.use('Agg')
|
3 |
-
from tasks.base_task import data_loader
|
4 |
-
from tasks.tts.fs2 import FastSpeech2Task
|
5 |
-
from tasks.tts.dataset_utils import FastSpeechDataset, BaseTTSDataset
|
6 |
-
import glob
|
7 |
-
import importlib
|
8 |
-
from utils.pitch_utils import norm_interp_f0, denorm_f0, f0_to_coarse
|
9 |
-
from inference.base_tts_infer import load_data_preprocessor
|
10 |
-
from data_gen.tts.emotion import inference as EmotionEncoder
|
11 |
-
from data_gen.tts.emotion.inference import embed_utterance as Embed_utterance
|
12 |
-
from data_gen.tts.emotion.inference import preprocess_wav
|
13 |
-
from tqdm import tqdm
|
14 |
-
from utils.hparams import hparams
|
15 |
-
from data_gen.tts.data_gen_utils import build_phone_encoder, build_word_encoder
|
16 |
-
import random
|
17 |
-
import torch
|
18 |
-
import torch.optim
|
19 |
-
import torch.nn.functional as F
|
20 |
-
import torch.utils.data
|
21 |
-
from utils.indexed_datasets import IndexedDataset
|
22 |
-
from resemblyzer import VoiceEncoder
|
23 |
-
import torch.distributions
|
24 |
-
import numpy as np
|
25 |
-
import utils
|
26 |
-
import os
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
class GenerSpeech_dataset(BaseTTSDataset):
|
31 |
-
def __init__(self, prefix, shuffle=False, test_items=None, test_sizes=None, data_dir=None):
|
32 |
-
super().__init__(prefix, shuffle, test_items, test_sizes, data_dir)
|
33 |
-
self.f0_mean, self.f0_std = hparams.get('f0_mean', None), hparams.get('f0_std', None)
|
34 |
-
if prefix == 'valid':
|
35 |
-
indexed_ds = IndexedDataset(f'{self.data_dir}/train')
|
36 |
-
sizes = np.load(f'{self.data_dir}/train_lengths.npy')
|
37 |
-
index = [i for i in range(len(indexed_ds))]
|
38 |
-
random.shuffle(index)
|
39 |
-
index = index[:300]
|
40 |
-
self.sizes = sizes[index]
|
41 |
-
self.indexed_ds = []
|
42 |
-
for i in index:
|
43 |
-
self.indexed_ds.append(indexed_ds[i])
|
44 |
-
self.avail_idxs = list(range(len(self.sizes)))
|
45 |
-
if hparams['min_frames'] > 0:
|
46 |
-
self.avail_idxs = [x for x in self.avail_idxs if self.sizes[x] >= hparams['min_frames']]
|
47 |
-
self.sizes = [self.sizes[i] for i in self.avail_idxs]
|
48 |
-
|
49 |
-
if prefix == 'test' and hparams['test_input_dir'] != '':
|
50 |
-
self.preprocessor, self.preprocess_args = load_data_preprocessor()
|
51 |
-
self.indexed_ds, self.sizes = self.load_test_inputs(hparams['test_input_dir'])
|
52 |
-
self.avail_idxs = [i for i, _ in enumerate(self.sizes)]
|
53 |
-
|
54 |
-
|
55 |
-
def load_test_inputs(self, test_input_dir):
|
56 |
-
inp_wav_paths = sorted(glob.glob(f'{test_input_dir}/*.wav') + glob.glob(f'{test_input_dir}/*.mp3'))
|
57 |
-
binarizer_cls = hparams.get("binarizer_cls", 'data_gen.tts.base_binarizerr.BaseBinarizer')
|
58 |
-
pkg = ".".join(binarizer_cls.split(".")[:-1])
|
59 |
-
cls_name = binarizer_cls.split(".")[-1]
|
60 |
-
binarizer_cls = getattr(importlib.import_module(pkg), cls_name)
|
61 |
-
|
62 |
-
phone_encoder = build_phone_encoder(hparams['binary_data_dir'])
|
63 |
-
word_encoder = build_word_encoder(hparams['binary_data_dir'])
|
64 |
-
voice_encoder = VoiceEncoder().cuda()
|
65 |
-
|
66 |
-
encoder = [phone_encoder, word_encoder]
|
67 |
-
sizes = []
|
68 |
-
items = []
|
69 |
-
EmotionEncoder.load_model(hparams['emotion_encoder_path'])
|
70 |
-
preprocessor, preprocess_args = self.preprocessor, self.preprocess_args
|
71 |
-
|
72 |
-
for wav_fn in tqdm(inp_wav_paths):
|
73 |
-
item_name = wav_fn[len(test_input_dir) + 1:].replace("/", "_")
|
74 |
-
spk_id = emotion = 0
|
75 |
-
item2tgfn = wav_fn.replace('.wav', '.TextGrid') # prepare textgrid alignment
|
76 |
-
txtpath = wav_fn.replace('.wav', '.txt') # prepare text
|
77 |
-
with open(txtpath, 'r') as f:
|
78 |
-
text_raw = f.readlines()
|
79 |
-
f.close()
|
80 |
-
ph, txt = preprocessor.txt_to_ph(preprocessor.txt_processor, text_raw[0], preprocess_args)
|
81 |
-
|
82 |
-
item = binarizer_cls.process_item(item_name, ph, txt, item2tgfn, wav_fn, spk_id, emotion, encoder, hparams['binarization_args'])
|
83 |
-
item['emo_embed'] = Embed_utterance(preprocess_wav(item['wav_fn']))
|
84 |
-
item['spk_embed'] = voice_encoder.embed_utterance(item['wav'])
|
85 |
-
items.append(item)
|
86 |
-
sizes.append(item['len'])
|
87 |
-
return items, sizes
|
88 |
-
|
89 |
-
def _get_item(self, index):
|
90 |
-
if hasattr(self, 'avail_idxs') and self.avail_idxs is not None:
|
91 |
-
index = self.avail_idxs[index]
|
92 |
-
if self.indexed_ds is None:
|
93 |
-
self.indexed_ds = IndexedDataset(f'{self.data_dir}/{self.prefix}')
|
94 |
-
return self.indexed_ds[index]
|
95 |
-
|
96 |
-
def __getitem__(self, index):
|
97 |
-
hparams = self.hparams
|
98 |
-
item = self._get_item(index)
|
99 |
-
assert len(item['mel']) == self.sizes[index], (len(item['mel']), self.sizes[index])
|
100 |
-
max_frames = hparams['max_frames']
|
101 |
-
spec = torch.Tensor(item['mel'])[:max_frames]
|
102 |
-
max_frames = spec.shape[0] // hparams['frames_multiple'] * hparams['frames_multiple']
|
103 |
-
spec = spec[:max_frames]
|
104 |
-
phone = torch.LongTensor(item['phone'][:hparams['max_input_tokens']])
|
105 |
-
sample = {
|
106 |
-
"id": index,
|
107 |
-
"item_name": item['item_name'],
|
108 |
-
"text": item['txt'],
|
109 |
-
"txt_token": phone,
|
110 |
-
"mel": spec,
|
111 |
-
"mel_nonpadding": spec.abs().sum(-1) > 0,
|
112 |
-
}
|
113 |
-
spec = sample['mel']
|
114 |
-
T = spec.shape[0]
|
115 |
-
sample['mel2ph'] = mel2ph = torch.LongTensor(item['mel2ph'])[:T] if 'mel2ph' in item else None
|
116 |
-
if hparams['use_pitch_embed']:
|
117 |
-
assert 'f0' in item
|
118 |
-
if hparams.get('normalize_pitch', False):
|
119 |
-
f0 = item["f0"]
|
120 |
-
if len(f0 > 0) > 0 and f0[f0 > 0].std() > 0:
|
121 |
-
f0[f0 > 0] = (f0[f0 > 0] - f0[f0 > 0].mean()) / f0[f0 > 0].std() * hparams['f0_std'] + \
|
122 |
-
hparams['f0_mean']
|
123 |
-
f0[f0 > 0] = f0[f0 > 0].clip(min=60, max=500)
|
124 |
-
pitch = f0_to_coarse(f0)
|
125 |
-
pitch = torch.LongTensor(pitch[:max_frames])
|
126 |
-
else:
|
127 |
-
pitch = torch.LongTensor(item.get("pitch"))[:max_frames] if "pitch" in item else None
|
128 |
-
f0, uv = norm_interp_f0(item["f0"][:max_frames], hparams)
|
129 |
-
uv = torch.FloatTensor(uv)
|
130 |
-
f0 = torch.FloatTensor(f0)
|
131 |
-
else:
|
132 |
-
f0 = uv = torch.zeros_like(mel2ph)
|
133 |
-
pitch = None
|
134 |
-
sample["f0"], sample["uv"], sample["pitch"] = f0, uv, pitch
|
135 |
-
sample["spk_embed"] = torch.Tensor(item['spk_embed'])
|
136 |
-
sample["emotion"] = item['emotion']
|
137 |
-
sample["emo_embed"] = torch.Tensor(item['emo_embed'])
|
138 |
-
|
139 |
-
if hparams.get('use_word', False):
|
140 |
-
sample["ph_words"] = item["ph_words"]
|
141 |
-
sample["word_tokens"] = torch.LongTensor(item["word_tokens"])
|
142 |
-
sample["mel2word"] = torch.LongTensor(item.get("mel2word"))[:max_frames]
|
143 |
-
sample["ph2word"] = torch.LongTensor(item['ph2word'][:hparams['max_input_tokens']])
|
144 |
-
return sample
|
145 |
-
|
146 |
-
def collater(self, samples):
|
147 |
-
if len(samples) == 0:
|
148 |
-
return {}
|
149 |
-
hparams = self.hparams
|
150 |
-
id = torch.LongTensor([s['id'] for s in samples])
|
151 |
-
item_names = [s['item_name'] for s in samples]
|
152 |
-
text = [s['text'] for s in samples]
|
153 |
-
txt_tokens = utils.collate_1d([s['txt_token'] for s in samples], 0)
|
154 |
-
mels = utils.collate_2d([s['mel'] for s in samples], 0.0)
|
155 |
-
txt_lengths = torch.LongTensor([s['txt_token'].numel() for s in samples])
|
156 |
-
mel_lengths = torch.LongTensor([s['mel'].shape[0] for s in samples])
|
157 |
-
|
158 |
-
batch = {
|
159 |
-
'id': id,
|
160 |
-
'item_name': item_names,
|
161 |
-
'nsamples': len(samples),
|
162 |
-
'text': text,
|
163 |
-
'txt_tokens': txt_tokens,
|
164 |
-
'txt_lengths': txt_lengths,
|
165 |
-
'mels': mels,
|
166 |
-
'mel_lengths': mel_lengths,
|
167 |
-
}
|
168 |
-
|
169 |
-
f0 = utils.collate_1d([s['f0'] for s in samples], 0.0)
|
170 |
-
pitch = utils.collate_1d([s['pitch'] for s in samples]) if samples[0]['pitch'] is not None else None
|
171 |
-
uv = utils.collate_1d([s['uv'] for s in samples])
|
172 |
-
mel2ph = utils.collate_1d([s['mel2ph'] for s in samples], 0.0) if samples[0]['mel2ph'] is not None else None
|
173 |
-
batch.update({
|
174 |
-
'mel2ph': mel2ph,
|
175 |
-
'pitch': pitch,
|
176 |
-
'f0': f0,
|
177 |
-
'uv': uv,
|
178 |
-
})
|
179 |
-
spk_embed = torch.stack([s['spk_embed'] for s in samples])
|
180 |
-
batch['spk_embed'] = spk_embed
|
181 |
-
emo_embed = torch.stack([s['emo_embed'] for s in samples])
|
182 |
-
batch['emo_embed'] = emo_embed
|
183 |
-
|
184 |
-
if hparams.get('use_word', False):
|
185 |
-
ph_words = [s['ph_words'] for s in samples]
|
186 |
-
batch['ph_words'] = ph_words
|
187 |
-
word_tokens = utils.collate_1d([s['word_tokens'] for s in samples], 0)
|
188 |
-
batch['word_tokens'] = word_tokens
|
189 |
-
mel2word = utils.collate_1d([s['mel2word'] for s in samples], 0)
|
190 |
-
batch['mel2word'] = mel2word
|
191 |
-
ph2word = utils.collate_1d([s['ph2word'] for s in samples], 0)
|
192 |
-
batch['ph2word'] = ph2word
|
193 |
-
return batch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AIGC-Audio/AudioGPT/NeuralSeq/modules/diffsinger_midi/fs2.py
DELETED
@@ -1,119 +0,0 @@
|
|
1 |
-
from modules.commons.common_layers import *
|
2 |
-
from modules.commons.common_layers import Embedding
|
3 |
-
from modules.fastspeech.tts_modules import FastspeechDecoder, DurationPredictor, LengthRegulator, PitchPredictor, \
|
4 |
-
EnergyPredictor, FastspeechEncoder
|
5 |
-
from utils.cwt import cwt2f0
|
6 |
-
from utils.hparams import hparams
|
7 |
-
from utils.pitch_utils import f0_to_coarse, denorm_f0, norm_f0
|
8 |
-
from modules.fastspeech.fs2 import FastSpeech2
|
9 |
-
|
10 |
-
|
11 |
-
class FastspeechMIDIEncoder(FastspeechEncoder):
|
12 |
-
def forward_embedding(self, txt_tokens, midi_embedding, midi_dur_embedding, slur_embedding):
|
13 |
-
# embed tokens and positions
|
14 |
-
x = self.embed_scale * self.embed_tokens(txt_tokens)
|
15 |
-
x = x + midi_embedding + midi_dur_embedding + slur_embedding
|
16 |
-
if hparams['use_pos_embed']:
|
17 |
-
if hparams.get('rel_pos') is not None and hparams['rel_pos']:
|
18 |
-
x = self.embed_positions(x)
|
19 |
-
else:
|
20 |
-
positions = self.embed_positions(txt_tokens)
|
21 |
-
x = x + positions
|
22 |
-
x = F.dropout(x, p=self.dropout, training=self.training)
|
23 |
-
return x
|
24 |
-
|
25 |
-
def forward(self, txt_tokens, midi_embedding, midi_dur_embedding, slur_embedding):
|
26 |
-
"""
|
27 |
-
|
28 |
-
:param txt_tokens: [B, T]
|
29 |
-
:return: {
|
30 |
-
'encoder_out': [T x B x C]
|
31 |
-
}
|
32 |
-
"""
|
33 |
-
encoder_padding_mask = txt_tokens.eq(self.padding_idx).data
|
34 |
-
x = self.forward_embedding(txt_tokens, midi_embedding, midi_dur_embedding, slur_embedding) # [B, T, H]
|
35 |
-
x = super(FastspeechEncoder, self).forward(x, encoder_padding_mask)
|
36 |
-
return x
|
37 |
-
|
38 |
-
|
39 |
-
FS_ENCODERS = {
|
40 |
-
'fft': lambda hp, embed_tokens, d: FastspeechMIDIEncoder(
|
41 |
-
embed_tokens, hp['hidden_size'], hp['enc_layers'], hp['enc_ffn_kernel_size'],
|
42 |
-
num_heads=hp['num_heads']),
|
43 |
-
}
|
44 |
-
|
45 |
-
|
46 |
-
class FastSpeech2MIDI(FastSpeech2):
|
47 |
-
def __init__(self, dictionary, out_dims=None):
|
48 |
-
super().__init__(dictionary, out_dims)
|
49 |
-
del self.encoder
|
50 |
-
self.encoder = FS_ENCODERS[hparams['encoder_type']](hparams, self.encoder_embed_tokens, self.dictionary)
|
51 |
-
self.midi_embed = Embedding(300, self.hidden_size, self.padding_idx)
|
52 |
-
self.midi_dur_layer = Linear(1, self.hidden_size)
|
53 |
-
self.is_slur_embed = Embedding(2, self.hidden_size)
|
54 |
-
|
55 |
-
def forward(self, txt_tokens, mel2ph=None, spk_embed=None,
|
56 |
-
ref_mels=None, f0=None, uv=None, energy=None, skip_decoder=False,
|
57 |
-
spk_embed_dur_id=None, spk_embed_f0_id=None, infer=False, **kwargs):
|
58 |
-
ret = {}
|
59 |
-
|
60 |
-
midi_embedding = self.midi_embed(kwargs['pitch_midi'])
|
61 |
-
midi_dur_embedding, slur_embedding = 0, 0
|
62 |
-
if kwargs.get('midi_dur') is not None:
|
63 |
-
midi_dur_embedding = self.midi_dur_layer(kwargs['midi_dur'][:, :, None]) # [B, T, 1] -> [B, T, H]
|
64 |
-
if kwargs.get('is_slur') is not None:
|
65 |
-
slur_embedding = self.is_slur_embed(kwargs['is_slur'])
|
66 |
-
encoder_out = self.encoder(txt_tokens, midi_embedding, midi_dur_embedding, slur_embedding) # [B, T, C]
|
67 |
-
src_nonpadding = (txt_tokens > 0).float()[:, :, None]
|
68 |
-
|
69 |
-
# add ref style embed
|
70 |
-
# Not implemented
|
71 |
-
# variance encoder
|
72 |
-
var_embed = 0
|
73 |
-
|
74 |
-
# encoder_out_dur denotes encoder outputs for duration predictor
|
75 |
-
# in speech adaptation, duration predictor use old speaker embedding
|
76 |
-
if hparams['use_spk_embed']:
|
77 |
-
spk_embed_dur = spk_embed_f0 = spk_embed = self.spk_embed_proj(spk_embed)[:, None, :]
|
78 |
-
elif hparams['use_spk_id']:
|
79 |
-
spk_embed_id = spk_embed
|
80 |
-
if spk_embed_dur_id is None:
|
81 |
-
spk_embed_dur_id = spk_embed_id
|
82 |
-
if spk_embed_f0_id is None:
|
83 |
-
spk_embed_f0_id = spk_embed_id
|
84 |
-
spk_embed = self.spk_embed_proj(spk_embed_id)[:, None, :]
|
85 |
-
spk_embed_dur = spk_embed_f0 = spk_embed
|
86 |
-
if hparams['use_split_spk_id']:
|
87 |
-
spk_embed_dur = self.spk_embed_dur(spk_embed_dur_id)[:, None, :]
|
88 |
-
spk_embed_f0 = self.spk_embed_f0(spk_embed_f0_id)[:, None, :]
|
89 |
-
else:
|
90 |
-
spk_embed_dur = spk_embed_f0 = spk_embed = 0
|
91 |
-
|
92 |
-
# add dur
|
93 |
-
dur_inp = (encoder_out + var_embed + spk_embed_dur) * src_nonpadding
|
94 |
-
|
95 |
-
mel2ph = self.add_dur(dur_inp, mel2ph, txt_tokens, ret)
|
96 |
-
|
97 |
-
decoder_inp = F.pad(encoder_out, [0, 0, 1, 0])
|
98 |
-
|
99 |
-
mel2ph_ = mel2ph[..., None].repeat([1, 1, encoder_out.shape[-1]])
|
100 |
-
decoder_inp_origin = decoder_inp = torch.gather(decoder_inp, 1, mel2ph_) # [B, T, H]
|
101 |
-
|
102 |
-
tgt_nonpadding = (mel2ph > 0).float()[:, :, None]
|
103 |
-
|
104 |
-
# add pitch and energy embed
|
105 |
-
pitch_inp = (decoder_inp_origin + var_embed + spk_embed_f0) * tgt_nonpadding
|
106 |
-
if hparams['use_pitch_embed']:
|
107 |
-
pitch_inp_ph = (encoder_out + var_embed + spk_embed_f0) * src_nonpadding
|
108 |
-
decoder_inp = decoder_inp + self.add_pitch(pitch_inp, f0, uv, mel2ph, ret, encoder_out=pitch_inp_ph)
|
109 |
-
if hparams['use_energy_embed']:
|
110 |
-
decoder_inp = decoder_inp + self.add_energy(pitch_inp, energy, ret)
|
111 |
-
|
112 |
-
ret['decoder_inp'] = decoder_inp = (decoder_inp + spk_embed) * tgt_nonpadding
|
113 |
-
|
114 |
-
if skip_decoder:
|
115 |
-
return ret
|
116 |
-
ret['mel_out'] = self.run_decoder(decoder_inp, tgt_nonpadding, ret, infer=infer, **kwargs)
|
117 |
-
|
118 |
-
return ret
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AIGC-Audio/AudioGPT/text_to_audio/Make_An_Audio/ldm/modules/discriminator/multi_window_disc.py
DELETED
@@ -1,196 +0,0 @@
|
|
1 |
-
import numpy as np
|
2 |
-
import torch
|
3 |
-
import torch.nn as nn
|
4 |
-
|
5 |
-
|
6 |
-
class Discriminator2DFactory(nn.Module):
|
7 |
-
def __init__(self, time_length, freq_length=80, kernel=(3, 3), c_in=1, hidden_size=128,
|
8 |
-
norm_type='bn', reduction='sum'):
|
9 |
-
super(Discriminator2DFactory, self).__init__()
|
10 |
-
padding = (kernel[0] // 2, kernel[1] // 2)
|
11 |
-
|
12 |
-
def discriminator_block(in_filters, out_filters, first=False):
|
13 |
-
"""
|
14 |
-
Input: (B, in, 2H, 2W)
|
15 |
-
Output:(B, out, H, W)
|
16 |
-
"""
|
17 |
-
conv = nn.Conv2d(in_filters, out_filters, kernel, (2, 2), padding)
|
18 |
-
if norm_type == 'sn':
|
19 |
-
conv = nn.utils.spectral_norm(conv)
|
20 |
-
block = [
|
21 |
-
conv, # padding = kernel//2
|
22 |
-
nn.LeakyReLU(0.2, inplace=True),
|
23 |
-
nn.Dropout2d(0.25)
|
24 |
-
]
|
25 |
-
if norm_type == 'bn' and not first:
|
26 |
-
block.append(nn.BatchNorm2d(out_filters, 0.8))
|
27 |
-
if norm_type == 'in' and not first:
|
28 |
-
block.append(nn.InstanceNorm2d(out_filters, affine=True))
|
29 |
-
block = nn.Sequential(*block)
|
30 |
-
return block
|
31 |
-
|
32 |
-
self.model = nn.ModuleList([
|
33 |
-
discriminator_block(c_in, hidden_size, first=True),
|
34 |
-
discriminator_block(hidden_size, hidden_size),
|
35 |
-
discriminator_block(hidden_size, hidden_size),
|
36 |
-
])
|
37 |
-
|
38 |
-
self.reduction = reduction
|
39 |
-
ds_size = (time_length // 2 ** 3, (freq_length + 7) // 2 ** 3)
|
40 |
-
if reduction != 'none':
|
41 |
-
# The height and width of downsampled image
|
42 |
-
self.adv_layer = nn.Linear(hidden_size * ds_size[0] * ds_size[1], 1)
|
43 |
-
else:
|
44 |
-
self.adv_layer = nn.Linear(hidden_size * ds_size[1], 1)
|
45 |
-
|
46 |
-
def forward(self, x):
|
47 |
-
"""
|
48 |
-
|
49 |
-
:param x: [B, C, T, n_bins]
|
50 |
-
:return: validity: [B, 1], h: List of hiddens
|
51 |
-
"""
|
52 |
-
h = []
|
53 |
-
for l in self.model:
|
54 |
-
x = l(x)
|
55 |
-
h.append(x)
|
56 |
-
if self.reduction != 'none':
|
57 |
-
x = x.view(x.shape[0], -1)
|
58 |
-
validity = self.adv_layer(x) # [B, 1]
|
59 |
-
else:
|
60 |
-
B, _, T_, _ = x.shape
|
61 |
-
x = x.transpose(1, 2).reshape(B, T_, -1)
|
62 |
-
validity = self.adv_layer(x)[:, :, 0] # [B, T]
|
63 |
-
return validity, h
|
64 |
-
|
65 |
-
|
66 |
-
class MultiWindowDiscriminator(nn.Module):
|
67 |
-
def __init__(self, time_lengths, cond_size=0, freq_length=80, kernel=(3, 3),
|
68 |
-
c_in=1, hidden_size=128, norm_type='bn', reduction='sum'):
|
69 |
-
super(MultiWindowDiscriminator, self).__init__()
|
70 |
-
self.win_lengths = time_lengths
|
71 |
-
self.reduction = reduction
|
72 |
-
|
73 |
-
self.conv_layers = nn.ModuleList()
|
74 |
-
if cond_size > 0:
|
75 |
-
self.cond_proj_layers = nn.ModuleList()
|
76 |
-
self.mel_proj_layers = nn.ModuleList()
|
77 |
-
for time_length in time_lengths:
|
78 |
-
conv_layer = [
|
79 |
-
Discriminator2DFactory(
|
80 |
-
time_length, freq_length, kernel, c_in=c_in, hidden_size=hidden_size,
|
81 |
-
norm_type=norm_type, reduction=reduction)
|
82 |
-
]
|
83 |
-
self.conv_layers += conv_layer
|
84 |
-
if cond_size > 0:
|
85 |
-
self.cond_proj_layers.append(nn.Linear(cond_size, freq_length))
|
86 |
-
self.mel_proj_layers.append(nn.Linear(freq_length, freq_length))
|
87 |
-
|
88 |
-
def forward(self, x, x_len, cond=None, start_frames_wins=None):
|
89 |
-
'''
|
90 |
-
Args:
|
91 |
-
x (tensor): input mel, (B, c_in, T, n_bins).
|
92 |
-
x_length (tensor): len of per mel. (B,).
|
93 |
-
|
94 |
-
Returns:
|
95 |
-
tensor : (B).
|
96 |
-
'''
|
97 |
-
validity = []
|
98 |
-
if start_frames_wins is None:
|
99 |
-
start_frames_wins = [None] * len(self.conv_layers)
|
100 |
-
h = []
|
101 |
-
for i, start_frames in zip(range(len(self.conv_layers)), start_frames_wins):
|
102 |
-
x_clip, c_clip, start_frames = self.clip(
|
103 |
-
x, cond, x_len, self.win_lengths[i], start_frames) # (B, win_length, C)
|
104 |
-
start_frames_wins[i] = start_frames
|
105 |
-
if x_clip is None:
|
106 |
-
continue
|
107 |
-
if cond is not None:
|
108 |
-
x_clip = self.mel_proj_layers[i](x_clip) # (B, 1, win_length, C)
|
109 |
-
c_clip = self.cond_proj_layers[i](c_clip)[:, None] # (B, 1, win_length, C)
|
110 |
-
x_clip = x_clip + c_clip
|
111 |
-
x_clip, h_ = self.conv_layers[i](x_clip)
|
112 |
-
h += h_
|
113 |
-
validity.append(x_clip)
|
114 |
-
if len(validity) != len(self.conv_layers):
|
115 |
-
return None, start_frames_wins, h
|
116 |
-
if self.reduction == 'sum':
|
117 |
-
validity = sum(validity) # [B]
|
118 |
-
elif self.reduction == 'stack':
|
119 |
-
validity = torch.stack(validity, -1) # [B, W_L]
|
120 |
-
elif self.reduction == 'none':
|
121 |
-
validity = torch.cat(validity, -1) # [B, W_sum]
|
122 |
-
return validity, start_frames_wins, h
|
123 |
-
|
124 |
-
def clip(self, x, cond, x_len, win_length, start_frames=None):
|
125 |
-
'''Ramdom clip x to win_length.
|
126 |
-
Args:
|
127 |
-
x (tensor) : (B, c_in, T, n_bins).
|
128 |
-
cond (tensor) : (B, T, H).
|
129 |
-
x_len (tensor) : (B,).
|
130 |
-
win_length (int): target clip length
|
131 |
-
|
132 |
-
Returns:
|
133 |
-
(tensor) : (B, c_in, win_length, n_bins).
|
134 |
-
|
135 |
-
'''
|
136 |
-
T_start = 0
|
137 |
-
T_end = x_len.max() - win_length
|
138 |
-
if T_end < 0:
|
139 |
-
return None, None, start_frames
|
140 |
-
T_end = T_end.item()
|
141 |
-
if start_frames is None:
|
142 |
-
start_frame = np.random.randint(low=T_start, high=T_end + 1)
|
143 |
-
start_frames = [start_frame] * x.size(0)
|
144 |
-
else:
|
145 |
-
start_frame = start_frames[0]
|
146 |
-
x_batch = x[:, :, start_frame: start_frame + win_length]
|
147 |
-
c_batch = cond[:, start_frame: start_frame + win_length] if cond is not None else None
|
148 |
-
return x_batch, c_batch, start_frames
|
149 |
-
|
150 |
-
|
151 |
-
class Discriminator(nn.Module):
|
152 |
-
def __init__(self, time_lengths=[32, 64, 128], freq_length=80, cond_size=0, kernel=(3, 3), c_in=1,
|
153 |
-
hidden_size=128, norm_type='bn', reduction='sum', uncond_disc=True):
|
154 |
-
super(Discriminator, self).__init__()
|
155 |
-
self.time_lengths = time_lengths
|
156 |
-
self.cond_size = cond_size
|
157 |
-
self.reduction = reduction
|
158 |
-
self.uncond_disc = uncond_disc
|
159 |
-
if uncond_disc:
|
160 |
-
self.discriminator = MultiWindowDiscriminator(
|
161 |
-
freq_length=freq_length,
|
162 |
-
time_lengths=time_lengths,
|
163 |
-
kernel=kernel,
|
164 |
-
c_in=c_in, hidden_size=hidden_size, norm_type=norm_type,
|
165 |
-
reduction=reduction
|
166 |
-
)
|
167 |
-
if cond_size > 0:
|
168 |
-
self.cond_disc = MultiWindowDiscriminator(
|
169 |
-
freq_length=freq_length,
|
170 |
-
time_lengths=time_lengths,
|
171 |
-
cond_size=cond_size,
|
172 |
-
kernel=kernel,
|
173 |
-
c_in=c_in, hidden_size=hidden_size, norm_type=norm_type,
|
174 |
-
reduction=reduction
|
175 |
-
)
|
176 |
-
|
177 |
-
def forward(self, x, cond=None, start_frames_wins=None):
|
178 |
-
"""
|
179 |
-
|
180 |
-
:param x: [B, T, 80]
|
181 |
-
:param cond: [B, T, cond_size]
|
182 |
-
:param return_y_only:
|
183 |
-
:return:
|
184 |
-
"""
|
185 |
-
if len(x.shape) == 3:
|
186 |
-
x = x[:, None, :, :]
|
187 |
-
x_len = x.sum([1, -1]).ne(0).int().sum([-1])
|
188 |
-
ret = {'y_c': None, 'y': None}
|
189 |
-
if self.uncond_disc:
|
190 |
-
ret['y'], start_frames_wins, ret['h'] = self.discriminator(
|
191 |
-
x, x_len, start_frames_wins=start_frames_wins)
|
192 |
-
if self.cond_size > 0 and cond is not None:
|
193 |
-
ret['y_c'], start_frames_wins, ret['h_c'] = self.cond_disc(
|
194 |
-
x, x_len, cond, start_frames_wins=start_frames_wins)
|
195 |
-
ret['start_frames_wins'] = start_frames_wins
|
196 |
-
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AILab-CVC/EvalCrafter/constants.py
DELETED
@@ -1,47 +0,0 @@
|
|
1 |
-
# this is .py for store constants
|
2 |
-
MODEL_INFO = ['Models', 'Ver.','Abilities']
|
3 |
-
TASK_INFO = [ 'Resolution', 'FPS', 'Open Source', 'Length', 'Speed', 'Motion', 'Camera', 'Final Sum Score', 'Motion Quality', 'Text-Video Alignment', 'Visual Quality', 'Temporal Consistency']
|
4 |
-
TASK_INFO_v2 = ['Final Sum Score', 'Motion Quality', 'Text-Video Alignment', 'Visual Quality', 'Temporal Consistency', 'Resolution', 'FPS', 'Open Source', 'Length', 'Speed', 'Motion', 'Camera']
|
5 |
-
|
6 |
-
AVG_INFO = ['Final Sum Score', 'Motion Quality', 'Text-Video Alignment', 'Visual Quality', 'Temporal Consistency']
|
7 |
-
DATA_TITILE_TYPE = ["markdown", "number", "number", "number", "number", "number", "number", "number", "number", "number", "number", "number", "number", "number", "number"]
|
8 |
-
CSV_DIR = "./file/result.csv"
|
9 |
-
|
10 |
-
# COLUMN_NAMES = MODEL_INFO + TASK_INFO
|
11 |
-
COLUMN_NAMES = MODEL_INFO + TASK_INFO_v2
|
12 |
-
|
13 |
-
DATA_NUM = [3158, 1831, 4649, 978, 2447, 657, 97, 331, 85, 1740, 2077, 1192]
|
14 |
-
|
15 |
-
|
16 |
-
LEADERBORAD_INTRODUCTION = """# EvalCrafter Leaderboard 🏆
|
17 |
-
|
18 |
-
Welcome to the cutting-edge leaderboard for text-to-video generation, where we meticulously evaluate state-of-the-art generative models using our comprehensive framework, ensuring high-quality results that align with user opinions. Join us in this exciting journey towards excellence! 🛫
|
19 |
-
|
20 |
-
More methods will be evalcrafted soon, stay tunned ❤️ Join our evaluation by sending an email 📧 ([email protected])! You may also read the [EvalCrafter paper](https://arxiv.org/abs/2310.11440) for more detailed information 🤗
|
21 |
-
"""
|
22 |
-
|
23 |
-
TABLE_INTRODUCTION = """In the table below, we summarize each dimension performance of all the models. """
|
24 |
-
|
25 |
-
LEADERBORAD_INFO = """
|
26 |
-
The vision and language generative models have been overgrown in recent years. For video generation,
|
27 |
-
various open-sourced models and public-available services are released for generating high-visual quality videos.
|
28 |
-
However, these methods often use a few academic metrics, \eg, FVD or IS, to evaluate the performance. We argue that
|
29 |
-
it is hard to judge the large conditional generative models from the simple metrics since these models are often trained
|
30 |
-
on very large datasets with multi-aspect abilities. Thus, we propose a new framework and pipeline to exhaustively evaluate
|
31 |
-
the performance of the generated videos. To achieve this, we first conduct a new prompt list for text-to-video generation
|
32 |
-
by analyzing the real-world prompt list with the help of the large language model. Then, we evaluate the state-of-the-art video
|
33 |
-
generative models on our carefully designed benchmarks, in terms of visual qualities, content qualities, motion qualities, and
|
34 |
-
text-caption alignment with around 18 objective metrics. To obtain the final leaderboard of the models, we also fit a series of
|
35 |
-
coefficients to align the objective metrics to the users' opinions. Based on the proposed opinion alignment method, our final score
|
36 |
-
shows a higher correlation than simply averaging the metrics, showing the effectiveness of the proposed evaluation method.
|
37 |
-
"""
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results"
|
42 |
-
CITATION_BUTTON_TEXT = r"""@inproceedings{Liu2023EvalCrafterBA,
|
43 |
-
title={EvalCrafter: Benchmarking and Evaluating Large Video Generation Models},
|
44 |
-
author={Yaofang Liu and Xiaodong Cun and Xuebo Liu and Xintao Wang and Yong Zhang and Haoxin Chen and Yang Liu and Tieyong Zeng and Raymond Chan and Ying Shan},
|
45 |
-
year={2023},
|
46 |
-
url={https://api.semanticscholar.org/CorpusID:264172222}
|
47 |
-
}"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AIZero2Hero4Health/5-ImageToLineDrawing-GR/README.md
DELETED
@@ -1,12 +0,0 @@
|
|
1 |
-
---
|
2 |
-
title: ZZ-ImageToLineDrawing GR
|
3 |
-
emoji: 💻
|
4 |
-
colorFrom: gray
|
5 |
-
colorTo: red
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 3.8.2
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AchyuthGamer/OpenGPT-Chat-UI/src/routes/LocalDB.ts
DELETED
@@ -1,173 +0,0 @@
|
|
1 |
-
import Dexie, { type Table, liveQuery } from "dexie";
|
2 |
-
import { refresh_chats_writable_empty, refresh_chats_writable } from "../routes/LayoutWritable";
|
3 |
-
import { env } from "$env/dynamic/public";
|
4 |
-
|
5 |
-
export interface Chat {
|
6 |
-
index?: number;
|
7 |
-
title: string;
|
8 |
-
id: string;
|
9 |
-
createdAt: Date;
|
10 |
-
model: string;
|
11 |
-
message?: Array<MessageDb>;
|
12 |
-
}
|
13 |
-
|
14 |
-
export interface MessageDb {
|
15 |
-
content: string;
|
16 |
-
from: string;
|
17 |
-
id: string;
|
18 |
-
createdAt: Date;
|
19 |
-
updatedAt: Date;
|
20 |
-
}
|
21 |
-
|
22 |
-
export class ChatDatabase extends Dexie {
|
23 |
-
chats!: Table<Chat>;
|
24 |
-
|
25 |
-
constructor() {
|
26 |
-
super("opengptchat");
|
27 |
-
this.version(16).stores({
|
28 |
-
chats: null,
|
29 |
-
});
|
30 |
-
this.version(17).stores({
|
31 |
-
chats: null,
|
32 |
-
});
|
33 |
-
this.version(18).stores({
|
34 |
-
chats: "++index, title, createdAt, id, message, model",
|
35 |
-
});
|
36 |
-
}
|
37 |
-
}
|
38 |
-
|
39 |
-
export async function createChat(
|
40 |
-
id_chat: string,
|
41 |
-
msg: MessageDb | undefined,
|
42 |
-
model: string,
|
43 |
-
title?: string
|
44 |
-
) {
|
45 |
-
try {
|
46 |
-
let title_f = "";
|
47 |
-
if (title === undefined) {
|
48 |
-
let count = (await db.chats.count()) + 1;
|
49 |
-
title_f = "Untitled " + count;
|
50 |
-
} else title_f = title;
|
51 |
-
const chat = {
|
52 |
-
id: id_chat,
|
53 |
-
title: title_f,
|
54 |
-
message: msg === undefined ? undefined : [msg],
|
55 |
-
createdAt: new Date(),
|
56 |
-
model: model,
|
57 |
-
};
|
58 |
-
const id = await db.chats.add(chat);
|
59 |
-
} catch (error) {
|
60 |
-
console.log(error);
|
61 |
-
}
|
62 |
-
let push = await getChats();
|
63 |
-
refresh_chats_writable.set(push);
|
64 |
-
}
|
65 |
-
|
66 |
-
export async function deleteAllChats() {
|
67 |
-
const chat_ret = await db.chats.clear();
|
68 |
-
refresh_chats_writable_empty.set(true);
|
69 |
-
}
|
70 |
-
|
71 |
-
export async function deleteChat(id_chat: string) {
|
72 |
-
const chat_ret = await db.chats.where("id").equals(id_chat).delete();
|
73 |
-
let count = await db.chats.count();
|
74 |
-
if (count > 0) {
|
75 |
-
let push = await getChats();
|
76 |
-
refresh_chats_writable.set(push);
|
77 |
-
} else {
|
78 |
-
refresh_chats_writable_empty.set(true);
|
79 |
-
}
|
80 |
-
}
|
81 |
-
|
82 |
-
export async function modifyTitle(id_chat: string, newTitle: string) {
|
83 |
-
const chat_ret = db.chats.where("id").equals(id_chat);
|
84 |
-
let count = await chat_ret.count();
|
85 |
-
if (count > 0) {
|
86 |
-
let res = await chat_ret.first();
|
87 |
-
chat_ret.modify({ title: newTitle });
|
88 |
-
let push = await getChats();
|
89 |
-
refresh_chats_writable.set(push);
|
90 |
-
}
|
91 |
-
}
|
92 |
-
|
93 |
-
export async function addMessageToChat(id_chat: string, msg: MessageDb, model: string) {
|
94 |
-
const chat_ret = db.chats.where("id").equals(id_chat);
|
95 |
-
let count = await chat_ret.count();
|
96 |
-
if (count < 1) {
|
97 |
-
createChat(id_chat, msg, model);
|
98 |
-
} else {
|
99 |
-
let msgs: MessageDb[];
|
100 |
-
chat_ret.first().then((res) => {
|
101 |
-
if (res?.message == undefined) {
|
102 |
-
msgs.push(msg);
|
103 |
-
res.message = msgs;
|
104 |
-
}
|
105 |
-
res.message.push(msg);
|
106 |
-
chat_ret.modify({ id: id_chat, message: res.message });
|
107 |
-
});
|
108 |
-
}
|
109 |
-
}
|
110 |
-
|
111 |
-
export async function getTitle(id_chat: string) {
|
112 |
-
let title_ret = env.PUBLIC_APP_NAME;
|
113 |
-
try {
|
114 |
-
const chat_ret = await db.chats.where("id").equals(id_chat).first();
|
115 |
-
title_ret = chat_ret!.title;
|
116 |
-
} catch (err) {
|
117 |
-
console.log(err);
|
118 |
-
}
|
119 |
-
return title_ret;
|
120 |
-
}
|
121 |
-
|
122 |
-
export async function getMessages(id_chat: string) {
|
123 |
-
try {
|
124 |
-
const chat_ret = await db.chats.where("id").equals(id_chat).first();
|
125 |
-
const msg = chat_ret?.message;
|
126 |
-
return [...msg];
|
127 |
-
} catch (err) {
|
128 |
-
console.log(err);
|
129 |
-
}
|
130 |
-
return undefined;
|
131 |
-
}
|
132 |
-
|
133 |
-
export async function getModel(id_chat: string) {
|
134 |
-
try {
|
135 |
-
const chat_ret = await db.chats.where("id").equals(id_chat).first();
|
136 |
-
let model = chat_ret?.model;
|
137 |
-
if (model === undefined) return "";
|
138 |
-
return model;
|
139 |
-
} catch (err) {
|
140 |
-
console.log(err);
|
141 |
-
}
|
142 |
-
return "";
|
143 |
-
}
|
144 |
-
|
145 |
-
export async function getChats() {
|
146 |
-
let titles = [];
|
147 |
-
try {
|
148 |
-
const all = (await db.chats.orderBy("createdAt").toArray()).forEach(function (chat) {
|
149 |
-
titles.push({
|
150 |
-
title: chat.title,
|
151 |
-
model: "", // Hardcoded for now
|
152 |
-
id: chat.id,
|
153 |
-
updatedAt: chat.createdAt,
|
154 |
-
createdAt: chat.createdAt,
|
155 |
-
});
|
156 |
-
});
|
157 |
-
} catch (err) {
|
158 |
-
console.log(err);
|
159 |
-
}
|
160 |
-
return titles;
|
161 |
-
}
|
162 |
-
|
163 |
-
export async function getChat(id_chat: string) {
|
164 |
-
const chat_ret = db.chats
|
165 |
-
.where("id")
|
166 |
-
.equals(id_chat)
|
167 |
-
.first()
|
168 |
-
.then((res) => {
|
169 |
-
return res;
|
170 |
-
});
|
171 |
-
}
|
172 |
-
|
173 |
-
export const db = new ChatDatabase();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AchyuthGamer/OpenGPT/g4f/Provider/AItianhu.py
DELETED
@@ -1,77 +0,0 @@
|
|
1 |
-
from __future__ import annotations
|
2 |
-
|
3 |
-
import json
|
4 |
-
|
5 |
-
from ..typing import AsyncGenerator
|
6 |
-
from ..requests import StreamSession
|
7 |
-
from .base_provider import AsyncGeneratorProvider, format_prompt, get_cookies
|
8 |
-
|
9 |
-
|
10 |
-
class AItianhu(AsyncGeneratorProvider):
|
11 |
-
url = "https://www.aitianhu.com"
|
12 |
-
working = True
|
13 |
-
supports_gpt_35_turbo = True
|
14 |
-
|
15 |
-
@classmethod
|
16 |
-
async def create_async_generator(
|
17 |
-
cls,
|
18 |
-
model: str,
|
19 |
-
messages: list[dict[str, str]],
|
20 |
-
proxy: str = None,
|
21 |
-
cookies: dict = None,
|
22 |
-
timeout: int = 30,
|
23 |
-
**kwargs
|
24 |
-
) -> AsyncGenerator:
|
25 |
-
if not cookies:
|
26 |
-
cookies = get_cookies("www.aitianhu.com")
|
27 |
-
data = {
|
28 |
-
"prompt": format_prompt(messages),
|
29 |
-
"options": {},
|
30 |
-
"systemMessage": "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully.",
|
31 |
-
"temperature": 0.8,
|
32 |
-
"top_p": 1,
|
33 |
-
**kwargs
|
34 |
-
}
|
35 |
-
headers = {
|
36 |
-
"Authority": cls.url,
|
37 |
-
"Accept": "application/json, text/plain, */*",
|
38 |
-
"Origin": cls.url,
|
39 |
-
"Referer": f"{cls.url}/"
|
40 |
-
}
|
41 |
-
async with StreamSession(
|
42 |
-
headers=headers,
|
43 |
-
cookies=cookies,
|
44 |
-
timeout=timeout,
|
45 |
-
proxies={"https": proxy},
|
46 |
-
impersonate="chrome107",
|
47 |
-
verify=False
|
48 |
-
) as session:
|
49 |
-
async with session.post(f"{cls.url}/api/chat-process", json=data) as response:
|
50 |
-
response.raise_for_status()
|
51 |
-
async for line in response.iter_lines():
|
52 |
-
if line == b"<script>":
|
53 |
-
raise RuntimeError("Solve challenge and pass cookies")
|
54 |
-
if b"platform's risk control" in line:
|
55 |
-
raise RuntimeError("Platform's Risk Control")
|
56 |
-
line = json.loads(line)
|
57 |
-
if "detail" in line:
|
58 |
-
content = line["detail"]["choices"][0]["delta"].get("content")
|
59 |
-
if content:
|
60 |
-
yield content
|
61 |
-
else:
|
62 |
-
raise RuntimeError(f"Response: {line}")
|
63 |
-
|
64 |
-
|
65 |
-
@classmethod
|
66 |
-
@property
|
67 |
-
def params(cls):
|
68 |
-
params = [
|
69 |
-
("model", "str"),
|
70 |
-
("messages", "list[dict[str, str]]"),
|
71 |
-
("stream", "bool"),
|
72 |
-
("proxy", "str"),
|
73 |
-
("temperature", "float"),
|
74 |
-
("top_p", "int"),
|
75 |
-
]
|
76 |
-
param = ", ".join([": ".join(p) for p in params])
|
77 |
-
return f"g4f.provider.{cls.__name__} supports: ({param})"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Adapter/T2I-Adapter/ldm/modules/extra_condition/midas/__init__.py
DELETED
File without changes
|
spaces/Akmyradov/TurkmenTTSweSTT/tts.py
DELETED
@@ -1,173 +0,0 @@
|
|
1 |
-
# Copyright (c) Facebook, Inc. and its affiliates.
|
2 |
-
#
|
3 |
-
# This source code is licensed under the MIT license found in the
|
4 |
-
# LICENSE file in the root directory of this source tree.
|
5 |
-
|
6 |
-
import os
|
7 |
-
import re
|
8 |
-
import tempfile
|
9 |
-
import torch
|
10 |
-
import sys
|
11 |
-
import gradio as gr
|
12 |
-
|
13 |
-
from huggingface_hub import hf_hub_download
|
14 |
-
|
15 |
-
# Setup TTS env
|
16 |
-
if "vits" not in sys.path:
|
17 |
-
sys.path.append("vits")
|
18 |
-
|
19 |
-
from vits import commons, utils
|
20 |
-
from vits.models import SynthesizerTrn
|
21 |
-
|
22 |
-
|
23 |
-
class TextMapper(object):
|
24 |
-
def __init__(self, vocab_file):
|
25 |
-
self.symbols = [
|
26 |
-
x.replace("\n", "") for x in open(vocab_file, encoding="utf-8").readlines()
|
27 |
-
]
|
28 |
-
self.SPACE_ID = self.symbols.index(" ")
|
29 |
-
self._symbol_to_id = {s: i for i, s in enumerate(self.symbols)}
|
30 |
-
self._id_to_symbol = {i: s for i, s in enumerate(self.symbols)}
|
31 |
-
|
32 |
-
def text_to_sequence(self, text, cleaner_names):
|
33 |
-
"""Converts a string of text to a sequence of IDs corresponding to the symbols in the text.
|
34 |
-
Args:
|
35 |
-
text: string to convert to a sequence
|
36 |
-
cleaner_names: names of the cleaner functions to run the text through
|
37 |
-
Returns:
|
38 |
-
List of integers corresponding to the symbols in the text
|
39 |
-
"""
|
40 |
-
sequence = []
|
41 |
-
clean_text = text.strip()
|
42 |
-
for symbol in clean_text:
|
43 |
-
symbol_id = self._symbol_to_id[symbol]
|
44 |
-
sequence += [symbol_id]
|
45 |
-
return sequence
|
46 |
-
|
47 |
-
def uromanize(self, text, uroman_pl):
|
48 |
-
iso = "xxx"
|
49 |
-
with tempfile.NamedTemporaryFile() as tf, tempfile.NamedTemporaryFile() as tf2:
|
50 |
-
with open(tf.name, "w") as f:
|
51 |
-
f.write("\n".join([text]))
|
52 |
-
cmd = f"perl " + uroman_pl
|
53 |
-
cmd += f" -l {iso} "
|
54 |
-
cmd += f" < {tf.name} > {tf2.name}"
|
55 |
-
os.system(cmd)
|
56 |
-
outtexts = []
|
57 |
-
with open(tf2.name) as f:
|
58 |
-
for line in f:
|
59 |
-
line = re.sub(r"\s+", " ", line).strip()
|
60 |
-
outtexts.append(line)
|
61 |
-
outtext = outtexts[0]
|
62 |
-
return outtext
|
63 |
-
|
64 |
-
def get_text(self, text, hps):
|
65 |
-
text_norm = self.text_to_sequence(text, hps.data.text_cleaners)
|
66 |
-
if hps.data.add_blank:
|
67 |
-
text_norm = commons.intersperse(text_norm, 0)
|
68 |
-
text_norm = torch.LongTensor(text_norm)
|
69 |
-
return text_norm
|
70 |
-
|
71 |
-
def filter_oov(self, text, lang=None):
|
72 |
-
text = self.preprocess_char(text, lang=lang)
|
73 |
-
val_chars = self._symbol_to_id
|
74 |
-
txt_filt = "".join(list(filter(lambda x: x in val_chars, text)))
|
75 |
-
return txt_filt
|
76 |
-
|
77 |
-
def preprocess_char(self, text, lang=None):
|
78 |
-
"""
|
79 |
-
Special treatement of characters in certain languages
|
80 |
-
"""
|
81 |
-
if lang == "ron":
|
82 |
-
text = text.replace("ț", "ţ")
|
83 |
-
print(f"{lang} (ț -> ţ): {text}")
|
84 |
-
return text
|
85 |
-
|
86 |
-
|
87 |
-
def synthesize(text, lang, speed):
|
88 |
-
|
89 |
-
if speed is None:
|
90 |
-
speed = 1.0
|
91 |
-
|
92 |
-
lang_code = lang.split(":")[0].strip()
|
93 |
-
|
94 |
-
vocab_file = hf_hub_download(
|
95 |
-
repo_id="facebook/mms-tts",
|
96 |
-
filename="vocab.txt",
|
97 |
-
subfolder=f"models/{lang_code}",
|
98 |
-
)
|
99 |
-
config_file = hf_hub_download(
|
100 |
-
repo_id="facebook/mms-tts",
|
101 |
-
filename="config.json",
|
102 |
-
subfolder=f"models/{lang_code}",
|
103 |
-
)
|
104 |
-
g_pth = hf_hub_download(
|
105 |
-
repo_id="facebook/mms-tts",
|
106 |
-
filename="G_100000.pth",
|
107 |
-
subfolder=f"models/{lang_code}",
|
108 |
-
)
|
109 |
-
|
110 |
-
if torch.cuda.is_available():
|
111 |
-
device = torch.device("cuda")
|
112 |
-
elif (
|
113 |
-
hasattr(torch.backends, "mps")
|
114 |
-
and torch.backends.mps.is_available()
|
115 |
-
and torch.backends.mps.is_built()
|
116 |
-
):
|
117 |
-
device = torch.device("mps")
|
118 |
-
else:
|
119 |
-
device = torch.device("cpu")
|
120 |
-
|
121 |
-
print(f"Run inference with {device}")
|
122 |
-
|
123 |
-
assert os.path.isfile(config_file), f"{config_file} doesn't exist"
|
124 |
-
hps = utils.get_hparams_from_file(config_file)
|
125 |
-
text_mapper = TextMapper(vocab_file)
|
126 |
-
net_g = SynthesizerTrn(
|
127 |
-
len(text_mapper.symbols),
|
128 |
-
hps.data.filter_length // 2 + 1,
|
129 |
-
hps.train.segment_size // hps.data.hop_length,
|
130 |
-
**hps.model,
|
131 |
-
)
|
132 |
-
net_g.to(device)
|
133 |
-
_ = net_g.eval()
|
134 |
-
|
135 |
-
_ = utils.load_checkpoint(g_pth, net_g, None)
|
136 |
-
|
137 |
-
is_uroman = hps.data.training_files.split(".")[-1] == "uroman"
|
138 |
-
|
139 |
-
if is_uroman:
|
140 |
-
uroman_dir = "uroman"
|
141 |
-
assert os.path.exists(uroman_dir)
|
142 |
-
uroman_pl = os.path.join(uroman_dir, "bin", "uroman.pl")
|
143 |
-
text = text_mapper.uromanize(text, uroman_pl)
|
144 |
-
|
145 |
-
text = text.lower()
|
146 |
-
text = text_mapper.filter_oov(text, lang=lang)
|
147 |
-
stn_tst = text_mapper.get_text(text, hps)
|
148 |
-
with torch.no_grad():
|
149 |
-
x_tst = stn_tst.unsqueeze(0).to(device)
|
150 |
-
x_tst_lengths = torch.LongTensor([stn_tst.size(0)]).to(device)
|
151 |
-
hyp = (
|
152 |
-
net_g.infer(
|
153 |
-
x_tst,
|
154 |
-
x_tst_lengths,
|
155 |
-
noise_scale=0.667,
|
156 |
-
noise_scale_w=0.8,
|
157 |
-
length_scale=1.0 / speed,
|
158 |
-
)[0][0, 0]
|
159 |
-
.cpu()
|
160 |
-
.float()
|
161 |
-
.numpy()
|
162 |
-
)
|
163 |
-
|
164 |
-
return gr.Audio.update(value=(hps.data.sampling_rate, hyp)), text
|
165 |
-
|
166 |
-
|
167 |
-
TTS_EXAMPLES = [
|
168 |
-
["Salam. Men indi ýuwaş ýuwaşdan size düşünip başladym", "tuk-script_latin: Turkmen"],
|
169 |
-
["Türkmençe bir bilýäňmow sen?", "tuk-script_latin: Turkmen"],
|
170 |
-
["Iň gowy adamlar, yzyny özüň bilýäň.", "tuk-script_latin: Turkmen"],
|
171 |
-
["Siz bilen tanyşanyma örän şat.", "tuk-script_latin: Turkmen"],
|
172 |
-
["Esasy zat jan saglyk.", "tuk-script_latin: Turkmen"],
|
173 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Al-Chan/Vits_League_of_Legends_Yuumi_TTS/text/korean.py
DELETED
@@ -1,210 +0,0 @@
|
|
1 |
-
import re
|
2 |
-
from jamo import h2j, j2hcj
|
3 |
-
import ko_pron
|
4 |
-
|
5 |
-
|
6 |
-
# This is a list of Korean classifiers preceded by pure Korean numerals.
|
7 |
-
_korean_classifiers = '군데 권 개 그루 닢 대 두 마리 모 모금 뭇 발 발짝 방 번 벌 보루 살 수 술 시 쌈 움큼 정 짝 채 척 첩 축 켤레 톨 통'
|
8 |
-
|
9 |
-
# List of (hangul, hangul divided) pairs:
|
10 |
-
_hangul_divided = [(re.compile('%s' % x[0]), x[1]) for x in [
|
11 |
-
('ㄳ', 'ㄱㅅ'),
|
12 |
-
('ㄵ', 'ㄴㅈ'),
|
13 |
-
('ㄶ', 'ㄴㅎ'),
|
14 |
-
('ㄺ', 'ㄹㄱ'),
|
15 |
-
('ㄻ', 'ㄹㅁ'),
|
16 |
-
('ㄼ', 'ㄹㅂ'),
|
17 |
-
('ㄽ', 'ㄹㅅ'),
|
18 |
-
('ㄾ', 'ㄹㅌ'),
|
19 |
-
('ㄿ', 'ㄹㅍ'),
|
20 |
-
('ㅀ', 'ㄹㅎ'),
|
21 |
-
('ㅄ', 'ㅂㅅ'),
|
22 |
-
('ㅘ', 'ㅗㅏ'),
|
23 |
-
('ㅙ', 'ㅗㅐ'),
|
24 |
-
('ㅚ', 'ㅗㅣ'),
|
25 |
-
('ㅝ', 'ㅜㅓ'),
|
26 |
-
('ㅞ', 'ㅜㅔ'),
|
27 |
-
('ㅟ', 'ㅜㅣ'),
|
28 |
-
('ㅢ', 'ㅡㅣ'),
|
29 |
-
('ㅑ', 'ㅣㅏ'),
|
30 |
-
('ㅒ', 'ㅣㅐ'),
|
31 |
-
('ㅕ', 'ㅣㅓ'),
|
32 |
-
('ㅖ', 'ㅣㅔ'),
|
33 |
-
('ㅛ', 'ㅣㅗ'),
|
34 |
-
('ㅠ', 'ㅣㅜ')
|
35 |
-
]]
|
36 |
-
|
37 |
-
# List of (Latin alphabet, hangul) pairs:
|
38 |
-
_latin_to_hangul = [(re.compile('%s' % x[0], re.IGNORECASE), x[1]) for x in [
|
39 |
-
('a', '에이'),
|
40 |
-
('b', '비'),
|
41 |
-
('c', '시'),
|
42 |
-
('d', '디'),
|
43 |
-
('e', '이'),
|
44 |
-
('f', '에프'),
|
45 |
-
('g', '지'),
|
46 |
-
('h', '에이치'),
|
47 |
-
('i', '아이'),
|
48 |
-
('j', '제이'),
|
49 |
-
('k', '케이'),
|
50 |
-
('l', '엘'),
|
51 |
-
('m', '엠'),
|
52 |
-
('n', '엔'),
|
53 |
-
('o', '오'),
|
54 |
-
('p', '피'),
|
55 |
-
('q', '큐'),
|
56 |
-
('r', '아르'),
|
57 |
-
('s', '에스'),
|
58 |
-
('t', '티'),
|
59 |
-
('u', '유'),
|
60 |
-
('v', '브이'),
|
61 |
-
('w', '더블유'),
|
62 |
-
('x', '엑스'),
|
63 |
-
('y', '와이'),
|
64 |
-
('z', '제트')
|
65 |
-
]]
|
66 |
-
|
67 |
-
# List of (ipa, lazy ipa) pairs:
|
68 |
-
_ipa_to_lazy_ipa = [(re.compile('%s' % x[0], re.IGNORECASE), x[1]) for x in [
|
69 |
-
('t͡ɕ','ʧ'),
|
70 |
-
('d͡ʑ','ʥ'),
|
71 |
-
('ɲ','n^'),
|
72 |
-
('ɕ','ʃ'),
|
73 |
-
('ʷ','w'),
|
74 |
-
('ɭ','l`'),
|
75 |
-
('ʎ','ɾ'),
|
76 |
-
('ɣ','ŋ'),
|
77 |
-
('ɰ','ɯ'),
|
78 |
-
('ʝ','j'),
|
79 |
-
('ʌ','ə'),
|
80 |
-
('ɡ','g'),
|
81 |
-
('\u031a','#'),
|
82 |
-
('\u0348','='),
|
83 |
-
('\u031e',''),
|
84 |
-
('\u0320',''),
|
85 |
-
('\u0339','')
|
86 |
-
]]
|
87 |
-
|
88 |
-
|
89 |
-
def latin_to_hangul(text):
|
90 |
-
for regex, replacement in _latin_to_hangul:
|
91 |
-
text = re.sub(regex, replacement, text)
|
92 |
-
return text
|
93 |
-
|
94 |
-
|
95 |
-
def divide_hangul(text):
|
96 |
-
text = j2hcj(h2j(text))
|
97 |
-
for regex, replacement in _hangul_divided:
|
98 |
-
text = re.sub(regex, replacement, text)
|
99 |
-
return text
|
100 |
-
|
101 |
-
|
102 |
-
def hangul_number(num, sino=True):
|
103 |
-
'''Reference https://github.com/Kyubyong/g2pK'''
|
104 |
-
num = re.sub(',', '', num)
|
105 |
-
|
106 |
-
if num == '0':
|
107 |
-
return '영'
|
108 |
-
if not sino and num == '20':
|
109 |
-
return '스무'
|
110 |
-
|
111 |
-
digits = '123456789'
|
112 |
-
names = '일이삼사오육칠팔구'
|
113 |
-
digit2name = {d: n for d, n in zip(digits, names)}
|
114 |
-
|
115 |
-
modifiers = '한 두 세 네 다섯 여섯 일곱 여덟 아홉'
|
116 |
-
decimals = '열 스물 서른 마흔 쉰 예순 일흔 여든 아흔'
|
117 |
-
digit2mod = {d: mod for d, mod in zip(digits, modifiers.split())}
|
118 |
-
digit2dec = {d: dec for d, dec in zip(digits, decimals.split())}
|
119 |
-
|
120 |
-
spelledout = []
|
121 |
-
for i, digit in enumerate(num):
|
122 |
-
i = len(num) - i - 1
|
123 |
-
if sino:
|
124 |
-
if i == 0:
|
125 |
-
name = digit2name.get(digit, '')
|
126 |
-
elif i == 1:
|
127 |
-
name = digit2name.get(digit, '') + '십'
|
128 |
-
name = name.replace('일십', '십')
|
129 |
-
else:
|
130 |
-
if i == 0:
|
131 |
-
name = digit2mod.get(digit, '')
|
132 |
-
elif i == 1:
|
133 |
-
name = digit2dec.get(digit, '')
|
134 |
-
if digit == '0':
|
135 |
-
if i % 4 == 0:
|
136 |
-
last_three = spelledout[-min(3, len(spelledout)):]
|
137 |
-
if ''.join(last_three) == '':
|
138 |
-
spelledout.append('')
|
139 |
-
continue
|
140 |
-
else:
|
141 |
-
spelledout.append('')
|
142 |
-
continue
|
143 |
-
if i == 2:
|
144 |
-
name = digit2name.get(digit, '') + '백'
|
145 |
-
name = name.replace('일백', '백')
|
146 |
-
elif i == 3:
|
147 |
-
name = digit2name.get(digit, '') + '천'
|
148 |
-
name = name.replace('일천', '천')
|
149 |
-
elif i == 4:
|
150 |
-
name = digit2name.get(digit, '') + '만'
|
151 |
-
name = name.replace('일만', '만')
|
152 |
-
elif i == 5:
|
153 |
-
name = digit2name.get(digit, '') + '십'
|
154 |
-
name = name.replace('일십', '십')
|
155 |
-
elif i == 6:
|
156 |
-
name = digit2name.get(digit, '') + '백'
|
157 |
-
name = name.replace('일백', '백')
|
158 |
-
elif i == 7:
|
159 |
-
name = digit2name.get(digit, '') + '천'
|
160 |
-
name = name.replace('일천', '천')
|
161 |
-
elif i == 8:
|
162 |
-
name = digit2name.get(digit, '') + '억'
|
163 |
-
elif i == 9:
|
164 |
-
name = digit2name.get(digit, '') + '십'
|
165 |
-
elif i == 10:
|
166 |
-
name = digit2name.get(digit, '') + '백'
|
167 |
-
elif i == 11:
|
168 |
-
name = digit2name.get(digit, '') + '천'
|
169 |
-
elif i == 12:
|
170 |
-
name = digit2name.get(digit, '') + '조'
|
171 |
-
elif i == 13:
|
172 |
-
name = digit2name.get(digit, '') + '십'
|
173 |
-
elif i == 14:
|
174 |
-
name = digit2name.get(digit, '') + '백'
|
175 |
-
elif i == 15:
|
176 |
-
name = digit2name.get(digit, '') + '천'
|
177 |
-
spelledout.append(name)
|
178 |
-
return ''.join(elem for elem in spelledout)
|
179 |
-
|
180 |
-
|
181 |
-
def number_to_hangul(text):
|
182 |
-
'''Reference https://github.com/Kyubyong/g2pK'''
|
183 |
-
tokens = set(re.findall(r'(\d[\d,]*)([\uac00-\ud71f]+)', text))
|
184 |
-
for token in tokens:
|
185 |
-
num, classifier = token
|
186 |
-
if classifier[:2] in _korean_classifiers or classifier[0] in _korean_classifiers:
|
187 |
-
spelledout = hangul_number(num, sino=False)
|
188 |
-
else:
|
189 |
-
spelledout = hangul_number(num, sino=True)
|
190 |
-
text = text.replace(f'{num}{classifier}', f'{spelledout}{classifier}')
|
191 |
-
# digit by digit for remaining digits
|
192 |
-
digits = '0123456789'
|
193 |
-
names = '영일이삼사오육칠팔구'
|
194 |
-
for d, n in zip(digits, names):
|
195 |
-
text = text.replace(d, n)
|
196 |
-
return text
|
197 |
-
|
198 |
-
|
199 |
-
def korean_to_lazy_ipa(text):
|
200 |
-
text = latin_to_hangul(text)
|
201 |
-
text = number_to_hangul(text)
|
202 |
-
text=re.sub('[\uac00-\ud7af]+',lambda x:ko_pron.romanise(x.group(0),'ipa').split('] ~ [')[0],text)
|
203 |
-
for regex, replacement in _ipa_to_lazy_ipa:
|
204 |
-
text = re.sub(regex, replacement, text)
|
205 |
-
return text
|
206 |
-
|
207 |
-
|
208 |
-
def korean_to_ipa(text):
|
209 |
-
text = korean_to_lazy_ipa(text)
|
210 |
-
return text.replace('ʧ','tʃ').replace('ʥ','dʑ')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Alpaca233/SadTalker/src/utils/hparams.py
DELETED
@@ -1,160 +0,0 @@
|
|
1 |
-
from glob import glob
|
2 |
-
import os
|
3 |
-
|
4 |
-
class HParams:
|
5 |
-
def __init__(self, **kwargs):
|
6 |
-
self.data = {}
|
7 |
-
|
8 |
-
for key, value in kwargs.items():
|
9 |
-
self.data[key] = value
|
10 |
-
|
11 |
-
def __getattr__(self, key):
|
12 |
-
if key not in self.data:
|
13 |
-
raise AttributeError("'HParams' object has no attribute %s" % key)
|
14 |
-
return self.data[key]
|
15 |
-
|
16 |
-
def set_hparam(self, key, value):
|
17 |
-
self.data[key] = value
|
18 |
-
|
19 |
-
|
20 |
-
# Default hyperparameters
|
21 |
-
hparams = HParams(
|
22 |
-
num_mels=80, # Number of mel-spectrogram channels and local conditioning dimensionality
|
23 |
-
# network
|
24 |
-
rescale=True, # Whether to rescale audio prior to preprocessing
|
25 |
-
rescaling_max=0.9, # Rescaling value
|
26 |
-
|
27 |
-
# Use LWS (https://github.com/Jonathan-LeRoux/lws) for STFT and phase reconstruction
|
28 |
-
# It"s preferred to set True to use with https://github.com/r9y9/wavenet_vocoder
|
29 |
-
# Does not work if n_ffit is not multiple of hop_size!!
|
30 |
-
use_lws=False,
|
31 |
-
|
32 |
-
n_fft=800, # Extra window size is filled with 0 paddings to match this parameter
|
33 |
-
hop_size=200, # For 16000Hz, 200 = 12.5 ms (0.0125 * sample_rate)
|
34 |
-
win_size=800, # For 16000Hz, 800 = 50 ms (If None, win_size = n_fft) (0.05 * sample_rate)
|
35 |
-
sample_rate=16000, # 16000Hz (corresponding to librispeech) (sox --i <filename>)
|
36 |
-
|
37 |
-
frame_shift_ms=None, # Can replace hop_size parameter. (Recommended: 12.5)
|
38 |
-
|
39 |
-
# Mel and Linear spectrograms normalization/scaling and clipping
|
40 |
-
signal_normalization=True,
|
41 |
-
# Whether to normalize mel spectrograms to some predefined range (following below parameters)
|
42 |
-
allow_clipping_in_normalization=True, # Only relevant if mel_normalization = True
|
43 |
-
symmetric_mels=True,
|
44 |
-
# Whether to scale the data to be symmetric around 0. (Also multiplies the output range by 2,
|
45 |
-
# faster and cleaner convergence)
|
46 |
-
max_abs_value=4.,
|
47 |
-
# max absolute value of data. If symmetric, data will be [-max, max] else [0, max] (Must not
|
48 |
-
# be too big to avoid gradient explosion,
|
49 |
-
# not too small for fast convergence)
|
50 |
-
# Contribution by @begeekmyfriend
|
51 |
-
# Spectrogram Pre-Emphasis (Lfilter: Reduce spectrogram noise and helps model certitude
|
52 |
-
# levels. Also allows for better G&L phase reconstruction)
|
53 |
-
preemphasize=True, # whether to apply filter
|
54 |
-
preemphasis=0.97, # filter coefficient.
|
55 |
-
|
56 |
-
# Limits
|
57 |
-
min_level_db=-100,
|
58 |
-
ref_level_db=20,
|
59 |
-
fmin=55,
|
60 |
-
# Set this to 55 if your speaker is male! if female, 95 should help taking off noise. (To
|
61 |
-
# test depending on dataset. Pitch info: male~[65, 260], female~[100, 525])
|
62 |
-
fmax=7600, # To be increased/reduced depending on data.
|
63 |
-
|
64 |
-
###################### Our training parameters #################################
|
65 |
-
img_size=96,
|
66 |
-
fps=25,
|
67 |
-
|
68 |
-
batch_size=16,
|
69 |
-
initial_learning_rate=1e-4,
|
70 |
-
nepochs=300000, ### ctrl + c, stop whenever eval loss is consistently greater than train loss for ~10 epochs
|
71 |
-
num_workers=20,
|
72 |
-
checkpoint_interval=3000,
|
73 |
-
eval_interval=3000,
|
74 |
-
writer_interval=300,
|
75 |
-
save_optimizer_state=True,
|
76 |
-
|
77 |
-
syncnet_wt=0.0, # is initially zero, will be set automatically to 0.03 later. Leads to faster convergence.
|
78 |
-
syncnet_batch_size=64,
|
79 |
-
syncnet_lr=1e-4,
|
80 |
-
syncnet_eval_interval=1000,
|
81 |
-
syncnet_checkpoint_interval=10000,
|
82 |
-
|
83 |
-
disc_wt=0.07,
|
84 |
-
disc_initial_learning_rate=1e-4,
|
85 |
-
)
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
# Default hyperparameters
|
90 |
-
hparamsdebug = HParams(
|
91 |
-
num_mels=80, # Number of mel-spectrogram channels and local conditioning dimensionality
|
92 |
-
# network
|
93 |
-
rescale=True, # Whether to rescale audio prior to preprocessing
|
94 |
-
rescaling_max=0.9, # Rescaling value
|
95 |
-
|
96 |
-
# Use LWS (https://github.com/Jonathan-LeRoux/lws) for STFT and phase reconstruction
|
97 |
-
# It"s preferred to set True to use with https://github.com/r9y9/wavenet_vocoder
|
98 |
-
# Does not work if n_ffit is not multiple of hop_size!!
|
99 |
-
use_lws=False,
|
100 |
-
|
101 |
-
n_fft=800, # Extra window size is filled with 0 paddings to match this parameter
|
102 |
-
hop_size=200, # For 16000Hz, 200 = 12.5 ms (0.0125 * sample_rate)
|
103 |
-
win_size=800, # For 16000Hz, 800 = 50 ms (If None, win_size = n_fft) (0.05 * sample_rate)
|
104 |
-
sample_rate=16000, # 16000Hz (corresponding to librispeech) (sox --i <filename>)
|
105 |
-
|
106 |
-
frame_shift_ms=None, # Can replace hop_size parameter. (Recommended: 12.5)
|
107 |
-
|
108 |
-
# Mel and Linear spectrograms normalization/scaling and clipping
|
109 |
-
signal_normalization=True,
|
110 |
-
# Whether to normalize mel spectrograms to some predefined range (following below parameters)
|
111 |
-
allow_clipping_in_normalization=True, # Only relevant if mel_normalization = True
|
112 |
-
symmetric_mels=True,
|
113 |
-
# Whether to scale the data to be symmetric around 0. (Also multiplies the output range by 2,
|
114 |
-
# faster and cleaner convergence)
|
115 |
-
max_abs_value=4.,
|
116 |
-
# max absolute value of data. If symmetric, data will be [-max, max] else [0, max] (Must not
|
117 |
-
# be too big to avoid gradient explosion,
|
118 |
-
# not too small for fast convergence)
|
119 |
-
# Contribution by @begeekmyfriend
|
120 |
-
# Spectrogram Pre-Emphasis (Lfilter: Reduce spectrogram noise and helps model certitude
|
121 |
-
# levels. Also allows for better G&L phase reconstruction)
|
122 |
-
preemphasize=True, # whether to apply filter
|
123 |
-
preemphasis=0.97, # filter coefficient.
|
124 |
-
|
125 |
-
# Limits
|
126 |
-
min_level_db=-100,
|
127 |
-
ref_level_db=20,
|
128 |
-
fmin=55,
|
129 |
-
# Set this to 55 if your speaker is male! if female, 95 should help taking off noise. (To
|
130 |
-
# test depending on dataset. Pitch info: male~[65, 260], female~[100, 525])
|
131 |
-
fmax=7600, # To be increased/reduced depending on data.
|
132 |
-
|
133 |
-
###################### Our training parameters #################################
|
134 |
-
img_size=96,
|
135 |
-
fps=25,
|
136 |
-
|
137 |
-
batch_size=2,
|
138 |
-
initial_learning_rate=1e-3,
|
139 |
-
nepochs=100000, ### ctrl + c, stop whenever eval loss is consistently greater than train loss for ~10 epochs
|
140 |
-
num_workers=0,
|
141 |
-
checkpoint_interval=10000,
|
142 |
-
eval_interval=10,
|
143 |
-
writer_interval=5,
|
144 |
-
save_optimizer_state=True,
|
145 |
-
|
146 |
-
syncnet_wt=0.0, # is initially zero, will be set automatically to 0.03 later. Leads to faster convergence.
|
147 |
-
syncnet_batch_size=64,
|
148 |
-
syncnet_lr=1e-4,
|
149 |
-
syncnet_eval_interval=10000,
|
150 |
-
syncnet_checkpoint_interval=10000,
|
151 |
-
|
152 |
-
disc_wt=0.07,
|
153 |
-
disc_initial_learning_rate=1e-4,
|
154 |
-
)
|
155 |
-
|
156 |
-
|
157 |
-
def hparams_debug_string():
|
158 |
-
values = hparams.values()
|
159 |
-
hp = [" %s: %s" % (name, values[name]) for name in sorted(values) if name != "sentences"]
|
160 |
-
return "Hyperparameters:\n" + "\n".join(hp)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Amrrs/DragGan-Inversion/PTI/training/projectors/__init__.py
DELETED
File without changes
|
spaces/Androidonnxfork/CivitAi-to-Diffusers/diffusers/examples/research_projects/onnxruntime/text_to_image/train_text_to_image.py
DELETED
@@ -1,965 +0,0 @@
|
|
1 |
-
#!/usr/bin/env python
|
2 |
-
# coding=utf-8
|
3 |
-
# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
|
4 |
-
#
|
5 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
-
# you may not use this file except in compliance with the License.
|
7 |
-
# You may obtain a copy of the License at
|
8 |
-
#
|
9 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10 |
-
#
|
11 |
-
# Unless required by applicable law or agreed to in writing, software
|
12 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
-
# See the License for the specific language governing permissions and
|
15 |
-
|
16 |
-
import argparse
|
17 |
-
import logging
|
18 |
-
import math
|
19 |
-
import os
|
20 |
-
import random
|
21 |
-
from pathlib import Path
|
22 |
-
|
23 |
-
import accelerate
|
24 |
-
import datasets
|
25 |
-
import numpy as np
|
26 |
-
import torch
|
27 |
-
import torch.nn.functional as F
|
28 |
-
import torch.utils.checkpoint
|
29 |
-
import transformers
|
30 |
-
from accelerate import Accelerator
|
31 |
-
from accelerate.logging import get_logger
|
32 |
-
from accelerate.state import AcceleratorState
|
33 |
-
from accelerate.utils import ProjectConfiguration, set_seed
|
34 |
-
from datasets import load_dataset
|
35 |
-
from huggingface_hub import create_repo, upload_folder
|
36 |
-
from onnxruntime.training.optim.fp16_optimizer import FP16_Optimizer as ORT_FP16_Optimizer
|
37 |
-
from onnxruntime.training.ortmodule import ORTModule
|
38 |
-
from packaging import version
|
39 |
-
from torchvision import transforms
|
40 |
-
from tqdm.auto import tqdm
|
41 |
-
from transformers import CLIPTextModel, CLIPTokenizer
|
42 |
-
from transformers.utils import ContextManagers
|
43 |
-
|
44 |
-
import diffusers
|
45 |
-
from diffusers import AutoencoderKL, DDPMScheduler, StableDiffusionPipeline, UNet2DConditionModel
|
46 |
-
from diffusers.optimization import get_scheduler
|
47 |
-
from diffusers.training_utils import EMAModel
|
48 |
-
from diffusers.utils import check_min_version, deprecate, is_wandb_available
|
49 |
-
from diffusers.utils.import_utils import is_xformers_available
|
50 |
-
|
51 |
-
|
52 |
-
if is_wandb_available():
|
53 |
-
import wandb
|
54 |
-
|
55 |
-
|
56 |
-
# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
|
57 |
-
check_min_version("0.17.0.dev0")
|
58 |
-
|
59 |
-
logger = get_logger(__name__, log_level="INFO")
|
60 |
-
|
61 |
-
DATASET_NAME_MAPPING = {
|
62 |
-
"lambdalabs/pokemon-blip-captions": ("image", "text"),
|
63 |
-
}
|
64 |
-
|
65 |
-
|
66 |
-
def log_validation(vae, text_encoder, tokenizer, unet, args, accelerator, weight_dtype, epoch):
|
67 |
-
logger.info("Running validation... ")
|
68 |
-
|
69 |
-
pipeline = StableDiffusionPipeline.from_pretrained(
|
70 |
-
args.pretrained_model_name_or_path,
|
71 |
-
vae=accelerator.unwrap_model(vae),
|
72 |
-
text_encoder=accelerator.unwrap_model(text_encoder),
|
73 |
-
tokenizer=tokenizer,
|
74 |
-
unet=accelerator.unwrap_model(unet),
|
75 |
-
safety_checker=None,
|
76 |
-
revision=args.revision,
|
77 |
-
torch_dtype=weight_dtype,
|
78 |
-
)
|
79 |
-
pipeline = pipeline.to(accelerator.device)
|
80 |
-
pipeline.set_progress_bar_config(disable=True)
|
81 |
-
|
82 |
-
if args.enable_xformers_memory_efficient_attention:
|
83 |
-
pipeline.enable_xformers_memory_efficient_attention()
|
84 |
-
|
85 |
-
if args.seed is None:
|
86 |
-
generator = None
|
87 |
-
else:
|
88 |
-
generator = torch.Generator(device=accelerator.device).manual_seed(args.seed)
|
89 |
-
|
90 |
-
images = []
|
91 |
-
for i in range(len(args.validation_prompts)):
|
92 |
-
with torch.autocast("cuda"):
|
93 |
-
image = pipeline(args.validation_prompts[i], num_inference_steps=20, generator=generator).images[0]
|
94 |
-
|
95 |
-
images.append(image)
|
96 |
-
|
97 |
-
for tracker in accelerator.trackers:
|
98 |
-
if tracker.name == "tensorboard":
|
99 |
-
np_images = np.stack([np.asarray(img) for img in images])
|
100 |
-
tracker.writer.add_images("validation", np_images, epoch, dataformats="NHWC")
|
101 |
-
elif tracker.name == "wandb":
|
102 |
-
tracker.log(
|
103 |
-
{
|
104 |
-
"validation": [
|
105 |
-
wandb.Image(image, caption=f"{i}: {args.validation_prompts[i]}")
|
106 |
-
for i, image in enumerate(images)
|
107 |
-
]
|
108 |
-
}
|
109 |
-
)
|
110 |
-
else:
|
111 |
-
logger.warn(f"image logging not implemented for {tracker.name}")
|
112 |
-
|
113 |
-
del pipeline
|
114 |
-
torch.cuda.empty_cache()
|
115 |
-
|
116 |
-
|
117 |
-
def parse_args():
|
118 |
-
parser = argparse.ArgumentParser(description="Simple example of a training script.")
|
119 |
-
parser.add_argument(
|
120 |
-
"--input_pertubation", type=float, default=0, help="The scale of input pretubation. Recommended 0.1."
|
121 |
-
)
|
122 |
-
parser.add_argument(
|
123 |
-
"--pretrained_model_name_or_path",
|
124 |
-
type=str,
|
125 |
-
default=None,
|
126 |
-
required=True,
|
127 |
-
help="Path to pretrained model or model identifier from huggingface.co/models.",
|
128 |
-
)
|
129 |
-
parser.add_argument(
|
130 |
-
"--revision",
|
131 |
-
type=str,
|
132 |
-
default=None,
|
133 |
-
required=False,
|
134 |
-
help="Revision of pretrained model identifier from huggingface.co/models.",
|
135 |
-
)
|
136 |
-
parser.add_argument(
|
137 |
-
"--dataset_name",
|
138 |
-
type=str,
|
139 |
-
default=None,
|
140 |
-
help=(
|
141 |
-
"The name of the Dataset (from the HuggingFace hub) to train on (could be your own, possibly private,"
|
142 |
-
" dataset). It can also be a path pointing to a local copy of a dataset in your filesystem,"
|
143 |
-
" or to a folder containing files that 🤗 Datasets can understand."
|
144 |
-
),
|
145 |
-
)
|
146 |
-
parser.add_argument(
|
147 |
-
"--dataset_config_name",
|
148 |
-
type=str,
|
149 |
-
default=None,
|
150 |
-
help="The config of the Dataset, leave as None if there's only one config.",
|
151 |
-
)
|
152 |
-
parser.add_argument(
|
153 |
-
"--train_data_dir",
|
154 |
-
type=str,
|
155 |
-
default=None,
|
156 |
-
help=(
|
157 |
-
"A folder containing the training data. Folder contents must follow the structure described in"
|
158 |
-
" https://huggingface.co/docs/datasets/image_dataset#imagefolder. In particular, a `metadata.jsonl` file"
|
159 |
-
" must exist to provide the captions for the images. Ignored if `dataset_name` is specified."
|
160 |
-
),
|
161 |
-
)
|
162 |
-
parser.add_argument(
|
163 |
-
"--image_column", type=str, default="image", help="The column of the dataset containing an image."
|
164 |
-
)
|
165 |
-
parser.add_argument(
|
166 |
-
"--caption_column",
|
167 |
-
type=str,
|
168 |
-
default="text",
|
169 |
-
help="The column of the dataset containing a caption or a list of captions.",
|
170 |
-
)
|
171 |
-
parser.add_argument(
|
172 |
-
"--max_train_samples",
|
173 |
-
type=int,
|
174 |
-
default=None,
|
175 |
-
help=(
|
176 |
-
"For debugging purposes or quicker training, truncate the number of training examples to this "
|
177 |
-
"value if set."
|
178 |
-
),
|
179 |
-
)
|
180 |
-
parser.add_argument(
|
181 |
-
"--validation_prompts",
|
182 |
-
type=str,
|
183 |
-
default=None,
|
184 |
-
nargs="+",
|
185 |
-
help=("A set of prompts evaluated every `--validation_epochs` and logged to `--report_to`."),
|
186 |
-
)
|
187 |
-
parser.add_argument(
|
188 |
-
"--output_dir",
|
189 |
-
type=str,
|
190 |
-
default="sd-model-finetuned",
|
191 |
-
help="The output directory where the model predictions and checkpoints will be written.",
|
192 |
-
)
|
193 |
-
parser.add_argument(
|
194 |
-
"--cache_dir",
|
195 |
-
type=str,
|
196 |
-
default=None,
|
197 |
-
help="The directory where the downloaded models and datasets will be stored.",
|
198 |
-
)
|
199 |
-
parser.add_argument("--seed", type=int, default=None, help="A seed for reproducible training.")
|
200 |
-
parser.add_argument(
|
201 |
-
"--resolution",
|
202 |
-
type=int,
|
203 |
-
default=512,
|
204 |
-
help=(
|
205 |
-
"The resolution for input images, all the images in the train/validation dataset will be resized to this"
|
206 |
-
" resolution"
|
207 |
-
),
|
208 |
-
)
|
209 |
-
parser.add_argument(
|
210 |
-
"--center_crop",
|
211 |
-
default=False,
|
212 |
-
action="store_true",
|
213 |
-
help=(
|
214 |
-
"Whether to center crop the input images to the resolution. If not set, the images will be randomly"
|
215 |
-
" cropped. The images will be resized to the resolution first before cropping."
|
216 |
-
),
|
217 |
-
)
|
218 |
-
parser.add_argument(
|
219 |
-
"--random_flip",
|
220 |
-
action="store_true",
|
221 |
-
help="whether to randomly flip images horizontally",
|
222 |
-
)
|
223 |
-
parser.add_argument(
|
224 |
-
"--train_batch_size", type=int, default=16, help="Batch size (per device) for the training dataloader."
|
225 |
-
)
|
226 |
-
parser.add_argument("--num_train_epochs", type=int, default=100)
|
227 |
-
parser.add_argument(
|
228 |
-
"--max_train_steps",
|
229 |
-
type=int,
|
230 |
-
default=None,
|
231 |
-
help="Total number of training steps to perform. If provided, overrides num_train_epochs.",
|
232 |
-
)
|
233 |
-
parser.add_argument(
|
234 |
-
"--gradient_accumulation_steps",
|
235 |
-
type=int,
|
236 |
-
default=1,
|
237 |
-
help="Number of updates steps to accumulate before performing a backward/update pass.",
|
238 |
-
)
|
239 |
-
parser.add_argument(
|
240 |
-
"--gradient_checkpointing",
|
241 |
-
action="store_true",
|
242 |
-
help="Whether or not to use gradient checkpointing to save memory at the expense of slower backward pass.",
|
243 |
-
)
|
244 |
-
parser.add_argument(
|
245 |
-
"--learning_rate",
|
246 |
-
type=float,
|
247 |
-
default=1e-4,
|
248 |
-
help="Initial learning rate (after the potential warmup period) to use.",
|
249 |
-
)
|
250 |
-
parser.add_argument(
|
251 |
-
"--scale_lr",
|
252 |
-
action="store_true",
|
253 |
-
default=False,
|
254 |
-
help="Scale the learning rate by the number of GPUs, gradient accumulation steps, and batch size.",
|
255 |
-
)
|
256 |
-
parser.add_argument(
|
257 |
-
"--lr_scheduler",
|
258 |
-
type=str,
|
259 |
-
default="constant",
|
260 |
-
help=(
|
261 |
-
'The scheduler type to use. Choose between ["linear", "cosine", "cosine_with_restarts", "polynomial",'
|
262 |
-
' "constant", "constant_with_warmup"]'
|
263 |
-
),
|
264 |
-
)
|
265 |
-
parser.add_argument(
|
266 |
-
"--lr_warmup_steps", type=int, default=500, help="Number of steps for the warmup in the lr scheduler."
|
267 |
-
)
|
268 |
-
parser.add_argument(
|
269 |
-
"--snr_gamma",
|
270 |
-
type=float,
|
271 |
-
default=None,
|
272 |
-
help="SNR weighting gamma to be used if rebalancing the loss. Recommended value is 5.0. "
|
273 |
-
"More details here: https://arxiv.org/abs/2303.09556.",
|
274 |
-
)
|
275 |
-
parser.add_argument(
|
276 |
-
"--use_8bit_adam", action="store_true", help="Whether or not to use 8-bit Adam from bitsandbytes."
|
277 |
-
)
|
278 |
-
parser.add_argument(
|
279 |
-
"--allow_tf32",
|
280 |
-
action="store_true",
|
281 |
-
help=(
|
282 |
-
"Whether or not to allow TF32 on Ampere GPUs. Can be used to speed up training. For more information, see"
|
283 |
-
" https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices"
|
284 |
-
),
|
285 |
-
)
|
286 |
-
parser.add_argument("--use_ema", action="store_true", help="Whether to use EMA model.")
|
287 |
-
parser.add_argument(
|
288 |
-
"--non_ema_revision",
|
289 |
-
type=str,
|
290 |
-
default=None,
|
291 |
-
required=False,
|
292 |
-
help=(
|
293 |
-
"Revision of pretrained non-ema model identifier. Must be a branch, tag or git identifier of the local or"
|
294 |
-
" remote repository specified with --pretrained_model_name_or_path."
|
295 |
-
),
|
296 |
-
)
|
297 |
-
parser.add_argument(
|
298 |
-
"--dataloader_num_workers",
|
299 |
-
type=int,
|
300 |
-
default=0,
|
301 |
-
help=(
|
302 |
-
"Number of subprocesses to use for data loading. 0 means that the data will be loaded in the main process."
|
303 |
-
),
|
304 |
-
)
|
305 |
-
parser.add_argument("--adam_beta1", type=float, default=0.9, help="The beta1 parameter for the Adam optimizer.")
|
306 |
-
parser.add_argument("--adam_beta2", type=float, default=0.999, help="The beta2 parameter for the Adam optimizer.")
|
307 |
-
parser.add_argument("--adam_weight_decay", type=float, default=1e-2, help="Weight decay to use.")
|
308 |
-
parser.add_argument("--adam_epsilon", type=float, default=1e-08, help="Epsilon value for the Adam optimizer")
|
309 |
-
parser.add_argument("--max_grad_norm", default=1.0, type=float, help="Max gradient norm.")
|
310 |
-
parser.add_argument("--push_to_hub", action="store_true", help="Whether or not to push the model to the Hub.")
|
311 |
-
parser.add_argument("--hub_token", type=str, default=None, help="The token to use to push to the Model Hub.")
|
312 |
-
parser.add_argument(
|
313 |
-
"--hub_model_id",
|
314 |
-
type=str,
|
315 |
-
default=None,
|
316 |
-
help="The name of the repository to keep in sync with the local `output_dir`.",
|
317 |
-
)
|
318 |
-
parser.add_argument(
|
319 |
-
"--logging_dir",
|
320 |
-
type=str,
|
321 |
-
default="logs",
|
322 |
-
help=(
|
323 |
-
"[TensorBoard](https://www.tensorflow.org/tensorboard) log directory. Will default to"
|
324 |
-
" *output_dir/runs/**CURRENT_DATETIME_HOSTNAME***."
|
325 |
-
),
|
326 |
-
)
|
327 |
-
parser.add_argument(
|
328 |
-
"--mixed_precision",
|
329 |
-
type=str,
|
330 |
-
default=None,
|
331 |
-
choices=["no", "fp16", "bf16"],
|
332 |
-
help=(
|
333 |
-
"Whether to use mixed precision. Choose between fp16 and bf16 (bfloat16). Bf16 requires PyTorch >="
|
334 |
-
" 1.10.and an Nvidia Ampere GPU. Default to the value of accelerate config of the current system or the"
|
335 |
-
" flag passed with the `accelerate.launch` command. Use this argument to override the accelerate config."
|
336 |
-
),
|
337 |
-
)
|
338 |
-
parser.add_argument(
|
339 |
-
"--report_to",
|
340 |
-
type=str,
|
341 |
-
default="tensorboard",
|
342 |
-
help=(
|
343 |
-
'The integration to report the results and logs to. Supported platforms are `"tensorboard"`'
|
344 |
-
' (default), `"wandb"` and `"comet_ml"`. Use `"all"` to report to all integrations.'
|
345 |
-
),
|
346 |
-
)
|
347 |
-
parser.add_argument("--local_rank", type=int, default=-1, help="For distributed training: local_rank")
|
348 |
-
parser.add_argument(
|
349 |
-
"--checkpointing_steps",
|
350 |
-
type=int,
|
351 |
-
default=500,
|
352 |
-
help=(
|
353 |
-
"Save a checkpoint of the training state every X updates. These checkpoints are only suitable for resuming"
|
354 |
-
" training using `--resume_from_checkpoint`."
|
355 |
-
),
|
356 |
-
)
|
357 |
-
parser.add_argument(
|
358 |
-
"--checkpoints_total_limit",
|
359 |
-
type=int,
|
360 |
-
default=None,
|
361 |
-
help=(
|
362 |
-
"Max number of checkpoints to store. Passed as `total_limit` to the `Accelerator` `ProjectConfiguration`."
|
363 |
-
" See Accelerator::save_state https://huggingface.co/docs/accelerate/package_reference/accelerator#accelerate.Accelerator.save_state"
|
364 |
-
" for more docs"
|
365 |
-
),
|
366 |
-
)
|
367 |
-
parser.add_argument(
|
368 |
-
"--resume_from_checkpoint",
|
369 |
-
type=str,
|
370 |
-
default=None,
|
371 |
-
help=(
|
372 |
-
"Whether training should be resumed from a previous checkpoint. Use a path saved by"
|
373 |
-
' `--checkpointing_steps`, or `"latest"` to automatically select the last available checkpoint.'
|
374 |
-
),
|
375 |
-
)
|
376 |
-
parser.add_argument(
|
377 |
-
"--enable_xformers_memory_efficient_attention", action="store_true", help="Whether or not to use xformers."
|
378 |
-
)
|
379 |
-
parser.add_argument("--noise_offset", type=float, default=0, help="The scale of noise offset.")
|
380 |
-
parser.add_argument(
|
381 |
-
"--validation_epochs",
|
382 |
-
type=int,
|
383 |
-
default=5,
|
384 |
-
help="Run validation every X epochs.",
|
385 |
-
)
|
386 |
-
parser.add_argument(
|
387 |
-
"--tracker_project_name",
|
388 |
-
type=str,
|
389 |
-
default="text2image-fine-tune",
|
390 |
-
help=(
|
391 |
-
"The `project_name` argument passed to Accelerator.init_trackers for"
|
392 |
-
" more information see https://huggingface.co/docs/accelerate/v0.17.0/en/package_reference/accelerator#accelerate.Accelerator"
|
393 |
-
),
|
394 |
-
)
|
395 |
-
|
396 |
-
args = parser.parse_args()
|
397 |
-
env_local_rank = int(os.environ.get("LOCAL_RANK", -1))
|
398 |
-
if env_local_rank != -1 and env_local_rank != args.local_rank:
|
399 |
-
args.local_rank = env_local_rank
|
400 |
-
|
401 |
-
# Sanity checks
|
402 |
-
if args.dataset_name is None and args.train_data_dir is None:
|
403 |
-
raise ValueError("Need either a dataset name or a training folder.")
|
404 |
-
|
405 |
-
# default to using the same revision for the non-ema model if not specified
|
406 |
-
if args.non_ema_revision is None:
|
407 |
-
args.non_ema_revision = args.revision
|
408 |
-
|
409 |
-
return args
|
410 |
-
|
411 |
-
|
412 |
-
def main():
|
413 |
-
args = parse_args()
|
414 |
-
|
415 |
-
if args.non_ema_revision is not None:
|
416 |
-
deprecate(
|
417 |
-
"non_ema_revision!=None",
|
418 |
-
"0.15.0",
|
419 |
-
message=(
|
420 |
-
"Downloading 'non_ema' weights from revision branches of the Hub is deprecated. Please make sure to"
|
421 |
-
" use `--variant=non_ema` instead."
|
422 |
-
),
|
423 |
-
)
|
424 |
-
logging_dir = os.path.join(args.output_dir, args.logging_dir)
|
425 |
-
accelerator_project_config = ProjectConfiguration(
|
426 |
-
total_limit=args.checkpoints_total_limit, project_dir=args.output_dir, logging_dir=logging_dir
|
427 |
-
)
|
428 |
-
|
429 |
-
accelerator = Accelerator(
|
430 |
-
gradient_accumulation_steps=args.gradient_accumulation_steps,
|
431 |
-
mixed_precision=args.mixed_precision,
|
432 |
-
log_with=args.report_to,
|
433 |
-
project_config=accelerator_project_config,
|
434 |
-
)
|
435 |
-
|
436 |
-
# Make one log on every process with the configuration for debugging.
|
437 |
-
logging.basicConfig(
|
438 |
-
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
|
439 |
-
datefmt="%m/%d/%Y %H:%M:%S",
|
440 |
-
level=logging.INFO,
|
441 |
-
)
|
442 |
-
logger.info(accelerator.state, main_process_only=False)
|
443 |
-
if accelerator.is_local_main_process:
|
444 |
-
datasets.utils.logging.set_verbosity_warning()
|
445 |
-
transformers.utils.logging.set_verbosity_warning()
|
446 |
-
diffusers.utils.logging.set_verbosity_info()
|
447 |
-
else:
|
448 |
-
datasets.utils.logging.set_verbosity_error()
|
449 |
-
transformers.utils.logging.set_verbosity_error()
|
450 |
-
diffusers.utils.logging.set_verbosity_error()
|
451 |
-
|
452 |
-
# If passed along, set the training seed now.
|
453 |
-
if args.seed is not None:
|
454 |
-
set_seed(args.seed)
|
455 |
-
|
456 |
-
# Handle the repository creation
|
457 |
-
if accelerator.is_main_process:
|
458 |
-
if args.output_dir is not None:
|
459 |
-
os.makedirs(args.output_dir, exist_ok=True)
|
460 |
-
|
461 |
-
if args.push_to_hub:
|
462 |
-
repo_id = create_repo(
|
463 |
-
repo_id=args.hub_model_id or Path(args.output_dir).name, exist_ok=True, token=args.hub_token
|
464 |
-
).repo_id
|
465 |
-
|
466 |
-
# Load scheduler, tokenizer and models.
|
467 |
-
noise_scheduler = DDPMScheduler.from_pretrained(args.pretrained_model_name_or_path, subfolder="scheduler")
|
468 |
-
tokenizer = CLIPTokenizer.from_pretrained(
|
469 |
-
args.pretrained_model_name_or_path, subfolder="tokenizer", revision=args.revision
|
470 |
-
)
|
471 |
-
|
472 |
-
def deepspeed_zero_init_disabled_context_manager():
|
473 |
-
"""
|
474 |
-
returns either a context list that includes one that will disable zero.Init or an empty context list
|
475 |
-
"""
|
476 |
-
deepspeed_plugin = AcceleratorState().deepspeed_plugin if accelerate.state.is_initialized() else None
|
477 |
-
if deepspeed_plugin is None:
|
478 |
-
return []
|
479 |
-
|
480 |
-
return [deepspeed_plugin.zero3_init_context_manager(enable=False)]
|
481 |
-
|
482 |
-
# Currently Accelerate doesn't know how to handle multiple models under Deepspeed ZeRO stage 3.
|
483 |
-
# For this to work properly all models must be run through `accelerate.prepare`. But accelerate
|
484 |
-
# will try to assign the same optimizer with the same weights to all models during
|
485 |
-
# `deepspeed.initialize`, which of course doesn't work.
|
486 |
-
#
|
487 |
-
# For now the following workaround will partially support Deepspeed ZeRO-3, by excluding the 2
|
488 |
-
# frozen models from being partitioned during `zero.Init` which gets called during
|
489 |
-
# `from_pretrained` So CLIPTextModel and AutoencoderKL will not enjoy the parameter sharding
|
490 |
-
# across multiple gpus and only UNet2DConditionModel will get ZeRO sharded.
|
491 |
-
with ContextManagers(deepspeed_zero_init_disabled_context_manager()):
|
492 |
-
text_encoder = CLIPTextModel.from_pretrained(
|
493 |
-
args.pretrained_model_name_or_path, subfolder="text_encoder", revision=args.revision
|
494 |
-
)
|
495 |
-
vae = AutoencoderKL.from_pretrained(
|
496 |
-
args.pretrained_model_name_or_path, subfolder="vae", revision=args.revision
|
497 |
-
)
|
498 |
-
|
499 |
-
unet = UNet2DConditionModel.from_pretrained(
|
500 |
-
args.pretrained_model_name_or_path, subfolder="unet", revision=args.non_ema_revision
|
501 |
-
)
|
502 |
-
|
503 |
-
# Freeze vae and text_encoder
|
504 |
-
vae.requires_grad_(False)
|
505 |
-
text_encoder.requires_grad_(False)
|
506 |
-
|
507 |
-
# Create EMA for the unet.
|
508 |
-
if args.use_ema:
|
509 |
-
ema_unet = UNet2DConditionModel.from_pretrained(
|
510 |
-
args.pretrained_model_name_or_path, subfolder="unet", revision=args.revision
|
511 |
-
)
|
512 |
-
ema_unet = EMAModel(ema_unet.parameters(), model_cls=UNet2DConditionModel, model_config=ema_unet.config)
|
513 |
-
|
514 |
-
if args.enable_xformers_memory_efficient_attention:
|
515 |
-
if is_xformers_available():
|
516 |
-
import xformers
|
517 |
-
|
518 |
-
xformers_version = version.parse(xformers.__version__)
|
519 |
-
if xformers_version == version.parse("0.0.16"):
|
520 |
-
logger.warn(
|
521 |
-
"xFormers 0.0.16 cannot be used for training in some GPUs. If you observe problems during training, please update xFormers to at least 0.0.17. See https://huggingface.co/docs/diffusers/main/en/optimization/xformers for more details."
|
522 |
-
)
|
523 |
-
unet.enable_xformers_memory_efficient_attention()
|
524 |
-
else:
|
525 |
-
raise ValueError("xformers is not available. Make sure it is installed correctly")
|
526 |
-
|
527 |
-
def compute_snr(timesteps):
|
528 |
-
"""
|
529 |
-
Computes SNR as per https://github.com/TiankaiHang/Min-SNR-Diffusion-Training/blob/521b624bd70c67cee4bdf49225915f5945a872e3/guided_diffusion/gaussian_diffusion.py#L847-L849
|
530 |
-
"""
|
531 |
-
alphas_cumprod = noise_scheduler.alphas_cumprod
|
532 |
-
sqrt_alphas_cumprod = alphas_cumprod**0.5
|
533 |
-
sqrt_one_minus_alphas_cumprod = (1.0 - alphas_cumprod) ** 0.5
|
534 |
-
|
535 |
-
# Expand the tensors.
|
536 |
-
# Adapted from https://github.com/TiankaiHang/Min-SNR-Diffusion-Training/blob/521b624bd70c67cee4bdf49225915f5945a872e3/guided_diffusion/gaussian_diffusion.py#L1026
|
537 |
-
sqrt_alphas_cumprod = sqrt_alphas_cumprod.to(device=timesteps.device)[timesteps].float()
|
538 |
-
while len(sqrt_alphas_cumprod.shape) < len(timesteps.shape):
|
539 |
-
sqrt_alphas_cumprod = sqrt_alphas_cumprod[..., None]
|
540 |
-
alpha = sqrt_alphas_cumprod.expand(timesteps.shape)
|
541 |
-
|
542 |
-
sqrt_one_minus_alphas_cumprod = sqrt_one_minus_alphas_cumprod.to(device=timesteps.device)[timesteps].float()
|
543 |
-
while len(sqrt_one_minus_alphas_cumprod.shape) < len(timesteps.shape):
|
544 |
-
sqrt_one_minus_alphas_cumprod = sqrt_one_minus_alphas_cumprod[..., None]
|
545 |
-
sigma = sqrt_one_minus_alphas_cumprod.expand(timesteps.shape)
|
546 |
-
|
547 |
-
# Compute SNR.
|
548 |
-
snr = (alpha / sigma) ** 2
|
549 |
-
return snr
|
550 |
-
|
551 |
-
# `accelerate` 0.16.0 will have better support for customized saving
|
552 |
-
if version.parse(accelerate.__version__) >= version.parse("0.16.0"):
|
553 |
-
# create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format
|
554 |
-
def save_model_hook(models, weights, output_dir):
|
555 |
-
if args.use_ema:
|
556 |
-
ema_unet.save_pretrained(os.path.join(output_dir, "unet_ema"))
|
557 |
-
|
558 |
-
for i, model in enumerate(models):
|
559 |
-
model.save_pretrained(os.path.join(output_dir, "unet"))
|
560 |
-
|
561 |
-
# make sure to pop weight so that corresponding model is not saved again
|
562 |
-
weights.pop()
|
563 |
-
|
564 |
-
def load_model_hook(models, input_dir):
|
565 |
-
if args.use_ema:
|
566 |
-
load_model = EMAModel.from_pretrained(os.path.join(input_dir, "unet_ema"), UNet2DConditionModel)
|
567 |
-
ema_unet.load_state_dict(load_model.state_dict())
|
568 |
-
ema_unet.to(accelerator.device)
|
569 |
-
del load_model
|
570 |
-
|
571 |
-
for i in range(len(models)):
|
572 |
-
# pop models so that they are not loaded again
|
573 |
-
model = models.pop()
|
574 |
-
|
575 |
-
# load diffusers style into model
|
576 |
-
load_model = UNet2DConditionModel.from_pretrained(input_dir, subfolder="unet")
|
577 |
-
model.register_to_config(**load_model.config)
|
578 |
-
|
579 |
-
model.load_state_dict(load_model.state_dict())
|
580 |
-
del load_model
|
581 |
-
|
582 |
-
accelerator.register_save_state_pre_hook(save_model_hook)
|
583 |
-
accelerator.register_load_state_pre_hook(load_model_hook)
|
584 |
-
|
585 |
-
if args.gradient_checkpointing:
|
586 |
-
unet.enable_gradient_checkpointing()
|
587 |
-
|
588 |
-
# Enable TF32 for faster training on Ampere GPUs,
|
589 |
-
# cf https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices
|
590 |
-
if args.allow_tf32:
|
591 |
-
torch.backends.cuda.matmul.allow_tf32 = True
|
592 |
-
|
593 |
-
if args.scale_lr:
|
594 |
-
args.learning_rate = (
|
595 |
-
args.learning_rate * args.gradient_accumulation_steps * args.train_batch_size * accelerator.num_processes
|
596 |
-
)
|
597 |
-
|
598 |
-
# Initialize the optimizer
|
599 |
-
if args.use_8bit_adam:
|
600 |
-
try:
|
601 |
-
import bitsandbytes as bnb
|
602 |
-
except ImportError:
|
603 |
-
raise ImportError(
|
604 |
-
"Please install bitsandbytes to use 8-bit Adam. You can do so by running `pip install bitsandbytes`"
|
605 |
-
)
|
606 |
-
|
607 |
-
optimizer_cls = bnb.optim.AdamW8bit
|
608 |
-
else:
|
609 |
-
optimizer_cls = torch.optim.AdamW
|
610 |
-
|
611 |
-
optimizer = optimizer_cls(
|
612 |
-
unet.parameters(),
|
613 |
-
lr=args.learning_rate,
|
614 |
-
betas=(args.adam_beta1, args.adam_beta2),
|
615 |
-
weight_decay=args.adam_weight_decay,
|
616 |
-
eps=args.adam_epsilon,
|
617 |
-
)
|
618 |
-
|
619 |
-
optimizer = ORT_FP16_Optimizer(optimizer)
|
620 |
-
|
621 |
-
# Get the datasets: you can either provide your own training and evaluation files (see below)
|
622 |
-
# or specify a Dataset from the hub (the dataset will be downloaded automatically from the datasets Hub).
|
623 |
-
|
624 |
-
# In distributed training, the load_dataset function guarantees that only one local process can concurrently
|
625 |
-
# download the dataset.
|
626 |
-
if args.dataset_name is not None:
|
627 |
-
# Downloading and loading a dataset from the hub.
|
628 |
-
dataset = load_dataset(
|
629 |
-
args.dataset_name,
|
630 |
-
args.dataset_config_name,
|
631 |
-
cache_dir=args.cache_dir,
|
632 |
-
)
|
633 |
-
else:
|
634 |
-
data_files = {}
|
635 |
-
if args.train_data_dir is not None:
|
636 |
-
data_files["train"] = os.path.join(args.train_data_dir, "**")
|
637 |
-
dataset = load_dataset(
|
638 |
-
"imagefolder",
|
639 |
-
data_files=data_files,
|
640 |
-
cache_dir=args.cache_dir,
|
641 |
-
)
|
642 |
-
# See more about loading custom images at
|
643 |
-
# https://huggingface.co/docs/datasets/v2.4.0/en/image_load#imagefolder
|
644 |
-
|
645 |
-
# Preprocessing the datasets.
|
646 |
-
# We need to tokenize inputs and targets.
|
647 |
-
column_names = dataset["train"].column_names
|
648 |
-
|
649 |
-
# 6. Get the column names for input/target.
|
650 |
-
dataset_columns = DATASET_NAME_MAPPING.get(args.dataset_name, None)
|
651 |
-
if args.image_column is None:
|
652 |
-
image_column = dataset_columns[0] if dataset_columns is not None else column_names[0]
|
653 |
-
else:
|
654 |
-
image_column = args.image_column
|
655 |
-
if image_column not in column_names:
|
656 |
-
raise ValueError(
|
657 |
-
f"--image_column' value '{args.image_column}' needs to be one of: {', '.join(column_names)}"
|
658 |
-
)
|
659 |
-
if args.caption_column is None:
|
660 |
-
caption_column = dataset_columns[1] if dataset_columns is not None else column_names[1]
|
661 |
-
else:
|
662 |
-
caption_column = args.caption_column
|
663 |
-
if caption_column not in column_names:
|
664 |
-
raise ValueError(
|
665 |
-
f"--caption_column' value '{args.caption_column}' needs to be one of: {', '.join(column_names)}"
|
666 |
-
)
|
667 |
-
|
668 |
-
# Preprocessing the datasets.
|
669 |
-
# We need to tokenize input captions and transform the images.
|
670 |
-
def tokenize_captions(examples, is_train=True):
|
671 |
-
captions = []
|
672 |
-
for caption in examples[caption_column]:
|
673 |
-
if isinstance(caption, str):
|
674 |
-
captions.append(caption)
|
675 |
-
elif isinstance(caption, (list, np.ndarray)):
|
676 |
-
# take a random caption if there are multiple
|
677 |
-
captions.append(random.choice(caption) if is_train else caption[0])
|
678 |
-
else:
|
679 |
-
raise ValueError(
|
680 |
-
f"Caption column `{caption_column}` should contain either strings or lists of strings."
|
681 |
-
)
|
682 |
-
inputs = tokenizer(
|
683 |
-
captions, max_length=tokenizer.model_max_length, padding="max_length", truncation=True, return_tensors="pt"
|
684 |
-
)
|
685 |
-
return inputs.input_ids
|
686 |
-
|
687 |
-
# Preprocessing the datasets.
|
688 |
-
train_transforms = transforms.Compose(
|
689 |
-
[
|
690 |
-
transforms.Resize(args.resolution, interpolation=transforms.InterpolationMode.BILINEAR),
|
691 |
-
transforms.CenterCrop(args.resolution) if args.center_crop else transforms.RandomCrop(args.resolution),
|
692 |
-
transforms.RandomHorizontalFlip() if args.random_flip else transforms.Lambda(lambda x: x),
|
693 |
-
transforms.ToTensor(),
|
694 |
-
transforms.Normalize([0.5], [0.5]),
|
695 |
-
]
|
696 |
-
)
|
697 |
-
|
698 |
-
def preprocess_train(examples):
|
699 |
-
images = [image.convert("RGB") for image in examples[image_column]]
|
700 |
-
examples["pixel_values"] = [train_transforms(image) for image in images]
|
701 |
-
examples["input_ids"] = tokenize_captions(examples)
|
702 |
-
return examples
|
703 |
-
|
704 |
-
with accelerator.main_process_first():
|
705 |
-
if args.max_train_samples is not None:
|
706 |
-
dataset["train"] = dataset["train"].shuffle(seed=args.seed).select(range(args.max_train_samples))
|
707 |
-
# Set the training transforms
|
708 |
-
train_dataset = dataset["train"].with_transform(preprocess_train)
|
709 |
-
|
710 |
-
def collate_fn(examples):
|
711 |
-
pixel_values = torch.stack([example["pixel_values"] for example in examples])
|
712 |
-
pixel_values = pixel_values.to(memory_format=torch.contiguous_format).float()
|
713 |
-
input_ids = torch.stack([example["input_ids"] for example in examples])
|
714 |
-
return {"pixel_values": pixel_values, "input_ids": input_ids}
|
715 |
-
|
716 |
-
# DataLoaders creation:
|
717 |
-
train_dataloader = torch.utils.data.DataLoader(
|
718 |
-
train_dataset,
|
719 |
-
shuffle=True,
|
720 |
-
collate_fn=collate_fn,
|
721 |
-
batch_size=args.train_batch_size,
|
722 |
-
num_workers=args.dataloader_num_workers,
|
723 |
-
)
|
724 |
-
|
725 |
-
# Scheduler and math around the number of training steps.
|
726 |
-
overrode_max_train_steps = False
|
727 |
-
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
|
728 |
-
if args.max_train_steps is None:
|
729 |
-
args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch
|
730 |
-
overrode_max_train_steps = True
|
731 |
-
|
732 |
-
lr_scheduler = get_scheduler(
|
733 |
-
args.lr_scheduler,
|
734 |
-
optimizer=optimizer,
|
735 |
-
num_warmup_steps=args.lr_warmup_steps * accelerator.num_processes,
|
736 |
-
num_training_steps=args.max_train_steps * accelerator.num_processes,
|
737 |
-
)
|
738 |
-
|
739 |
-
# Prepare everything with our `accelerator`.
|
740 |
-
unet, optimizer, train_dataloader, lr_scheduler = accelerator.prepare(
|
741 |
-
unet, optimizer, train_dataloader, lr_scheduler
|
742 |
-
)
|
743 |
-
|
744 |
-
if args.use_ema:
|
745 |
-
ema_unet.to(accelerator.device)
|
746 |
-
|
747 |
-
unet = ORTModule(unet)
|
748 |
-
|
749 |
-
# For mixed precision training we cast the text_encoder and vae weights to half-precision
|
750 |
-
# as these models are only used for inference, keeping weights in full precision is not required.
|
751 |
-
weight_dtype = torch.float32
|
752 |
-
if accelerator.mixed_precision == "fp16":
|
753 |
-
weight_dtype = torch.float16
|
754 |
-
elif accelerator.mixed_precision == "bf16":
|
755 |
-
weight_dtype = torch.bfloat16
|
756 |
-
|
757 |
-
# Move text_encode and vae to gpu and cast to weight_dtype
|
758 |
-
text_encoder.to(accelerator.device, dtype=weight_dtype)
|
759 |
-
vae.to(accelerator.device, dtype=weight_dtype)
|
760 |
-
|
761 |
-
# We need to recalculate our total training steps as the size of the training dataloader may have changed.
|
762 |
-
num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps)
|
763 |
-
if overrode_max_train_steps:
|
764 |
-
args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch
|
765 |
-
# Afterwards we recalculate our number of training epochs
|
766 |
-
args.num_train_epochs = math.ceil(args.max_train_steps / num_update_steps_per_epoch)
|
767 |
-
|
768 |
-
# We need to initialize the trackers we use, and also store our configuration.
|
769 |
-
# The trackers initializes automatically on the main process.
|
770 |
-
if accelerator.is_main_process:
|
771 |
-
tracker_config = dict(vars(args))
|
772 |
-
tracker_config.pop("validation_prompts")
|
773 |
-
accelerator.init_trackers(args.tracker_project_name, tracker_config)
|
774 |
-
|
775 |
-
# Train!
|
776 |
-
total_batch_size = args.train_batch_size * accelerator.num_processes * args.gradient_accumulation_steps
|
777 |
-
|
778 |
-
logger.info("***** Running training *****")
|
779 |
-
logger.info(f" Num examples = {len(train_dataset)}")
|
780 |
-
logger.info(f" Num Epochs = {args.num_train_epochs}")
|
781 |
-
logger.info(f" Instantaneous batch size per device = {args.train_batch_size}")
|
782 |
-
logger.info(f" Total train batch size (w. parallel, distributed & accumulation) = {total_batch_size}")
|
783 |
-
logger.info(f" Gradient Accumulation steps = {args.gradient_accumulation_steps}")
|
784 |
-
logger.info(f" Total optimization steps = {args.max_train_steps}")
|
785 |
-
global_step = 0
|
786 |
-
first_epoch = 0
|
787 |
-
|
788 |
-
# Potentially load in the weights and states from a previous save
|
789 |
-
if args.resume_from_checkpoint:
|
790 |
-
if args.resume_from_checkpoint != "latest":
|
791 |
-
path = os.path.basename(args.resume_from_checkpoint)
|
792 |
-
else:
|
793 |
-
# Get the most recent checkpoint
|
794 |
-
dirs = os.listdir(args.output_dir)
|
795 |
-
dirs = [d for d in dirs if d.startswith("checkpoint")]
|
796 |
-
dirs = sorted(dirs, key=lambda x: int(x.split("-")[1]))
|
797 |
-
path = dirs[-1] if len(dirs) > 0 else None
|
798 |
-
|
799 |
-
if path is None:
|
800 |
-
accelerator.print(
|
801 |
-
f"Checkpoint '{args.resume_from_checkpoint}' does not exist. Starting a new training run."
|
802 |
-
)
|
803 |
-
args.resume_from_checkpoint = None
|
804 |
-
else:
|
805 |
-
accelerator.print(f"Resuming from checkpoint {path}")
|
806 |
-
accelerator.load_state(os.path.join(args.output_dir, path))
|
807 |
-
global_step = int(path.split("-")[1])
|
808 |
-
|
809 |
-
resume_global_step = global_step * args.gradient_accumulation_steps
|
810 |
-
first_epoch = global_step // num_update_steps_per_epoch
|
811 |
-
resume_step = resume_global_step % (num_update_steps_per_epoch * args.gradient_accumulation_steps)
|
812 |
-
|
813 |
-
# Only show the progress bar once on each machine.
|
814 |
-
progress_bar = tqdm(range(global_step, args.max_train_steps), disable=not accelerator.is_local_main_process)
|
815 |
-
progress_bar.set_description("Steps")
|
816 |
-
|
817 |
-
for epoch in range(first_epoch, args.num_train_epochs):
|
818 |
-
unet.train()
|
819 |
-
train_loss = 0.0
|
820 |
-
for step, batch in enumerate(train_dataloader):
|
821 |
-
# Skip steps until we reach the resumed step
|
822 |
-
if args.resume_from_checkpoint and epoch == first_epoch and step < resume_step:
|
823 |
-
if step % args.gradient_accumulation_steps == 0:
|
824 |
-
progress_bar.update(1)
|
825 |
-
continue
|
826 |
-
|
827 |
-
with accelerator.accumulate(unet):
|
828 |
-
# Convert images to latent space
|
829 |
-
latents = vae.encode(batch["pixel_values"].to(weight_dtype)).latent_dist.sample()
|
830 |
-
latents = latents * vae.config.scaling_factor
|
831 |
-
|
832 |
-
# Sample noise that we'll add to the latents
|
833 |
-
noise = torch.randn_like(latents)
|
834 |
-
if args.noise_offset:
|
835 |
-
# https://www.crosslabs.org//blog/diffusion-with-offset-noise
|
836 |
-
noise += args.noise_offset * torch.randn(
|
837 |
-
(latents.shape[0], latents.shape[1], 1, 1), device=latents.device
|
838 |
-
)
|
839 |
-
if args.input_pertubation:
|
840 |
-
new_noise = noise + args.input_pertubation * torch.randn_like(noise)
|
841 |
-
bsz = latents.shape[0]
|
842 |
-
# Sample a random timestep for each image
|
843 |
-
timesteps = torch.randint(0, noise_scheduler.config.num_train_timesteps, (bsz,), device=latents.device)
|
844 |
-
timesteps = timesteps.long()
|
845 |
-
|
846 |
-
# Add noise to the latents according to the noise magnitude at each timestep
|
847 |
-
# (this is the forward diffusion process)
|
848 |
-
if args.input_pertubation:
|
849 |
-
noisy_latents = noise_scheduler.add_noise(latents, new_noise, timesteps)
|
850 |
-
else:
|
851 |
-
noisy_latents = noise_scheduler.add_noise(latents, noise, timesteps)
|
852 |
-
|
853 |
-
# Get the text embedding for conditioning
|
854 |
-
encoder_hidden_states = text_encoder(batch["input_ids"])[0]
|
855 |
-
|
856 |
-
# Get the target for loss depending on the prediction type
|
857 |
-
if noise_scheduler.config.prediction_type == "epsilon":
|
858 |
-
target = noise
|
859 |
-
elif noise_scheduler.config.prediction_type == "v_prediction":
|
860 |
-
target = noise_scheduler.get_velocity(latents, noise, timesteps)
|
861 |
-
else:
|
862 |
-
raise ValueError(f"Unknown prediction type {noise_scheduler.config.prediction_type}")
|
863 |
-
|
864 |
-
# Predict the noise residual and compute loss
|
865 |
-
model_pred = unet(noisy_latents, timesteps, encoder_hidden_states).sample
|
866 |
-
|
867 |
-
if args.snr_gamma is None:
|
868 |
-
loss = F.mse_loss(model_pred.float(), target.float(), reduction="mean")
|
869 |
-
else:
|
870 |
-
# Compute loss-weights as per Section 3.4 of https://arxiv.org/abs/2303.09556.
|
871 |
-
# Since we predict the noise instead of x_0, the original formulation is slightly changed.
|
872 |
-
# This is discussed in Section 4.2 of the same paper.
|
873 |
-
snr = compute_snr(timesteps)
|
874 |
-
mse_loss_weights = (
|
875 |
-
torch.stack([snr, args.snr_gamma * torch.ones_like(timesteps)], dim=1).min(dim=1)[0] / snr
|
876 |
-
)
|
877 |
-
# We first calculate the original loss. Then we mean over the non-batch dimensions and
|
878 |
-
# rebalance the sample-wise losses with their respective loss weights.
|
879 |
-
# Finally, we take the mean of the rebalanced loss.
|
880 |
-
loss = F.mse_loss(model_pred.float(), target.float(), reduction="none")
|
881 |
-
loss = loss.mean(dim=list(range(1, len(loss.shape)))) * mse_loss_weights
|
882 |
-
loss = loss.mean()
|
883 |
-
|
884 |
-
# Gather the losses across all processes for logging (if we use distributed training).
|
885 |
-
avg_loss = accelerator.gather(loss.repeat(args.train_batch_size)).mean()
|
886 |
-
train_loss += avg_loss.item() / args.gradient_accumulation_steps
|
887 |
-
|
888 |
-
# Backpropagate
|
889 |
-
accelerator.backward(loss)
|
890 |
-
if accelerator.sync_gradients:
|
891 |
-
accelerator.clip_grad_norm_(unet.parameters(), args.max_grad_norm)
|
892 |
-
optimizer.step()
|
893 |
-
lr_scheduler.step()
|
894 |
-
optimizer.zero_grad()
|
895 |
-
|
896 |
-
# Checks if the accelerator has performed an optimization step behind the scenes
|
897 |
-
if accelerator.sync_gradients:
|
898 |
-
if args.use_ema:
|
899 |
-
ema_unet.step(unet.parameters())
|
900 |
-
progress_bar.update(1)
|
901 |
-
global_step += 1
|
902 |
-
accelerator.log({"train_loss": train_loss}, step=global_step)
|
903 |
-
train_loss = 0.0
|
904 |
-
|
905 |
-
if global_step % args.checkpointing_steps == 0:
|
906 |
-
if accelerator.is_main_process:
|
907 |
-
save_path = os.path.join(args.output_dir, f"checkpoint-{global_step}")
|
908 |
-
accelerator.save_state(save_path)
|
909 |
-
logger.info(f"Saved state to {save_path}")
|
910 |
-
|
911 |
-
logs = {"step_loss": loss.detach().item(), "lr": lr_scheduler.get_last_lr()[0]}
|
912 |
-
progress_bar.set_postfix(**logs)
|
913 |
-
|
914 |
-
if global_step >= args.max_train_steps:
|
915 |
-
break
|
916 |
-
|
917 |
-
if accelerator.is_main_process:
|
918 |
-
if args.validation_prompts is not None and epoch % args.validation_epochs == 0:
|
919 |
-
if args.use_ema:
|
920 |
-
# Store the UNet parameters temporarily and load the EMA parameters to perform inference.
|
921 |
-
ema_unet.store(unet.parameters())
|
922 |
-
ema_unet.copy_to(unet.parameters())
|
923 |
-
log_validation(
|
924 |
-
vae,
|
925 |
-
text_encoder,
|
926 |
-
tokenizer,
|
927 |
-
unet,
|
928 |
-
args,
|
929 |
-
accelerator,
|
930 |
-
weight_dtype,
|
931 |
-
global_step,
|
932 |
-
)
|
933 |
-
if args.use_ema:
|
934 |
-
# Switch back to the original UNet parameters.
|
935 |
-
ema_unet.restore(unet.parameters())
|
936 |
-
|
937 |
-
# Create the pipeline using the trained modules and save it.
|
938 |
-
accelerator.wait_for_everyone()
|
939 |
-
if accelerator.is_main_process:
|
940 |
-
unet = accelerator.unwrap_model(unet)
|
941 |
-
if args.use_ema:
|
942 |
-
ema_unet.copy_to(unet.parameters())
|
943 |
-
|
944 |
-
pipeline = StableDiffusionPipeline.from_pretrained(
|
945 |
-
args.pretrained_model_name_or_path,
|
946 |
-
text_encoder=text_encoder,
|
947 |
-
vae=vae,
|
948 |
-
unet=unet,
|
949 |
-
revision=args.revision,
|
950 |
-
)
|
951 |
-
pipeline.save_pretrained(args.output_dir)
|
952 |
-
|
953 |
-
if args.push_to_hub:
|
954 |
-
upload_folder(
|
955 |
-
repo_id=repo_id,
|
956 |
-
folder_path=args.output_dir,
|
957 |
-
commit_message="End of training",
|
958 |
-
ignore_patterns=["step_*", "epoch_*"],
|
959 |
-
)
|
960 |
-
|
961 |
-
accelerator.end_training()
|
962 |
-
|
963 |
-
|
964 |
-
if __name__ == "__main__":
|
965 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Androidonnxfork/CivitAi-to-Diffusers/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py
DELETED
@@ -1,1102 +0,0 @@
|
|
1 |
-
# Copyright 2023 The HuggingFace Team. All rights reserved.
|
2 |
-
#
|
3 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
-
# you may not use this file except in compliance with the License.
|
5 |
-
# You may obtain a copy of the License at
|
6 |
-
#
|
7 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
-
#
|
9 |
-
# Unless required by applicable law or agreed to in writing, software
|
10 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
-
# See the License for the specific language governing permissions and
|
13 |
-
# limitations under the License.
|
14 |
-
|
15 |
-
|
16 |
-
import inspect
|
17 |
-
import warnings
|
18 |
-
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
19 |
-
|
20 |
-
import numpy as np
|
21 |
-
import PIL.Image
|
22 |
-
import torch
|
23 |
-
import torch.nn.functional as F
|
24 |
-
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer
|
25 |
-
|
26 |
-
from ...image_processor import VaeImageProcessor
|
27 |
-
from ...loaders import FromSingleFileMixin, LoraLoaderMixin, TextualInversionLoaderMixin
|
28 |
-
from ...models import AutoencoderKL, ControlNetModel, UNet2DConditionModel
|
29 |
-
from ...schedulers import KarrasDiffusionSchedulers
|
30 |
-
from ...utils import (
|
31 |
-
deprecate,
|
32 |
-
is_accelerate_available,
|
33 |
-
is_accelerate_version,
|
34 |
-
is_compiled_module,
|
35 |
-
logging,
|
36 |
-
randn_tensor,
|
37 |
-
replace_example_docstring,
|
38 |
-
)
|
39 |
-
from ..pipeline_utils import DiffusionPipeline
|
40 |
-
from ..stable_diffusion import StableDiffusionPipelineOutput
|
41 |
-
from ..stable_diffusion.safety_checker import StableDiffusionSafetyChecker
|
42 |
-
from .multicontrolnet import MultiControlNetModel
|
43 |
-
|
44 |
-
|
45 |
-
logger = logging.get_logger(__name__) # pylint: disable=invalid-name
|
46 |
-
|
47 |
-
|
48 |
-
EXAMPLE_DOC_STRING = """
|
49 |
-
Examples:
|
50 |
-
```py
|
51 |
-
>>> # !pip install opencv-python transformers accelerate
|
52 |
-
>>> from diffusers import StableDiffusionControlNetImg2ImgPipeline, ControlNetModel, UniPCMultistepScheduler
|
53 |
-
>>> from diffusers.utils import load_image
|
54 |
-
>>> import numpy as np
|
55 |
-
>>> import torch
|
56 |
-
|
57 |
-
>>> import cv2
|
58 |
-
>>> from PIL import Image
|
59 |
-
|
60 |
-
>>> # download an image
|
61 |
-
>>> image = load_image(
|
62 |
-
... "https://hf.co/datasets/huggingface/documentation-images/resolve/main/diffusers/input_image_vermeer.png"
|
63 |
-
... )
|
64 |
-
>>> np_image = np.array(image)
|
65 |
-
|
66 |
-
>>> # get canny image
|
67 |
-
>>> np_image = cv2.Canny(np_image, 100, 200)
|
68 |
-
>>> np_image = np_image[:, :, None]
|
69 |
-
>>> np_image = np.concatenate([np_image, np_image, np_image], axis=2)
|
70 |
-
>>> canny_image = Image.fromarray(np_image)
|
71 |
-
|
72 |
-
>>> # load control net and stable diffusion v1-5
|
73 |
-
>>> controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-canny", torch_dtype=torch.float16)
|
74 |
-
>>> pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
75 |
-
... "runwayml/stable-diffusion-v1-5", controlnet=controlnet, torch_dtype=torch.float16
|
76 |
-
... )
|
77 |
-
|
78 |
-
>>> # speed up diffusion process with faster scheduler and memory optimization
|
79 |
-
>>> pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
80 |
-
>>> pipe.enable_model_cpu_offload()
|
81 |
-
|
82 |
-
>>> # generate image
|
83 |
-
>>> generator = torch.manual_seed(0)
|
84 |
-
>>> image = pipe(
|
85 |
-
... "futuristic-looking woman",
|
86 |
-
... num_inference_steps=20,
|
87 |
-
... generator=generator,
|
88 |
-
... image=image,
|
89 |
-
... control_image=canny_image,
|
90 |
-
... ).images[0]
|
91 |
-
```
|
92 |
-
"""
|
93 |
-
|
94 |
-
|
95 |
-
def prepare_image(image):
|
96 |
-
if isinstance(image, torch.Tensor):
|
97 |
-
# Batch single image
|
98 |
-
if image.ndim == 3:
|
99 |
-
image = image.unsqueeze(0)
|
100 |
-
|
101 |
-
image = image.to(dtype=torch.float32)
|
102 |
-
else:
|
103 |
-
# preprocess image
|
104 |
-
if isinstance(image, (PIL.Image.Image, np.ndarray)):
|
105 |
-
image = [image]
|
106 |
-
|
107 |
-
if isinstance(image, list) and isinstance(image[0], PIL.Image.Image):
|
108 |
-
image = [np.array(i.convert("RGB"))[None, :] for i in image]
|
109 |
-
image = np.concatenate(image, axis=0)
|
110 |
-
elif isinstance(image, list) and isinstance(image[0], np.ndarray):
|
111 |
-
image = np.concatenate([i[None, :] for i in image], axis=0)
|
112 |
-
|
113 |
-
image = image.transpose(0, 3, 1, 2)
|
114 |
-
image = torch.from_numpy(image).to(dtype=torch.float32) / 127.5 - 1.0
|
115 |
-
|
116 |
-
return image
|
117 |
-
|
118 |
-
|
119 |
-
class StableDiffusionControlNetImg2ImgPipeline(
|
120 |
-
DiffusionPipeline, TextualInversionLoaderMixin, LoraLoaderMixin, FromSingleFileMixin
|
121 |
-
):
|
122 |
-
r"""
|
123 |
-
Pipeline for text-to-image generation using Stable Diffusion with ControlNet guidance.
|
124 |
-
|
125 |
-
This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the
|
126 |
-
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)
|
127 |
-
|
128 |
-
In addition the pipeline inherits the following loading methods:
|
129 |
-
- *Textual-Inversion*: [`loaders.TextualInversionLoaderMixin.load_textual_inversion`]
|
130 |
-
|
131 |
-
Args:
|
132 |
-
vae ([`AutoencoderKL`]):
|
133 |
-
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
|
134 |
-
text_encoder ([`CLIPTextModel`]):
|
135 |
-
Frozen text-encoder. Stable Diffusion uses the text portion of
|
136 |
-
[CLIP](https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel), specifically
|
137 |
-
the [clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14) variant.
|
138 |
-
tokenizer (`CLIPTokenizer`):
|
139 |
-
Tokenizer of class
|
140 |
-
[CLIPTokenizer](https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer).
|
141 |
-
unet ([`UNet2DConditionModel`]): Conditional U-Net architecture to denoise the encoded image latents.
|
142 |
-
controlnet ([`ControlNetModel`] or `List[ControlNetModel]`):
|
143 |
-
Provides additional conditioning to the unet during the denoising process. If you set multiple ControlNets
|
144 |
-
as a list, the outputs from each ControlNet are added together to create one combined additional
|
145 |
-
conditioning.
|
146 |
-
scheduler ([`SchedulerMixin`]):
|
147 |
-
A scheduler to be used in combination with `unet` to denoise the encoded image latents. Can be one of
|
148 |
-
[`DDIMScheduler`], [`LMSDiscreteScheduler`], or [`PNDMScheduler`].
|
149 |
-
safety_checker ([`StableDiffusionSafetyChecker`]):
|
150 |
-
Classification module that estimates whether generated images could be considered offensive or harmful.
|
151 |
-
Please, refer to the [model card](https://huggingface.co/runwayml/stable-diffusion-v1-5) for details.
|
152 |
-
feature_extractor ([`CLIPImageProcessor`]):
|
153 |
-
Model that extracts features from generated images to be used as inputs for the `safety_checker`.
|
154 |
-
"""
|
155 |
-
_optional_components = ["safety_checker", "feature_extractor"]
|
156 |
-
|
157 |
-
def __init__(
|
158 |
-
self,
|
159 |
-
vae: AutoencoderKL,
|
160 |
-
text_encoder: CLIPTextModel,
|
161 |
-
tokenizer: CLIPTokenizer,
|
162 |
-
unet: UNet2DConditionModel,
|
163 |
-
controlnet: Union[ControlNetModel, List[ControlNetModel], Tuple[ControlNetModel], MultiControlNetModel],
|
164 |
-
scheduler: KarrasDiffusionSchedulers,
|
165 |
-
safety_checker: StableDiffusionSafetyChecker,
|
166 |
-
feature_extractor: CLIPImageProcessor,
|
167 |
-
requires_safety_checker: bool = True,
|
168 |
-
):
|
169 |
-
super().__init__()
|
170 |
-
|
171 |
-
if safety_checker is None and requires_safety_checker:
|
172 |
-
logger.warning(
|
173 |
-
f"You have disabled the safety checker for {self.__class__} by passing `safety_checker=None`. Ensure"
|
174 |
-
" that you abide to the conditions of the Stable Diffusion license and do not expose unfiltered"
|
175 |
-
" results in services or applications open to the public. Both the diffusers team and Hugging Face"
|
176 |
-
" strongly recommend to keep the safety filter enabled in all public facing circumstances, disabling"
|
177 |
-
" it only for use-cases that involve analyzing network behavior or auditing its results. For more"
|
178 |
-
" information, please have a look at https://github.com/huggingface/diffusers/pull/254 ."
|
179 |
-
)
|
180 |
-
|
181 |
-
if safety_checker is not None and feature_extractor is None:
|
182 |
-
raise ValueError(
|
183 |
-
"Make sure to define a feature extractor when loading {self.__class__} if you want to use the safety"
|
184 |
-
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` instead."
|
185 |
-
)
|
186 |
-
|
187 |
-
if isinstance(controlnet, (list, tuple)):
|
188 |
-
controlnet = MultiControlNetModel(controlnet)
|
189 |
-
|
190 |
-
self.register_modules(
|
191 |
-
vae=vae,
|
192 |
-
text_encoder=text_encoder,
|
193 |
-
tokenizer=tokenizer,
|
194 |
-
unet=unet,
|
195 |
-
controlnet=controlnet,
|
196 |
-
scheduler=scheduler,
|
197 |
-
safety_checker=safety_checker,
|
198 |
-
feature_extractor=feature_extractor,
|
199 |
-
)
|
200 |
-
self.vae_scale_factor = 2 ** (len(self.vae.config.block_out_channels) - 1)
|
201 |
-
self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor, do_convert_rgb=True)
|
202 |
-
self.control_image_processor = VaeImageProcessor(
|
203 |
-
vae_scale_factor=self.vae_scale_factor, do_convert_rgb=True, do_normalize=False
|
204 |
-
)
|
205 |
-
self.register_to_config(requires_safety_checker=requires_safety_checker)
|
206 |
-
|
207 |
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_slicing
|
208 |
-
def enable_vae_slicing(self):
|
209 |
-
r"""
|
210 |
-
Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to
|
211 |
-
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes.
|
212 |
-
"""
|
213 |
-
self.vae.enable_slicing()
|
214 |
-
|
215 |
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_slicing
|
216 |
-
def disable_vae_slicing(self):
|
217 |
-
r"""
|
218 |
-
Disable sliced VAE decoding. If `enable_vae_slicing` was previously enabled, this method will go back to
|
219 |
-
computing decoding in one step.
|
220 |
-
"""
|
221 |
-
self.vae.disable_slicing()
|
222 |
-
|
223 |
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.enable_vae_tiling
|
224 |
-
def enable_vae_tiling(self):
|
225 |
-
r"""
|
226 |
-
Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to
|
227 |
-
compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow
|
228 |
-
processing larger images.
|
229 |
-
"""
|
230 |
-
self.vae.enable_tiling()
|
231 |
-
|
232 |
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.disable_vae_tiling
|
233 |
-
def disable_vae_tiling(self):
|
234 |
-
r"""
|
235 |
-
Disable tiled VAE decoding. If `enable_vae_tiling` was previously enabled, this method will go back to
|
236 |
-
computing decoding in one step.
|
237 |
-
"""
|
238 |
-
self.vae.disable_tiling()
|
239 |
-
|
240 |
-
def enable_model_cpu_offload(self, gpu_id=0):
|
241 |
-
r"""
|
242 |
-
Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
|
243 |
-
to `enable_sequential_cpu_offload`, this method moves one whole model at a time to the GPU when its `forward`
|
244 |
-
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
|
245 |
-
`enable_sequential_cpu_offload`, but performance is much better due to the iterative execution of the `unet`.
|
246 |
-
"""
|
247 |
-
if is_accelerate_available() and is_accelerate_version(">=", "0.17.0.dev0"):
|
248 |
-
from accelerate import cpu_offload_with_hook
|
249 |
-
else:
|
250 |
-
raise ImportError("`enable_model_cpu_offload` requires `accelerate v0.17.0` or higher.")
|
251 |
-
|
252 |
-
device = torch.device(f"cuda:{gpu_id}")
|
253 |
-
|
254 |
-
hook = None
|
255 |
-
for cpu_offloaded_model in [self.text_encoder, self.unet, self.vae]:
|
256 |
-
_, hook = cpu_offload_with_hook(cpu_offloaded_model, device, prev_module_hook=hook)
|
257 |
-
|
258 |
-
if self.safety_checker is not None:
|
259 |
-
# the safety checker can offload the vae again
|
260 |
-
_, hook = cpu_offload_with_hook(self.safety_checker, device, prev_module_hook=hook)
|
261 |
-
|
262 |
-
# control net hook has be manually offloaded as it alternates with unet
|
263 |
-
cpu_offload_with_hook(self.controlnet, device)
|
264 |
-
|
265 |
-
# We'll offload the last model manually.
|
266 |
-
self.final_offload_hook = hook
|
267 |
-
|
268 |
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline._encode_prompt
|
269 |
-
def _encode_prompt(
|
270 |
-
self,
|
271 |
-
prompt,
|
272 |
-
device,
|
273 |
-
num_images_per_prompt,
|
274 |
-
do_classifier_free_guidance,
|
275 |
-
negative_prompt=None,
|
276 |
-
prompt_embeds: Optional[torch.FloatTensor] = None,
|
277 |
-
negative_prompt_embeds: Optional[torch.FloatTensor] = None,
|
278 |
-
lora_scale: Optional[float] = None,
|
279 |
-
):
|
280 |
-
r"""
|
281 |
-
Encodes the prompt into text encoder hidden states.
|
282 |
-
|
283 |
-
Args:
|
284 |
-
prompt (`str` or `List[str]`, *optional*):
|
285 |
-
prompt to be encoded
|
286 |
-
device: (`torch.device`):
|
287 |
-
torch device
|
288 |
-
num_images_per_prompt (`int`):
|
289 |
-
number of images that should be generated per prompt
|
290 |
-
do_classifier_free_guidance (`bool`):
|
291 |
-
whether to use classifier free guidance or not
|
292 |
-
negative_prompt (`str` or `List[str]`, *optional*):
|
293 |
-
The prompt or prompts not to guide the image generation. If not defined, one has to pass
|
294 |
-
`negative_prompt_embeds` instead. Ignored when not using guidance (i.e., ignored if `guidance_scale` is
|
295 |
-
less than `1`).
|
296 |
-
prompt_embeds (`torch.FloatTensor`, *optional*):
|
297 |
-
Pre-generated text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting. If not
|
298 |
-
provided, text embeddings will be generated from `prompt` input argument.
|
299 |
-
negative_prompt_embeds (`torch.FloatTensor`, *optional*):
|
300 |
-
Pre-generated negative text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt
|
301 |
-
weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt` input
|
302 |
-
argument.
|
303 |
-
lora_scale (`float`, *optional*):
|
304 |
-
A lora scale that will be applied to all LoRA layers of the text encoder if LoRA layers are loaded.
|
305 |
-
"""
|
306 |
-
# set lora scale so that monkey patched LoRA
|
307 |
-
# function of text encoder can correctly access it
|
308 |
-
if lora_scale is not None and isinstance(self, LoraLoaderMixin):
|
309 |
-
self._lora_scale = lora_scale
|
310 |
-
|
311 |
-
if prompt is not None and isinstance(prompt, str):
|
312 |
-
batch_size = 1
|
313 |
-
elif prompt is not None and isinstance(prompt, list):
|
314 |
-
batch_size = len(prompt)
|
315 |
-
else:
|
316 |
-
batch_size = prompt_embeds.shape[0]
|
317 |
-
|
318 |
-
if prompt_embeds is None:
|
319 |
-
# textual inversion: procecss multi-vector tokens if necessary
|
320 |
-
if isinstance(self, TextualInversionLoaderMixin):
|
321 |
-
prompt = self.maybe_convert_prompt(prompt, self.tokenizer)
|
322 |
-
|
323 |
-
text_inputs = self.tokenizer(
|
324 |
-
prompt,
|
325 |
-
padding="max_length",
|
326 |
-
max_length=self.tokenizer.model_max_length,
|
327 |
-
truncation=True,
|
328 |
-
return_tensors="pt",
|
329 |
-
)
|
330 |
-
text_input_ids = text_inputs.input_ids
|
331 |
-
untruncated_ids = self.tokenizer(prompt, padding="longest", return_tensors="pt").input_ids
|
332 |
-
|
333 |
-
if untruncated_ids.shape[-1] >= text_input_ids.shape[-1] and not torch.equal(
|
334 |
-
text_input_ids, untruncated_ids
|
335 |
-
):
|
336 |
-
removed_text = self.tokenizer.batch_decode(
|
337 |
-
untruncated_ids[:, self.tokenizer.model_max_length - 1 : -1]
|
338 |
-
)
|
339 |
-
logger.warning(
|
340 |
-
"The following part of your input was truncated because CLIP can only handle sequences up to"
|
341 |
-
f" {self.tokenizer.model_max_length} tokens: {removed_text}"
|
342 |
-
)
|
343 |
-
|
344 |
-
if hasattr(self.text_encoder.config, "use_attention_mask") and self.text_encoder.config.use_attention_mask:
|
345 |
-
attention_mask = text_inputs.attention_mask.to(device)
|
346 |
-
else:
|
347 |
-
attention_mask = None
|
348 |
-
|
349 |
-
prompt_embeds = self.text_encoder(
|
350 |
-
text_input_ids.to(device),
|
351 |
-
attention_mask=attention_mask,
|
352 |
-
)
|
353 |
-
prompt_embeds = prompt_embeds[0]
|
354 |
-
|
355 |
-
prompt_embeds = prompt_embeds.to(dtype=self.text_encoder.dtype, device=device)
|
356 |
-
|
357 |
-
bs_embed, seq_len, _ = prompt_embeds.shape
|
358 |
-
# duplicate text embeddings for each generation per prompt, using mps friendly method
|
359 |
-
prompt_embeds = prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
360 |
-
prompt_embeds = prompt_embeds.view(bs_embed * num_images_per_prompt, seq_len, -1)
|
361 |
-
|
362 |
-
# get unconditional embeddings for classifier free guidance
|
363 |
-
if do_classifier_free_guidance and negative_prompt_embeds is None:
|
364 |
-
uncond_tokens: List[str]
|
365 |
-
if negative_prompt is None:
|
366 |
-
uncond_tokens = [""] * batch_size
|
367 |
-
elif prompt is not None and type(prompt) is not type(negative_prompt):
|
368 |
-
raise TypeError(
|
369 |
-
f"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !="
|
370 |
-
f" {type(prompt)}."
|
371 |
-
)
|
372 |
-
elif isinstance(negative_prompt, str):
|
373 |
-
uncond_tokens = [negative_prompt]
|
374 |
-
elif batch_size != len(negative_prompt):
|
375 |
-
raise ValueError(
|
376 |
-
f"`negative_prompt`: {negative_prompt} has batch size {len(negative_prompt)}, but `prompt`:"
|
377 |
-
f" {prompt} has batch size {batch_size}. Please make sure that passed `negative_prompt` matches"
|
378 |
-
" the batch size of `prompt`."
|
379 |
-
)
|
380 |
-
else:
|
381 |
-
uncond_tokens = negative_prompt
|
382 |
-
|
383 |
-
# textual inversion: procecss multi-vector tokens if necessary
|
384 |
-
if isinstance(self, TextualInversionLoaderMixin):
|
385 |
-
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
|
386 |
-
|
387 |
-
max_length = prompt_embeds.shape[1]
|
388 |
-
uncond_input = self.tokenizer(
|
389 |
-
uncond_tokens,
|
390 |
-
padding="max_length",
|
391 |
-
max_length=max_length,
|
392 |
-
truncation=True,
|
393 |
-
return_tensors="pt",
|
394 |
-
)
|
395 |
-
|
396 |
-
if hasattr(self.text_encoder.config, "use_attention_mask") and self.text_encoder.config.use_attention_mask:
|
397 |
-
attention_mask = uncond_input.attention_mask.to(device)
|
398 |
-
else:
|
399 |
-
attention_mask = None
|
400 |
-
|
401 |
-
negative_prompt_embeds = self.text_encoder(
|
402 |
-
uncond_input.input_ids.to(device),
|
403 |
-
attention_mask=attention_mask,
|
404 |
-
)
|
405 |
-
negative_prompt_embeds = negative_prompt_embeds[0]
|
406 |
-
|
407 |
-
if do_classifier_free_guidance:
|
408 |
-
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
|
409 |
-
seq_len = negative_prompt_embeds.shape[1]
|
410 |
-
|
411 |
-
negative_prompt_embeds = negative_prompt_embeds.to(dtype=self.text_encoder.dtype, device=device)
|
412 |
-
|
413 |
-
negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1)
|
414 |
-
negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1)
|
415 |
-
|
416 |
-
# For classifier free guidance, we need to do two forward passes.
|
417 |
-
# Here we concatenate the unconditional and text embeddings into a single batch
|
418 |
-
# to avoid doing two forward passes
|
419 |
-
prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds])
|
420 |
-
|
421 |
-
return prompt_embeds
|
422 |
-
|
423 |
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.run_safety_checker
|
424 |
-
def run_safety_checker(self, image, device, dtype):
|
425 |
-
if self.safety_checker is None:
|
426 |
-
has_nsfw_concept = None
|
427 |
-
else:
|
428 |
-
if torch.is_tensor(image):
|
429 |
-
feature_extractor_input = self.image_processor.postprocess(image, output_type="pil")
|
430 |
-
else:
|
431 |
-
feature_extractor_input = self.image_processor.numpy_to_pil(image)
|
432 |
-
safety_checker_input = self.feature_extractor(feature_extractor_input, return_tensors="pt").to(device)
|
433 |
-
image, has_nsfw_concept = self.safety_checker(
|
434 |
-
images=image, clip_input=safety_checker_input.pixel_values.to(dtype)
|
435 |
-
)
|
436 |
-
return image, has_nsfw_concept
|
437 |
-
|
438 |
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.decode_latents
|
439 |
-
def decode_latents(self, latents):
|
440 |
-
warnings.warn(
|
441 |
-
"The decode_latents method is deprecated and will be removed in a future version. Please"
|
442 |
-
" use VaeImageProcessor instead",
|
443 |
-
FutureWarning,
|
444 |
-
)
|
445 |
-
latents = 1 / self.vae.config.scaling_factor * latents
|
446 |
-
image = self.vae.decode(latents, return_dict=False)[0]
|
447 |
-
image = (image / 2 + 0.5).clamp(0, 1)
|
448 |
-
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
|
449 |
-
image = image.cpu().permute(0, 2, 3, 1).float().numpy()
|
450 |
-
return image
|
451 |
-
|
452 |
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_extra_step_kwargs
|
453 |
-
def prepare_extra_step_kwargs(self, generator, eta):
|
454 |
-
# prepare extra kwargs for the scheduler step, since not all schedulers have the same signature
|
455 |
-
# eta (η) is only used with the DDIMScheduler, it will be ignored for other schedulers.
|
456 |
-
# eta corresponds to η in DDIM paper: https://arxiv.org/abs/2010.02502
|
457 |
-
# and should be between [0, 1]
|
458 |
-
|
459 |
-
accepts_eta = "eta" in set(inspect.signature(self.scheduler.step).parameters.keys())
|
460 |
-
extra_step_kwargs = {}
|
461 |
-
if accepts_eta:
|
462 |
-
extra_step_kwargs["eta"] = eta
|
463 |
-
|
464 |
-
# check if the scheduler accepts generator
|
465 |
-
accepts_generator = "generator" in set(inspect.signature(self.scheduler.step).parameters.keys())
|
466 |
-
if accepts_generator:
|
467 |
-
extra_step_kwargs["generator"] = generator
|
468 |
-
return extra_step_kwargs
|
469 |
-
|
470 |
-
def check_inputs(
|
471 |
-
self,
|
472 |
-
prompt,
|
473 |
-
image,
|
474 |
-
callback_steps,
|
475 |
-
negative_prompt=None,
|
476 |
-
prompt_embeds=None,
|
477 |
-
negative_prompt_embeds=None,
|
478 |
-
controlnet_conditioning_scale=1.0,
|
479 |
-
control_guidance_start=0.0,
|
480 |
-
control_guidance_end=1.0,
|
481 |
-
):
|
482 |
-
if (callback_steps is None) or (
|
483 |
-
callback_steps is not None and (not isinstance(callback_steps, int) or callback_steps <= 0)
|
484 |
-
):
|
485 |
-
raise ValueError(
|
486 |
-
f"`callback_steps` has to be a positive integer but is {callback_steps} of type"
|
487 |
-
f" {type(callback_steps)}."
|
488 |
-
)
|
489 |
-
|
490 |
-
if prompt is not None and prompt_embeds is not None:
|
491 |
-
raise ValueError(
|
492 |
-
f"Cannot forward both `prompt`: {prompt} and `prompt_embeds`: {prompt_embeds}. Please make sure to"
|
493 |
-
" only forward one of the two."
|
494 |
-
)
|
495 |
-
elif prompt is None and prompt_embeds is None:
|
496 |
-
raise ValueError(
|
497 |
-
"Provide either `prompt` or `prompt_embeds`. Cannot leave both `prompt` and `prompt_embeds` undefined."
|
498 |
-
)
|
499 |
-
elif prompt is not None and (not isinstance(prompt, str) and not isinstance(prompt, list)):
|
500 |
-
raise ValueError(f"`prompt` has to be of type `str` or `list` but is {type(prompt)}")
|
501 |
-
|
502 |
-
if negative_prompt is not None and negative_prompt_embeds is not None:
|
503 |
-
raise ValueError(
|
504 |
-
f"Cannot forward both `negative_prompt`: {negative_prompt} and `negative_prompt_embeds`:"
|
505 |
-
f" {negative_prompt_embeds}. Please make sure to only forward one of the two."
|
506 |
-
)
|
507 |
-
|
508 |
-
if prompt_embeds is not None and negative_prompt_embeds is not None:
|
509 |
-
if prompt_embeds.shape != negative_prompt_embeds.shape:
|
510 |
-
raise ValueError(
|
511 |
-
"`prompt_embeds` and `negative_prompt_embeds` must have the same shape when passed directly, but"
|
512 |
-
f" got: `prompt_embeds` {prompt_embeds.shape} != `negative_prompt_embeds`"
|
513 |
-
f" {negative_prompt_embeds.shape}."
|
514 |
-
)
|
515 |
-
|
516 |
-
# `prompt` needs more sophisticated handling when there are multiple
|
517 |
-
# conditionings.
|
518 |
-
if isinstance(self.controlnet, MultiControlNetModel):
|
519 |
-
if isinstance(prompt, list):
|
520 |
-
logger.warning(
|
521 |
-
f"You have {len(self.controlnet.nets)} ControlNets and you have passed {len(prompt)}"
|
522 |
-
" prompts. The conditionings will be fixed across the prompts."
|
523 |
-
)
|
524 |
-
|
525 |
-
# Check `image`
|
526 |
-
is_compiled = hasattr(F, "scaled_dot_product_attention") and isinstance(
|
527 |
-
self.controlnet, torch._dynamo.eval_frame.OptimizedModule
|
528 |
-
)
|
529 |
-
if (
|
530 |
-
isinstance(self.controlnet, ControlNetModel)
|
531 |
-
or is_compiled
|
532 |
-
and isinstance(self.controlnet._orig_mod, ControlNetModel)
|
533 |
-
):
|
534 |
-
self.check_image(image, prompt, prompt_embeds)
|
535 |
-
elif (
|
536 |
-
isinstance(self.controlnet, MultiControlNetModel)
|
537 |
-
or is_compiled
|
538 |
-
and isinstance(self.controlnet._orig_mod, MultiControlNetModel)
|
539 |
-
):
|
540 |
-
if not isinstance(image, list):
|
541 |
-
raise TypeError("For multiple controlnets: `image` must be type `list`")
|
542 |
-
|
543 |
-
# When `image` is a nested list:
|
544 |
-
# (e.g. [[canny_image_1, pose_image_1], [canny_image_2, pose_image_2]])
|
545 |
-
elif any(isinstance(i, list) for i in image):
|
546 |
-
raise ValueError("A single batch of multiple conditionings are supported at the moment.")
|
547 |
-
elif len(image) != len(self.controlnet.nets):
|
548 |
-
raise ValueError(
|
549 |
-
f"For multiple controlnets: `image` must have the same length as the number of controlnets, but got {len(image)} images and {len(self.controlnet.nets)} ControlNets."
|
550 |
-
)
|
551 |
-
|
552 |
-
for image_ in image:
|
553 |
-
self.check_image(image_, prompt, prompt_embeds)
|
554 |
-
else:
|
555 |
-
assert False
|
556 |
-
|
557 |
-
# Check `controlnet_conditioning_scale`
|
558 |
-
if (
|
559 |
-
isinstance(self.controlnet, ControlNetModel)
|
560 |
-
or is_compiled
|
561 |
-
and isinstance(self.controlnet._orig_mod, ControlNetModel)
|
562 |
-
):
|
563 |
-
if not isinstance(controlnet_conditioning_scale, float):
|
564 |
-
raise TypeError("For single controlnet: `controlnet_conditioning_scale` must be type `float`.")
|
565 |
-
elif (
|
566 |
-
isinstance(self.controlnet, MultiControlNetModel)
|
567 |
-
or is_compiled
|
568 |
-
and isinstance(self.controlnet._orig_mod, MultiControlNetModel)
|
569 |
-
):
|
570 |
-
if isinstance(controlnet_conditioning_scale, list):
|
571 |
-
if any(isinstance(i, list) for i in controlnet_conditioning_scale):
|
572 |
-
raise ValueError("A single batch of multiple conditionings are supported at the moment.")
|
573 |
-
elif isinstance(controlnet_conditioning_scale, list) and len(controlnet_conditioning_scale) != len(
|
574 |
-
self.controlnet.nets
|
575 |
-
):
|
576 |
-
raise ValueError(
|
577 |
-
"For multiple controlnets: When `controlnet_conditioning_scale` is specified as `list`, it must have"
|
578 |
-
" the same length as the number of controlnets"
|
579 |
-
)
|
580 |
-
else:
|
581 |
-
assert False
|
582 |
-
|
583 |
-
if len(control_guidance_start) != len(control_guidance_end):
|
584 |
-
raise ValueError(
|
585 |
-
f"`control_guidance_start` has {len(control_guidance_start)} elements, but `control_guidance_end` has {len(control_guidance_end)} elements. Make sure to provide the same number of elements to each list."
|
586 |
-
)
|
587 |
-
|
588 |
-
if isinstance(self.controlnet, MultiControlNetModel):
|
589 |
-
if len(control_guidance_start) != len(self.controlnet.nets):
|
590 |
-
raise ValueError(
|
591 |
-
f"`control_guidance_start`: {control_guidance_start} has {len(control_guidance_start)} elements but there are {len(self.controlnet.nets)} controlnets available. Make sure to provide {len(self.controlnet.nets)}."
|
592 |
-
)
|
593 |
-
|
594 |
-
for start, end in zip(control_guidance_start, control_guidance_end):
|
595 |
-
if start >= end:
|
596 |
-
raise ValueError(
|
597 |
-
f"control guidance start: {start} cannot be larger or equal to control guidance end: {end}."
|
598 |
-
)
|
599 |
-
if start < 0.0:
|
600 |
-
raise ValueError(f"control guidance start: {start} can't be smaller than 0.")
|
601 |
-
if end > 1.0:
|
602 |
-
raise ValueError(f"control guidance end: {end} can't be larger than 1.0.")
|
603 |
-
|
604 |
-
# Copied from diffusers.pipelines.controlnet.pipeline_controlnet.StableDiffusionControlNetPipeline.check_image
|
605 |
-
def check_image(self, image, prompt, prompt_embeds):
|
606 |
-
image_is_pil = isinstance(image, PIL.Image.Image)
|
607 |
-
image_is_tensor = isinstance(image, torch.Tensor)
|
608 |
-
image_is_np = isinstance(image, np.ndarray)
|
609 |
-
image_is_pil_list = isinstance(image, list) and isinstance(image[0], PIL.Image.Image)
|
610 |
-
image_is_tensor_list = isinstance(image, list) and isinstance(image[0], torch.Tensor)
|
611 |
-
image_is_np_list = isinstance(image, list) and isinstance(image[0], np.ndarray)
|
612 |
-
|
613 |
-
if (
|
614 |
-
not image_is_pil
|
615 |
-
and not image_is_tensor
|
616 |
-
and not image_is_np
|
617 |
-
and not image_is_pil_list
|
618 |
-
and not image_is_tensor_list
|
619 |
-
and not image_is_np_list
|
620 |
-
):
|
621 |
-
raise TypeError(
|
622 |
-
f"image must be passed and be one of PIL image, numpy array, torch tensor, list of PIL images, list of numpy arrays or list of torch tensors, but is {type(image)}"
|
623 |
-
)
|
624 |
-
|
625 |
-
if image_is_pil:
|
626 |
-
image_batch_size = 1
|
627 |
-
else:
|
628 |
-
image_batch_size = len(image)
|
629 |
-
|
630 |
-
if prompt is not None and isinstance(prompt, str):
|
631 |
-
prompt_batch_size = 1
|
632 |
-
elif prompt is not None and isinstance(prompt, list):
|
633 |
-
prompt_batch_size = len(prompt)
|
634 |
-
elif prompt_embeds is not None:
|
635 |
-
prompt_batch_size = prompt_embeds.shape[0]
|
636 |
-
|
637 |
-
if image_batch_size != 1 and image_batch_size != prompt_batch_size:
|
638 |
-
raise ValueError(
|
639 |
-
f"If image batch size is not 1, image batch size must be same as prompt batch size. image batch size: {image_batch_size}, prompt batch size: {prompt_batch_size}"
|
640 |
-
)
|
641 |
-
|
642 |
-
# Copied from diffusers.pipelines.controlnet.pipeline_controlnet.StableDiffusionControlNetPipeline.prepare_image
|
643 |
-
def prepare_control_image(
|
644 |
-
self,
|
645 |
-
image,
|
646 |
-
width,
|
647 |
-
height,
|
648 |
-
batch_size,
|
649 |
-
num_images_per_prompt,
|
650 |
-
device,
|
651 |
-
dtype,
|
652 |
-
do_classifier_free_guidance=False,
|
653 |
-
guess_mode=False,
|
654 |
-
):
|
655 |
-
image = self.control_image_processor.preprocess(image, height=height, width=width).to(dtype=torch.float32)
|
656 |
-
image_batch_size = image.shape[0]
|
657 |
-
|
658 |
-
if image_batch_size == 1:
|
659 |
-
repeat_by = batch_size
|
660 |
-
else:
|
661 |
-
# image batch size is the same as prompt batch size
|
662 |
-
repeat_by = num_images_per_prompt
|
663 |
-
|
664 |
-
image = image.repeat_interleave(repeat_by, dim=0)
|
665 |
-
|
666 |
-
image = image.to(device=device, dtype=dtype)
|
667 |
-
|
668 |
-
if do_classifier_free_guidance and not guess_mode:
|
669 |
-
image = torch.cat([image] * 2)
|
670 |
-
|
671 |
-
return image
|
672 |
-
|
673 |
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_img2img.StableDiffusionImg2ImgPipeline.get_timesteps
|
674 |
-
def get_timesteps(self, num_inference_steps, strength, device):
|
675 |
-
# get the original timestep using init_timestep
|
676 |
-
init_timestep = min(int(num_inference_steps * strength), num_inference_steps)
|
677 |
-
|
678 |
-
t_start = max(num_inference_steps - init_timestep, 0)
|
679 |
-
timesteps = self.scheduler.timesteps[t_start * self.scheduler.order :]
|
680 |
-
|
681 |
-
return timesteps, num_inference_steps - t_start
|
682 |
-
|
683 |
-
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_img2img.StableDiffusionImg2ImgPipeline.prepare_latents
|
684 |
-
def prepare_latents(self, image, timestep, batch_size, num_images_per_prompt, dtype, device, generator=None):
|
685 |
-
if not isinstance(image, (torch.Tensor, PIL.Image.Image, list)):
|
686 |
-
raise ValueError(
|
687 |
-
f"`image` has to be of type `torch.Tensor`, `PIL.Image.Image` or list but is {type(image)}"
|
688 |
-
)
|
689 |
-
|
690 |
-
image = image.to(device=device, dtype=dtype)
|
691 |
-
|
692 |
-
batch_size = batch_size * num_images_per_prompt
|
693 |
-
|
694 |
-
if image.shape[1] == 4:
|
695 |
-
init_latents = image
|
696 |
-
|
697 |
-
else:
|
698 |
-
if isinstance(generator, list) and len(generator) != batch_size:
|
699 |
-
raise ValueError(
|
700 |
-
f"You have passed a list of generators of length {len(generator)}, but requested an effective batch"
|
701 |
-
f" size of {batch_size}. Make sure the batch size matches the length of the generators."
|
702 |
-
)
|
703 |
-
|
704 |
-
elif isinstance(generator, list):
|
705 |
-
init_latents = [
|
706 |
-
self.vae.encode(image[i : i + 1]).latent_dist.sample(generator[i]) for i in range(batch_size)
|
707 |
-
]
|
708 |
-
init_latents = torch.cat(init_latents, dim=0)
|
709 |
-
else:
|
710 |
-
init_latents = self.vae.encode(image).latent_dist.sample(generator)
|
711 |
-
|
712 |
-
init_latents = self.vae.config.scaling_factor * init_latents
|
713 |
-
|
714 |
-
if batch_size > init_latents.shape[0] and batch_size % init_latents.shape[0] == 0:
|
715 |
-
# expand init_latents for batch_size
|
716 |
-
deprecation_message = (
|
717 |
-
f"You have passed {batch_size} text prompts (`prompt`), but only {init_latents.shape[0]} initial"
|
718 |
-
" images (`image`). Initial images are now duplicating to match the number of text prompts. Note"
|
719 |
-
" that this behavior is deprecated and will be removed in a version 1.0.0. Please make sure to update"
|
720 |
-
" your script to pass as many initial images as text prompts to suppress this warning."
|
721 |
-
)
|
722 |
-
deprecate("len(prompt) != len(image)", "1.0.0", deprecation_message, standard_warn=False)
|
723 |
-
additional_image_per_prompt = batch_size // init_latents.shape[0]
|
724 |
-
init_latents = torch.cat([init_latents] * additional_image_per_prompt, dim=0)
|
725 |
-
elif batch_size > init_latents.shape[0] and batch_size % init_latents.shape[0] != 0:
|
726 |
-
raise ValueError(
|
727 |
-
f"Cannot duplicate `image` of batch size {init_latents.shape[0]} to {batch_size} text prompts."
|
728 |
-
)
|
729 |
-
else:
|
730 |
-
init_latents = torch.cat([init_latents], dim=0)
|
731 |
-
|
732 |
-
shape = init_latents.shape
|
733 |
-
noise = randn_tensor(shape, generator=generator, device=device, dtype=dtype)
|
734 |
-
|
735 |
-
# get latents
|
736 |
-
init_latents = self.scheduler.add_noise(init_latents, noise, timestep)
|
737 |
-
latents = init_latents
|
738 |
-
|
739 |
-
return latents
|
740 |
-
|
741 |
-
@torch.no_grad()
|
742 |
-
@replace_example_docstring(EXAMPLE_DOC_STRING)
|
743 |
-
def __call__(
|
744 |
-
self,
|
745 |
-
prompt: Union[str, List[str]] = None,
|
746 |
-
image: Union[
|
747 |
-
torch.FloatTensor,
|
748 |
-
PIL.Image.Image,
|
749 |
-
np.ndarray,
|
750 |
-
List[torch.FloatTensor],
|
751 |
-
List[PIL.Image.Image],
|
752 |
-
List[np.ndarray],
|
753 |
-
] = None,
|
754 |
-
control_image: Union[
|
755 |
-
torch.FloatTensor,
|
756 |
-
PIL.Image.Image,
|
757 |
-
np.ndarray,
|
758 |
-
List[torch.FloatTensor],
|
759 |
-
List[PIL.Image.Image],
|
760 |
-
List[np.ndarray],
|
761 |
-
] = None,
|
762 |
-
height: Optional[int] = None,
|
763 |
-
width: Optional[int] = None,
|
764 |
-
strength: float = 0.8,
|
765 |
-
num_inference_steps: int = 50,
|
766 |
-
guidance_scale: float = 7.5,
|
767 |
-
negative_prompt: Optional[Union[str, List[str]]] = None,
|
768 |
-
num_images_per_prompt: Optional[int] = 1,
|
769 |
-
eta: float = 0.0,
|
770 |
-
generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
|
771 |
-
latents: Optional[torch.FloatTensor] = None,
|
772 |
-
prompt_embeds: Optional[torch.FloatTensor] = None,
|
773 |
-
negative_prompt_embeds: Optional[torch.FloatTensor] = None,
|
774 |
-
output_type: Optional[str] = "pil",
|
775 |
-
return_dict: bool = True,
|
776 |
-
callback: Optional[Callable[[int, int, torch.FloatTensor], None]] = None,
|
777 |
-
callback_steps: int = 1,
|
778 |
-
cross_attention_kwargs: Optional[Dict[str, Any]] = None,
|
779 |
-
controlnet_conditioning_scale: Union[float, List[float]] = 0.8,
|
780 |
-
guess_mode: bool = False,
|
781 |
-
control_guidance_start: Union[float, List[float]] = 0.0,
|
782 |
-
control_guidance_end: Union[float, List[float]] = 1.0,
|
783 |
-
):
|
784 |
-
r"""
|
785 |
-
Function invoked when calling the pipeline for generation.
|
786 |
-
|
787 |
-
Args:
|
788 |
-
prompt (`str` or `List[str]`, *optional*):
|
789 |
-
The prompt or prompts to guide the image generation. If not defined, one has to pass `prompt_embeds`.
|
790 |
-
instead.
|
791 |
-
image (`torch.FloatTensor`, `PIL.Image.Image`, `np.ndarray`, `List[torch.FloatTensor]`, `List[PIL.Image.Image]`, `List[np.ndarray]`,:
|
792 |
-
`List[List[torch.FloatTensor]]`, `List[List[np.ndarray]]` or `List[List[PIL.Image.Image]]`):
|
793 |
-
The initial image will be used as the starting point for the image generation process. Can also accpet
|
794 |
-
image latents as `image`, if passing latents directly, it will not be encoded again.
|
795 |
-
control_image (`torch.FloatTensor`, `PIL.Image.Image`, `np.ndarray`, `List[torch.FloatTensor]`, `List[PIL.Image.Image]`, `List[np.ndarray]`,:
|
796 |
-
`List[List[torch.FloatTensor]]`, `List[List[np.ndarray]]` or `List[List[PIL.Image.Image]]`):
|
797 |
-
The ControlNet input condition. ControlNet uses this input condition to generate guidance to Unet. If
|
798 |
-
the type is specified as `Torch.FloatTensor`, it is passed to ControlNet as is. `PIL.Image.Image` can
|
799 |
-
also be accepted as an image. The dimensions of the output image defaults to `image`'s dimensions. If
|
800 |
-
height and/or width are passed, `image` is resized according to them. If multiple ControlNets are
|
801 |
-
specified in init, images must be passed as a list such that each element of the list can be correctly
|
802 |
-
batched for input to a single controlnet.
|
803 |
-
height (`int`, *optional*, defaults to self.unet.config.sample_size * self.vae_scale_factor):
|
804 |
-
The height in pixels of the generated image.
|
805 |
-
width (`int`, *optional*, defaults to self.unet.config.sample_size * self.vae_scale_factor):
|
806 |
-
The width in pixels of the generated image.
|
807 |
-
num_inference_steps (`int`, *optional*, defaults to 50):
|
808 |
-
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
|
809 |
-
expense of slower inference.
|
810 |
-
guidance_scale (`float`, *optional*, defaults to 7.5):
|
811 |
-
Guidance scale as defined in [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598).
|
812 |
-
`guidance_scale` is defined as `w` of equation 2. of [Imagen
|
813 |
-
Paper](https://arxiv.org/pdf/2205.11487.pdf). Guidance scale is enabled by setting `guidance_scale >
|
814 |
-
1`. Higher guidance scale encourages to generate images that are closely linked to the text `prompt`,
|
815 |
-
usually at the expense of lower image quality.
|
816 |
-
negative_prompt (`str` or `List[str]`, *optional*):
|
817 |
-
The prompt or prompts not to guide the image generation. If not defined, one has to pass
|
818 |
-
`negative_prompt_embeds` instead. Ignored when not using guidance (i.e., ignored if `guidance_scale` is
|
819 |
-
less than `1`).
|
820 |
-
num_images_per_prompt (`int`, *optional*, defaults to 1):
|
821 |
-
The number of images to generate per prompt.
|
822 |
-
eta (`float`, *optional*, defaults to 0.0):
|
823 |
-
Corresponds to parameter eta (η) in the DDIM paper: https://arxiv.org/abs/2010.02502. Only applies to
|
824 |
-
[`schedulers.DDIMScheduler`], will be ignored for others.
|
825 |
-
generator (`torch.Generator` or `List[torch.Generator]`, *optional*):
|
826 |
-
One or a list of [torch generator(s)](https://pytorch.org/docs/stable/generated/torch.Generator.html)
|
827 |
-
to make generation deterministic.
|
828 |
-
latents (`torch.FloatTensor`, *optional*):
|
829 |
-
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
|
830 |
-
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
|
831 |
-
tensor will ge generated by sampling using the supplied random `generator`.
|
832 |
-
prompt_embeds (`torch.FloatTensor`, *optional*):
|
833 |
-
Pre-generated text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting. If not
|
834 |
-
provided, text embeddings will be generated from `prompt` input argument.
|
835 |
-
negative_prompt_embeds (`torch.FloatTensor`, *optional*):
|
836 |
-
Pre-generated negative text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt
|
837 |
-
weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt` input
|
838 |
-
argument.
|
839 |
-
output_type (`str`, *optional*, defaults to `"pil"`):
|
840 |
-
The output format of the generate image. Choose between
|
841 |
-
[PIL](https://pillow.readthedocs.io/en/stable/): `PIL.Image.Image` or `np.array`.
|
842 |
-
return_dict (`bool`, *optional*, defaults to `True`):
|
843 |
-
Whether or not to return a [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] instead of a
|
844 |
-
plain tuple.
|
845 |
-
callback (`Callable`, *optional*):
|
846 |
-
A function that will be called every `callback_steps` steps during inference. The function will be
|
847 |
-
called with the following arguments: `callback(step: int, timestep: int, latents: torch.FloatTensor)`.
|
848 |
-
callback_steps (`int`, *optional*, defaults to 1):
|
849 |
-
The frequency at which the `callback` function will be called. If not specified, the callback will be
|
850 |
-
called at every step.
|
851 |
-
cross_attention_kwargs (`dict`, *optional*):
|
852 |
-
A kwargs dictionary that if specified is passed along to the `AttentionProcessor` as defined under
|
853 |
-
`self.processor` in
|
854 |
-
[diffusers.cross_attention](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/cross_attention.py).
|
855 |
-
controlnet_conditioning_scale (`float` or `List[float]`, *optional*, defaults to 1.0):
|
856 |
-
The outputs of the controlnet are multiplied by `controlnet_conditioning_scale` before they are added
|
857 |
-
to the residual in the original unet. If multiple ControlNets are specified in init, you can set the
|
858 |
-
corresponding scale as a list. Note that by default, we use a smaller conditioning scale for inpainting
|
859 |
-
than for [`~StableDiffusionControlNetPipeline.__call__`].
|
860 |
-
guess_mode (`bool`, *optional*, defaults to `False`):
|
861 |
-
In this mode, the ControlNet encoder will try best to recognize the content of the input image even if
|
862 |
-
you remove all prompts. The `guidance_scale` between 3.0 and 5.0 is recommended.
|
863 |
-
control_guidance_start (`float` or `List[float]`, *optional*, defaults to 0.0):
|
864 |
-
The percentage of total steps at which the controlnet starts applying.
|
865 |
-
control_guidance_end (`float` or `List[float]`, *optional*, defaults to 1.0):
|
866 |
-
The percentage of total steps at which the controlnet stops applying.
|
867 |
-
|
868 |
-
Examples:
|
869 |
-
|
870 |
-
Returns:
|
871 |
-
[`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] or `tuple`:
|
872 |
-
[`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] if `return_dict` is True, otherwise a `tuple.
|
873 |
-
When returning a tuple, the first element is a list with the generated images, and the second element is a
|
874 |
-
list of `bool`s denoting whether the corresponding generated image likely represents "not-safe-for-work"
|
875 |
-
(nsfw) content, according to the `safety_checker`.
|
876 |
-
"""
|
877 |
-
controlnet = self.controlnet._orig_mod if is_compiled_module(self.controlnet) else self.controlnet
|
878 |
-
|
879 |
-
# align format for control guidance
|
880 |
-
if not isinstance(control_guidance_start, list) and isinstance(control_guidance_end, list):
|
881 |
-
control_guidance_start = len(control_guidance_end) * [control_guidance_start]
|
882 |
-
elif not isinstance(control_guidance_end, list) and isinstance(control_guidance_start, list):
|
883 |
-
control_guidance_end = len(control_guidance_start) * [control_guidance_end]
|
884 |
-
elif not isinstance(control_guidance_start, list) and not isinstance(control_guidance_end, list):
|
885 |
-
mult = len(controlnet.nets) if isinstance(controlnet, MultiControlNetModel) else 1
|
886 |
-
control_guidance_start, control_guidance_end = mult * [control_guidance_start], mult * [
|
887 |
-
control_guidance_end
|
888 |
-
]
|
889 |
-
|
890 |
-
# 1. Check inputs. Raise error if not correct
|
891 |
-
self.check_inputs(
|
892 |
-
prompt,
|
893 |
-
control_image,
|
894 |
-
callback_steps,
|
895 |
-
negative_prompt,
|
896 |
-
prompt_embeds,
|
897 |
-
negative_prompt_embeds,
|
898 |
-
controlnet_conditioning_scale,
|
899 |
-
control_guidance_start,
|
900 |
-
control_guidance_end,
|
901 |
-
)
|
902 |
-
|
903 |
-
# 2. Define call parameters
|
904 |
-
if prompt is not None and isinstance(prompt, str):
|
905 |
-
batch_size = 1
|
906 |
-
elif prompt is not None and isinstance(prompt, list):
|
907 |
-
batch_size = len(prompt)
|
908 |
-
else:
|
909 |
-
batch_size = prompt_embeds.shape[0]
|
910 |
-
|
911 |
-
device = self._execution_device
|
912 |
-
# here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
|
913 |
-
# of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
|
914 |
-
# corresponds to doing no classifier free guidance.
|
915 |
-
do_classifier_free_guidance = guidance_scale > 1.0
|
916 |
-
|
917 |
-
controlnet = self.controlnet._orig_mod if is_compiled_module(self.controlnet) else self.controlnet
|
918 |
-
|
919 |
-
if isinstance(controlnet, MultiControlNetModel) and isinstance(controlnet_conditioning_scale, float):
|
920 |
-
controlnet_conditioning_scale = [controlnet_conditioning_scale] * len(controlnet.nets)
|
921 |
-
|
922 |
-
global_pool_conditions = (
|
923 |
-
controlnet.config.global_pool_conditions
|
924 |
-
if isinstance(controlnet, ControlNetModel)
|
925 |
-
else controlnet.nets[0].config.global_pool_conditions
|
926 |
-
)
|
927 |
-
guess_mode = guess_mode or global_pool_conditions
|
928 |
-
|
929 |
-
# 3. Encode input prompt
|
930 |
-
text_encoder_lora_scale = (
|
931 |
-
cross_attention_kwargs.get("scale", None) if cross_attention_kwargs is not None else None
|
932 |
-
)
|
933 |
-
prompt_embeds = self._encode_prompt(
|
934 |
-
prompt,
|
935 |
-
device,
|
936 |
-
num_images_per_prompt,
|
937 |
-
do_classifier_free_guidance,
|
938 |
-
negative_prompt,
|
939 |
-
prompt_embeds=prompt_embeds,
|
940 |
-
negative_prompt_embeds=negative_prompt_embeds,
|
941 |
-
lora_scale=text_encoder_lora_scale,
|
942 |
-
)
|
943 |
-
# 4. Prepare image
|
944 |
-
image = self.image_processor.preprocess(image).to(dtype=torch.float32)
|
945 |
-
|
946 |
-
# 5. Prepare controlnet_conditioning_image
|
947 |
-
if isinstance(controlnet, ControlNetModel):
|
948 |
-
control_image = self.prepare_control_image(
|
949 |
-
image=control_image,
|
950 |
-
width=width,
|
951 |
-
height=height,
|
952 |
-
batch_size=batch_size * num_images_per_prompt,
|
953 |
-
num_images_per_prompt=num_images_per_prompt,
|
954 |
-
device=device,
|
955 |
-
dtype=controlnet.dtype,
|
956 |
-
do_classifier_free_guidance=do_classifier_free_guidance,
|
957 |
-
guess_mode=guess_mode,
|
958 |
-
)
|
959 |
-
elif isinstance(controlnet, MultiControlNetModel):
|
960 |
-
control_images = []
|
961 |
-
|
962 |
-
for control_image_ in control_image:
|
963 |
-
control_image_ = self.prepare_control_image(
|
964 |
-
image=control_image_,
|
965 |
-
width=width,
|
966 |
-
height=height,
|
967 |
-
batch_size=batch_size * num_images_per_prompt,
|
968 |
-
num_images_per_prompt=num_images_per_prompt,
|
969 |
-
device=device,
|
970 |
-
dtype=controlnet.dtype,
|
971 |
-
do_classifier_free_guidance=do_classifier_free_guidance,
|
972 |
-
guess_mode=guess_mode,
|
973 |
-
)
|
974 |
-
|
975 |
-
control_images.append(control_image_)
|
976 |
-
|
977 |
-
control_image = control_images
|
978 |
-
else:
|
979 |
-
assert False
|
980 |
-
|
981 |
-
# 5. Prepare timesteps
|
982 |
-
self.scheduler.set_timesteps(num_inference_steps, device=device)
|
983 |
-
timesteps, num_inference_steps = self.get_timesteps(num_inference_steps, strength, device)
|
984 |
-
latent_timestep = timesteps[:1].repeat(batch_size * num_images_per_prompt)
|
985 |
-
|
986 |
-
# 6. Prepare latent variables
|
987 |
-
latents = self.prepare_latents(
|
988 |
-
image,
|
989 |
-
latent_timestep,
|
990 |
-
batch_size,
|
991 |
-
num_images_per_prompt,
|
992 |
-
prompt_embeds.dtype,
|
993 |
-
device,
|
994 |
-
generator,
|
995 |
-
)
|
996 |
-
|
997 |
-
# 7. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
|
998 |
-
extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
|
999 |
-
|
1000 |
-
# 7.1 Create tensor stating which controlnets to keep
|
1001 |
-
controlnet_keep = []
|
1002 |
-
for i in range(len(timesteps)):
|
1003 |
-
keeps = [
|
1004 |
-
1.0 - float(i / len(timesteps) < s or (i + 1) / len(timesteps) > e)
|
1005 |
-
for s, e in zip(control_guidance_start, control_guidance_end)
|
1006 |
-
]
|
1007 |
-
controlnet_keep.append(keeps[0] if isinstance(controlnet, ControlNetModel) else keeps)
|
1008 |
-
|
1009 |
-
# 8. Denoising loop
|
1010 |
-
num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order
|
1011 |
-
with self.progress_bar(total=num_inference_steps) as progress_bar:
|
1012 |
-
for i, t in enumerate(timesteps):
|
1013 |
-
# expand the latents if we are doing classifier free guidance
|
1014 |
-
latent_model_input = torch.cat([latents] * 2) if do_classifier_free_guidance else latents
|
1015 |
-
latent_model_input = self.scheduler.scale_model_input(latent_model_input, t)
|
1016 |
-
|
1017 |
-
# controlnet(s) inference
|
1018 |
-
if guess_mode and do_classifier_free_guidance:
|
1019 |
-
# Infer ControlNet only for the conditional batch.
|
1020 |
-
control_model_input = latents
|
1021 |
-
control_model_input = self.scheduler.scale_model_input(control_model_input, t)
|
1022 |
-
controlnet_prompt_embeds = prompt_embeds.chunk(2)[1]
|
1023 |
-
else:
|
1024 |
-
control_model_input = latent_model_input
|
1025 |
-
controlnet_prompt_embeds = prompt_embeds
|
1026 |
-
|
1027 |
-
if isinstance(controlnet_keep[i], list):
|
1028 |
-
cond_scale = [c * s for c, s in zip(controlnet_conditioning_scale, controlnet_keep[i])]
|
1029 |
-
else:
|
1030 |
-
cond_scale = controlnet_conditioning_scale * controlnet_keep[i]
|
1031 |
-
|
1032 |
-
down_block_res_samples, mid_block_res_sample = self.controlnet(
|
1033 |
-
control_model_input,
|
1034 |
-
t,
|
1035 |
-
encoder_hidden_states=controlnet_prompt_embeds,
|
1036 |
-
controlnet_cond=control_image,
|
1037 |
-
conditioning_scale=cond_scale,
|
1038 |
-
guess_mode=guess_mode,
|
1039 |
-
return_dict=False,
|
1040 |
-
)
|
1041 |
-
|
1042 |
-
if guess_mode and do_classifier_free_guidance:
|
1043 |
-
# Infered ControlNet only for the conditional batch.
|
1044 |
-
# To apply the output of ControlNet to both the unconditional and conditional batches,
|
1045 |
-
# add 0 to the unconditional batch to keep it unchanged.
|
1046 |
-
down_block_res_samples = [torch.cat([torch.zeros_like(d), d]) for d in down_block_res_samples]
|
1047 |
-
mid_block_res_sample = torch.cat([torch.zeros_like(mid_block_res_sample), mid_block_res_sample])
|
1048 |
-
|
1049 |
-
# predict the noise residual
|
1050 |
-
noise_pred = self.unet(
|
1051 |
-
latent_model_input,
|
1052 |
-
t,
|
1053 |
-
encoder_hidden_states=prompt_embeds,
|
1054 |
-
cross_attention_kwargs=cross_attention_kwargs,
|
1055 |
-
down_block_additional_residuals=down_block_res_samples,
|
1056 |
-
mid_block_additional_residual=mid_block_res_sample,
|
1057 |
-
return_dict=False,
|
1058 |
-
)[0]
|
1059 |
-
|
1060 |
-
# perform guidance
|
1061 |
-
if do_classifier_free_guidance:
|
1062 |
-
noise_pred_uncond, noise_pred_text = noise_pred.chunk(2)
|
1063 |
-
noise_pred = noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond)
|
1064 |
-
|
1065 |
-
# compute the previous noisy sample x_t -> x_t-1
|
1066 |
-
latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs, return_dict=False)[0]
|
1067 |
-
|
1068 |
-
# call the callback, if provided
|
1069 |
-
if i == len(timesteps) - 1 or ((i + 1) > num_warmup_steps and (i + 1) % self.scheduler.order == 0):
|
1070 |
-
progress_bar.update()
|
1071 |
-
if callback is not None and i % callback_steps == 0:
|
1072 |
-
callback(i, t, latents)
|
1073 |
-
|
1074 |
-
# If we do sequential model offloading, let's offload unet and controlnet
|
1075 |
-
# manually for max memory savings
|
1076 |
-
if hasattr(self, "final_offload_hook") and self.final_offload_hook is not None:
|
1077 |
-
self.unet.to("cpu")
|
1078 |
-
self.controlnet.to("cpu")
|
1079 |
-
torch.cuda.empty_cache()
|
1080 |
-
|
1081 |
-
if not output_type == "latent":
|
1082 |
-
image = self.vae.decode(latents / self.vae.config.scaling_factor, return_dict=False)[0]
|
1083 |
-
image, has_nsfw_concept = self.run_safety_checker(image, device, prompt_embeds.dtype)
|
1084 |
-
else:
|
1085 |
-
image = latents
|
1086 |
-
has_nsfw_concept = None
|
1087 |
-
|
1088 |
-
if has_nsfw_concept is None:
|
1089 |
-
do_denormalize = [True] * image.shape[0]
|
1090 |
-
else:
|
1091 |
-
do_denormalize = [not has_nsfw for has_nsfw in has_nsfw_concept]
|
1092 |
-
|
1093 |
-
image = self.image_processor.postprocess(image, output_type=output_type, do_denormalize=do_denormalize)
|
1094 |
-
|
1095 |
-
# Offload last model to CPU
|
1096 |
-
if hasattr(self, "final_offload_hook") and self.final_offload_hook is not None:
|
1097 |
-
self.final_offload_hook.offload()
|
1098 |
-
|
1099 |
-
if not return_dict:
|
1100 |
-
return (image, has_nsfw_concept)
|
1101 |
-
|
1102 |
-
return StableDiffusionPipelineOutput(images=image, nsfw_content_detected=has_nsfw_concept)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Androidonnxfork/CivitAi-to-Diffusers/diffusers/src/diffusers/pipelines/stable_diffusion/stable_unclip_image_normalizer.py
DELETED
@@ -1,57 +0,0 @@
|
|
1 |
-
# Copyright 2023 The HuggingFace Team. All rights reserved.
|
2 |
-
#
|
3 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
-
# you may not use this file except in compliance with the License.
|
5 |
-
# You may obtain a copy of the License at
|
6 |
-
#
|
7 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
-
#
|
9 |
-
# Unless required by applicable law or agreed to in writing, software
|
10 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
-
# See the License for the specific language governing permissions and
|
13 |
-
# limitations under the License.
|
14 |
-
|
15 |
-
from typing import Optional, Union
|
16 |
-
|
17 |
-
import torch
|
18 |
-
from torch import nn
|
19 |
-
|
20 |
-
from ...configuration_utils import ConfigMixin, register_to_config
|
21 |
-
from ...models.modeling_utils import ModelMixin
|
22 |
-
|
23 |
-
|
24 |
-
class StableUnCLIPImageNormalizer(ModelMixin, ConfigMixin):
|
25 |
-
"""
|
26 |
-
This class is used to hold the mean and standard deviation of the CLIP embedder used in stable unCLIP.
|
27 |
-
|
28 |
-
It is used to normalize the image embeddings before the noise is applied and un-normalize the noised image
|
29 |
-
embeddings.
|
30 |
-
"""
|
31 |
-
|
32 |
-
@register_to_config
|
33 |
-
def __init__(
|
34 |
-
self,
|
35 |
-
embedding_dim: int = 768,
|
36 |
-
):
|
37 |
-
super().__init__()
|
38 |
-
|
39 |
-
self.mean = nn.Parameter(torch.zeros(1, embedding_dim))
|
40 |
-
self.std = nn.Parameter(torch.ones(1, embedding_dim))
|
41 |
-
|
42 |
-
def to(
|
43 |
-
self,
|
44 |
-
torch_device: Optional[Union[str, torch.device]] = None,
|
45 |
-
torch_dtype: Optional[torch.dtype] = None,
|
46 |
-
):
|
47 |
-
self.mean = nn.Parameter(self.mean.to(torch_device).to(torch_dtype))
|
48 |
-
self.std = nn.Parameter(self.std.to(torch_device).to(torch_dtype))
|
49 |
-
return self
|
50 |
-
|
51 |
-
def scale(self, embeds):
|
52 |
-
embeds = (embeds - self.mean) * 1.0 / self.std
|
53 |
-
return embeds
|
54 |
-
|
55 |
-
def unscale(self, embeds):
|
56 |
-
embeds = (embeds * self.std) + self.mean
|
57 |
-
return embeds
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Androidonnxfork/CivitAi-to-Diffusers/diffusers/tests/pipelines/ddpm/__init__.py
DELETED
File without changes
|
spaces/Anonymous-sub/Rerender/ControlNet/annotator/uniformer/mmcv/ops/voxelize.py
DELETED
@@ -1,132 +0,0 @@
|
|
1 |
-
# Copyright (c) OpenMMLab. All rights reserved.
|
2 |
-
import torch
|
3 |
-
from torch import nn
|
4 |
-
from torch.autograd import Function
|
5 |
-
from torch.nn.modules.utils import _pair
|
6 |
-
|
7 |
-
from ..utils import ext_loader
|
8 |
-
|
9 |
-
ext_module = ext_loader.load_ext(
|
10 |
-
'_ext', ['dynamic_voxelize_forward', 'hard_voxelize_forward'])
|
11 |
-
|
12 |
-
|
13 |
-
class _Voxelization(Function):
|
14 |
-
|
15 |
-
@staticmethod
|
16 |
-
def forward(ctx,
|
17 |
-
points,
|
18 |
-
voxel_size,
|
19 |
-
coors_range,
|
20 |
-
max_points=35,
|
21 |
-
max_voxels=20000):
|
22 |
-
"""Convert kitti points(N, >=3) to voxels.
|
23 |
-
|
24 |
-
Args:
|
25 |
-
points (torch.Tensor): [N, ndim]. Points[:, :3] contain xyz points
|
26 |
-
and points[:, 3:] contain other information like reflectivity.
|
27 |
-
voxel_size (tuple or float): The size of voxel with the shape of
|
28 |
-
[3].
|
29 |
-
coors_range (tuple or float): The coordinate range of voxel with
|
30 |
-
the shape of [6].
|
31 |
-
max_points (int, optional): maximum points contained in a voxel. if
|
32 |
-
max_points=-1, it means using dynamic_voxelize. Default: 35.
|
33 |
-
max_voxels (int, optional): maximum voxels this function create.
|
34 |
-
for second, 20000 is a good choice. Users should shuffle points
|
35 |
-
before call this function because max_voxels may drop points.
|
36 |
-
Default: 20000.
|
37 |
-
|
38 |
-
Returns:
|
39 |
-
voxels_out (torch.Tensor): Output voxels with the shape of [M,
|
40 |
-
max_points, ndim]. Only contain points and returned when
|
41 |
-
max_points != -1.
|
42 |
-
coors_out (torch.Tensor): Output coordinates with the shape of
|
43 |
-
[M, 3].
|
44 |
-
num_points_per_voxel_out (torch.Tensor): Num points per voxel with
|
45 |
-
the shape of [M]. Only returned when max_points != -1.
|
46 |
-
"""
|
47 |
-
if max_points == -1 or max_voxels == -1:
|
48 |
-
coors = points.new_zeros(size=(points.size(0), 3), dtype=torch.int)
|
49 |
-
ext_module.dynamic_voxelize_forward(points, coors, voxel_size,
|
50 |
-
coors_range, 3)
|
51 |
-
return coors
|
52 |
-
else:
|
53 |
-
voxels = points.new_zeros(
|
54 |
-
size=(max_voxels, max_points, points.size(1)))
|
55 |
-
coors = points.new_zeros(size=(max_voxels, 3), dtype=torch.int)
|
56 |
-
num_points_per_voxel = points.new_zeros(
|
57 |
-
size=(max_voxels, ), dtype=torch.int)
|
58 |
-
voxel_num = ext_module.hard_voxelize_forward(
|
59 |
-
points, voxels, coors, num_points_per_voxel, voxel_size,
|
60 |
-
coors_range, max_points, max_voxels, 3)
|
61 |
-
# select the valid voxels
|
62 |
-
voxels_out = voxels[:voxel_num]
|
63 |
-
coors_out = coors[:voxel_num]
|
64 |
-
num_points_per_voxel_out = num_points_per_voxel[:voxel_num]
|
65 |
-
return voxels_out, coors_out, num_points_per_voxel_out
|
66 |
-
|
67 |
-
|
68 |
-
voxelization = _Voxelization.apply
|
69 |
-
|
70 |
-
|
71 |
-
class Voxelization(nn.Module):
|
72 |
-
"""Convert kitti points(N, >=3) to voxels.
|
73 |
-
|
74 |
-
Please refer to `PVCNN <https://arxiv.org/abs/1907.03739>`_ for more
|
75 |
-
details.
|
76 |
-
|
77 |
-
Args:
|
78 |
-
voxel_size (tuple or float): The size of voxel with the shape of [3].
|
79 |
-
point_cloud_range (tuple or float): The coordinate range of voxel with
|
80 |
-
the shape of [6].
|
81 |
-
max_num_points (int): maximum points contained in a voxel. if
|
82 |
-
max_points=-1, it means using dynamic_voxelize.
|
83 |
-
max_voxels (int, optional): maximum voxels this function create.
|
84 |
-
for second, 20000 is a good choice. Users should shuffle points
|
85 |
-
before call this function because max_voxels may drop points.
|
86 |
-
Default: 20000.
|
87 |
-
"""
|
88 |
-
|
89 |
-
def __init__(self,
|
90 |
-
voxel_size,
|
91 |
-
point_cloud_range,
|
92 |
-
max_num_points,
|
93 |
-
max_voxels=20000):
|
94 |
-
super().__init__()
|
95 |
-
|
96 |
-
self.voxel_size = voxel_size
|
97 |
-
self.point_cloud_range = point_cloud_range
|
98 |
-
self.max_num_points = max_num_points
|
99 |
-
if isinstance(max_voxels, tuple):
|
100 |
-
self.max_voxels = max_voxels
|
101 |
-
else:
|
102 |
-
self.max_voxels = _pair(max_voxels)
|
103 |
-
|
104 |
-
point_cloud_range = torch.tensor(
|
105 |
-
point_cloud_range, dtype=torch.float32)
|
106 |
-
voxel_size = torch.tensor(voxel_size, dtype=torch.float32)
|
107 |
-
grid_size = (point_cloud_range[3:] -
|
108 |
-
point_cloud_range[:3]) / voxel_size
|
109 |
-
grid_size = torch.round(grid_size).long()
|
110 |
-
input_feat_shape = grid_size[:2]
|
111 |
-
self.grid_size = grid_size
|
112 |
-
# the origin shape is as [x-len, y-len, z-len]
|
113 |
-
# [w, h, d] -> [d, h, w]
|
114 |
-
self.pcd_shape = [*input_feat_shape, 1][::-1]
|
115 |
-
|
116 |
-
def forward(self, input):
|
117 |
-
if self.training:
|
118 |
-
max_voxels = self.max_voxels[0]
|
119 |
-
else:
|
120 |
-
max_voxels = self.max_voxels[1]
|
121 |
-
|
122 |
-
return voxelization(input, self.voxel_size, self.point_cloud_range,
|
123 |
-
self.max_num_points, max_voxels)
|
124 |
-
|
125 |
-
def __repr__(self):
|
126 |
-
s = self.__class__.__name__ + '('
|
127 |
-
s += 'voxel_size=' + str(self.voxel_size)
|
128 |
-
s += ', point_cloud_range=' + str(self.point_cloud_range)
|
129 |
-
s += ', max_num_points=' + str(self.max_num_points)
|
130 |
-
s += ', max_voxels=' + str(self.max_voxels)
|
131 |
-
s += ')'
|
132 |
-
return s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AnticPan/Clothes2Human/util.py
DELETED
@@ -1,25 +0,0 @@
|
|
1 |
-
from PIL import Image
|
2 |
-
import base64
|
3 |
-
from io import BytesIO
|
4 |
-
from pydantic import BaseModel, validator
|
5 |
-
|
6 |
-
def img_to_base64(img):
|
7 |
-
buffer = BytesIO()
|
8 |
-
img.save(buffer, "jpeg")
|
9 |
-
content = base64.b64encode(buffer.getvalue())
|
10 |
-
return str(content, 'utf-8')
|
11 |
-
|
12 |
-
def base64_to_img(content):
|
13 |
-
decoded_image = base64.b64decode(content)
|
14 |
-
image_buffer = BytesIO(decoded_image)
|
15 |
-
image = Image.open(image_buffer)
|
16 |
-
return image
|
17 |
-
|
18 |
-
def resize_image(img, maxlen=2048):
|
19 |
-
if max(img.size)<maxlen:
|
20 |
-
return img
|
21 |
-
if img.width > img.height:
|
22 |
-
img = img.resize((maxlen, int(img.height*maxlen/img.width)//8*8))
|
23 |
-
else:
|
24 |
-
img = img.resize((int(img.width*maxlen/img.height)//8*8, maxlen))
|
25 |
-
return img
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Arnaudding001/FrenchTranslationAI/app.py
DELETED
@@ -1,29 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import gradio as gr
|
3 |
-
import language_tool_python
|
4 |
-
|
5 |
-
tool = language_tool_python.LanguageToolPublicAPI('fr')
|
6 |
-
|
7 |
-
|
8 |
-
# corrected_text = tool.correct(text)
|
9 |
-
# print(corrected_text)
|
10 |
-
|
11 |
-
def inference(input_text):
|
12 |
-
return tool.correct(input_text)
|
13 |
-
|
14 |
-
title = "法语语法修改App"
|
15 |
-
|
16 |
-
description = "将需要校对的文字贴在左侧方框中,点击Submit,稍等片刻,右侧Output将给出修改后的文本,字数限制300字。"
|
17 |
-
|
18 |
-
|
19 |
-
demo = gr.Interface(
|
20 |
-
fn = inference,
|
21 |
-
inputs = 'text',
|
22 |
-
outputs = 'text',
|
23 |
-
title=title,
|
24 |
-
description=description
|
25 |
-
)
|
26 |
-
|
27 |
-
|
28 |
-
demo.launch()
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Ataturk-Chatbot/HuggingFaceChat/venv/lib/python3.11/site-packages/setuptools/_vendor/pyparsing/util.py
DELETED
@@ -1,235 +0,0 @@
|
|
1 |
-
# util.py
|
2 |
-
import warnings
|
3 |
-
import types
|
4 |
-
import collections
|
5 |
-
import itertools
|
6 |
-
from functools import lru_cache
|
7 |
-
from typing import List, Union, Iterable
|
8 |
-
|
9 |
-
_bslash = chr(92)
|
10 |
-
|
11 |
-
|
12 |
-
class __config_flags:
|
13 |
-
"""Internal class for defining compatibility and debugging flags"""
|
14 |
-
|
15 |
-
_all_names: List[str] = []
|
16 |
-
_fixed_names: List[str] = []
|
17 |
-
_type_desc = "configuration"
|
18 |
-
|
19 |
-
@classmethod
|
20 |
-
def _set(cls, dname, value):
|
21 |
-
if dname in cls._fixed_names:
|
22 |
-
warnings.warn(
|
23 |
-
"{}.{} {} is {} and cannot be overridden".format(
|
24 |
-
cls.__name__,
|
25 |
-
dname,
|
26 |
-
cls._type_desc,
|
27 |
-
str(getattr(cls, dname)).upper(),
|
28 |
-
)
|
29 |
-
)
|
30 |
-
return
|
31 |
-
if dname in cls._all_names:
|
32 |
-
setattr(cls, dname, value)
|
33 |
-
else:
|
34 |
-
raise ValueError("no such {} {!r}".format(cls._type_desc, dname))
|
35 |
-
|
36 |
-
enable = classmethod(lambda cls, name: cls._set(name, True))
|
37 |
-
disable = classmethod(lambda cls, name: cls._set(name, False))
|
38 |
-
|
39 |
-
|
40 |
-
@lru_cache(maxsize=128)
|
41 |
-
def col(loc: int, strg: str) -> int:
|
42 |
-
"""
|
43 |
-
Returns current column within a string, counting newlines as line separators.
|
44 |
-
The first column is number 1.
|
45 |
-
|
46 |
-
Note: the default parsing behavior is to expand tabs in the input string
|
47 |
-
before starting the parsing process. See
|
48 |
-
:class:`ParserElement.parseString` for more
|
49 |
-
information on parsing strings containing ``<TAB>`` s, and suggested
|
50 |
-
methods to maintain a consistent view of the parsed string, the parse
|
51 |
-
location, and line and column positions within the parsed string.
|
52 |
-
"""
|
53 |
-
s = strg
|
54 |
-
return 1 if 0 < loc < len(s) and s[loc - 1] == "\n" else loc - s.rfind("\n", 0, loc)
|
55 |
-
|
56 |
-
|
57 |
-
@lru_cache(maxsize=128)
|
58 |
-
def lineno(loc: int, strg: str) -> int:
|
59 |
-
"""Returns current line number within a string, counting newlines as line separators.
|
60 |
-
The first line is number 1.
|
61 |
-
|
62 |
-
Note - the default parsing behavior is to expand tabs in the input string
|
63 |
-
before starting the parsing process. See :class:`ParserElement.parseString`
|
64 |
-
for more information on parsing strings containing ``<TAB>`` s, and
|
65 |
-
suggested methods to maintain a consistent view of the parsed string, the
|
66 |
-
parse location, and line and column positions within the parsed string.
|
67 |
-
"""
|
68 |
-
return strg.count("\n", 0, loc) + 1
|
69 |
-
|
70 |
-
|
71 |
-
@lru_cache(maxsize=128)
|
72 |
-
def line(loc: int, strg: str) -> str:
|
73 |
-
"""
|
74 |
-
Returns the line of text containing loc within a string, counting newlines as line separators.
|
75 |
-
"""
|
76 |
-
last_cr = strg.rfind("\n", 0, loc)
|
77 |
-
next_cr = strg.find("\n", loc)
|
78 |
-
return strg[last_cr + 1 : next_cr] if next_cr >= 0 else strg[last_cr + 1 :]
|
79 |
-
|
80 |
-
|
81 |
-
class _UnboundedCache:
|
82 |
-
def __init__(self):
|
83 |
-
cache = {}
|
84 |
-
cache_get = cache.get
|
85 |
-
self.not_in_cache = not_in_cache = object()
|
86 |
-
|
87 |
-
def get(_, key):
|
88 |
-
return cache_get(key, not_in_cache)
|
89 |
-
|
90 |
-
def set_(_, key, value):
|
91 |
-
cache[key] = value
|
92 |
-
|
93 |
-
def clear(_):
|
94 |
-
cache.clear()
|
95 |
-
|
96 |
-
self.size = None
|
97 |
-
self.get = types.MethodType(get, self)
|
98 |
-
self.set = types.MethodType(set_, self)
|
99 |
-
self.clear = types.MethodType(clear, self)
|
100 |
-
|
101 |
-
|
102 |
-
class _FifoCache:
|
103 |
-
def __init__(self, size):
|
104 |
-
self.not_in_cache = not_in_cache = object()
|
105 |
-
cache = collections.OrderedDict()
|
106 |
-
cache_get = cache.get
|
107 |
-
|
108 |
-
def get(_, key):
|
109 |
-
return cache_get(key, not_in_cache)
|
110 |
-
|
111 |
-
def set_(_, key, value):
|
112 |
-
cache[key] = value
|
113 |
-
while len(cache) > size:
|
114 |
-
cache.popitem(last=False)
|
115 |
-
|
116 |
-
def clear(_):
|
117 |
-
cache.clear()
|
118 |
-
|
119 |
-
self.size = size
|
120 |
-
self.get = types.MethodType(get, self)
|
121 |
-
self.set = types.MethodType(set_, self)
|
122 |
-
self.clear = types.MethodType(clear, self)
|
123 |
-
|
124 |
-
|
125 |
-
class LRUMemo:
|
126 |
-
"""
|
127 |
-
A memoizing mapping that retains `capacity` deleted items
|
128 |
-
|
129 |
-
The memo tracks retained items by their access order; once `capacity` items
|
130 |
-
are retained, the least recently used item is discarded.
|
131 |
-
"""
|
132 |
-
|
133 |
-
def __init__(self, capacity):
|
134 |
-
self._capacity = capacity
|
135 |
-
self._active = {}
|
136 |
-
self._memory = collections.OrderedDict()
|
137 |
-
|
138 |
-
def __getitem__(self, key):
|
139 |
-
try:
|
140 |
-
return self._active[key]
|
141 |
-
except KeyError:
|
142 |
-
self._memory.move_to_end(key)
|
143 |
-
return self._memory[key]
|
144 |
-
|
145 |
-
def __setitem__(self, key, value):
|
146 |
-
self._memory.pop(key, None)
|
147 |
-
self._active[key] = value
|
148 |
-
|
149 |
-
def __delitem__(self, key):
|
150 |
-
try:
|
151 |
-
value = self._active.pop(key)
|
152 |
-
except KeyError:
|
153 |
-
pass
|
154 |
-
else:
|
155 |
-
while len(self._memory) >= self._capacity:
|
156 |
-
self._memory.popitem(last=False)
|
157 |
-
self._memory[key] = value
|
158 |
-
|
159 |
-
def clear(self):
|
160 |
-
self._active.clear()
|
161 |
-
self._memory.clear()
|
162 |
-
|
163 |
-
|
164 |
-
class UnboundedMemo(dict):
|
165 |
-
"""
|
166 |
-
A memoizing mapping that retains all deleted items
|
167 |
-
"""
|
168 |
-
|
169 |
-
def __delitem__(self, key):
|
170 |
-
pass
|
171 |
-
|
172 |
-
|
173 |
-
def _escape_regex_range_chars(s: str) -> str:
|
174 |
-
# escape these chars: ^-[]
|
175 |
-
for c in r"\^-[]":
|
176 |
-
s = s.replace(c, _bslash + c)
|
177 |
-
s = s.replace("\n", r"\n")
|
178 |
-
s = s.replace("\t", r"\t")
|
179 |
-
return str(s)
|
180 |
-
|
181 |
-
|
182 |
-
def _collapse_string_to_ranges(
|
183 |
-
s: Union[str, Iterable[str]], re_escape: bool = True
|
184 |
-
) -> str:
|
185 |
-
def is_consecutive(c):
|
186 |
-
c_int = ord(c)
|
187 |
-
is_consecutive.prev, prev = c_int, is_consecutive.prev
|
188 |
-
if c_int - prev > 1:
|
189 |
-
is_consecutive.value = next(is_consecutive.counter)
|
190 |
-
return is_consecutive.value
|
191 |
-
|
192 |
-
is_consecutive.prev = 0
|
193 |
-
is_consecutive.counter = itertools.count()
|
194 |
-
is_consecutive.value = -1
|
195 |
-
|
196 |
-
def escape_re_range_char(c):
|
197 |
-
return "\\" + c if c in r"\^-][" else c
|
198 |
-
|
199 |
-
def no_escape_re_range_char(c):
|
200 |
-
return c
|
201 |
-
|
202 |
-
if not re_escape:
|
203 |
-
escape_re_range_char = no_escape_re_range_char
|
204 |
-
|
205 |
-
ret = []
|
206 |
-
s = "".join(sorted(set(s)))
|
207 |
-
if len(s) > 3:
|
208 |
-
for _, chars in itertools.groupby(s, key=is_consecutive):
|
209 |
-
first = last = next(chars)
|
210 |
-
last = collections.deque(
|
211 |
-
itertools.chain(iter([last]), chars), maxlen=1
|
212 |
-
).pop()
|
213 |
-
if first == last:
|
214 |
-
ret.append(escape_re_range_char(first))
|
215 |
-
else:
|
216 |
-
sep = "" if ord(last) == ord(first) + 1 else "-"
|
217 |
-
ret.append(
|
218 |
-
"{}{}{}".format(
|
219 |
-
escape_re_range_char(first), sep, escape_re_range_char(last)
|
220 |
-
)
|
221 |
-
)
|
222 |
-
else:
|
223 |
-
ret = [escape_re_range_char(c) for c in s]
|
224 |
-
|
225 |
-
return "".join(ret)
|
226 |
-
|
227 |
-
|
228 |
-
def _flatten(ll: list) -> list:
|
229 |
-
ret = []
|
230 |
-
for i in ll:
|
231 |
-
if isinstance(i, list):
|
232 |
-
ret.extend(_flatten(i))
|
233 |
-
else:
|
234 |
-
ret.append(i)
|
235 |
-
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Bart92/RVC_HF/lib/uvr5_pack/lib_v5/layers_new.py
DELETED
@@ -1,125 +0,0 @@
|
|
1 |
-
import torch
|
2 |
-
from torch import nn
|
3 |
-
import torch.nn.functional as F
|
4 |
-
|
5 |
-
from . import spec_utils
|
6 |
-
|
7 |
-
|
8 |
-
class Conv2DBNActiv(nn.Module):
|
9 |
-
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, dilation=1, activ=nn.ReLU):
|
10 |
-
super(Conv2DBNActiv, self).__init__()
|
11 |
-
self.conv = nn.Sequential(
|
12 |
-
nn.Conv2d(
|
13 |
-
nin,
|
14 |
-
nout,
|
15 |
-
kernel_size=ksize,
|
16 |
-
stride=stride,
|
17 |
-
padding=pad,
|
18 |
-
dilation=dilation,
|
19 |
-
bias=False,
|
20 |
-
),
|
21 |
-
nn.BatchNorm2d(nout),
|
22 |
-
activ(),
|
23 |
-
)
|
24 |
-
|
25 |
-
def __call__(self, x):
|
26 |
-
return self.conv(x)
|
27 |
-
|
28 |
-
|
29 |
-
class Encoder(nn.Module):
|
30 |
-
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, activ=nn.LeakyReLU):
|
31 |
-
super(Encoder, self).__init__()
|
32 |
-
self.conv1 = Conv2DBNActiv(nin, nout, ksize, stride, pad, activ=activ)
|
33 |
-
self.conv2 = Conv2DBNActiv(nout, nout, ksize, 1, pad, activ=activ)
|
34 |
-
|
35 |
-
def __call__(self, x):
|
36 |
-
h = self.conv1(x)
|
37 |
-
h = self.conv2(h)
|
38 |
-
|
39 |
-
return h
|
40 |
-
|
41 |
-
|
42 |
-
class Decoder(nn.Module):
|
43 |
-
def __init__(
|
44 |
-
self, nin, nout, ksize=3, stride=1, pad=1, activ=nn.ReLU, dropout=False
|
45 |
-
):
|
46 |
-
super(Decoder, self).__init__()
|
47 |
-
self.conv1 = Conv2DBNActiv(nin, nout, ksize, 1, pad, activ=activ)
|
48 |
-
# self.conv2 = Conv2DBNActiv(nout, nout, ksize, 1, pad, activ=activ)
|
49 |
-
self.dropout = nn.Dropout2d(0.1) if dropout else None
|
50 |
-
|
51 |
-
def __call__(self, x, skip=None):
|
52 |
-
x = F.interpolate(x, scale_factor=2, mode="bilinear", align_corners=True)
|
53 |
-
|
54 |
-
if skip is not None:
|
55 |
-
skip = spec_utils.crop_center(skip, x)
|
56 |
-
x = torch.cat([x, skip], dim=1)
|
57 |
-
|
58 |
-
h = self.conv1(x)
|
59 |
-
# h = self.conv2(h)
|
60 |
-
|
61 |
-
if self.dropout is not None:
|
62 |
-
h = self.dropout(h)
|
63 |
-
|
64 |
-
return h
|
65 |
-
|
66 |
-
|
67 |
-
class ASPPModule(nn.Module):
|
68 |
-
def __init__(self, nin, nout, dilations=(4, 8, 12), activ=nn.ReLU, dropout=False):
|
69 |
-
super(ASPPModule, self).__init__()
|
70 |
-
self.conv1 = nn.Sequential(
|
71 |
-
nn.AdaptiveAvgPool2d((1, None)),
|
72 |
-
Conv2DBNActiv(nin, nout, 1, 1, 0, activ=activ),
|
73 |
-
)
|
74 |
-
self.conv2 = Conv2DBNActiv(nin, nout, 1, 1, 0, activ=activ)
|
75 |
-
self.conv3 = Conv2DBNActiv(
|
76 |
-
nin, nout, 3, 1, dilations[0], dilations[0], activ=activ
|
77 |
-
)
|
78 |
-
self.conv4 = Conv2DBNActiv(
|
79 |
-
nin, nout, 3, 1, dilations[1], dilations[1], activ=activ
|
80 |
-
)
|
81 |
-
self.conv5 = Conv2DBNActiv(
|
82 |
-
nin, nout, 3, 1, dilations[2], dilations[2], activ=activ
|
83 |
-
)
|
84 |
-
self.bottleneck = Conv2DBNActiv(nout * 5, nout, 1, 1, 0, activ=activ)
|
85 |
-
self.dropout = nn.Dropout2d(0.1) if dropout else None
|
86 |
-
|
87 |
-
def forward(self, x):
|
88 |
-
_, _, h, w = x.size()
|
89 |
-
feat1 = F.interpolate(
|
90 |
-
self.conv1(x), size=(h, w), mode="bilinear", align_corners=True
|
91 |
-
)
|
92 |
-
feat2 = self.conv2(x)
|
93 |
-
feat3 = self.conv3(x)
|
94 |
-
feat4 = self.conv4(x)
|
95 |
-
feat5 = self.conv5(x)
|
96 |
-
out = torch.cat((feat1, feat2, feat3, feat4, feat5), dim=1)
|
97 |
-
out = self.bottleneck(out)
|
98 |
-
|
99 |
-
if self.dropout is not None:
|
100 |
-
out = self.dropout(out)
|
101 |
-
|
102 |
-
return out
|
103 |
-
|
104 |
-
|
105 |
-
class LSTMModule(nn.Module):
|
106 |
-
def __init__(self, nin_conv, nin_lstm, nout_lstm):
|
107 |
-
super(LSTMModule, self).__init__()
|
108 |
-
self.conv = Conv2DBNActiv(nin_conv, 1, 1, 1, 0)
|
109 |
-
self.lstm = nn.LSTM(
|
110 |
-
input_size=nin_lstm, hidden_size=nout_lstm // 2, bidirectional=True
|
111 |
-
)
|
112 |
-
self.dense = nn.Sequential(
|
113 |
-
nn.Linear(nout_lstm, nin_lstm), nn.BatchNorm1d(nin_lstm), nn.ReLU()
|
114 |
-
)
|
115 |
-
|
116 |
-
def forward(self, x):
|
117 |
-
N, _, nbins, nframes = x.size()
|
118 |
-
h = self.conv(x)[:, 0] # N, nbins, nframes
|
119 |
-
h = h.permute(2, 0, 1) # nframes, N, nbins
|
120 |
-
h, _ = self.lstm(h)
|
121 |
-
h = self.dense(h.reshape(-1, h.size()[-1])) # nframes * N, nbins
|
122 |
-
h = h.reshape(nframes, N, 1, nbins)
|
123 |
-
h = h.permute(1, 2, 3, 0)
|
124 |
-
|
125 |
-
return h
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Benson/text-generation/Examples/Descargar Cabra Simulador Mod Apk.md
DELETED
@@ -1,82 +0,0 @@
|
|
1 |
-
|
2 |
-
<h1>Cómo descargar Goat Simulator Mod APK 2023(V2.16.4) - Monedas ilimitadas</h1>
|
3 |
-
<p>¿Alguna vez has soñado con ser una cabra y causar estragos en un pueblo suburbano? Si es así, entonces necesitas probar Goat Simulator, uno de los juegos más divertidos y absurdos jamás creados. Y si usted quiere hacer su experiencia cabra aún más divertido y loco, usted debe descargar Goat Simulator Mod APK, que le da monedas ilimitadas y el acceso a todas las cabras en el juego. </p>
|
4 |
-
<h2>descargar cabra simulador mod apk</h2><br /><p><b><b>Download File</b> ✏ <a href="https://bltlly.com/2v6MYM">https://bltlly.com/2v6MYM</a></b></p><br /><br />
|
5 |
-
<p>En este artículo, le diremos todo lo que necesita saber sobre Goat Simulator, su mod APK, cómo descargarlo e instalarlo, y cómo jugarlo. ¡Así que abróchate el cinturón y prepárate para un poco de acción tástica! </p>
|
6 |
-
<h2>¿Qué es Goat Simulator? </h2>
|
7 |
-
<p>Goat Simulator es un juego de acción en tercera persona desarrollado y publicado por Coffee Stain Studios en 2014. Es una parodia de los juegos de simulación, donde en lugar de ser un simulador realista, es un juego completamente estúpido lleno de errores y fallos que lo hacen hilarante. </p>
|
8 |
-
<p>El juego le permite controlar a una cabra llamada Pilgor, que puede correr, saltar, cabezazo, lamer y destruir cualquier cosa en su camino. El juego no tiene objetivos ni metas, excepto causar tanto caos y destrucción como sea posible en un mapa de mundo abierto. También puedes realizar varios trucos y acrobacias con tu cabra, como rebotar en trampolines, volar con jetpacks o unirte a un culto de cabras. </p>
|
9 |
-
<p>El juego ha sido elogiado por su humor, física y creatividad, así como criticado por su falta de pulido y profundidad. Ha recibido críticas mixtas de críticos y jugadores por igual, pero también ha ganado seguidores de culto y ha generado varios spin-offs y DLCs.</p>
|
10 |
-
<p>Algunas de las características de Goat Simulator son:</p>
|
11 |
-
<ul>
|
12 |
-
<li>Puedes ser una cabra</li>
|
13 |
-
<li>Puedes obtener puntos por destruir cosas</li>
|
14 |
-
<li>Puedes usar Steam Workshop para crear tus propias cabras, niveles, misiones y más</li>
|
15 |
-
<li>Puedes disfrutar de millones de errores y fallos que hacen que el juego sea más divertido</li>
|
16 |
-
|
17 |
-
<li>Puedes explorar un entorno suburbano lleno de secretos y sorpresas</li>
|
18 |
-
</ul>
|
19 |
-
<h2>¿Qué es Goat Simulator Mod APK? </h2>
|
20 |
-
<p>Goat Simulator Mod APK es una versión modificada del juego original que le da algunas características y ventajas adicionales que no están disponibles en la versión oficial. </p>
|
21 |
-
<p></p>
|
22 |
-
<p>Algunos de los beneficios de Goat Simulator Mod APK son:</p>
|
23 |
-
<ul>
|
24 |
-
<li>Obtienes monedas ilimitadas que puedes usar para comprar cualquier cosa en el juego</li>
|
25 |
-
<li>Obtienes acceso a todas las cabras en el juego sin tener que desbloquearlas</li>
|
26 |
-
<li>Obtienes tiempos de carga más rápidos y un rendimiento más suave</li>
|
27 |
-
<li>Te deshaces de anuncios molestos y ventanas emergentes</li>
|
28 |
-
<li>Obtienes compatibilidad con la mayoría de dispositivos Android</li>
|
29 |
-
</ul>
|
30 |
-
<p>Algunas de las características de Goat Simulator Mod APK son:</p>
|
31 |
-
<ul>
|
32 |
-
<li>versión V2.16.4</li>
|
33 |
-
<li>Tamaño: 27 MB + 500 MB Archivo OBB</li>
|
34 |
-
<li>Requiere Android 4.0.3 o superior</li>
|
35 |
-
<li>No se requiere raíz</li>
|
36 |
-
<li>Seguro y libre de virus</li> <h2>Cómo descargar e instalar Goat Simulator Mod APK? </h2>
|
37 |
-
<p>Si desea descargar e instalar Goat Simulator Mod APK en su dispositivo Android, es necesario seguir estos sencillos pasos:</p>
|
38 |
-
<ol>
|
39 |
-
<li>En primer lugar, es necesario descargar el archivo Goat Simulator Mod APK y el archivo OBB de una fuente de confianza. Puede utilizar los siguientes enlaces para obtenerlos:</li>
|
40 |
-
<li><a href="">Simulador de cabra Mod APK Enlace de descarga</a></li>
|
41 |
-
<li><a href="">Archivo OBB de Goat Simulator Enlace de descarga</a></li>
|
42 |
-
<li>Siguiente, es necesario habilitar la instalación de aplicaciones de fuentes desconocidas en el dispositivo. Para hacer esto, vaya a Configuración > Seguridad > Fuentes desconocidas y conéctelo. </li>
|
43 |
-
<li>Entonces, necesita localizar los archivos descargados en su dispositivo utilizando una aplicación de administrador de archivos. Puedes usar cualquier aplicación que prefieras, como ES File Explorer o ZArchiver.</li>
|
44 |
-
<li>Después de eso, es necesario instalar el archivo Goat Simulator Mod APK tocando en él y siguiendo las instrucciones en la pantalla. </li>
|
45 |
-
|
46 |
-
<li>Finalmente, debe mover la carpeta OBB extraída a la siguiente ubicación: Almacenamiento interno > Android > OBB > com.coffeestainstudios.goatsimulator. Si no hay ninguna carpeta OBB, puede crear una. </li>
|
47 |
-
</ol>
|
48 |
-
<p>Felicidades! Usted ha descargado con éxito e instalado Goat Simulator Mod APK en su dispositivo. Ahora puedes lanzar el juego y disfrutarlo con monedas ilimitadas y todas las cabras desbloqueadas. </p>
|
49 |
-
<h2>Cómo jugar Goat Simulator Mod APK? </h2>
|
50 |
-
<p>Jugar Goat Simulator Mod APK es muy fácil y divertido. Solo tienes que seguir estos consejos y trucos para aprovechar al máximo su aventura de cabra:</p>
|
51 |
-
<ul>
|
52 |
-
<li>Para mover la cabra, utilice el joystick en el lado izquierdo de la pantalla. Para mirar alrededor, pase el dedo por el lado derecho de la pantalla. </li>
|
53 |
-
<li>A tope de cabeza o lamer algo, toque en los botones en la esquina inferior derecha de la pantalla. También puede arrastrar y soltar objetos con la lengua. </li>
|
54 |
-
<li>Para saltar, toca el botón en la esquina inferior izquierda de la pantalla. También puedes hacer doble salto o salto de pared tocando de nuevo en el aire. </li>
|
55 |
-
<li> Para realizar trucos y acrobacias, toque el botón en la esquina superior derecha de la pantalla. También puede combinar diferentes trucos para obtener más puntos. </li>
|
56 |
-
<li>Para cambiar su cabra, toque el botón en la esquina superior izquierda de la pantalla. Puedes elegir entre diferentes tipos de cabras, como Cabra Alta, Cabra Pluma o Cabra Elegante.</li>
|
57 |
-
<li>Para utilizar sus monedas ilimitadas, toque en el icono de la tienda en el centro superior de la pantalla. Puedes comprar varios artículos y accesorios para tu cabra, como sombreros, gafas o jetpacks. </li>
|
58 |
-
<li>Para explorar el mapa, simplemente deambular y descubrir nuevos lugares y secretos. También puedes interactuar con varios objetos y personajes del juego, como coches, personas o extraterrestres. </li>
|
59 |
-
</ul>
|
60 |
-
<p>Diviértete jugando Goat Simulator Mod APK y dar rienda suelta a su cabra interior! </p>
|
61 |
-
<h2>Conclusión</h2>
|
62 |
-
|
63 |
-
<p>Si desea descargar Goat Simulator Mod APK 2023(V2.16.4), solo tiene que seguir nuestra guía anterior y disfrutar de ser una cabra como nunca antes. Esperamos que haya encontrado este artículo útil e informativo. Gracias por leer y tener un día de cabra-tastic! </p>
|
64 |
-
<h3>Preguntas frecuentes</h3>
|
65 |
-
<p>Aquí están algunas de las preguntas y respuestas más frecuentes sobre Goat Simulator y su mod APK:</p>
|
66 |
-
<tabla>
|
67 |
-
<tr><td><b>Q: ¿Es Goat Simulator gratis? </b></td><td><b>A: No, Goat Simulator es un juego pagado que cuesta $4.99 en Google Play Store. Sin embargo, puede descargar Goat Simulator Mod APK gratis desde nuestros enlaces anteriores. </b></td></tr>
|
68 |
-
<tr><td><b>Q: ¿Es seguro Goat Simulator Mod APK? </b></td><td><b>A: Sí, Goat Simulator Mod APK es seguro y libre de virus. Lo hemos probado nosotros mismos y no encontramos problemas o malware. Sin embargo, le recomendamos que lo descargue de una fuente confiable y lo escanee con una aplicación antivirus antes de instalarlo. </b></td></tr>
|
69 |
-
<tr><td><b>Q: ¿Cuáles son algunas de las mejores cabras en Goat Simulator? </b></td><td <b>A: Algunas de las mejores cabras en Goat Simulator son:</b></td><td><b>A: Algunas de las mejores cabras en Goat Simulator son:</b>>
|
70 |
-
<ul>
|
71 |
-
<li>Angel Goat: Una cabra que puede volar y tiene un halo. </li>
|
72 |
-
<li>Cabra Diabólica: Una cabra que puede invocar demonios y tiene cuernos. </li>
|
73 |
-
<li>Spider Goat: Una cabra que puede disparar telarañas y subir paredes. </li>
|
74 |
-
<li>Cabra Reina: Una cabra que puede controlar a otras cabras y tiene una corona. </li>
|
75 |
-
<li>Anti-Gravity Goat: Una cabra que puede desafiar la gravedad y flotar en el aire. </li>
|
76 |
-
</ul>
|
77 |
-
</td></tr>
|
78 |
-
<tr><td><b>Q: ¿Cómo actualizo Goat Simulator Mod APK? </b></td><td><b>A: Para actualizar Goat Simulator Mod APK, es necesario descargar la última versión del archivo APK mod y el archivo OBB de nuestros enlaces anteriores. Luego, debe desinstalar la versión anterior del juego e instalar la nueva. También debe reemplazar la carpeta OBB antigua con la nueva. Puedes seguir los mismos pasos de arriba para hacer esto. </b></td></tr>
|
79 |
-
|
80 |
-
</table></p> 64aa2da5cf<br />
|
81 |
-
<br />
|
82 |
-
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/BetterAPI/BetterChat/src/styles/highlight-js.css
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
@import "highlight.js/styles/atom-one-dark";
|
|
|
|
spaces/BetterAPI/BetterChat_new/src/lib/utils/trimPrefix.ts
DELETED
@@ -1,6 +0,0 @@
|
|
1 |
-
export function trimPrefix(input: string, prefix: string) {
|
2 |
-
if (input.startsWith(prefix)) {
|
3 |
-
return input.slice(prefix.length);
|
4 |
-
}
|
5 |
-
return input;
|
6 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Big-Web/MMSD/env/Lib/site-packages/setuptools/_distutils/bcppcompiler.py
DELETED
@@ -1,408 +0,0 @@
|
|
1 |
-
"""distutils.bcppcompiler
|
2 |
-
|
3 |
-
Contains BorlandCCompiler, an implementation of the abstract CCompiler class
|
4 |
-
for the Borland C++ compiler.
|
5 |
-
"""
|
6 |
-
|
7 |
-
# This implementation by Lyle Johnson, based on the original msvccompiler.py
|
8 |
-
# module and using the directions originally published by Gordon Williams.
|
9 |
-
|
10 |
-
# XXX looks like there's a LOT of overlap between these two classes:
|
11 |
-
# someone should sit down and factor out the common code as
|
12 |
-
# WindowsCCompiler! --GPW
|
13 |
-
|
14 |
-
|
15 |
-
import os
|
16 |
-
import warnings
|
17 |
-
|
18 |
-
from distutils.errors import (
|
19 |
-
DistutilsExecError,
|
20 |
-
CompileError,
|
21 |
-
LibError,
|
22 |
-
LinkError,
|
23 |
-
UnknownFileError,
|
24 |
-
)
|
25 |
-
from distutils.ccompiler import CCompiler, gen_preprocess_options
|
26 |
-
from distutils.file_util import write_file
|
27 |
-
from distutils.dep_util import newer
|
28 |
-
from distutils import log
|
29 |
-
|
30 |
-
|
31 |
-
warnings.warn(
|
32 |
-
"bcppcompiler is deprecated and slated to be removed "
|
33 |
-
"in the future. Please discontinue use or file an issue "
|
34 |
-
"with pypa/distutils describing your use case.",
|
35 |
-
DeprecationWarning,
|
36 |
-
)
|
37 |
-
|
38 |
-
|
39 |
-
class BCPPCompiler(CCompiler):
|
40 |
-
"""Concrete class that implements an interface to the Borland C/C++
|
41 |
-
compiler, as defined by the CCompiler abstract class.
|
42 |
-
"""
|
43 |
-
|
44 |
-
compiler_type = 'bcpp'
|
45 |
-
|
46 |
-
# Just set this so CCompiler's constructor doesn't barf. We currently
|
47 |
-
# don't use the 'set_executables()' bureaucracy provided by CCompiler,
|
48 |
-
# as it really isn't necessary for this sort of single-compiler class.
|
49 |
-
# Would be nice to have a consistent interface with UnixCCompiler,
|
50 |
-
# though, so it's worth thinking about.
|
51 |
-
executables = {}
|
52 |
-
|
53 |
-
# Private class data (need to distinguish C from C++ source for compiler)
|
54 |
-
_c_extensions = ['.c']
|
55 |
-
_cpp_extensions = ['.cc', '.cpp', '.cxx']
|
56 |
-
|
57 |
-
# Needed for the filename generation methods provided by the
|
58 |
-
# base class, CCompiler.
|
59 |
-
src_extensions = _c_extensions + _cpp_extensions
|
60 |
-
obj_extension = '.obj'
|
61 |
-
static_lib_extension = '.lib'
|
62 |
-
shared_lib_extension = '.dll'
|
63 |
-
static_lib_format = shared_lib_format = '%s%s'
|
64 |
-
exe_extension = '.exe'
|
65 |
-
|
66 |
-
def __init__(self, verbose=0, dry_run=0, force=0):
|
67 |
-
|
68 |
-
super().__init__(verbose, dry_run, force)
|
69 |
-
|
70 |
-
# These executables are assumed to all be in the path.
|
71 |
-
# Borland doesn't seem to use any special registry settings to
|
72 |
-
# indicate their installation locations.
|
73 |
-
|
74 |
-
self.cc = "bcc32.exe"
|
75 |
-
self.linker = "ilink32.exe"
|
76 |
-
self.lib = "tlib.exe"
|
77 |
-
|
78 |
-
self.preprocess_options = None
|
79 |
-
self.compile_options = ['/tWM', '/O2', '/q', '/g0']
|
80 |
-
self.compile_options_debug = ['/tWM', '/Od', '/q', '/g0']
|
81 |
-
|
82 |
-
self.ldflags_shared = ['/Tpd', '/Gn', '/q', '/x']
|
83 |
-
self.ldflags_shared_debug = ['/Tpd', '/Gn', '/q', '/x']
|
84 |
-
self.ldflags_static = []
|
85 |
-
self.ldflags_exe = ['/Gn', '/q', '/x']
|
86 |
-
self.ldflags_exe_debug = ['/Gn', '/q', '/x', '/r']
|
87 |
-
|
88 |
-
# -- Worker methods ------------------------------------------------
|
89 |
-
|
90 |
-
def compile( # noqa: C901
|
91 |
-
self,
|
92 |
-
sources,
|
93 |
-
output_dir=None,
|
94 |
-
macros=None,
|
95 |
-
include_dirs=None,
|
96 |
-
debug=0,
|
97 |
-
extra_preargs=None,
|
98 |
-
extra_postargs=None,
|
99 |
-
depends=None,
|
100 |
-
):
|
101 |
-
|
102 |
-
macros, objects, extra_postargs, pp_opts, build = self._setup_compile(
|
103 |
-
output_dir, macros, include_dirs, sources, depends, extra_postargs
|
104 |
-
)
|
105 |
-
compile_opts = extra_preargs or []
|
106 |
-
compile_opts.append('-c')
|
107 |
-
if debug:
|
108 |
-
compile_opts.extend(self.compile_options_debug)
|
109 |
-
else:
|
110 |
-
compile_opts.extend(self.compile_options)
|
111 |
-
|
112 |
-
for obj in objects:
|
113 |
-
try:
|
114 |
-
src, ext = build[obj]
|
115 |
-
except KeyError:
|
116 |
-
continue
|
117 |
-
# XXX why do the normpath here?
|
118 |
-
src = os.path.normpath(src)
|
119 |
-
obj = os.path.normpath(obj)
|
120 |
-
# XXX _setup_compile() did a mkpath() too but before the normpath.
|
121 |
-
# Is it possible to skip the normpath?
|
122 |
-
self.mkpath(os.path.dirname(obj))
|
123 |
-
|
124 |
-
if ext == '.res':
|
125 |
-
# This is already a binary file -- skip it.
|
126 |
-
continue # the 'for' loop
|
127 |
-
if ext == '.rc':
|
128 |
-
# This needs to be compiled to a .res file -- do it now.
|
129 |
-
try:
|
130 |
-
self.spawn(["brcc32", "-fo", obj, src])
|
131 |
-
except DistutilsExecError as msg:
|
132 |
-
raise CompileError(msg)
|
133 |
-
continue # the 'for' loop
|
134 |
-
|
135 |
-
# The next two are both for the real compiler.
|
136 |
-
if ext in self._c_extensions:
|
137 |
-
input_opt = ""
|
138 |
-
elif ext in self._cpp_extensions:
|
139 |
-
input_opt = "-P"
|
140 |
-
else:
|
141 |
-
# Unknown file type -- no extra options. The compiler
|
142 |
-
# will probably fail, but let it just in case this is a
|
143 |
-
# file the compiler recognizes even if we don't.
|
144 |
-
input_opt = ""
|
145 |
-
|
146 |
-
output_opt = "-o" + obj
|
147 |
-
|
148 |
-
# Compiler command line syntax is: "bcc32 [options] file(s)".
|
149 |
-
# Note that the source file names must appear at the end of
|
150 |
-
# the command line.
|
151 |
-
try:
|
152 |
-
self.spawn(
|
153 |
-
[self.cc]
|
154 |
-
+ compile_opts
|
155 |
-
+ pp_opts
|
156 |
-
+ [input_opt, output_opt]
|
157 |
-
+ extra_postargs
|
158 |
-
+ [src]
|
159 |
-
)
|
160 |
-
except DistutilsExecError as msg:
|
161 |
-
raise CompileError(msg)
|
162 |
-
|
163 |
-
return objects
|
164 |
-
|
165 |
-
# compile ()
|
166 |
-
|
167 |
-
def create_static_lib(
|
168 |
-
self, objects, output_libname, output_dir=None, debug=0, target_lang=None
|
169 |
-
):
|
170 |
-
|
171 |
-
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
172 |
-
output_filename = self.library_filename(output_libname, output_dir=output_dir)
|
173 |
-
|
174 |
-
if self._need_link(objects, output_filename):
|
175 |
-
lib_args = [output_filename, '/u'] + objects
|
176 |
-
if debug:
|
177 |
-
pass # XXX what goes here?
|
178 |
-
try:
|
179 |
-
self.spawn([self.lib] + lib_args)
|
180 |
-
except DistutilsExecError as msg:
|
181 |
-
raise LibError(msg)
|
182 |
-
else:
|
183 |
-
log.debug("skipping %s (up-to-date)", output_filename)
|
184 |
-
|
185 |
-
# create_static_lib ()
|
186 |
-
|
187 |
-
def link( # noqa: C901
|
188 |
-
self,
|
189 |
-
target_desc,
|
190 |
-
objects,
|
191 |
-
output_filename,
|
192 |
-
output_dir=None,
|
193 |
-
libraries=None,
|
194 |
-
library_dirs=None,
|
195 |
-
runtime_library_dirs=None,
|
196 |
-
export_symbols=None,
|
197 |
-
debug=0,
|
198 |
-
extra_preargs=None,
|
199 |
-
extra_postargs=None,
|
200 |
-
build_temp=None,
|
201 |
-
target_lang=None,
|
202 |
-
):
|
203 |
-
|
204 |
-
# XXX this ignores 'build_temp'! should follow the lead of
|
205 |
-
# msvccompiler.py
|
206 |
-
|
207 |
-
(objects, output_dir) = self._fix_object_args(objects, output_dir)
|
208 |
-
(libraries, library_dirs, runtime_library_dirs) = self._fix_lib_args(
|
209 |
-
libraries, library_dirs, runtime_library_dirs
|
210 |
-
)
|
211 |
-
|
212 |
-
if runtime_library_dirs:
|
213 |
-
log.warn(
|
214 |
-
"I don't know what to do with 'runtime_library_dirs': %s",
|
215 |
-
str(runtime_library_dirs),
|
216 |
-
)
|
217 |
-
|
218 |
-
if output_dir is not None:
|
219 |
-
output_filename = os.path.join(output_dir, output_filename)
|
220 |
-
|
221 |
-
if self._need_link(objects, output_filename):
|
222 |
-
|
223 |
-
# Figure out linker args based on type of target.
|
224 |
-
if target_desc == CCompiler.EXECUTABLE:
|
225 |
-
startup_obj = 'c0w32'
|
226 |
-
if debug:
|
227 |
-
ld_args = self.ldflags_exe_debug[:]
|
228 |
-
else:
|
229 |
-
ld_args = self.ldflags_exe[:]
|
230 |
-
else:
|
231 |
-
startup_obj = 'c0d32'
|
232 |
-
if debug:
|
233 |
-
ld_args = self.ldflags_shared_debug[:]
|
234 |
-
else:
|
235 |
-
ld_args = self.ldflags_shared[:]
|
236 |
-
|
237 |
-
# Create a temporary exports file for use by the linker
|
238 |
-
if export_symbols is None:
|
239 |
-
def_file = ''
|
240 |
-
else:
|
241 |
-
head, tail = os.path.split(output_filename)
|
242 |
-
modname, ext = os.path.splitext(tail)
|
243 |
-
temp_dir = os.path.dirname(objects[0]) # preserve tree structure
|
244 |
-
def_file = os.path.join(temp_dir, '%s.def' % modname)
|
245 |
-
contents = ['EXPORTS']
|
246 |
-
for sym in export_symbols or []:
|
247 |
-
contents.append(' {}=_{}'.format(sym, sym))
|
248 |
-
self.execute(write_file, (def_file, contents), "writing %s" % def_file)
|
249 |
-
|
250 |
-
# Borland C++ has problems with '/' in paths
|
251 |
-
objects2 = map(os.path.normpath, objects)
|
252 |
-
# split objects in .obj and .res files
|
253 |
-
# Borland C++ needs them at different positions in the command line
|
254 |
-
objects = [startup_obj]
|
255 |
-
resources = []
|
256 |
-
for file in objects2:
|
257 |
-
(base, ext) = os.path.splitext(os.path.normcase(file))
|
258 |
-
if ext == '.res':
|
259 |
-
resources.append(file)
|
260 |
-
else:
|
261 |
-
objects.append(file)
|
262 |
-
|
263 |
-
for ell in library_dirs:
|
264 |
-
ld_args.append("/L%s" % os.path.normpath(ell))
|
265 |
-
ld_args.append("/L.") # we sometimes use relative paths
|
266 |
-
|
267 |
-
# list of object files
|
268 |
-
ld_args.extend(objects)
|
269 |
-
|
270 |
-
# XXX the command-line syntax for Borland C++ is a bit wonky;
|
271 |
-
# certain filenames are jammed together in one big string, but
|
272 |
-
# comma-delimited. This doesn't mesh too well with the
|
273 |
-
# Unix-centric attitude (with a DOS/Windows quoting hack) of
|
274 |
-
# 'spawn()', so constructing the argument list is a bit
|
275 |
-
# awkward. Note that doing the obvious thing and jamming all
|
276 |
-
# the filenames and commas into one argument would be wrong,
|
277 |
-
# because 'spawn()' would quote any filenames with spaces in
|
278 |
-
# them. Arghghh!. Apparently it works fine as coded...
|
279 |
-
|
280 |
-
# name of dll/exe file
|
281 |
-
ld_args.extend([',', output_filename])
|
282 |
-
# no map file and start libraries
|
283 |
-
ld_args.append(',,')
|
284 |
-
|
285 |
-
for lib in libraries:
|
286 |
-
# see if we find it and if there is a bcpp specific lib
|
287 |
-
# (xxx_bcpp.lib)
|
288 |
-
libfile = self.find_library_file(library_dirs, lib, debug)
|
289 |
-
if libfile is None:
|
290 |
-
ld_args.append(lib)
|
291 |
-
# probably a BCPP internal library -- don't warn
|
292 |
-
else:
|
293 |
-
# full name which prefers bcpp_xxx.lib over xxx.lib
|
294 |
-
ld_args.append(libfile)
|
295 |
-
|
296 |
-
# some default libraries
|
297 |
-
ld_args.append('import32')
|
298 |
-
ld_args.append('cw32mt')
|
299 |
-
|
300 |
-
# def file for export symbols
|
301 |
-
ld_args.extend([',', def_file])
|
302 |
-
# add resource files
|
303 |
-
ld_args.append(',')
|
304 |
-
ld_args.extend(resources)
|
305 |
-
|
306 |
-
if extra_preargs:
|
307 |
-
ld_args[:0] = extra_preargs
|
308 |
-
if extra_postargs:
|
309 |
-
ld_args.extend(extra_postargs)
|
310 |
-
|
311 |
-
self.mkpath(os.path.dirname(output_filename))
|
312 |
-
try:
|
313 |
-
self.spawn([self.linker] + ld_args)
|
314 |
-
except DistutilsExecError as msg:
|
315 |
-
raise LinkError(msg)
|
316 |
-
|
317 |
-
else:
|
318 |
-
log.debug("skipping %s (up-to-date)", output_filename)
|
319 |
-
|
320 |
-
# link ()
|
321 |
-
|
322 |
-
# -- Miscellaneous methods -----------------------------------------
|
323 |
-
|
324 |
-
def find_library_file(self, dirs, lib, debug=0):
|
325 |
-
# List of effective library names to try, in order of preference:
|
326 |
-
# xxx_bcpp.lib is better than xxx.lib
|
327 |
-
# and xxx_d.lib is better than xxx.lib if debug is set
|
328 |
-
#
|
329 |
-
# The "_bcpp" suffix is to handle a Python installation for people
|
330 |
-
# with multiple compilers (primarily Distutils hackers, I suspect
|
331 |
-
# ;-). The idea is they'd have one static library for each
|
332 |
-
# compiler they care about, since (almost?) every Windows compiler
|
333 |
-
# seems to have a different format for static libraries.
|
334 |
-
if debug:
|
335 |
-
dlib = lib + "_d"
|
336 |
-
try_names = (dlib + "_bcpp", lib + "_bcpp", dlib, lib)
|
337 |
-
else:
|
338 |
-
try_names = (lib + "_bcpp", lib)
|
339 |
-
|
340 |
-
for dir in dirs:
|
341 |
-
for name in try_names:
|
342 |
-
libfile = os.path.join(dir, self.library_filename(name))
|
343 |
-
if os.path.exists(libfile):
|
344 |
-
return libfile
|
345 |
-
else:
|
346 |
-
# Oops, didn't find it in *any* of 'dirs'
|
347 |
-
return None
|
348 |
-
|
349 |
-
# overwrite the one from CCompiler to support rc and res-files
|
350 |
-
def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
|
351 |
-
if output_dir is None:
|
352 |
-
output_dir = ''
|
353 |
-
obj_names = []
|
354 |
-
for src_name in source_filenames:
|
355 |
-
# use normcase to make sure '.rc' is really '.rc' and not '.RC'
|
356 |
-
(base, ext) = os.path.splitext(os.path.normcase(src_name))
|
357 |
-
if ext not in (self.src_extensions + ['.rc', '.res']):
|
358 |
-
raise UnknownFileError(
|
359 |
-
"unknown file type '{}' (from '{}')".format(ext, src_name)
|
360 |
-
)
|
361 |
-
if strip_dir:
|
362 |
-
base = os.path.basename(base)
|
363 |
-
if ext == '.res':
|
364 |
-
# these can go unchanged
|
365 |
-
obj_names.append(os.path.join(output_dir, base + ext))
|
366 |
-
elif ext == '.rc':
|
367 |
-
# these need to be compiled to .res-files
|
368 |
-
obj_names.append(os.path.join(output_dir, base + '.res'))
|
369 |
-
else:
|
370 |
-
obj_names.append(os.path.join(output_dir, base + self.obj_extension))
|
371 |
-
return obj_names
|
372 |
-
|
373 |
-
# object_filenames ()
|
374 |
-
|
375 |
-
def preprocess(
|
376 |
-
self,
|
377 |
-
source,
|
378 |
-
output_file=None,
|
379 |
-
macros=None,
|
380 |
-
include_dirs=None,
|
381 |
-
extra_preargs=None,
|
382 |
-
extra_postargs=None,
|
383 |
-
):
|
384 |
-
|
385 |
-
(_, macros, include_dirs) = self._fix_compile_args(None, macros, include_dirs)
|
386 |
-
pp_opts = gen_preprocess_options(macros, include_dirs)
|
387 |
-
pp_args = ['cpp32.exe'] + pp_opts
|
388 |
-
if output_file is not None:
|
389 |
-
pp_args.append('-o' + output_file)
|
390 |
-
if extra_preargs:
|
391 |
-
pp_args[:0] = extra_preargs
|
392 |
-
if extra_postargs:
|
393 |
-
pp_args.extend(extra_postargs)
|
394 |
-
pp_args.append(source)
|
395 |
-
|
396 |
-
# We need to preprocess: either we're being forced to, or the
|
397 |
-
# source file is newer than the target (or the target doesn't
|
398 |
-
# exist).
|
399 |
-
if self.force or output_file is None or newer(source, output_file):
|
400 |
-
if output_file:
|
401 |
-
self.mkpath(os.path.dirname(output_file))
|
402 |
-
try:
|
403 |
-
self.spawn(pp_args)
|
404 |
-
except DistutilsExecError as msg:
|
405 |
-
print(msg)
|
406 |
-
raise CompileError(msg)
|
407 |
-
|
408 |
-
# preprocess()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/BraydenMoore/MARCI-NFL-Betting/update_data.bat
DELETED
@@ -1,11 +0,0 @@
|
|
1 |
-
python "C:\Users\Brayden\OneDrive - stern.nyu.edu\Brayden Moore LLC\Python\Projects\MARCI 3.0\MARCI-NFL-Betting\Source\Build\update.py"
|
2 |
-
python "C:\Users\Brayden\OneDrive - stern.nyu.edu\Brayden Moore LLC\Python\Projects\MARCI 3.0\MARCI-NFL-Betting\get_record.py"
|
3 |
-
cd "C:\Users\Brayden\OneDrive - stern.nyu.edu\Brayden Moore LLC\Python\Projects\MARCI 3.0\MARCI-NFL-Betting"
|
4 |
-
git add "Source\Data\gbg_and_odds_this_year.csv"
|
5 |
-
git add "Source\Data\gbg_this_year.csv"
|
6 |
-
git add "Source\Data\results.csv"
|
7 |
-
git add "Source\Data\record.json"
|
8 |
-
git add "Source\Data\lines.json"
|
9 |
-
git commit -m "Update with up to date data"
|
10 |
-
git push
|
11 |
-
pause
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CALM/Dashboard/streamlit_observable/frontend/src/streamlit/StreamlitReact.tsx
DELETED
@@ -1,150 +0,0 @@
|
|
1 |
-
import hoistNonReactStatics from "hoist-non-react-statics"
|
2 |
-
import React, { ReactNode } from "react"
|
3 |
-
import { RenderData, Streamlit } from "./streamlit"
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Props passed to custom Streamlit components.
|
7 |
-
*/
|
8 |
-
export interface ComponentProps {
|
9 |
-
/** Named dictionary of arguments passed from Python. */
|
10 |
-
args: any
|
11 |
-
|
12 |
-
/** The component's width. */
|
13 |
-
width: number
|
14 |
-
|
15 |
-
/**
|
16 |
-
* True if the component should be disabled.
|
17 |
-
* All components get disabled while the app is being re-run,
|
18 |
-
* and become re-enabled when the re-run has finished.
|
19 |
-
*/
|
20 |
-
disabled: boolean
|
21 |
-
}
|
22 |
-
|
23 |
-
/**
|
24 |
-
* Optional Streamlit React-based component base class.
|
25 |
-
*
|
26 |
-
* You are not required to extend this base class to create a Streamlit
|
27 |
-
* component. If you decide not to extend it, you should implement the
|
28 |
-
* `componentDidMount` and `componentDidUpdate` functions in your own class,
|
29 |
-
* so that your plugin properly resizes.
|
30 |
-
*/
|
31 |
-
export class StreamlitComponentBase<S = {}> extends React.PureComponent<
|
32 |
-
ComponentProps,
|
33 |
-
S
|
34 |
-
> {
|
35 |
-
public componentDidMount(): void {
|
36 |
-
// After we're rendered for the first time, tell Streamlit that our height
|
37 |
-
// has changed.
|
38 |
-
Streamlit.setFrameHeight()
|
39 |
-
}
|
40 |
-
|
41 |
-
public componentDidUpdate(): void {
|
42 |
-
// After we're updated, tell Streamlit that our height may have changed.
|
43 |
-
Streamlit.setFrameHeight()
|
44 |
-
}
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* Wrapper for React-based Streamlit components.
|
49 |
-
*
|
50 |
-
* Bootstraps the communication interface between Streamlit and the component.
|
51 |
-
*/
|
52 |
-
export function withStreamlitConnection(
|
53 |
-
WrappedComponent: React.ComponentType<ComponentProps>
|
54 |
-
): React.ComponentType {
|
55 |
-
interface WrapperProps { }
|
56 |
-
|
57 |
-
interface WrapperState {
|
58 |
-
renderData?: RenderData
|
59 |
-
componentError?: Error
|
60 |
-
}
|
61 |
-
|
62 |
-
class ComponentWrapper extends React.PureComponent<
|
63 |
-
WrapperProps,
|
64 |
-
WrapperState
|
65 |
-
> {
|
66 |
-
public constructor(props: WrapperProps) {
|
67 |
-
super(props)
|
68 |
-
this.state = {
|
69 |
-
renderData: undefined,
|
70 |
-
componentError: undefined,
|
71 |
-
}
|
72 |
-
}
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Error boundary function. This will be called if our wrapped
|
76 |
-
* component throws an error. We store the caught error in our state,
|
77 |
-
* and display it in the next render().
|
78 |
-
*/
|
79 |
-
public static getDerivedStateFromError = (
|
80 |
-
error: Error
|
81 |
-
): Partial<WrapperState> => {
|
82 |
-
return { componentError: error }
|
83 |
-
}
|
84 |
-
|
85 |
-
public componentDidMount = (): void => {
|
86 |
-
// Set up event listeners, and signal to Streamlit that we're ready.
|
87 |
-
// We won't render the component until we receive the first RENDER_EVENT.
|
88 |
-
Streamlit.events.addEventListener(
|
89 |
-
Streamlit.RENDER_EVENT,
|
90 |
-
this.onRenderEvent
|
91 |
-
)
|
92 |
-
Streamlit.setComponentReady()
|
93 |
-
}
|
94 |
-
|
95 |
-
public componentDidUpdate = (prevProps: any): void => {
|
96 |
-
// If our child threw an error, we display it in render(). In this
|
97 |
-
// case, the child won't be mounted and therefore won't call
|
98 |
-
// `setFrameHeight` on its own. We do it here so that the rendered
|
99 |
-
// error will be visible.
|
100 |
-
if (this.state.componentError != null) {
|
101 |
-
Streamlit.setFrameHeight()
|
102 |
-
}
|
103 |
-
}
|
104 |
-
|
105 |
-
public componentWillUnmount = (): void => {
|
106 |
-
Streamlit.events.removeEventListener(
|
107 |
-
Streamlit.RENDER_EVENT,
|
108 |
-
this.onRenderEvent
|
109 |
-
)
|
110 |
-
}
|
111 |
-
|
112 |
-
/**
|
113 |
-
* Streamlit is telling this component to redraw.
|
114 |
-
* We save the render data in State, so that it can be passed to the
|
115 |
-
* component in our own render() function.
|
116 |
-
*/
|
117 |
-
private onRenderEvent = (event: Event): void => {
|
118 |
-
// Update our state with the newest render data
|
119 |
-
const renderEvent = event as CustomEvent<RenderData>
|
120 |
-
this.setState({ renderData: renderEvent.detail })
|
121 |
-
}
|
122 |
-
|
123 |
-
public render = (): ReactNode => {
|
124 |
-
// If our wrapped component threw an error, display it.
|
125 |
-
if (this.state.componentError != null) {
|
126 |
-
return (
|
127 |
-
<div>
|
128 |
-
<h1>Component Error</h1>
|
129 |
-
<span>{this.state.componentError.message}</span>
|
130 |
-
</div>
|
131 |
-
)
|
132 |
-
}
|
133 |
-
|
134 |
-
// Don't render until we've gotten our first RENDER_EVENT from Streamlit.
|
135 |
-
if (this.state.renderData == null) {
|
136 |
-
return null
|
137 |
-
}
|
138 |
-
|
139 |
-
return (
|
140 |
-
<WrappedComponent
|
141 |
-
width={window.innerWidth}
|
142 |
-
disabled={this.state.renderData.disabled}
|
143 |
-
args={this.state.renderData.args}
|
144 |
-
/>
|
145 |
-
)
|
146 |
-
}
|
147 |
-
}
|
148 |
-
|
149 |
-
return hoistNonReactStatics(ComponentWrapper, WrappedComponent)
|
150 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CVPR/Dual-Key_Backdoor_Attacks/weight_analysis/wt_hist_classifier.py
DELETED
@@ -1,158 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
=========================================================================================
|
3 |
-
Trojan VQA
|
4 |
-
Written by Indranil Sur
|
5 |
-
|
6 |
-
Weight sensitivity analysis on last layers of TrojVQA clean and trojan models.
|
7 |
-
=========================================================================================
|
8 |
-
"""
|
9 |
-
import os
|
10 |
-
import copy
|
11 |
-
import json
|
12 |
-
import torch
|
13 |
-
import errno
|
14 |
-
import pandas as pd
|
15 |
-
import numpy as np
|
16 |
-
import argparse
|
17 |
-
from pathlib import Path
|
18 |
-
|
19 |
-
|
20 |
-
from xgboost import XGBClassifier
|
21 |
-
from sklearn.linear_model import LogisticRegression
|
22 |
-
from sklearn.ensemble import RandomForestClassifier, StackingClassifier
|
23 |
-
from sklearn.svm import SVC
|
24 |
-
from sklearn.metrics import roc_curve,auc
|
25 |
-
from sklearn.model_selection import StratifiedKFold
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
# List of shallow classifiers to test
|
30 |
-
e1 = [
|
31 |
-
('rf', RandomForestClassifier(n_estimators=10, random_state=42)),
|
32 |
-
('svr', SVC(kernel='linear', probability=True))
|
33 |
-
]
|
34 |
-
|
35 |
-
clfs = [
|
36 |
-
('XGB', XGBClassifier(eval_metric='mlogloss',use_label_encoder=False)),
|
37 |
-
('XGB_2', XGBClassifier(max_depth=2,gamma=2,eta=0.8,reg_alpha=0.5,reg_lambda=0.5,eval_metric='mlogloss',use_label_encoder=False)),
|
38 |
-
('LR', LogisticRegression(random_state=0, class_weight='balanced', C=1)),
|
39 |
-
('RF', RandomForestClassifier(random_state=0)),
|
40 |
-
('RF_10', RandomForestClassifier(n_estimators=10, random_state=42)),
|
41 |
-
('SVC_l', SVC(kernel='linear', probability=True)),
|
42 |
-
('SVC_r', SVC(kernel='rbf', probability=True)),
|
43 |
-
# ('SVC_p', SVC(kernel='poly', probability=True)),
|
44 |
-
('RF+SVC', StackingClassifier(estimators=e1, final_estimator=LogisticRegression())),
|
45 |
-
]
|
46 |
-
|
47 |
-
# List of all the architectures
|
48 |
-
model_archs = ['butd_eff', 'mfb', 'mfh', 'mcan_small', 'mcan_large', 'mmnasnet_small', 'mmnasnet_large', 'ban_4', 'ban_8', 'butd']
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
def cross_entropy(prob, labels):
|
53 |
-
"""
|
54 |
-
Code to compute cross-entropy
|
55 |
-
prob: probabilities from the model (numpy: Nx1)
|
56 |
-
labels: ground-truth labels (numpy: Nx1)
|
57 |
-
"""
|
58 |
-
prob = torch.Tensor(prob).squeeze()
|
59 |
-
labels = torch.Tensor(labels).squeeze()
|
60 |
-
assert (
|
61 |
-
prob.shape == labels.shape
|
62 |
-
), "Check size of labels and probabilities in computing cross-entropy"
|
63 |
-
ce = torch.nn.functional.binary_cross_entropy(prob, labels, reduction='none')
|
64 |
-
return ce.mean().item()
|
65 |
-
|
66 |
-
|
67 |
-
def get_feature(metadata, root):
|
68 |
-
feature_lst = []
|
69 |
-
for model_id in metadata.model_name.to_list():
|
70 |
-
feat = np.load('{}/{}.npy'.format(root, model_id))
|
71 |
-
feature_lst.append(feat)
|
72 |
-
return feature_lst
|
73 |
-
|
74 |
-
|
75 |
-
def get_measures(features_train, labels_train, features_test, labels_test, ret_ce=True, n_splits=5):
|
76 |
-
ret = {}
|
77 |
-
for name, _clf in clfs:
|
78 |
-
# print (name)
|
79 |
-
clf = copy.deepcopy(_clf)
|
80 |
-
clf = clf.fit(features_train, labels_train)
|
81 |
-
pred_test = clf.predict_proba(features_test)
|
82 |
-
|
83 |
-
fpr, tpr, t = roc_curve(labels_test, pred_test[:, 1])
|
84 |
-
roc_auc = auc(fpr, tpr)
|
85 |
-
ret[name] = {'auc': roc_auc}
|
86 |
-
|
87 |
-
if ret_ce:
|
88 |
-
ret[name]['ce'] = cross_entropy(pred_test[:, 1], labels_test)
|
89 |
-
|
90 |
-
if n_splits is not None:
|
91 |
-
kfold = StratifiedKFold(n_splits=5,shuffle=False)
|
92 |
-
cv_rocs = []
|
93 |
-
cv_ces = []
|
94 |
-
for train, test in kfold.split(features_train, labels_train):
|
95 |
-
clf = copy.deepcopy(_clf)
|
96 |
-
clf = clf.fit(features_train[train], labels_train[train])
|
97 |
-
pred_test = clf.predict_proba(features_train[test])
|
98 |
-
|
99 |
-
fpr, tpr, t = roc_curve(labels_train[test], pred_test[:, 1])
|
100 |
-
roc_auc = auc(fpr, tpr)
|
101 |
-
cv_rocs.append(roc_auc)
|
102 |
-
|
103 |
-
if ret_ce:
|
104 |
-
ce = cross_entropy(pred_test[:, 1], labels_train[test])
|
105 |
-
cv_ces.append(ce)
|
106 |
-
|
107 |
-
ret[name]['cv_auc_mean'] = np.mean(cv_rocs)
|
108 |
-
ret[name]['cv_auc_std'] = np.std(cv_rocs)
|
109 |
-
if ret_ce:
|
110 |
-
ret[name]['cv_ce_mean'] = np.mean(cv_ces)
|
111 |
-
ret[name]['cv_ce_std'] = np.std(cv_ces)
|
112 |
-
return ret
|
113 |
-
|
114 |
-
|
115 |
-
if __name__ == "__main__":
|
116 |
-
parser = argparse.ArgumentParser(description='Train shallow classifiers from wt features')
|
117 |
-
parser.add_argument('--ds_root', type=str, help='Root of data', required=True)
|
118 |
-
parser.add_argument('--ds', type=str, help='dataset', default='v1')
|
119 |
-
parser.add_argument('--feat_root', type=str, help='Root of features directory', default='features')
|
120 |
-
parser.add_argument('--feat_name', type=str, help='feature name', default='fc_wt_hist_50')
|
121 |
-
parser.add_argument('--result', type=str, help='feature name', default='result')
|
122 |
-
args = parser.parse_args()
|
123 |
-
|
124 |
-
root_train = Path(args.ds_root)/'{}-train-dataset/'.format(args.ds)
|
125 |
-
root_test = Path(args.ds_root)/'{}-test-dataset/'.format(args.ds)
|
126 |
-
metadata_train = pd.read_csv(root_train/'METADATA.csv')
|
127 |
-
metadata_test = pd.read_csv(root_test/'METADATA.csv')
|
128 |
-
|
129 |
-
feature_dir_train = Path(args.feat_root)/args.ds/args.feat_name/'train'
|
130 |
-
feature_dir_test = Path(args.feat_root)/args.ds/args.feat_name/'test'
|
131 |
-
feature_lst_train = get_feature(metadata_train, feature_dir_train)
|
132 |
-
feature_lst_test = get_feature(metadata_test, feature_dir_test)
|
133 |
-
|
134 |
-
features_train = np.stack(feature_lst_train)
|
135 |
-
features_test = np.stack(feature_lst_test)
|
136 |
-
labels_train = metadata_train.d_clean.to_numpy()
|
137 |
-
labels_test = metadata_test.d_clean.to_numpy()
|
138 |
-
|
139 |
-
try:
|
140 |
-
os.makedirs(args.result)
|
141 |
-
except OSError as e:
|
142 |
-
if e.errno != errno.EEXIST:
|
143 |
-
pass
|
144 |
-
out_file = Path(args.result)/'{}.json'.format(args.ds)
|
145 |
-
|
146 |
-
all_results = {}
|
147 |
-
all_results['ALL'] = get_measures(features_train, labels_train, features_test, labels_test)
|
148 |
-
|
149 |
-
for model in model_archs:
|
150 |
-
_features_train = features_train[metadata_train.model==model]
|
151 |
-
_labels_train = labels_train[metadata_train.model==model]
|
152 |
-
_features_test = features_test[metadata_test.model==model]
|
153 |
-
_labels_test = labels_test[metadata_test.model==model]
|
154 |
-
|
155 |
-
all_results[model] = get_measures(_features_train, _labels_train, _features_test, _labels_test)
|
156 |
-
|
157 |
-
with open(out_file, 'w') as outfile:
|
158 |
-
json.dump(all_results, outfile, indent=4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CVPR/LIVE/thrust/thrust/system/cuda/detail/copy.h
DELETED
@@ -1,198 +0,0 @@
|
|
1 |
-
/******************************************************************************
|
2 |
-
* Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
|
3 |
-
*
|
4 |
-
* Redistribution and use in source and binary forms, with or without
|
5 |
-
* modification, are permitted provided that the following conditions are met:
|
6 |
-
* * Redistributions of source code must retain the above copyright
|
7 |
-
* notice, this list of conditions and the following disclaimer.
|
8 |
-
* * Redistributions in binary form must reproduce the above copyright
|
9 |
-
* notice, this list of conditions and the following disclaimer in the
|
10 |
-
* documentation and/or other materials provided with the distribution.
|
11 |
-
* * Neither the name of the NVIDIA CORPORATION nor the
|
12 |
-
* names of its contributors may be used to endorse or promote products
|
13 |
-
* derived from this software without specific prior written permission.
|
14 |
-
*
|
15 |
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16 |
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17 |
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
18 |
-
* ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
|
19 |
-
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20 |
-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21 |
-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22 |
-
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23 |
-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24 |
-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25 |
-
*
|
26 |
-
******************************************************************************/
|
27 |
-
#pragma once
|
28 |
-
|
29 |
-
|
30 |
-
#include <thrust/system/cuda/config.h>
|
31 |
-
#include <thrust/system/cuda/detail/execution_policy.h>
|
32 |
-
#include <thrust/system/cuda/detail/cross_system.h>
|
33 |
-
|
34 |
-
namespace thrust
|
35 |
-
{
|
36 |
-
|
37 |
-
template <typename DerivedPolicy, typename InputIt, typename OutputIt>
|
38 |
-
__host__ __device__ OutputIt
|
39 |
-
copy(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
|
40 |
-
InputIt first,
|
41 |
-
InputIt last,
|
42 |
-
OutputIt result);
|
43 |
-
|
44 |
-
template <class DerivedPolicy, class InputIt, class Size, class OutputIt>
|
45 |
-
__host__ __device__ OutputIt
|
46 |
-
copy_n(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
|
47 |
-
InputIt first,
|
48 |
-
Size n,
|
49 |
-
OutputIt result);
|
50 |
-
|
51 |
-
namespace cuda_cub {
|
52 |
-
|
53 |
-
// D->D copy requires NVCC compiler
|
54 |
-
template <class System,
|
55 |
-
class InputIterator,
|
56 |
-
class OutputIterator>
|
57 |
-
OutputIterator __host__ __device__
|
58 |
-
copy(execution_policy<System> &system,
|
59 |
-
InputIterator first,
|
60 |
-
InputIterator last,
|
61 |
-
OutputIterator result);
|
62 |
-
|
63 |
-
template <class System1,
|
64 |
-
class System2,
|
65 |
-
class InputIterator,
|
66 |
-
class OutputIterator>
|
67 |
-
OutputIterator __host__
|
68 |
-
copy(cross_system<System1, System2> systems,
|
69 |
-
InputIterator first,
|
70 |
-
InputIterator last,
|
71 |
-
OutputIterator result);
|
72 |
-
|
73 |
-
template <class System,
|
74 |
-
class InputIterator,
|
75 |
-
class Size,
|
76 |
-
class OutputIterator>
|
77 |
-
OutputIterator __host__ __device__
|
78 |
-
copy_n(execution_policy<System> &system,
|
79 |
-
InputIterator first,
|
80 |
-
Size n,
|
81 |
-
OutputIterator result);
|
82 |
-
|
83 |
-
template <class System1,
|
84 |
-
class System2,
|
85 |
-
class InputIterator,
|
86 |
-
class Size,
|
87 |
-
class OutputIterator>
|
88 |
-
OutputIterator __host__
|
89 |
-
copy_n(cross_system<System1, System2> systems,
|
90 |
-
InputIterator first,
|
91 |
-
Size n,
|
92 |
-
OutputIterator result);
|
93 |
-
|
94 |
-
} // namespace cuda_
|
95 |
-
} // end namespace thrust
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
#include <thrust/system/cuda/detail/internal/copy_device_to_device.h>
|
100 |
-
#include <thrust/system/cuda/detail/internal/copy_cross_system.h>
|
101 |
-
#include <thrust/system/cuda/detail/par_to_seq.h>
|
102 |
-
|
103 |
-
namespace thrust
|
104 |
-
{
|
105 |
-
namespace cuda_cub {
|
106 |
-
|
107 |
-
|
108 |
-
#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC
|
109 |
-
// D->D copy requires NVCC compiler
|
110 |
-
|
111 |
-
__thrust_exec_check_disable__
|
112 |
-
template <class System,
|
113 |
-
class InputIterator,
|
114 |
-
class OutputIterator>
|
115 |
-
OutputIterator __host__ __device__
|
116 |
-
copy(execution_policy<System> &system,
|
117 |
-
InputIterator first,
|
118 |
-
InputIterator last,
|
119 |
-
OutputIterator result)
|
120 |
-
{
|
121 |
-
OutputIterator ret = result;
|
122 |
-
if (__THRUST_HAS_CUDART__)
|
123 |
-
{
|
124 |
-
ret = __copy::device_to_device(system, first, last, result);
|
125 |
-
}
|
126 |
-
else
|
127 |
-
{
|
128 |
-
#if !__THRUST_HAS_CUDART__
|
129 |
-
ret = thrust::copy(cvt_to_seq(derived_cast(system)),
|
130 |
-
first,
|
131 |
-
last,
|
132 |
-
result);
|
133 |
-
#endif
|
134 |
-
}
|
135 |
-
|
136 |
-
return ret;
|
137 |
-
} // end copy()
|
138 |
-
|
139 |
-
__thrust_exec_check_disable__
|
140 |
-
template <class System,
|
141 |
-
class InputIterator,
|
142 |
-
class Size,
|
143 |
-
class OutputIterator>
|
144 |
-
OutputIterator __host__ __device__
|
145 |
-
copy_n(execution_policy<System> &system,
|
146 |
-
InputIterator first,
|
147 |
-
Size n,
|
148 |
-
OutputIterator result)
|
149 |
-
{
|
150 |
-
OutputIterator ret = result;
|
151 |
-
if (__THRUST_HAS_CUDART__)
|
152 |
-
{
|
153 |
-
ret = __copy::device_to_device(system, first, first + n, result);
|
154 |
-
}
|
155 |
-
else
|
156 |
-
{
|
157 |
-
#if !__THRUST_HAS_CUDART__
|
158 |
-
ret = thrust::copy_n(cvt_to_seq(derived_cast(system)), first, n, result);
|
159 |
-
#endif
|
160 |
-
}
|
161 |
-
|
162 |
-
return ret;
|
163 |
-
} // end copy_n()
|
164 |
-
#endif
|
165 |
-
|
166 |
-
template <class System1,
|
167 |
-
class System2,
|
168 |
-
class InputIterator,
|
169 |
-
class OutputIterator>
|
170 |
-
OutputIterator __host__
|
171 |
-
copy(cross_system<System1, System2> systems,
|
172 |
-
InputIterator first,
|
173 |
-
InputIterator last,
|
174 |
-
OutputIterator result)
|
175 |
-
{
|
176 |
-
return __copy::cross_system_copy(systems,first,last,result);
|
177 |
-
} // end copy()
|
178 |
-
|
179 |
-
template <class System1,
|
180 |
-
class System2,
|
181 |
-
class InputIterator,
|
182 |
-
class Size,
|
183 |
-
class OutputIterator>
|
184 |
-
OutputIterator __host__
|
185 |
-
copy_n(cross_system<System1, System2> systems,
|
186 |
-
InputIterator first,
|
187 |
-
Size n,
|
188 |
-
OutputIterator result)
|
189 |
-
{
|
190 |
-
return __copy::cross_system_copy_n(systems, first, n, result);
|
191 |
-
} // end copy_n()
|
192 |
-
|
193 |
-
|
194 |
-
} // namespace cuda_cub
|
195 |
-
} // end namespace thrust
|
196 |
-
|
197 |
-
#include <thrust/memory.h>
|
198 |
-
#include <thrust/detail/temporary_array.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CVPR/LIVE/thrust/thrust/system/cuda/detail/remove.h
DELETED
@@ -1,134 +0,0 @@
|
|
1 |
-
/******************************************************************************
|
2 |
-
* Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
|
3 |
-
*
|
4 |
-
* Redistribution and use in source and binary forms, with or without
|
5 |
-
* modification, are permitted provided that the following conditions are met:
|
6 |
-
* * Redistributions of source code must retain the above copyright
|
7 |
-
* notice, this list of conditions and the following disclaimer.
|
8 |
-
* * Redistributions in binary form must reproduce the above copyright
|
9 |
-
* notice, this list of conditions and the following disclaimer in the
|
10 |
-
* documentation and/or other materials provided with the distribution.
|
11 |
-
* * Neither the name of the NVIDIA CORPORATION nor the
|
12 |
-
* names of its contributors may be used to endorse or promote products
|
13 |
-
* derived from this software without specific prior written permission.
|
14 |
-
*
|
15 |
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16 |
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17 |
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
18 |
-
* ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
|
19 |
-
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20 |
-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21 |
-
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22 |
-
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23 |
-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24 |
-
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25 |
-
*
|
26 |
-
******************************************************************************/
|
27 |
-
#pragma once
|
28 |
-
|
29 |
-
|
30 |
-
#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC
|
31 |
-
#include <thrust/system/cuda/detail/copy_if.h>
|
32 |
-
|
33 |
-
namespace thrust
|
34 |
-
{
|
35 |
-
namespace cuda_cub {
|
36 |
-
|
37 |
-
// in-place
|
38 |
-
|
39 |
-
template <class Derived,
|
40 |
-
class InputIt,
|
41 |
-
class StencilIt,
|
42 |
-
class Predicate>
|
43 |
-
InputIt __host__ __device__
|
44 |
-
remove_if(execution_policy<Derived> &policy,
|
45 |
-
InputIt first,
|
46 |
-
InputIt last,
|
47 |
-
StencilIt stencil,
|
48 |
-
Predicate predicate)
|
49 |
-
{
|
50 |
-
return cuda_cub::copy_if(policy, first, last, stencil, first,
|
51 |
-
thrust::detail::not1(predicate));
|
52 |
-
}
|
53 |
-
|
54 |
-
template <class Derived,
|
55 |
-
class InputIt,
|
56 |
-
class Predicate>
|
57 |
-
InputIt __host__ __device__
|
58 |
-
remove_if(execution_policy<Derived> &policy,
|
59 |
-
InputIt first,
|
60 |
-
InputIt last,
|
61 |
-
Predicate predicate)
|
62 |
-
{
|
63 |
-
return cuda_cub::copy_if(policy, first, last, first,
|
64 |
-
thrust::detail::not1(predicate));
|
65 |
-
}
|
66 |
-
|
67 |
-
|
68 |
-
template <class Derived,
|
69 |
-
class InputIt,
|
70 |
-
class T>
|
71 |
-
InputIt __host__ __device__
|
72 |
-
remove(execution_policy<Derived> &policy,
|
73 |
-
InputIt first,
|
74 |
-
InputIt last,
|
75 |
-
const T & value)
|
76 |
-
{
|
77 |
-
using thrust::placeholders::_1;
|
78 |
-
|
79 |
-
return cuda_cub::remove_if(policy, first, last, _1 == value);
|
80 |
-
}
|
81 |
-
|
82 |
-
// copy
|
83 |
-
|
84 |
-
template <class Derived,
|
85 |
-
class InputIt,
|
86 |
-
class StencilIt,
|
87 |
-
class OutputIt,
|
88 |
-
class Predicate>
|
89 |
-
OutputIt __host__ __device__
|
90 |
-
remove_copy_if(execution_policy<Derived> &policy,
|
91 |
-
InputIt first,
|
92 |
-
InputIt last,
|
93 |
-
StencilIt stencil,
|
94 |
-
OutputIt result,
|
95 |
-
Predicate predicate)
|
96 |
-
{
|
97 |
-
return cuda_cub::copy_if(policy, first, last, stencil, result,
|
98 |
-
thrust::detail::not1(predicate));
|
99 |
-
}
|
100 |
-
|
101 |
-
template <class Derived,
|
102 |
-
class InputIt,
|
103 |
-
class OutputIt,
|
104 |
-
class Predicate>
|
105 |
-
OutputIt __host__ __device__
|
106 |
-
remove_copy_if(execution_policy<Derived> &policy,
|
107 |
-
InputIt first,
|
108 |
-
InputIt last,
|
109 |
-
OutputIt result,
|
110 |
-
Predicate predicate)
|
111 |
-
{
|
112 |
-
return cuda_cub::copy_if(policy, first, last, result,
|
113 |
-
thrust::detail::not1(predicate));
|
114 |
-
}
|
115 |
-
|
116 |
-
|
117 |
-
template <class Derived,
|
118 |
-
class InputIt,
|
119 |
-
class OutputIt,
|
120 |
-
class T>
|
121 |
-
OutputIt __host__ __device__
|
122 |
-
remove_copy(execution_policy<Derived> &policy,
|
123 |
-
InputIt first,
|
124 |
-
InputIt last,
|
125 |
-
OutputIt result,
|
126 |
-
const T & value)
|
127 |
-
{
|
128 |
-
thrust::detail::equal_to_value<T> pred(value);
|
129 |
-
return cuda_cub::remove_copy_if(policy, first, last, result, pred);
|
130 |
-
}
|
131 |
-
|
132 |
-
} // namespace cuda_cub
|
133 |
-
} // end namespace thrust
|
134 |
-
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CVPR/WALT/mmdet/models/dense_heads/base_dense_head.py
DELETED
@@ -1,59 +0,0 @@
|
|
1 |
-
from abc import ABCMeta, abstractmethod
|
2 |
-
|
3 |
-
import torch.nn as nn
|
4 |
-
|
5 |
-
|
6 |
-
class BaseDenseHead(nn.Module, metaclass=ABCMeta):
|
7 |
-
"""Base class for DenseHeads."""
|
8 |
-
|
9 |
-
def __init__(self):
|
10 |
-
super(BaseDenseHead, self).__init__()
|
11 |
-
|
12 |
-
@abstractmethod
|
13 |
-
def loss(self, **kwargs):
|
14 |
-
"""Compute losses of the head."""
|
15 |
-
pass
|
16 |
-
|
17 |
-
@abstractmethod
|
18 |
-
def get_bboxes(self, **kwargs):
|
19 |
-
"""Transform network output for a batch into bbox predictions."""
|
20 |
-
pass
|
21 |
-
|
22 |
-
def forward_train(self,
|
23 |
-
x,
|
24 |
-
img_metas,
|
25 |
-
gt_bboxes,
|
26 |
-
gt_labels=None,
|
27 |
-
gt_bboxes_ignore=None,
|
28 |
-
proposal_cfg=None,
|
29 |
-
**kwargs):
|
30 |
-
"""
|
31 |
-
Args:
|
32 |
-
x (list[Tensor]): Features from FPN.
|
33 |
-
img_metas (list[dict]): Meta information of each image, e.g.,
|
34 |
-
image size, scaling factor, etc.
|
35 |
-
gt_bboxes (Tensor): Ground truth bboxes of the image,
|
36 |
-
shape (num_gts, 4).
|
37 |
-
gt_labels (Tensor): Ground truth labels of each box,
|
38 |
-
shape (num_gts,).
|
39 |
-
gt_bboxes_ignore (Tensor): Ground truth bboxes to be
|
40 |
-
ignored, shape (num_ignored_gts, 4).
|
41 |
-
proposal_cfg (mmcv.Config): Test / postprocessing configuration,
|
42 |
-
if None, test_cfg would be used
|
43 |
-
|
44 |
-
Returns:
|
45 |
-
tuple:
|
46 |
-
losses: (dict[str, Tensor]): A dictionary of loss components.
|
47 |
-
proposal_list (list[Tensor]): Proposals of each image.
|
48 |
-
"""
|
49 |
-
outs = self(x)
|
50 |
-
if gt_labels is None:
|
51 |
-
loss_inputs = outs + (gt_bboxes, img_metas)
|
52 |
-
else:
|
53 |
-
loss_inputs = outs + (gt_bboxes, gt_labels, img_metas)
|
54 |
-
losses = self.loss(*loss_inputs, gt_bboxes_ignore=gt_bboxes_ignore)
|
55 |
-
if proposal_cfg is None:
|
56 |
-
return losses
|
57 |
-
else:
|
58 |
-
proposal_list = self.get_bboxes(*outs, img_metas, cfg=proposal_cfg)
|
59 |
-
return losses, proposal_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CVPR/WALT/mmdet/utils/optimizer.py
DELETED
@@ -1,33 +0,0 @@
|
|
1 |
-
from mmcv.runner import OptimizerHook, HOOKS
|
2 |
-
try:
|
3 |
-
import apex
|
4 |
-
except:
|
5 |
-
print('apex is not installed')
|
6 |
-
|
7 |
-
|
8 |
-
@HOOKS.register_module()
|
9 |
-
class DistOptimizerHook(OptimizerHook):
|
10 |
-
"""Optimizer hook for distributed training."""
|
11 |
-
|
12 |
-
def __init__(self, update_interval=1, grad_clip=None, coalesce=True, bucket_size_mb=-1, use_fp16=False):
|
13 |
-
self.grad_clip = grad_clip
|
14 |
-
self.coalesce = coalesce
|
15 |
-
self.bucket_size_mb = bucket_size_mb
|
16 |
-
self.update_interval = update_interval
|
17 |
-
self.use_fp16 = use_fp16
|
18 |
-
|
19 |
-
def before_run(self, runner):
|
20 |
-
runner.optimizer.zero_grad()
|
21 |
-
|
22 |
-
def after_train_iter(self, runner):
|
23 |
-
runner.outputs['loss'] /= self.update_interval
|
24 |
-
if self.use_fp16:
|
25 |
-
with apex.amp.scale_loss(runner.outputs['loss'], runner.optimizer) as scaled_loss:
|
26 |
-
scaled_loss.backward()
|
27 |
-
else:
|
28 |
-
runner.outputs['loss'].backward()
|
29 |
-
if self.every_n_iters(runner, self.update_interval):
|
30 |
-
if self.grad_clip is not None:
|
31 |
-
self.clip_grads(runner.model.parameters())
|
32 |
-
runner.optimizer.step()
|
33 |
-
runner.optimizer.zero_grad()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Caoyunkang/Segment-Any-Anomaly/GroundingDINO/groundingdino/models/GroundingDINO/fuse_modules.py
DELETED
@@ -1,297 +0,0 @@
|
|
1 |
-
# ------------------------------------------------------------------------
|
2 |
-
# Grounding DINO
|
3 |
-
# url: https://github.com/IDEA-Research/GroundingDINO
|
4 |
-
# Copyright (c) 2023 IDEA. All Rights Reserved.
|
5 |
-
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
|
6 |
-
# ------------------------------------------------------------------------
|
7 |
-
|
8 |
-
import torch
|
9 |
-
import torch.nn as nn
|
10 |
-
import torch.nn.functional as F
|
11 |
-
from timm.models.layers import DropPath
|
12 |
-
|
13 |
-
|
14 |
-
class FeatureResizer(nn.Module):
|
15 |
-
"""
|
16 |
-
This class takes as input a set of embeddings of dimension C1 and outputs a set of
|
17 |
-
embedding of dimension C2, after a linear transformation, dropout and normalization (LN).
|
18 |
-
"""
|
19 |
-
|
20 |
-
def __init__(self, input_feat_size, output_feat_size, dropout, do_ln=True):
|
21 |
-
super().__init__()
|
22 |
-
self.do_ln = do_ln
|
23 |
-
# Object feature encoding
|
24 |
-
self.fc = nn.Linear(input_feat_size, output_feat_size, bias=True)
|
25 |
-
self.layer_norm = nn.LayerNorm(output_feat_size, eps=1e-12)
|
26 |
-
self.dropout = nn.Dropout(dropout)
|
27 |
-
|
28 |
-
def forward(self, encoder_features):
|
29 |
-
x = self.fc(encoder_features)
|
30 |
-
if self.do_ln:
|
31 |
-
x = self.layer_norm(x)
|
32 |
-
output = self.dropout(x)
|
33 |
-
return output
|
34 |
-
|
35 |
-
|
36 |
-
def l1norm(X, dim, eps=1e-8):
|
37 |
-
"""L1-normalize columns of X"""
|
38 |
-
norm = torch.abs(X).sum(dim=dim, keepdim=True) + eps
|
39 |
-
X = torch.div(X, norm)
|
40 |
-
return X
|
41 |
-
|
42 |
-
|
43 |
-
def l2norm(X, dim, eps=1e-8):
|
44 |
-
"""L2-normalize columns of X"""
|
45 |
-
norm = torch.pow(X, 2).sum(dim=dim, keepdim=True).sqrt() + eps
|
46 |
-
X = torch.div(X, norm)
|
47 |
-
return X
|
48 |
-
|
49 |
-
|
50 |
-
def func_attention(query, context, smooth=1, raw_feature_norm="softmax", eps=1e-8):
|
51 |
-
"""
|
52 |
-
query: (n_context, queryL, d)
|
53 |
-
context: (n_context, sourceL, d)
|
54 |
-
"""
|
55 |
-
batch_size_q, queryL = query.size(0), query.size(1)
|
56 |
-
batch_size, sourceL = context.size(0), context.size(1)
|
57 |
-
|
58 |
-
# Get attention
|
59 |
-
# --> (batch, d, queryL)
|
60 |
-
queryT = torch.transpose(query, 1, 2)
|
61 |
-
|
62 |
-
# (batch, sourceL, d)(batch, d, queryL)
|
63 |
-
# --> (batch, sourceL, queryL)
|
64 |
-
attn = torch.bmm(context, queryT)
|
65 |
-
if raw_feature_norm == "softmax":
|
66 |
-
# --> (batch*sourceL, queryL)
|
67 |
-
attn = attn.view(batch_size * sourceL, queryL)
|
68 |
-
attn = nn.Softmax()(attn)
|
69 |
-
# --> (batch, sourceL, queryL)
|
70 |
-
attn = attn.view(batch_size, sourceL, queryL)
|
71 |
-
elif raw_feature_norm == "l2norm":
|
72 |
-
attn = l2norm(attn, 2)
|
73 |
-
elif raw_feature_norm == "clipped_l2norm":
|
74 |
-
attn = nn.LeakyReLU(0.1)(attn)
|
75 |
-
attn = l2norm(attn, 2)
|
76 |
-
else:
|
77 |
-
raise ValueError("unknown first norm type:", raw_feature_norm)
|
78 |
-
# --> (batch, queryL, sourceL)
|
79 |
-
attn = torch.transpose(attn, 1, 2).contiguous()
|
80 |
-
# --> (batch*queryL, sourceL)
|
81 |
-
attn = attn.view(batch_size * queryL, sourceL)
|
82 |
-
attn = nn.Softmax()(attn * smooth)
|
83 |
-
# --> (batch, queryL, sourceL)
|
84 |
-
attn = attn.view(batch_size, queryL, sourceL)
|
85 |
-
# --> (batch, sourceL, queryL)
|
86 |
-
attnT = torch.transpose(attn, 1, 2).contiguous()
|
87 |
-
|
88 |
-
# --> (batch, d, sourceL)
|
89 |
-
contextT = torch.transpose(context, 1, 2)
|
90 |
-
# (batch x d x sourceL)(batch x sourceL x queryL)
|
91 |
-
# --> (batch, d, queryL)
|
92 |
-
weightedContext = torch.bmm(contextT, attnT)
|
93 |
-
# --> (batch, queryL, d)
|
94 |
-
weightedContext = torch.transpose(weightedContext, 1, 2)
|
95 |
-
|
96 |
-
return weightedContext, attnT
|
97 |
-
|
98 |
-
|
99 |
-
class BiMultiHeadAttention(nn.Module):
|
100 |
-
def __init__(self, v_dim, l_dim, embed_dim, num_heads, dropout=0.1, cfg=None):
|
101 |
-
super(BiMultiHeadAttention, self).__init__()
|
102 |
-
|
103 |
-
self.embed_dim = embed_dim
|
104 |
-
self.num_heads = num_heads
|
105 |
-
self.head_dim = embed_dim // num_heads
|
106 |
-
self.v_dim = v_dim
|
107 |
-
self.l_dim = l_dim
|
108 |
-
|
109 |
-
assert (
|
110 |
-
self.head_dim * self.num_heads == self.embed_dim
|
111 |
-
), f"embed_dim must be divisible by num_heads (got `embed_dim`: {self.embed_dim} and `num_heads`: {self.num_heads})."
|
112 |
-
self.scale = self.head_dim ** (-0.5)
|
113 |
-
self.dropout = dropout
|
114 |
-
|
115 |
-
self.v_proj = nn.Linear(self.v_dim, self.embed_dim)
|
116 |
-
self.l_proj = nn.Linear(self.l_dim, self.embed_dim)
|
117 |
-
self.values_v_proj = nn.Linear(self.v_dim, self.embed_dim)
|
118 |
-
self.values_l_proj = nn.Linear(self.l_dim, self.embed_dim)
|
119 |
-
|
120 |
-
self.out_v_proj = nn.Linear(self.embed_dim, self.v_dim)
|
121 |
-
self.out_l_proj = nn.Linear(self.embed_dim, self.l_dim)
|
122 |
-
|
123 |
-
self.stable_softmax_2d = True
|
124 |
-
self.clamp_min_for_underflow = True
|
125 |
-
self.clamp_max_for_overflow = True
|
126 |
-
|
127 |
-
self._reset_parameters()
|
128 |
-
|
129 |
-
def _shape(self, tensor: torch.Tensor, seq_len: int, bsz: int):
|
130 |
-
return tensor.view(bsz, seq_len, self.num_heads, self.head_dim).transpose(1, 2).contiguous()
|
131 |
-
|
132 |
-
def _reset_parameters(self):
|
133 |
-
nn.init.xavier_uniform_(self.v_proj.weight)
|
134 |
-
self.v_proj.bias.data.fill_(0)
|
135 |
-
nn.init.xavier_uniform_(self.l_proj.weight)
|
136 |
-
self.l_proj.bias.data.fill_(0)
|
137 |
-
nn.init.xavier_uniform_(self.values_v_proj.weight)
|
138 |
-
self.values_v_proj.bias.data.fill_(0)
|
139 |
-
nn.init.xavier_uniform_(self.values_l_proj.weight)
|
140 |
-
self.values_l_proj.bias.data.fill_(0)
|
141 |
-
nn.init.xavier_uniform_(self.out_v_proj.weight)
|
142 |
-
self.out_v_proj.bias.data.fill_(0)
|
143 |
-
nn.init.xavier_uniform_(self.out_l_proj.weight)
|
144 |
-
self.out_l_proj.bias.data.fill_(0)
|
145 |
-
|
146 |
-
def forward(self, v, l, attention_mask_v=None, attention_mask_l=None):
|
147 |
-
"""_summary_
|
148 |
-
|
149 |
-
Args:
|
150 |
-
v (_type_): bs, n_img, dim
|
151 |
-
l (_type_): bs, n_text, dim
|
152 |
-
attention_mask_v (_type_, optional): _description_. bs, n_img
|
153 |
-
attention_mask_l (_type_, optional): _description_. bs, n_text
|
154 |
-
|
155 |
-
Returns:
|
156 |
-
_type_: _description_
|
157 |
-
"""
|
158 |
-
# if os.environ.get('IPDB_SHILONG_DEBUG', None) == 'INFO':
|
159 |
-
# import ipdb; ipdb.set_trace()
|
160 |
-
bsz, tgt_len, _ = v.size()
|
161 |
-
|
162 |
-
query_states = self.v_proj(v) * self.scale
|
163 |
-
key_states = self._shape(self.l_proj(l), -1, bsz)
|
164 |
-
value_v_states = self._shape(self.values_v_proj(v), -1, bsz)
|
165 |
-
value_l_states = self._shape(self.values_l_proj(l), -1, bsz)
|
166 |
-
|
167 |
-
proj_shape = (bsz * self.num_heads, -1, self.head_dim)
|
168 |
-
query_states = self._shape(query_states, tgt_len, bsz).view(*proj_shape)
|
169 |
-
key_states = key_states.view(*proj_shape)
|
170 |
-
value_v_states = value_v_states.view(*proj_shape)
|
171 |
-
value_l_states = value_l_states.view(*proj_shape)
|
172 |
-
|
173 |
-
src_len = key_states.size(1)
|
174 |
-
attn_weights = torch.bmm(query_states, key_states.transpose(1, 2)) # bs*nhead, nimg, ntxt
|
175 |
-
|
176 |
-
if attn_weights.size() != (bsz * self.num_heads, tgt_len, src_len):
|
177 |
-
raise ValueError(
|
178 |
-
f"Attention weights should be of size {(bsz * self.num_heads, tgt_len, src_len)}, but is {attn_weights.size()}"
|
179 |
-
)
|
180 |
-
|
181 |
-
if self.stable_softmax_2d:
|
182 |
-
attn_weights = attn_weights - attn_weights.max()
|
183 |
-
|
184 |
-
if self.clamp_min_for_underflow:
|
185 |
-
attn_weights = torch.clamp(
|
186 |
-
attn_weights, min=-50000
|
187 |
-
) # Do not increase -50000, data type half has quite limited range
|
188 |
-
if self.clamp_max_for_overflow:
|
189 |
-
attn_weights = torch.clamp(
|
190 |
-
attn_weights, max=50000
|
191 |
-
) # Do not increase 50000, data type half has quite limited range
|
192 |
-
|
193 |
-
attn_weights_T = attn_weights.transpose(1, 2)
|
194 |
-
attn_weights_l = attn_weights_T - torch.max(attn_weights_T, dim=-1, keepdim=True)[0]
|
195 |
-
if self.clamp_min_for_underflow:
|
196 |
-
attn_weights_l = torch.clamp(
|
197 |
-
attn_weights_l, min=-50000
|
198 |
-
) # Do not increase -50000, data type half has quite limited range
|
199 |
-
if self.clamp_max_for_overflow:
|
200 |
-
attn_weights_l = torch.clamp(
|
201 |
-
attn_weights_l, max=50000
|
202 |
-
) # Do not increase 50000, data type half has quite limited range
|
203 |
-
|
204 |
-
# mask vison for language
|
205 |
-
if attention_mask_v is not None:
|
206 |
-
attention_mask_v = (
|
207 |
-
attention_mask_v[:, None, None, :].repeat(1, self.num_heads, 1, 1).flatten(0, 1)
|
208 |
-
)
|
209 |
-
attn_weights_l.masked_fill_(attention_mask_v, float("-inf"))
|
210 |
-
|
211 |
-
attn_weights_l = attn_weights_l.softmax(dim=-1)
|
212 |
-
|
213 |
-
# mask language for vision
|
214 |
-
if attention_mask_l is not None:
|
215 |
-
attention_mask_l = (
|
216 |
-
attention_mask_l[:, None, None, :].repeat(1, self.num_heads, 1, 1).flatten(0, 1)
|
217 |
-
)
|
218 |
-
attn_weights.masked_fill_(attention_mask_l, float("-inf"))
|
219 |
-
attn_weights_v = attn_weights.softmax(dim=-1)
|
220 |
-
|
221 |
-
attn_probs_v = F.dropout(attn_weights_v, p=self.dropout, training=self.training)
|
222 |
-
attn_probs_l = F.dropout(attn_weights_l, p=self.dropout, training=self.training)
|
223 |
-
|
224 |
-
attn_output_v = torch.bmm(attn_probs_v, value_l_states)
|
225 |
-
attn_output_l = torch.bmm(attn_probs_l, value_v_states)
|
226 |
-
|
227 |
-
if attn_output_v.size() != (bsz * self.num_heads, tgt_len, self.head_dim):
|
228 |
-
raise ValueError(
|
229 |
-
f"`attn_output_v` should be of size {(bsz, self.num_heads, tgt_len, self.head_dim)}, but is {attn_output_v.size()}"
|
230 |
-
)
|
231 |
-
|
232 |
-
if attn_output_l.size() != (bsz * self.num_heads, src_len, self.head_dim):
|
233 |
-
raise ValueError(
|
234 |
-
f"`attn_output_l` should be of size {(bsz, self.num_heads, src_len, self.head_dim)}, but is {attn_output_l.size()}"
|
235 |
-
)
|
236 |
-
|
237 |
-
attn_output_v = attn_output_v.view(bsz, self.num_heads, tgt_len, self.head_dim)
|
238 |
-
attn_output_v = attn_output_v.transpose(1, 2)
|
239 |
-
attn_output_v = attn_output_v.reshape(bsz, tgt_len, self.embed_dim)
|
240 |
-
|
241 |
-
attn_output_l = attn_output_l.view(bsz, self.num_heads, src_len, self.head_dim)
|
242 |
-
attn_output_l = attn_output_l.transpose(1, 2)
|
243 |
-
attn_output_l = attn_output_l.reshape(bsz, src_len, self.embed_dim)
|
244 |
-
|
245 |
-
attn_output_v = self.out_v_proj(attn_output_v)
|
246 |
-
attn_output_l = self.out_l_proj(attn_output_l)
|
247 |
-
|
248 |
-
return attn_output_v, attn_output_l
|
249 |
-
|
250 |
-
|
251 |
-
# Bi-Direction MHA (text->image, image->text)
|
252 |
-
class BiAttentionBlock(nn.Module):
|
253 |
-
def __init__(
|
254 |
-
self,
|
255 |
-
v_dim,
|
256 |
-
l_dim,
|
257 |
-
embed_dim,
|
258 |
-
num_heads,
|
259 |
-
dropout=0.1,
|
260 |
-
drop_path=0.0,
|
261 |
-
init_values=1e-4,
|
262 |
-
cfg=None,
|
263 |
-
):
|
264 |
-
"""
|
265 |
-
Inputs:
|
266 |
-
embed_dim - Dimensionality of input and attention feature vectors
|
267 |
-
hidden_dim - Dimensionality of hidden layer in feed-forward network
|
268 |
-
(usually 2-4x larger than embed_dim)
|
269 |
-
num_heads - Number of heads to use in the Multi-Head Attention block
|
270 |
-
dropout - Amount of dropout to apply in the feed-forward network
|
271 |
-
"""
|
272 |
-
super(BiAttentionBlock, self).__init__()
|
273 |
-
|
274 |
-
# pre layer norm
|
275 |
-
self.layer_norm_v = nn.LayerNorm(v_dim)
|
276 |
-
self.layer_norm_l = nn.LayerNorm(l_dim)
|
277 |
-
self.attn = BiMultiHeadAttention(
|
278 |
-
v_dim=v_dim, l_dim=l_dim, embed_dim=embed_dim, num_heads=num_heads, dropout=dropout
|
279 |
-
)
|
280 |
-
|
281 |
-
# add layer scale for training stability
|
282 |
-
self.drop_path = DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
|
283 |
-
self.gamma_v = nn.Parameter(init_values * torch.ones((v_dim)), requires_grad=True)
|
284 |
-
self.gamma_l = nn.Parameter(init_values * torch.ones((l_dim)), requires_grad=True)
|
285 |
-
|
286 |
-
def forward(self, v, l, attention_mask_v=None, attention_mask_l=None):
|
287 |
-
v = self.layer_norm_v(v)
|
288 |
-
l = self.layer_norm_l(l)
|
289 |
-
delta_v, delta_l = self.attn(
|
290 |
-
v, l, attention_mask_v=attention_mask_v, attention_mask_l=attention_mask_l
|
291 |
-
)
|
292 |
-
# v, l = v + delta_v, l + delta_l
|
293 |
-
v = v + self.drop_path(self.gamma_v * delta_v)
|
294 |
-
l = l + self.drop_path(self.gamma_l * delta_l)
|
295 |
-
return v, l
|
296 |
-
|
297 |
-
# def forward(self, v:List[torch.Tensor], l, attention_mask_v=None, attention_mask_l=None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Caoyunkang/Segment-Any-Anomaly/README.md
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
---
|
2 |
-
title: Segment Any Anomaly
|
3 |
-
emoji: 🐨
|
4 |
-
colorFrom: blue
|
5 |
-
colorTo: red
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 3.32.0
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: mit
|
11 |
-
---
|
12 |
-
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CikeyQI/meme-api/meme_generator/memes/capoo_say/__init__.py
DELETED
@@ -1,67 +0,0 @@
|
|
1 |
-
from pathlib import Path
|
2 |
-
from typing import List
|
3 |
-
|
4 |
-
from PIL.Image import Image as IMG
|
5 |
-
from pil_utils import BuildImage
|
6 |
-
|
7 |
-
from meme_generator import add_meme
|
8 |
-
from meme_generator.exception import TextOverLength
|
9 |
-
from meme_generator.utils import save_gif
|
10 |
-
|
11 |
-
img_dir = Path(__file__).parent / "images"
|
12 |
-
|
13 |
-
|
14 |
-
def capoo_say_one_loop(text: str) -> List[IMG]:
|
15 |
-
text_frame = BuildImage.new("RGBA", (80, 80))
|
16 |
-
try:
|
17 |
-
text_frame.draw_text(
|
18 |
-
(0, 0, 80, 80),
|
19 |
-
text,
|
20 |
-
max_fontsize=80,
|
21 |
-
min_fontsize=20,
|
22 |
-
allow_wrap=True,
|
23 |
-
fontname="FZKaTong-M19S",
|
24 |
-
lines_align="center",
|
25 |
-
)
|
26 |
-
except ValueError:
|
27 |
-
raise TextOverLength(text)
|
28 |
-
|
29 |
-
params = [
|
30 |
-
None,
|
31 |
-
None,
|
32 |
-
None,
|
33 |
-
(45, 45, 74, 112, 25),
|
34 |
-
(73, 73, 41, 42, 17),
|
35 |
-
(80, 80, 43, 36, 0),
|
36 |
-
(80, 80, 43, 30, 0),
|
37 |
-
(78, 78, 44, 30, 0),
|
38 |
-
(78, 78, 44, 29, 0),
|
39 |
-
None,
|
40 |
-
]
|
41 |
-
|
42 |
-
frames: List[IMG] = []
|
43 |
-
for i in range(10):
|
44 |
-
frame = BuildImage.open(img_dir / f"{i}.png")
|
45 |
-
param = params[i]
|
46 |
-
if param:
|
47 |
-
x, y, w, h, angle = param
|
48 |
-
frame.paste(
|
49 |
-
text_frame.resize((x, y)).rotate(angle, expand=True), (w, h), alpha=True
|
50 |
-
)
|
51 |
-
frames.append(frame.image)
|
52 |
-
return frames
|
53 |
-
|
54 |
-
|
55 |
-
def capoo_say(images, texts: List[str], args):
|
56 |
-
frames = sum([capoo_say_one_loop(text) for text in texts], [])
|
57 |
-
return save_gif(frames, 0.1)
|
58 |
-
|
59 |
-
|
60 |
-
add_meme(
|
61 |
-
"capoo_say",
|
62 |
-
capoo_say,
|
63 |
-
min_texts=1,
|
64 |
-
max_texts=10,
|
65 |
-
default_texts=["寄"],
|
66 |
-
keywords=["咖波说"],
|
67 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Clebersla/RVC_V2_Huggingface_Version/app.py
DELETED
@@ -1,2090 +0,0 @@
|
|
1 |
-
import subprocess, torch, os, traceback, sys, warnings, shutil, numpy as np
|
2 |
-
from mega import Mega
|
3 |
-
os.environ["no_proxy"] = "localhost, 127.0.0.1, ::1"
|
4 |
-
import threading
|
5 |
-
from time import sleep
|
6 |
-
from subprocess import Popen
|
7 |
-
import faiss
|
8 |
-
from random import shuffle
|
9 |
-
import json, datetime, requests
|
10 |
-
from gtts import gTTS
|
11 |
-
now_dir = os.getcwd()
|
12 |
-
sys.path.append(now_dir)
|
13 |
-
tmp = os.path.join(now_dir, "TEMP")
|
14 |
-
shutil.rmtree(tmp, ignore_errors=True)
|
15 |
-
shutil.rmtree("%s/runtime/Lib/site-packages/infer_pack" % (now_dir), ignore_errors=True)
|
16 |
-
os.makedirs(tmp, exist_ok=True)
|
17 |
-
os.makedirs(os.path.join(now_dir, "logs"), exist_ok=True)
|
18 |
-
os.makedirs(os.path.join(now_dir, "weights"), exist_ok=True)
|
19 |
-
os.environ["TEMP"] = tmp
|
20 |
-
warnings.filterwarnings("ignore")
|
21 |
-
torch.manual_seed(114514)
|
22 |
-
from i18n import I18nAuto
|
23 |
-
|
24 |
-
import signal
|
25 |
-
|
26 |
-
import math
|
27 |
-
|
28 |
-
from utils import load_audio, CSVutil
|
29 |
-
|
30 |
-
global DoFormant, Quefrency, Timbre
|
31 |
-
|
32 |
-
if not os.path.isdir('csvdb/'):
|
33 |
-
os.makedirs('csvdb')
|
34 |
-
frmnt, stp = open("csvdb/formanting.csv", 'w'), open("csvdb/stop.csv", 'w')
|
35 |
-
frmnt.close()
|
36 |
-
stp.close()
|
37 |
-
|
38 |
-
try:
|
39 |
-
DoFormant, Quefrency, Timbre = CSVutil('csvdb/formanting.csv', 'r', 'formanting')
|
40 |
-
DoFormant = (
|
41 |
-
lambda DoFormant: True if DoFormant.lower() == 'true' else (False if DoFormant.lower() == 'false' else DoFormant)
|
42 |
-
)(DoFormant)
|
43 |
-
except (ValueError, TypeError, IndexError):
|
44 |
-
DoFormant, Quefrency, Timbre = False, 1.0, 1.0
|
45 |
-
CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, Quefrency, Timbre)
|
46 |
-
|
47 |
-
def download_models():
|
48 |
-
# Download hubert base model if not present
|
49 |
-
if not os.path.isfile('./hubert_base.pt'):
|
50 |
-
response = requests.get('https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/hubert_base.pt')
|
51 |
-
|
52 |
-
if response.status_code == 200:
|
53 |
-
with open('./hubert_base.pt', 'wb') as f:
|
54 |
-
f.write(response.content)
|
55 |
-
print("Downloaded hubert base model file successfully. File saved to ./hubert_base.pt.")
|
56 |
-
else:
|
57 |
-
raise Exception("Failed to download hubert base model file. Status code: " + str(response.status_code) + ".")
|
58 |
-
|
59 |
-
# Download rmvpe model if not present
|
60 |
-
if not os.path.isfile('./rmvpe.pt'):
|
61 |
-
response = requests.get('https://drive.usercontent.google.com/download?id=1Hkn4kNuVFRCNQwyxQFRtmzmMBGpQxptI&export=download&authuser=0&confirm=t&uuid=0b3a40de-465b-4c65-8c41-135b0b45c3f7&at=APZUnTV3lA3LnyTbeuduura6Dmi2:1693724254058')
|
62 |
-
|
63 |
-
if response.status_code == 200:
|
64 |
-
with open('./rmvpe.pt', 'wb') as f:
|
65 |
-
f.write(response.content)
|
66 |
-
print("Downloaded rmvpe model file successfully. File saved to ./rmvpe.pt.")
|
67 |
-
else:
|
68 |
-
raise Exception("Failed to download rmvpe model file. Status code: " + str(response.status_code) + ".")
|
69 |
-
|
70 |
-
download_models()
|
71 |
-
|
72 |
-
print("\n-------------------------------\nRVC v2 Easy GUI (Local Edition)\n-------------------------------\n")
|
73 |
-
|
74 |
-
def formant_apply(qfrency, tmbre):
|
75 |
-
Quefrency = qfrency
|
76 |
-
Timbre = tmbre
|
77 |
-
DoFormant = True
|
78 |
-
CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, qfrency, tmbre)
|
79 |
-
|
80 |
-
return ({"value": Quefrency, "__type__": "update"}, {"value": Timbre, "__type__": "update"})
|
81 |
-
|
82 |
-
def get_fshift_presets():
|
83 |
-
fshift_presets_list = []
|
84 |
-
for dirpath, _, filenames in os.walk("./formantshiftcfg/"):
|
85 |
-
for filename in filenames:
|
86 |
-
if filename.endswith(".txt"):
|
87 |
-
fshift_presets_list.append(os.path.join(dirpath,filename).replace('\\','/'))
|
88 |
-
|
89 |
-
if len(fshift_presets_list) > 0:
|
90 |
-
return fshift_presets_list
|
91 |
-
else:
|
92 |
-
return ''
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
def formant_enabled(cbox, qfrency, tmbre, frmntapply, formantpreset, formant_refresh_button):
|
97 |
-
|
98 |
-
if (cbox):
|
99 |
-
|
100 |
-
DoFormant = True
|
101 |
-
CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, qfrency, tmbre)
|
102 |
-
#print(f"is checked? - {cbox}\ngot {DoFormant}")
|
103 |
-
|
104 |
-
return (
|
105 |
-
{"value": True, "__type__": "update"},
|
106 |
-
{"visible": True, "__type__": "update"},
|
107 |
-
{"visible": True, "__type__": "update"},
|
108 |
-
{"visible": True, "__type__": "update"},
|
109 |
-
{"visible": True, "__type__": "update"},
|
110 |
-
{"visible": True, "__type__": "update"},
|
111 |
-
)
|
112 |
-
|
113 |
-
|
114 |
-
else:
|
115 |
-
|
116 |
-
DoFormant = False
|
117 |
-
CSVutil('csvdb/formanting.csv', 'w+', 'formanting', DoFormant, qfrency, tmbre)
|
118 |
-
|
119 |
-
#print(f"is checked? - {cbox}\ngot {DoFormant}")
|
120 |
-
return (
|
121 |
-
{"value": False, "__type__": "update"},
|
122 |
-
{"visible": False, "__type__": "update"},
|
123 |
-
{"visible": False, "__type__": "update"},
|
124 |
-
{"visible": False, "__type__": "update"},
|
125 |
-
{"visible": False, "__type__": "update"},
|
126 |
-
{"visible": False, "__type__": "update"},
|
127 |
-
{"visible": False, "__type__": "update"},
|
128 |
-
)
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
def preset_apply(preset, qfer, tmbr):
|
133 |
-
if str(preset) != '':
|
134 |
-
with open(str(preset), 'r') as p:
|
135 |
-
content = p.readlines()
|
136 |
-
qfer, tmbr = content[0].split('\n')[0], content[1]
|
137 |
-
|
138 |
-
formant_apply(qfer, tmbr)
|
139 |
-
else:
|
140 |
-
pass
|
141 |
-
return ({"value": qfer, "__type__": "update"}, {"value": tmbr, "__type__": "update"})
|
142 |
-
|
143 |
-
def update_fshift_presets(preset, qfrency, tmbre):
|
144 |
-
|
145 |
-
qfrency, tmbre = preset_apply(preset, qfrency, tmbre)
|
146 |
-
|
147 |
-
if (str(preset) != ''):
|
148 |
-
with open(str(preset), 'r') as p:
|
149 |
-
content = p.readlines()
|
150 |
-
qfrency, tmbre = content[0].split('\n')[0], content[1]
|
151 |
-
|
152 |
-
formant_apply(qfrency, tmbre)
|
153 |
-
else:
|
154 |
-
pass
|
155 |
-
return (
|
156 |
-
{"choices": get_fshift_presets(), "__type__": "update"},
|
157 |
-
{"value": qfrency, "__type__": "update"},
|
158 |
-
{"value": tmbre, "__type__": "update"},
|
159 |
-
)
|
160 |
-
|
161 |
-
i18n = I18nAuto()
|
162 |
-
#i18n.print()
|
163 |
-
# 判断是否有能用来训练和加速推理的N卡
|
164 |
-
ngpu = torch.cuda.device_count()
|
165 |
-
gpu_infos = []
|
166 |
-
mem = []
|
167 |
-
if (not torch.cuda.is_available()) or ngpu == 0:
|
168 |
-
if_gpu_ok = False
|
169 |
-
else:
|
170 |
-
if_gpu_ok = False
|
171 |
-
for i in range(ngpu):
|
172 |
-
gpu_name = torch.cuda.get_device_name(i)
|
173 |
-
if (
|
174 |
-
"10" in gpu_name
|
175 |
-
or "16" in gpu_name
|
176 |
-
or "20" in gpu_name
|
177 |
-
or "30" in gpu_name
|
178 |
-
or "40" in gpu_name
|
179 |
-
or "A2" in gpu_name.upper()
|
180 |
-
or "A3" in gpu_name.upper()
|
181 |
-
or "A4" in gpu_name.upper()
|
182 |
-
or "P4" in gpu_name.upper()
|
183 |
-
or "A50" in gpu_name.upper()
|
184 |
-
or "A60" in gpu_name.upper()
|
185 |
-
or "70" in gpu_name
|
186 |
-
or "80" in gpu_name
|
187 |
-
or "90" in gpu_name
|
188 |
-
or "M4" in gpu_name.upper()
|
189 |
-
or "T4" in gpu_name.upper()
|
190 |
-
or "TITAN" in gpu_name.upper()
|
191 |
-
): # A10#A100#V100#A40#P40#M40#K80#A4500
|
192 |
-
if_gpu_ok = True # 至少有一张能用的N卡
|
193 |
-
gpu_infos.append("%s\t%s" % (i, gpu_name))
|
194 |
-
mem.append(
|
195 |
-
int(
|
196 |
-
torch.cuda.get_device_properties(i).total_memory
|
197 |
-
/ 1024
|
198 |
-
/ 1024
|
199 |
-
/ 1024
|
200 |
-
+ 0.4
|
201 |
-
)
|
202 |
-
)
|
203 |
-
if if_gpu_ok == True and len(gpu_infos) > 0:
|
204 |
-
gpu_info = "\n".join(gpu_infos)
|
205 |
-
default_batch_size = min(mem) // 2
|
206 |
-
else:
|
207 |
-
gpu_info = i18n("很遗憾您这没有能用的显卡来支持您训练")
|
208 |
-
default_batch_size = 1
|
209 |
-
gpus = "-".join([i[0] for i in gpu_infos])
|
210 |
-
from lib.infer_pack.models import (
|
211 |
-
SynthesizerTrnMs256NSFsid,
|
212 |
-
SynthesizerTrnMs256NSFsid_nono,
|
213 |
-
SynthesizerTrnMs768NSFsid,
|
214 |
-
SynthesizerTrnMs768NSFsid_nono,
|
215 |
-
)
|
216 |
-
import soundfile as sf
|
217 |
-
from fairseq import checkpoint_utils
|
218 |
-
import gradio as gr
|
219 |
-
import logging
|
220 |
-
from vc_infer_pipeline import VC
|
221 |
-
from config import Config
|
222 |
-
|
223 |
-
config = Config()
|
224 |
-
# from trainset_preprocess_pipeline import PreProcess
|
225 |
-
logging.getLogger("numba").setLevel(logging.WARNING)
|
226 |
-
|
227 |
-
hubert_model = None
|
228 |
-
|
229 |
-
def load_hubert():
|
230 |
-
global hubert_model
|
231 |
-
models, _, _ = checkpoint_utils.load_model_ensemble_and_task(
|
232 |
-
["hubert_base.pt"],
|
233 |
-
suffix="",
|
234 |
-
)
|
235 |
-
hubert_model = models[0]
|
236 |
-
hubert_model = hubert_model.to(config.device)
|
237 |
-
if config.is_half:
|
238 |
-
hubert_model = hubert_model.half()
|
239 |
-
else:
|
240 |
-
hubert_model = hubert_model.float()
|
241 |
-
hubert_model.eval()
|
242 |
-
|
243 |
-
|
244 |
-
weight_root = "weights"
|
245 |
-
index_root = "logs"
|
246 |
-
names = []
|
247 |
-
for name in os.listdir(weight_root):
|
248 |
-
if name.endswith(".pth"):
|
249 |
-
names.append(name)
|
250 |
-
index_paths = []
|
251 |
-
for root, dirs, files in os.walk(index_root, topdown=False):
|
252 |
-
for name in files:
|
253 |
-
if name.endswith(".index") and "trained" not in name:
|
254 |
-
index_paths.append("%s/%s" % (root, name))
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
def vc_single(
|
259 |
-
sid,
|
260 |
-
input_audio_path,
|
261 |
-
f0_up_key,
|
262 |
-
f0_file,
|
263 |
-
f0_method,
|
264 |
-
file_index,
|
265 |
-
#file_index2,
|
266 |
-
# file_big_npy,
|
267 |
-
index_rate,
|
268 |
-
filter_radius,
|
269 |
-
resample_sr,
|
270 |
-
rms_mix_rate,
|
271 |
-
protect,
|
272 |
-
crepe_hop_length,
|
273 |
-
): # spk_item, input_audio0, vc_transform0,f0_file,f0method0
|
274 |
-
global tgt_sr, net_g, vc, hubert_model, version
|
275 |
-
if input_audio_path is None:
|
276 |
-
return "You need to upload an audio", None
|
277 |
-
f0_up_key = int(f0_up_key)
|
278 |
-
try:
|
279 |
-
audio = load_audio(input_audio_path, 16000, DoFormant, Quefrency, Timbre)
|
280 |
-
audio_max = np.abs(audio).max() / 0.95
|
281 |
-
if audio_max > 1:
|
282 |
-
audio /= audio_max
|
283 |
-
times = [0, 0, 0]
|
284 |
-
if hubert_model == None:
|
285 |
-
load_hubert()
|
286 |
-
if_f0 = cpt.get("f0", 1)
|
287 |
-
file_index = (
|
288 |
-
(
|
289 |
-
file_index.strip(" ")
|
290 |
-
.strip('"')
|
291 |
-
.strip("\n")
|
292 |
-
.strip('"')
|
293 |
-
.strip(" ")
|
294 |
-
.replace("trained", "added")
|
295 |
-
)
|
296 |
-
) # 防止小白写错,自动帮他替换掉
|
297 |
-
# file_big_npy = (
|
298 |
-
# file_big_npy.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
299 |
-
# )
|
300 |
-
audio_opt = vc.pipeline(
|
301 |
-
hubert_model,
|
302 |
-
net_g,
|
303 |
-
sid,
|
304 |
-
audio,
|
305 |
-
input_audio_path,
|
306 |
-
times,
|
307 |
-
f0_up_key,
|
308 |
-
f0_method,
|
309 |
-
file_index,
|
310 |
-
# file_big_npy,
|
311 |
-
index_rate,
|
312 |
-
if_f0,
|
313 |
-
filter_radius,
|
314 |
-
tgt_sr,
|
315 |
-
resample_sr,
|
316 |
-
rms_mix_rate,
|
317 |
-
version,
|
318 |
-
protect,
|
319 |
-
crepe_hop_length,
|
320 |
-
f0_file=f0_file,
|
321 |
-
)
|
322 |
-
if resample_sr >= 16000 and tgt_sr != resample_sr:
|
323 |
-
tgt_sr = resample_sr
|
324 |
-
index_info = (
|
325 |
-
"Using index:%s." % file_index
|
326 |
-
if os.path.exists(file_index)
|
327 |
-
else "Index not used."
|
328 |
-
)
|
329 |
-
return "Success.\n %s\nTime:\n npy:%ss, f0:%ss, infer:%ss" % (
|
330 |
-
index_info,
|
331 |
-
times[0],
|
332 |
-
times[1],
|
333 |
-
times[2],
|
334 |
-
), (tgt_sr, audio_opt)
|
335 |
-
except:
|
336 |
-
info = traceback.format_exc()
|
337 |
-
print(info)
|
338 |
-
return info, (None, None)
|
339 |
-
|
340 |
-
|
341 |
-
def vc_multi(
|
342 |
-
sid,
|
343 |
-
dir_path,
|
344 |
-
opt_root,
|
345 |
-
paths,
|
346 |
-
f0_up_key,
|
347 |
-
f0_method,
|
348 |
-
file_index,
|
349 |
-
file_index2,
|
350 |
-
# file_big_npy,
|
351 |
-
index_rate,
|
352 |
-
filter_radius,
|
353 |
-
resample_sr,
|
354 |
-
rms_mix_rate,
|
355 |
-
protect,
|
356 |
-
format1,
|
357 |
-
crepe_hop_length,
|
358 |
-
):
|
359 |
-
try:
|
360 |
-
dir_path = (
|
361 |
-
dir_path.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
362 |
-
) # 防止小白拷路径头尾带了空格和"和回车
|
363 |
-
opt_root = opt_root.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
|
364 |
-
os.makedirs(opt_root, exist_ok=True)
|
365 |
-
try:
|
366 |
-
if dir_path != "":
|
367 |
-
paths = [os.path.join(dir_path, name) for name in os.listdir(dir_path)]
|
368 |
-
else:
|
369 |
-
paths = [path.name for path in paths]
|
370 |
-
except:
|
371 |
-
traceback.print_exc()
|
372 |
-
paths = [path.name for path in paths]
|
373 |
-
infos = []
|
374 |
-
for path in paths:
|
375 |
-
info, opt = vc_single(
|
376 |
-
sid,
|
377 |
-
path,
|
378 |
-
f0_up_key,
|
379 |
-
None,
|
380 |
-
f0_method,
|
381 |
-
file_index,
|
382 |
-
# file_big_npy,
|
383 |
-
index_rate,
|
384 |
-
filter_radius,
|
385 |
-
resample_sr,
|
386 |
-
rms_mix_rate,
|
387 |
-
protect,
|
388 |
-
crepe_hop_length
|
389 |
-
)
|
390 |
-
if "Success" in info:
|
391 |
-
try:
|
392 |
-
tgt_sr, audio_opt = opt
|
393 |
-
if format1 in ["wav", "flac"]:
|
394 |
-
sf.write(
|
395 |
-
"%s/%s.%s" % (opt_root, os.path.basename(path), format1),
|
396 |
-
audio_opt,
|
397 |
-
tgt_sr,
|
398 |
-
)
|
399 |
-
else:
|
400 |
-
path = "%s/%s.wav" % (opt_root, os.path.basename(path))
|
401 |
-
sf.write(
|
402 |
-
path,
|
403 |
-
audio_opt,
|
404 |
-
tgt_sr,
|
405 |
-
)
|
406 |
-
if os.path.exists(path):
|
407 |
-
os.system(
|
408 |
-
"ffmpeg -i %s -vn %s -q:a 2 -y"
|
409 |
-
% (path, path[:-4] + ".%s" % format1)
|
410 |
-
)
|
411 |
-
except:
|
412 |
-
info += traceback.format_exc()
|
413 |
-
infos.append("%s->%s" % (os.path.basename(path), info))
|
414 |
-
yield "\n".join(infos)
|
415 |
-
yield "\n".join(infos)
|
416 |
-
except:
|
417 |
-
yield traceback.format_exc()
|
418 |
-
|
419 |
-
# 一个选项卡全局只能有一个音色
|
420 |
-
def get_vc(sid):
|
421 |
-
global n_spk, tgt_sr, net_g, vc, cpt, version
|
422 |
-
if sid == "" or sid == []:
|
423 |
-
global hubert_model
|
424 |
-
if hubert_model != None: # 考虑到轮询, 需要加个判断看是否 sid 是由有模型切换到无模型的
|
425 |
-
print("clean_empty_cache")
|
426 |
-
del net_g, n_spk, vc, hubert_model, tgt_sr # ,cpt
|
427 |
-
hubert_model = net_g = n_spk = vc = hubert_model = tgt_sr = None
|
428 |
-
if torch.cuda.is_available():
|
429 |
-
torch.cuda.empty_cache()
|
430 |
-
###楼下不这么折腾清理不干净
|
431 |
-
if_f0 = cpt.get("f0", 1)
|
432 |
-
version = cpt.get("version", "v1")
|
433 |
-
if version == "v1":
|
434 |
-
if if_f0 == 1:
|
435 |
-
net_g = SynthesizerTrnMs256NSFsid(
|
436 |
-
*cpt["config"], is_half=config.is_half
|
437 |
-
)
|
438 |
-
else:
|
439 |
-
net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
|
440 |
-
elif version == "v2":
|
441 |
-
if if_f0 == 1:
|
442 |
-
net_g = SynthesizerTrnMs768NSFsid(
|
443 |
-
*cpt["config"], is_half=config.is_half
|
444 |
-
)
|
445 |
-
else:
|
446 |
-
net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])
|
447 |
-
del net_g, cpt
|
448 |
-
if torch.cuda.is_available():
|
449 |
-
torch.cuda.empty_cache()
|
450 |
-
cpt = None
|
451 |
-
return {"visible": False, "__type__": "update"}
|
452 |
-
person = "%s/%s" % (weight_root, sid)
|
453 |
-
print("loading %s" % person)
|
454 |
-
cpt = torch.load(person, map_location="cpu")
|
455 |
-
tgt_sr = cpt["config"][-1]
|
456 |
-
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
|
457 |
-
if_f0 = cpt.get("f0", 1)
|
458 |
-
version = cpt.get("version", "v1")
|
459 |
-
if version == "v1":
|
460 |
-
if if_f0 == 1:
|
461 |
-
net_g = SynthesizerTrnMs256NSFsid(*cpt["config"], is_half=config.is_half)
|
462 |
-
else:
|
463 |
-
net_g = SynthesizerTrnMs256NSFsid_nono(*cpt["config"])
|
464 |
-
elif version == "v2":
|
465 |
-
if if_f0 == 1:
|
466 |
-
net_g = SynthesizerTrnMs768NSFsid(*cpt["config"], is_half=config.is_half)
|
467 |
-
else:
|
468 |
-
net_g = SynthesizerTrnMs768NSFsid_nono(*cpt["config"])
|
469 |
-
del net_g.enc_q
|
470 |
-
print(net_g.load_state_dict(cpt["weight"], strict=False))
|
471 |
-
net_g.eval().to(config.device)
|
472 |
-
if config.is_half:
|
473 |
-
net_g = net_g.half()
|
474 |
-
else:
|
475 |
-
net_g = net_g.float()
|
476 |
-
vc = VC(tgt_sr, config)
|
477 |
-
n_spk = cpt["config"][-3]
|
478 |
-
return {"visible": False, "maximum": n_spk, "__type__": "update"}
|
479 |
-
|
480 |
-
|
481 |
-
def change_choices():
|
482 |
-
names = []
|
483 |
-
for name in os.listdir(weight_root):
|
484 |
-
if name.endswith(".pth"):
|
485 |
-
names.append(name)
|
486 |
-
index_paths = []
|
487 |
-
for root, dirs, files in os.walk(index_root, topdown=False):
|
488 |
-
for name in files:
|
489 |
-
if name.endswith(".index") and "trained" not in name:
|
490 |
-
index_paths.append("%s/%s" % (root, name))
|
491 |
-
return {"choices": sorted(names), "__type__": "update"}, {
|
492 |
-
"choices": sorted(index_paths),
|
493 |
-
"__type__": "update",
|
494 |
-
}
|
495 |
-
|
496 |
-
|
497 |
-
def clean():
|
498 |
-
return {"value": "", "__type__": "update"}
|
499 |
-
|
500 |
-
|
501 |
-
sr_dict = {
|
502 |
-
"32k": 32000,
|
503 |
-
"40k": 40000,
|
504 |
-
"48k": 48000,
|
505 |
-
}
|
506 |
-
|
507 |
-
|
508 |
-
def if_done(done, p):
|
509 |
-
while 1:
|
510 |
-
if p.poll() == None:
|
511 |
-
sleep(0.5)
|
512 |
-
else:
|
513 |
-
break
|
514 |
-
done[0] = True
|
515 |
-
|
516 |
-
|
517 |
-
def if_done_multi(done, ps):
|
518 |
-
while 1:
|
519 |
-
# poll==None代表进程未结束
|
520 |
-
# 只要有一个进程未结束都不停
|
521 |
-
flag = 1
|
522 |
-
for p in ps:
|
523 |
-
if p.poll() == None:
|
524 |
-
flag = 0
|
525 |
-
sleep(0.5)
|
526 |
-
break
|
527 |
-
if flag == 1:
|
528 |
-
break
|
529 |
-
done[0] = True
|
530 |
-
|
531 |
-
|
532 |
-
def preprocess_dataset(trainset_dir, exp_dir, sr, n_p):
|
533 |
-
sr = sr_dict[sr]
|
534 |
-
os.makedirs("%s/logs/%s" % (now_dir, exp_dir), exist_ok=True)
|
535 |
-
f = open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "w")
|
536 |
-
f.close()
|
537 |
-
cmd = (
|
538 |
-
config.python_cmd
|
539 |
-
+ " trainset_preprocess_pipeline_print.py %s %s %s %s/logs/%s "
|
540 |
-
% (trainset_dir, sr, n_p, now_dir, exp_dir)
|
541 |
-
+ str(config.noparallel)
|
542 |
-
)
|
543 |
-
print(cmd)
|
544 |
-
p = Popen(cmd, shell=True) # , stdin=PIPE, stdout=PIPE,stderr=PIPE,cwd=now_dir
|
545 |
-
###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
|
546 |
-
done = [False]
|
547 |
-
threading.Thread(
|
548 |
-
target=if_done,
|
549 |
-
args=(
|
550 |
-
done,
|
551 |
-
p,
|
552 |
-
),
|
553 |
-
).start()
|
554 |
-
while 1:
|
555 |
-
with open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "r") as f:
|
556 |
-
yield (f.read())
|
557 |
-
sleep(1)
|
558 |
-
if done[0] == True:
|
559 |
-
break
|
560 |
-
with open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "r") as f:
|
561 |
-
log = f.read()
|
562 |
-
print(log)
|
563 |
-
yield log
|
564 |
-
|
565 |
-
# but2.click(extract_f0,[gpus6,np7,f0method8,if_f0_3,trainset_dir4],[info2])
|
566 |
-
def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19, echl):
|
567 |
-
gpus = gpus.split("-")
|
568 |
-
os.makedirs("%s/logs/%s" % (now_dir, exp_dir), exist_ok=True)
|
569 |
-
f = open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "w")
|
570 |
-
f.close()
|
571 |
-
if if_f0:
|
572 |
-
cmd = config.python_cmd + " extract_f0_print.py %s/logs/%s %s %s %s" % (
|
573 |
-
now_dir,
|
574 |
-
exp_dir,
|
575 |
-
n_p,
|
576 |
-
f0method,
|
577 |
-
echl,
|
578 |
-
)
|
579 |
-
print(cmd)
|
580 |
-
p = Popen(cmd, shell=True, cwd=now_dir) # , stdin=PIPE, stdout=PIPE,stderr=PIPE
|
581 |
-
###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
|
582 |
-
done = [False]
|
583 |
-
threading.Thread(
|
584 |
-
target=if_done,
|
585 |
-
args=(
|
586 |
-
done,
|
587 |
-
p,
|
588 |
-
),
|
589 |
-
).start()
|
590 |
-
while 1:
|
591 |
-
with open(
|
592 |
-
"%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r"
|
593 |
-
) as f:
|
594 |
-
yield (f.read())
|
595 |
-
sleep(1)
|
596 |
-
if done[0] == True:
|
597 |
-
break
|
598 |
-
with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
|
599 |
-
log = f.read()
|
600 |
-
print(log)
|
601 |
-
yield log
|
602 |
-
####对不同part分别开多进程
|
603 |
-
"""
|
604 |
-
n_part=int(sys.argv[1])
|
605 |
-
i_part=int(sys.argv[2])
|
606 |
-
i_gpu=sys.argv[3]
|
607 |
-
exp_dir=sys.argv[4]
|
608 |
-
os.environ["CUDA_VISIBLE_DEVICES"]=str(i_gpu)
|
609 |
-
"""
|
610 |
-
leng = len(gpus)
|
611 |
-
ps = []
|
612 |
-
for idx, n_g in enumerate(gpus):
|
613 |
-
cmd = (
|
614 |
-
config.python_cmd
|
615 |
-
+ " extract_feature_print.py %s %s %s %s %s/logs/%s %s"
|
616 |
-
% (
|
617 |
-
config.device,
|
618 |
-
leng,
|
619 |
-
idx,
|
620 |
-
n_g,
|
621 |
-
now_dir,
|
622 |
-
exp_dir,
|
623 |
-
version19,
|
624 |
-
)
|
625 |
-
)
|
626 |
-
print(cmd)
|
627 |
-
p = Popen(
|
628 |
-
cmd, shell=True, cwd=now_dir
|
629 |
-
) # , shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
|
630 |
-
ps.append(p)
|
631 |
-
###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
|
632 |
-
done = [False]
|
633 |
-
threading.Thread(
|
634 |
-
target=if_done_multi,
|
635 |
-
args=(
|
636 |
-
done,
|
637 |
-
ps,
|
638 |
-
),
|
639 |
-
).start()
|
640 |
-
while 1:
|
641 |
-
with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
|
642 |
-
yield (f.read())
|
643 |
-
sleep(1)
|
644 |
-
if done[0] == True:
|
645 |
-
break
|
646 |
-
with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
|
647 |
-
log = f.read()
|
648 |
-
print(log)
|
649 |
-
yield log
|
650 |
-
|
651 |
-
|
652 |
-
def change_sr2(sr2, if_f0_3, version19):
|
653 |
-
path_str = "" if version19 == "v1" else "_v2"
|
654 |
-
f0_str = "f0" if if_f0_3 else ""
|
655 |
-
if_pretrained_generator_exist = os.access("pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2), os.F_OK)
|
656 |
-
if_pretrained_discriminator_exist = os.access("pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2), os.F_OK)
|
657 |
-
if (if_pretrained_generator_exist == False):
|
658 |
-
print("pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2), "not exist, will not use pretrained model")
|
659 |
-
if (if_pretrained_discriminator_exist == False):
|
660 |
-
print("pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2), "not exist, will not use pretrained model")
|
661 |
-
return (
|
662 |
-
("pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2)) if if_pretrained_generator_exist else "",
|
663 |
-
("pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2)) if if_pretrained_discriminator_exist else "",
|
664 |
-
{"visible": True, "__type__": "update"}
|
665 |
-
)
|
666 |
-
|
667 |
-
def change_version19(sr2, if_f0_3, version19):
|
668 |
-
path_str = "" if version19 == "v1" else "_v2"
|
669 |
-
f0_str = "f0" if if_f0_3 else ""
|
670 |
-
if_pretrained_generator_exist = os.access("pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2), os.F_OK)
|
671 |
-
if_pretrained_discriminator_exist = os.access("pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2), os.F_OK)
|
672 |
-
if (if_pretrained_generator_exist == False):
|
673 |
-
print("pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2), "not exist, will not use pretrained model")
|
674 |
-
if (if_pretrained_discriminator_exist == False):
|
675 |
-
print("pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2), "not exist, will not use pretrained model")
|
676 |
-
return (
|
677 |
-
("pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2)) if if_pretrained_generator_exist else "",
|
678 |
-
("pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2)) if if_pretrained_discriminator_exist else "",
|
679 |
-
)
|
680 |
-
|
681 |
-
|
682 |
-
def change_f0(if_f0_3, sr2, version19): # f0method8,pretrained_G14,pretrained_D15
|
683 |
-
path_str = "" if version19 == "v1" else "_v2"
|
684 |
-
if_pretrained_generator_exist = os.access("pretrained%s/f0G%s.pth" % (path_str, sr2), os.F_OK)
|
685 |
-
if_pretrained_discriminator_exist = os.access("pretrained%s/f0D%s.pth" % (path_str, sr2), os.F_OK)
|
686 |
-
if (if_pretrained_generator_exist == False):
|
687 |
-
print("pretrained%s/f0G%s.pth" % (path_str, sr2), "not exist, will not use pretrained model")
|
688 |
-
if (if_pretrained_discriminator_exist == False):
|
689 |
-
print("pretrained%s/f0D%s.pth" % (path_str, sr2), "not exist, will not use pretrained model")
|
690 |
-
if if_f0_3:
|
691 |
-
return (
|
692 |
-
{"visible": True, "__type__": "update"},
|
693 |
-
"pretrained%s/f0G%s.pth" % (path_str, sr2) if if_pretrained_generator_exist else "",
|
694 |
-
"pretrained%s/f0D%s.pth" % (path_str, sr2) if if_pretrained_discriminator_exist else "",
|
695 |
-
)
|
696 |
-
return (
|
697 |
-
{"visible": False, "__type__": "update"},
|
698 |
-
("pretrained%s/G%s.pth" % (path_str, sr2)) if if_pretrained_generator_exist else "",
|
699 |
-
("pretrained%s/D%s.pth" % (path_str, sr2)) if if_pretrained_discriminator_exist else "",
|
700 |
-
)
|
701 |
-
|
702 |
-
|
703 |
-
global log_interval
|
704 |
-
|
705 |
-
|
706 |
-
def set_log_interval(exp_dir, batch_size12):
|
707 |
-
log_interval = 1
|
708 |
-
|
709 |
-
folder_path = os.path.join(exp_dir, "1_16k_wavs")
|
710 |
-
|
711 |
-
if os.path.exists(folder_path) and os.path.isdir(folder_path):
|
712 |
-
wav_files = [f for f in os.listdir(folder_path) if f.endswith(".wav")]
|
713 |
-
if wav_files:
|
714 |
-
sample_size = len(wav_files)
|
715 |
-
log_interval = math.ceil(sample_size / batch_size12)
|
716 |
-
if log_interval > 1:
|
717 |
-
log_interval += 1
|
718 |
-
return log_interval
|
719 |
-
|
720 |
-
# but3.click(click_train,[exp_dir1,sr2,if_f0_3,save_epoch10,total_epoch11,batch_size12,if_save_latest13,pretrained_G14,pretrained_D15,gpus16])
|
721 |
-
def click_train(
|
722 |
-
exp_dir1,
|
723 |
-
sr2,
|
724 |
-
if_f0_3,
|
725 |
-
spk_id5,
|
726 |
-
save_epoch10,
|
727 |
-
total_epoch11,
|
728 |
-
batch_size12,
|
729 |
-
if_save_latest13,
|
730 |
-
pretrained_G14,
|
731 |
-
pretrained_D15,
|
732 |
-
gpus16,
|
733 |
-
if_cache_gpu17,
|
734 |
-
if_save_every_weights18,
|
735 |
-
version19,
|
736 |
-
):
|
737 |
-
CSVutil('csvdb/stop.csv', 'w+', 'formanting', False)
|
738 |
-
# 生成filelist
|
739 |
-
exp_dir = "%s/logs/%s" % (now_dir, exp_dir1)
|
740 |
-
os.makedirs(exp_dir, exist_ok=True)
|
741 |
-
gt_wavs_dir = "%s/0_gt_wavs" % (exp_dir)
|
742 |
-
feature_dir = (
|
743 |
-
"%s/3_feature256" % (exp_dir)
|
744 |
-
if version19 == "v1"
|
745 |
-
else "%s/3_feature768" % (exp_dir)
|
746 |
-
)
|
747 |
-
|
748 |
-
log_interval = set_log_interval(exp_dir, batch_size12)
|
749 |
-
|
750 |
-
if if_f0_3:
|
751 |
-
f0_dir = "%s/2a_f0" % (exp_dir)
|
752 |
-
f0nsf_dir = "%s/2b-f0nsf" % (exp_dir)
|
753 |
-
names = (
|
754 |
-
set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)])
|
755 |
-
& set([name.split(".")[0] for name in os.listdir(feature_dir)])
|
756 |
-
& set([name.split(".")[0] for name in os.listdir(f0_dir)])
|
757 |
-
& set([name.split(".")[0] for name in os.listdir(f0nsf_dir)])
|
758 |
-
)
|
759 |
-
else:
|
760 |
-
names = set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)]) & set(
|
761 |
-
[name.split(".")[0] for name in os.listdir(feature_dir)]
|
762 |
-
)
|
763 |
-
opt = []
|
764 |
-
for name in names:
|
765 |
-
if if_f0_3:
|
766 |
-
opt.append(
|
767 |
-
"%s/%s.wav|%s/%s.npy|%s/%s.wav.npy|%s/%s.wav.npy|%s"
|
768 |
-
% (
|
769 |
-
gt_wavs_dir.replace("\\", "\\\\"),
|
770 |
-
name,
|
771 |
-
feature_dir.replace("\\", "\\\\"),
|
772 |
-
name,
|
773 |
-
f0_dir.replace("\\", "\\\\"),
|
774 |
-
name,
|
775 |
-
f0nsf_dir.replace("\\", "\\\\"),
|
776 |
-
name,
|
777 |
-
spk_id5,
|
778 |
-
)
|
779 |
-
)
|
780 |
-
else:
|
781 |
-
opt.append(
|
782 |
-
"%s/%s.wav|%s/%s.npy|%s"
|
783 |
-
% (
|
784 |
-
gt_wavs_dir.replace("\\", "\\\\"),
|
785 |
-
name,
|
786 |
-
feature_dir.replace("\\", "\\\\"),
|
787 |
-
name,
|
788 |
-
spk_id5,
|
789 |
-
)
|
790 |
-
)
|
791 |
-
fea_dim = 256 if version19 == "v1" else 768
|
792 |
-
if if_f0_3:
|
793 |
-
for _ in range(2):
|
794 |
-
opt.append(
|
795 |
-
"%s/logs/mute/0_gt_wavs/mute%s.wav|%s/logs/mute/3_feature%s/mute.npy|%s/logs/mute/2a_f0/mute.wav.npy|%s/logs/mute/2b-f0nsf/mute.wav.npy|%s"
|
796 |
-
% (now_dir, sr2, now_dir, fea_dim, now_dir, now_dir, spk_id5)
|
797 |
-
)
|
798 |
-
else:
|
799 |
-
for _ in range(2):
|
800 |
-
opt.append(
|
801 |
-
"%s/logs/mute/0_gt_wavs/mute%s.wav|%s/logs/mute/3_feature%s/mute.npy|%s"
|
802 |
-
% (now_dir, sr2, now_dir, fea_dim, spk_id5)
|
803 |
-
)
|
804 |
-
shuffle(opt)
|
805 |
-
with open("%s/filelist.txt" % exp_dir, "w") as f:
|
806 |
-
f.write("\n".join(opt))
|
807 |
-
print("write filelist done")
|
808 |
-
# 生成config#无需生成config
|
809 |
-
# cmd = python_cmd + " train_nsf_sim_cache_sid_load_pretrain.py -e mi-test -sr 40k -f0 1 -bs 4 -g 0 -te 10 -se 5 -pg pretrained/f0G40k.pth -pd pretrained/f0D40k.pth -l 1 -c 0"
|
810 |
-
print("use gpus:", gpus16)
|
811 |
-
if pretrained_G14 == "":
|
812 |
-
print("no pretrained Generator")
|
813 |
-
if pretrained_D15 == "":
|
814 |
-
print("no pretrained Discriminator")
|
815 |
-
if gpus16:
|
816 |
-
cmd = (
|
817 |
-
config.python_cmd
|
818 |
-
+ " train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -g %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s -li %s"
|
819 |
-
% (
|
820 |
-
exp_dir1,
|
821 |
-
sr2,
|
822 |
-
1 if if_f0_3 else 0,
|
823 |
-
batch_size12,
|
824 |
-
gpus16,
|
825 |
-
total_epoch11,
|
826 |
-
save_epoch10,
|
827 |
-
("-pg %s" % pretrained_G14) if pretrained_G14 != "" else "",
|
828 |
-
("-pd %s" % pretrained_D15) if pretrained_D15 != "" else "",
|
829 |
-
1 if if_save_latest13 == True else 0,
|
830 |
-
1 if if_cache_gpu17 == True else 0,
|
831 |
-
1 if if_save_every_weights18 == True else 0,
|
832 |
-
version19,
|
833 |
-
log_interval,
|
834 |
-
)
|
835 |
-
)
|
836 |
-
else:
|
837 |
-
cmd = (
|
838 |
-
config.python_cmd
|
839 |
-
+ " train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s -li %s"
|
840 |
-
% (
|
841 |
-
exp_dir1,
|
842 |
-
sr2,
|
843 |
-
1 if if_f0_3 else 0,
|
844 |
-
batch_size12,
|
845 |
-
total_epoch11,
|
846 |
-
save_epoch10,
|
847 |
-
("-pg %s" % pretrained_G14) if pretrained_G14 != "" else "\b",
|
848 |
-
("-pd %s" % pretrained_D15) if pretrained_D15 != "" else "\b",
|
849 |
-
1 if if_save_latest13 == True else 0,
|
850 |
-
1 if if_cache_gpu17 == True else 0,
|
851 |
-
1 if if_save_every_weights18 == True else 0,
|
852 |
-
version19,
|
853 |
-
log_interval,
|
854 |
-
)
|
855 |
-
)
|
856 |
-
print(cmd)
|
857 |
-
p = Popen(cmd, shell=True, cwd=now_dir)
|
858 |
-
global PID
|
859 |
-
PID = p.pid
|
860 |
-
p.wait()
|
861 |
-
return ("训练结束, 您可查看控制台训练日志或实验文件夹下的train.log", {"visible": False, "__type__": "update"}, {"visible": True, "__type__": "update"})
|
862 |
-
|
863 |
-
|
864 |
-
# but4.click(train_index, [exp_dir1], info3)
|
865 |
-
def train_index(exp_dir1, version19):
|
866 |
-
exp_dir = "%s/logs/%s" % (now_dir, exp_dir1)
|
867 |
-
os.makedirs(exp_dir, exist_ok=True)
|
868 |
-
feature_dir = (
|
869 |
-
"%s/3_feature256" % (exp_dir)
|
870 |
-
if version19 == "v1"
|
871 |
-
else "%s/3_feature768" % (exp_dir)
|
872 |
-
)
|
873 |
-
if os.path.exists(feature_dir) == False:
|
874 |
-
return "请先进行特征提取!"
|
875 |
-
listdir_res = list(os.listdir(feature_dir))
|
876 |
-
if len(listdir_res) == 0:
|
877 |
-
return "请先进行特征提取!"
|
878 |
-
npys = []
|
879 |
-
for name in sorted(listdir_res):
|
880 |
-
phone = np.load("%s/%s" % (feature_dir, name))
|
881 |
-
npys.append(phone)
|
882 |
-
big_npy = np.concatenate(npys, 0)
|
883 |
-
big_npy_idx = np.arange(big_npy.shape[0])
|
884 |
-
np.random.shuffle(big_npy_idx)
|
885 |
-
big_npy = big_npy[big_npy_idx]
|
886 |
-
np.save("%s/total_fea.npy" % exp_dir, big_npy)
|
887 |
-
# n_ivf = big_npy.shape[0] // 39
|
888 |
-
n_ivf = min(int(16 * np.sqrt(big_npy.shape[0])), big_npy.shape[0] // 39)
|
889 |
-
infos = []
|
890 |
-
infos.append("%s,%s" % (big_npy.shape, n_ivf))
|
891 |
-
yield "\n".join(infos)
|
892 |
-
index = faiss.index_factory(256 if version19 == "v1" else 768, "IVF%s,Flat" % n_ivf)
|
893 |
-
# index = faiss.index_factory(256if version19=="v1"else 768, "IVF%s,PQ128x4fs,RFlat"%n_ivf)
|
894 |
-
infos.append("training")
|
895 |
-
yield "\n".join(infos)
|
896 |
-
index_ivf = faiss.extract_index_ivf(index) #
|
897 |
-
index_ivf.nprobe = 1
|
898 |
-
index.train(big_npy)
|
899 |
-
faiss.write_index(
|
900 |
-
index,
|
901 |
-
"%s/trained_IVF%s_Flat_nprobe_%s_%s_%s.index"
|
902 |
-
% (exp_dir, n_ivf, index_ivf.nprobe, exp_dir1, version19),
|
903 |
-
)
|
904 |
-
# faiss.write_index(index, '%s/trained_IVF%s_Flat_FastScan_%s.index'%(exp_dir,n_ivf,version19))
|
905 |
-
infos.append("adding")
|
906 |
-
yield "\n".join(infos)
|
907 |
-
batch_size_add = 8192
|
908 |
-
for i in range(0, big_npy.shape[0], batch_size_add):
|
909 |
-
index.add(big_npy[i : i + batch_size_add])
|
910 |
-
faiss.write_index(
|
911 |
-
index,
|
912 |
-
"%s/added_IVF%s_Flat_nprobe_%s_%s_%s.index"
|
913 |
-
% (exp_dir, n_ivf, index_ivf.nprobe, exp_dir1, version19),
|
914 |
-
)
|
915 |
-
infos.append(
|
916 |
-
"成功构建索引,added_IVF%s_Flat_nprobe_%s_%s_%s.index"
|
917 |
-
% (n_ivf, index_ivf.nprobe, exp_dir1, version19)
|
918 |
-
)
|
919 |
-
# faiss.write_index(index, '%s/added_IVF%s_Flat_FastScan_%s.index'%(exp_dir,n_ivf,version19))
|
920 |
-
# infos.append("成功构建索引,added_IVF%s_Flat_FastScan_%s.index"%(n_ivf,version19))
|
921 |
-
yield "\n".join(infos)
|
922 |
-
|
923 |
-
|
924 |
-
# but5.click(train1key, [exp_dir1, sr2, if_f0_3, trainset_dir4, spk_id5, gpus6, np7, f0method8, save_epoch10, total_epoch11, batch_size12, if_save_latest13, pretrained_G14, pretrained_D15, gpus16, if_cache_gpu17], info3)
|
925 |
-
def train1key(
|
926 |
-
exp_dir1,
|
927 |
-
sr2,
|
928 |
-
if_f0_3,
|
929 |
-
trainset_dir4,
|
930 |
-
spk_id5,
|
931 |
-
np7,
|
932 |
-
f0method8,
|
933 |
-
save_epoch10,
|
934 |
-
total_epoch11,
|
935 |
-
batch_size12,
|
936 |
-
if_save_latest13,
|
937 |
-
pretrained_G14,
|
938 |
-
pretrained_D15,
|
939 |
-
gpus16,
|
940 |
-
if_cache_gpu17,
|
941 |
-
if_save_every_weights18,
|
942 |
-
version19,
|
943 |
-
echl
|
944 |
-
):
|
945 |
-
infos = []
|
946 |
-
|
947 |
-
def get_info_str(strr):
|
948 |
-
infos.append(strr)
|
949 |
-
return "\n".join(infos)
|
950 |
-
|
951 |
-
model_log_dir = "%s/logs/%s" % (now_dir, exp_dir1)
|
952 |
-
preprocess_log_path = "%s/preprocess.log" % model_log_dir
|
953 |
-
extract_f0_feature_log_path = "%s/extract_f0_feature.log" % model_log_dir
|
954 |
-
gt_wavs_dir = "%s/0_gt_wavs" % model_log_dir
|
955 |
-
feature_dir = (
|
956 |
-
"%s/3_feature256" % model_log_dir
|
957 |
-
if version19 == "v1"
|
958 |
-
else "%s/3_feature768" % model_log_dir
|
959 |
-
)
|
960 |
-
|
961 |
-
os.makedirs(model_log_dir, exist_ok=True)
|
962 |
-
#########step1:处理数据
|
963 |
-
open(preprocess_log_path, "w").close()
|
964 |
-
cmd = (
|
965 |
-
config.python_cmd
|
966 |
-
+ " trainset_preprocess_pipeline_print.py %s %s %s %s "
|
967 |
-
% (trainset_dir4, sr_dict[sr2], np7, model_log_dir)
|
968 |
-
+ str(config.noparallel)
|
969 |
-
)
|
970 |
-
yield get_info_str(i18n("step1:正在处理数据"))
|
971 |
-
yield get_info_str(cmd)
|
972 |
-
p = Popen(cmd, shell=True)
|
973 |
-
p.wait()
|
974 |
-
with open(preprocess_log_path, "r") as f:
|
975 |
-
print(f.read())
|
976 |
-
#########step2a:提取音高
|
977 |
-
open(extract_f0_feature_log_path, "w")
|
978 |
-
if if_f0_3:
|
979 |
-
yield get_info_str("step2a:正在提取音高")
|
980 |
-
cmd = config.python_cmd + " extract_f0_print.py %s %s %s %s" % (
|
981 |
-
model_log_dir,
|
982 |
-
np7,
|
983 |
-
f0method8,
|
984 |
-
echl
|
985 |
-
)
|
986 |
-
yield get_info_str(cmd)
|
987 |
-
p = Popen(cmd, shell=True, cwd=now_dir)
|
988 |
-
p.wait()
|
989 |
-
with open(extract_f0_feature_log_path, "r") as f:
|
990 |
-
print(f.read())
|
991 |
-
else:
|
992 |
-
yield get_info_str(i18n("step2a:无需提取音高"))
|
993 |
-
#######step2b:提取特征
|
994 |
-
yield get_info_str(i18n("step2b:正在提取特征"))
|
995 |
-
gpus = gpus16.split("-")
|
996 |
-
leng = len(gpus)
|
997 |
-
ps = []
|
998 |
-
for idx, n_g in enumerate(gpus):
|
999 |
-
cmd = config.python_cmd + " extract_feature_print.py %s %s %s %s %s %s" % (
|
1000 |
-
config.device,
|
1001 |
-
leng,
|
1002 |
-
idx,
|
1003 |
-
n_g,
|
1004 |
-
model_log_dir,
|
1005 |
-
version19,
|
1006 |
-
)
|
1007 |
-
yield get_info_str(cmd)
|
1008 |
-
p = Popen(
|
1009 |
-
cmd, shell=True, cwd=now_dir
|
1010 |
-
) # , shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
|
1011 |
-
ps.append(p)
|
1012 |
-
for p in ps:
|
1013 |
-
p.wait()
|
1014 |
-
with open(extract_f0_feature_log_path, "r") as f:
|
1015 |
-
print(f.read())
|
1016 |
-
#######step3a:训练模型
|
1017 |
-
yield get_info_str(i18n("step3a:正在训练模型"))
|
1018 |
-
# 生成filelist
|
1019 |
-
if if_f0_3:
|
1020 |
-
f0_dir = "%s/2a_f0" % model_log_dir
|
1021 |
-
f0nsf_dir = "%s/2b-f0nsf" % model_log_dir
|
1022 |
-
names = (
|
1023 |
-
set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)])
|
1024 |
-
& set([name.split(".")[0] for name in os.listdir(feature_dir)])
|
1025 |
-
& set([name.split(".")[0] for name in os.listdir(f0_dir)])
|
1026 |
-
& set([name.split(".")[0] for name in os.listdir(f0nsf_dir)])
|
1027 |
-
)
|
1028 |
-
else:
|
1029 |
-
names = set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)]) & set(
|
1030 |
-
[name.split(".")[0] for name in os.listdir(feature_dir)]
|
1031 |
-
)
|
1032 |
-
opt = []
|
1033 |
-
for name in names:
|
1034 |
-
if if_f0_3:
|
1035 |
-
opt.append(
|
1036 |
-
"%s/%s.wav|%s/%s.npy|%s/%s.wav.npy|%s/%s.wav.npy|%s"
|
1037 |
-
% (
|
1038 |
-
gt_wavs_dir.replace("\\", "\\\\"),
|
1039 |
-
name,
|
1040 |
-
feature_dir.replace("\\", "\\\\"),
|
1041 |
-
name,
|
1042 |
-
f0_dir.replace("\\", "\\\\"),
|
1043 |
-
name,
|
1044 |
-
f0nsf_dir.replace("\\", "\\\\"),
|
1045 |
-
name,
|
1046 |
-
spk_id5,
|
1047 |
-
)
|
1048 |
-
)
|
1049 |
-
else:
|
1050 |
-
opt.append(
|
1051 |
-
"%s/%s.wav|%s/%s.npy|%s"
|
1052 |
-
% (
|
1053 |
-
gt_wavs_dir.replace("\\", "\\\\"),
|
1054 |
-
name,
|
1055 |
-
feature_dir.replace("\\", "\\\\"),
|
1056 |
-
name,
|
1057 |
-
spk_id5,
|
1058 |
-
)
|
1059 |
-
)
|
1060 |
-
fea_dim = 256 if version19 == "v1" else 768
|
1061 |
-
if if_f0_3:
|
1062 |
-
for _ in range(2):
|
1063 |
-
opt.append(
|
1064 |
-
"%s/logs/mute/0_gt_wavs/mute%s.wav|%s/logs/mute/3_feature%s/mute.npy|%s/logs/mute/2a_f0/mute.wav.npy|%s/logs/mute/2b-f0nsf/mute.wav.npy|%s"
|
1065 |
-
% (now_dir, sr2, now_dir, fea_dim, now_dir, now_dir, spk_id5)
|
1066 |
-
)
|
1067 |
-
else:
|
1068 |
-
for _ in range(2):
|
1069 |
-
opt.append(
|
1070 |
-
"%s/logs/mute/0_gt_wavs/mute%s.wav|%s/logs/mute/3_feature%s/mute.npy|%s"
|
1071 |
-
% (now_dir, sr2, now_dir, fea_dim, spk_id5)
|
1072 |
-
)
|
1073 |
-
shuffle(opt)
|
1074 |
-
with open("%s/filelist.txt" % model_log_dir, "w") as f:
|
1075 |
-
f.write("\n".join(opt))
|
1076 |
-
yield get_info_str("write filelist done")
|
1077 |
-
if gpus16:
|
1078 |
-
cmd = (
|
1079 |
-
config.python_cmd
|
1080 |
-
+" train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -g %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s"
|
1081 |
-
% (
|
1082 |
-
exp_dir1,
|
1083 |
-
sr2,
|
1084 |
-
1 if if_f0_3 else 0,
|
1085 |
-
batch_size12,
|
1086 |
-
gpus16,
|
1087 |
-
total_epoch11,
|
1088 |
-
save_epoch10,
|
1089 |
-
("-pg %s" % pretrained_G14) if pretrained_G14 != "" else "",
|
1090 |
-
("-pd %s" % pretrained_D15) if pretrained_D15 != "" else "",
|
1091 |
-
1 if if_save_latest13 == True else 0,
|
1092 |
-
1 if if_cache_gpu17 == True else 0,
|
1093 |
-
1 if if_save_every_weights18 == True else 0,
|
1094 |
-
version19,
|
1095 |
-
)
|
1096 |
-
)
|
1097 |
-
else:
|
1098 |
-
cmd = (
|
1099 |
-
config.python_cmd
|
1100 |
-
+ " train_nsf_sim_cache_sid_load_pretrain.py -e %s -sr %s -f0 %s -bs %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s"
|
1101 |
-
% (
|
1102 |
-
exp_dir1,
|
1103 |
-
sr2,
|
1104 |
-
1 if if_f0_3 else 0,
|
1105 |
-
batch_size12,
|
1106 |
-
total_epoch11,
|
1107 |
-
save_epoch10,
|
1108 |
-
("-pg %s" % pretrained_G14) if pretrained_G14 != "" else "",
|
1109 |
-
("-pd %s" % pretrained_D15) if pretrained_D15 != "" else "",
|
1110 |
-
1 if if_save_latest13 == True else 0,
|
1111 |
-
1 if if_cache_gpu17 == True else 0,
|
1112 |
-
1 if if_save_every_weights18 == True else 0,
|
1113 |
-
version19,
|
1114 |
-
)
|
1115 |
-
)
|
1116 |
-
yield get_info_str(cmd)
|
1117 |
-
p = Popen(cmd, shell=True, cwd=now_dir)
|
1118 |
-
p.wait()
|
1119 |
-
yield get_info_str(i18n("训练结束, 您可查看控制台训练日志或实验文件夹下的train.log"))
|
1120 |
-
#######step3b:训练索引
|
1121 |
-
npys = []
|
1122 |
-
listdir_res = list(os.listdir(feature_dir))
|
1123 |
-
for name in sorted(listdir_res):
|
1124 |
-
phone = np.load("%s/%s" % (feature_dir, name))
|
1125 |
-
npys.append(phone)
|
1126 |
-
big_npy = np.concatenate(npys, 0)
|
1127 |
-
|
1128 |
-
big_npy_idx = np.arange(big_npy.shape[0])
|
1129 |
-
np.random.shuffle(big_npy_idx)
|
1130 |
-
big_npy = big_npy[big_npy_idx]
|
1131 |
-
np.save("%s/total_fea.npy" % model_log_dir, big_npy)
|
1132 |
-
|
1133 |
-
# n_ivf = big_npy.shape[0] // 39
|
1134 |
-
n_ivf = min(int(16 * np.sqrt(big_npy.shape[0])), big_npy.shape[0] // 39)
|
1135 |
-
yield get_info_str("%s,%s" % (big_npy.shape, n_ivf))
|
1136 |
-
index = faiss.index_factory(256 if version19 == "v1" else 768, "IVF%s,Flat" % n_ivf)
|
1137 |
-
yield get_info_str("training index")
|
1138 |
-
index_ivf = faiss.extract_index_ivf(index) #
|
1139 |
-
index_ivf.nprobe = 1
|
1140 |
-
index.train(big_npy)
|
1141 |
-
faiss.write_index(
|
1142 |
-
index,
|
1143 |
-
"%s/trained_IVF%s_Flat_nprobe_%s_%s_%s.index"
|
1144 |
-
% (model_log_dir, n_ivf, index_ivf.nprobe, exp_dir1, version19),
|
1145 |
-
)
|
1146 |
-
yield get_info_str("adding index")
|
1147 |
-
batch_size_add = 8192
|
1148 |
-
for i in range(0, big_npy.shape[0], batch_size_add):
|
1149 |
-
index.add(big_npy[i : i + batch_size_add])
|
1150 |
-
faiss.write_index(
|
1151 |
-
index,
|
1152 |
-
"%s/added_IVF%s_Flat_nprobe_%s_%s_%s.index"
|
1153 |
-
% (model_log_dir, n_ivf, index_ivf.nprobe, exp_dir1, version19),
|
1154 |
-
)
|
1155 |
-
yield get_info_str(
|
1156 |
-
"成功构建索引, added_IVF%s_Flat_nprobe_%s_%s_%s.index"
|
1157 |
-
% (n_ivf, index_ivf.nprobe, exp_dir1, version19)
|
1158 |
-
)
|
1159 |
-
yield get_info_str(i18n("全流程结束!"))
|
1160 |
-
|
1161 |
-
|
1162 |
-
def whethercrepeornah(radio):
|
1163 |
-
mango = True if radio == 'mangio-crepe' or radio == 'mangio-crepe-tiny' else False
|
1164 |
-
return ({"visible": mango, "__type__": "update"})
|
1165 |
-
|
1166 |
-
# ckpt_path2.change(change_info_,[ckpt_path2],[sr__,if_f0__])
|
1167 |
-
def change_info_(ckpt_path):
|
1168 |
-
if (
|
1169 |
-
os.path.exists(ckpt_path.replace(os.path.basename(ckpt_path), "train.log"))
|
1170 |
-
== False
|
1171 |
-
):
|
1172 |
-
return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
|
1173 |
-
try:
|
1174 |
-
with open(
|
1175 |
-
ckpt_path.replace(os.path.basename(ckpt_path), "train.log"), "r"
|
1176 |
-
) as f:
|
1177 |
-
info = eval(f.read().strip("\n").split("\n")[0].split("\t")[-1])
|
1178 |
-
sr, f0 = info["sample_rate"], info["if_f0"]
|
1179 |
-
version = "v2" if ("version" in info and info["version"] == "v2") else "v1"
|
1180 |
-
return sr, str(f0), version
|
1181 |
-
except:
|
1182 |
-
traceback.print_exc()
|
1183 |
-
return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
|
1184 |
-
|
1185 |
-
|
1186 |
-
from lib.infer_pack.models_onnx import SynthesizerTrnMsNSFsidM
|
1187 |
-
|
1188 |
-
|
1189 |
-
def export_onnx(ModelPath, ExportedPath, MoeVS=True):
|
1190 |
-
cpt = torch.load(ModelPath, map_location="cpu")
|
1191 |
-
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0] # n_spk
|
1192 |
-
hidden_channels = 256 if cpt.get("version","v1")=="v1"else 768#cpt["config"][-2] # hidden_channels,为768Vec做准备
|
1193 |
-
|
1194 |
-
test_phone = torch.rand(1, 200, hidden_channels) # hidden unit
|
1195 |
-
test_phone_lengths = torch.tensor([200]).long() # hidden unit 长度(貌似没啥用)
|
1196 |
-
test_pitch = torch.randint(size=(1, 200), low=5, high=255) # 基频(单位赫兹)
|
1197 |
-
test_pitchf = torch.rand(1, 200) # nsf基频
|
1198 |
-
test_ds = torch.LongTensor([0]) # 说话人ID
|
1199 |
-
test_rnd = torch.rand(1, 192, 200) # 噪声(加入随机因子)
|
1200 |
-
|
1201 |
-
device = "cpu" # 导出时设备(不影响使用模型)
|
1202 |
-
|
1203 |
-
|
1204 |
-
net_g = SynthesizerTrnMsNSFsidM(
|
1205 |
-
*cpt["config"], is_half=False,version=cpt.get("version","v1")
|
1206 |
-
) # fp32导出(C++要支持fp16必须手动将内存重新排列所以暂时不用fp16)
|
1207 |
-
net_g.load_state_dict(cpt["weight"], strict=False)
|
1208 |
-
input_names = ["phone", "phone_lengths", "pitch", "pitchf", "ds", "rnd"]
|
1209 |
-
output_names = [
|
1210 |
-
"audio",
|
1211 |
-
]
|
1212 |
-
# net_g.construct_spkmixmap(n_speaker) 多角色混合轨道导出
|
1213 |
-
torch.onnx.export(
|
1214 |
-
net_g,
|
1215 |
-
(
|
1216 |
-
test_phone.to(device),
|
1217 |
-
test_phone_lengths.to(device),
|
1218 |
-
test_pitch.to(device),
|
1219 |
-
test_pitchf.to(device),
|
1220 |
-
test_ds.to(device),
|
1221 |
-
test_rnd.to(device),
|
1222 |
-
),
|
1223 |
-
ExportedPath,
|
1224 |
-
dynamic_axes={
|
1225 |
-
"phone": [1],
|
1226 |
-
"pitch": [1],
|
1227 |
-
"pitchf": [1],
|
1228 |
-
"rnd": [2],
|
1229 |
-
},
|
1230 |
-
do_constant_folding=False,
|
1231 |
-
opset_version=16,
|
1232 |
-
verbose=False,
|
1233 |
-
input_names=input_names,
|
1234 |
-
output_names=output_names,
|
1235 |
-
)
|
1236 |
-
return "Finished"
|
1237 |
-
|
1238 |
-
#region RVC WebUI App
|
1239 |
-
|
1240 |
-
def get_presets():
|
1241 |
-
data = None
|
1242 |
-
with open('../inference-presets.json', 'r') as file:
|
1243 |
-
data = json.load(file)
|
1244 |
-
preset_names = []
|
1245 |
-
for preset in data['presets']:
|
1246 |
-
preset_names.append(preset['name'])
|
1247 |
-
|
1248 |
-
return preset_names
|
1249 |
-
|
1250 |
-
def change_choices2():
|
1251 |
-
audio_files=[]
|
1252 |
-
for filename in os.listdir("./audios"):
|
1253 |
-
if filename.endswith(('.wav','.mp3','.ogg','.flac','.m4a','.aac','.mp4')):
|
1254 |
-
audio_files.append(os.path.join('./audios',filename).replace('\\', '/'))
|
1255 |
-
return {"choices": sorted(audio_files), "__type__": "update"}, {"__type__": "update"}
|
1256 |
-
|
1257 |
-
audio_files=[]
|
1258 |
-
for filename in os.listdir("./audios"):
|
1259 |
-
if filename.endswith(('.wav','.mp3','.ogg','.flac','.m4a','.aac','.mp4')):
|
1260 |
-
audio_files.append(os.path.join('./audios',filename).replace('\\', '/'))
|
1261 |
-
|
1262 |
-
def get_index():
|
1263 |
-
if check_for_name() != '':
|
1264 |
-
chosen_model=sorted(names)[0].split(".")[0]
|
1265 |
-
logs_path="./logs/"+chosen_model
|
1266 |
-
if os.path.exists(logs_path):
|
1267 |
-
for file in os.listdir(logs_path):
|
1268 |
-
if file.endswith(".index"):
|
1269 |
-
return os.path.join(logs_path, file)
|
1270 |
-
return ''
|
1271 |
-
else:
|
1272 |
-
return ''
|
1273 |
-
|
1274 |
-
def get_indexes():
|
1275 |
-
indexes_list=[]
|
1276 |
-
for dirpath, dirnames, filenames in os.walk("./logs/"):
|
1277 |
-
for filename in filenames:
|
1278 |
-
if filename.endswith(".index"):
|
1279 |
-
indexes_list.append(os.path.join(dirpath,filename))
|
1280 |
-
if len(indexes_list) > 0:
|
1281 |
-
return indexes_list
|
1282 |
-
else:
|
1283 |
-
return ''
|
1284 |
-
|
1285 |
-
def get_name():
|
1286 |
-
if len(audio_files) > 0:
|
1287 |
-
return sorted(audio_files)[0]
|
1288 |
-
else:
|
1289 |
-
return ''
|
1290 |
-
|
1291 |
-
def save_to_wav(record_button):
|
1292 |
-
if record_button is None:
|
1293 |
-
pass
|
1294 |
-
else:
|
1295 |
-
path_to_file=record_button
|
1296 |
-
new_name = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")+'.wav'
|
1297 |
-
new_path='./audios/'+new_name
|
1298 |
-
shutil.move(path_to_file,new_path)
|
1299 |
-
return new_path
|
1300 |
-
|
1301 |
-
def save_to_wav2(dropbox):
|
1302 |
-
file_path=dropbox.name
|
1303 |
-
shutil.move(file_path,'./audios')
|
1304 |
-
return os.path.join('./audios',os.path.basename(file_path))
|
1305 |
-
|
1306 |
-
def match_index(sid0):
|
1307 |
-
folder=sid0.split(".")[0]
|
1308 |
-
parent_dir="./logs/"+folder
|
1309 |
-
if os.path.exists(parent_dir):
|
1310 |
-
for filename in os.listdir(parent_dir):
|
1311 |
-
if filename.endswith(".index"):
|
1312 |
-
index_path=os.path.join(parent_dir,filename)
|
1313 |
-
return index_path
|
1314 |
-
else:
|
1315 |
-
return ''
|
1316 |
-
|
1317 |
-
def check_for_name():
|
1318 |
-
if len(names) > 0:
|
1319 |
-
return sorted(names)[0]
|
1320 |
-
else:
|
1321 |
-
return ''
|
1322 |
-
|
1323 |
-
def download_from_url(url, model):
|
1324 |
-
if url == '':
|
1325 |
-
return "URL cannot be left empty."
|
1326 |
-
if model =='':
|
1327 |
-
return "You need to name your model. For example: My-Model"
|
1328 |
-
url = url.strip()
|
1329 |
-
zip_dirs = ["zips", "unzips"]
|
1330 |
-
for directory in zip_dirs:
|
1331 |
-
if os.path.exists(directory):
|
1332 |
-
shutil.rmtree(directory)
|
1333 |
-
os.makedirs("zips", exist_ok=True)
|
1334 |
-
os.makedirs("unzips", exist_ok=True)
|
1335 |
-
zipfile = model + '.zip'
|
1336 |
-
zipfile_path = './zips/' + zipfile
|
1337 |
-
try:
|
1338 |
-
if "drive.google.com" in url:
|
1339 |
-
subprocess.run(["gdown", url, "--fuzzy", "-O", zipfile_path])
|
1340 |
-
elif "mega.nz" in url:
|
1341 |
-
m = Mega()
|
1342 |
-
m.download_url(url, './zips')
|
1343 |
-
else:
|
1344 |
-
subprocess.run(["wget", url, "-O", zipfile_path])
|
1345 |
-
for filename in os.listdir("./zips"):
|
1346 |
-
if filename.endswith(".zip"):
|
1347 |
-
zipfile_path = os.path.join("./zips/",filename)
|
1348 |
-
shutil.unpack_archive(zipfile_path, "./unzips", 'zip')
|
1349 |
-
else:
|
1350 |
-
return "No zipfile found."
|
1351 |
-
for root, dirs, files in os.walk('./unzips'):
|
1352 |
-
for file in files:
|
1353 |
-
file_path = os.path.join(root, file)
|
1354 |
-
if file.endswith(".index"):
|
1355 |
-
os.mkdir(f'./logs/{model}')
|
1356 |
-
shutil.copy2(file_path,f'./logs/{model}')
|
1357 |
-
elif "G_" not in file and "D_" not in file and file.endswith(".pth"):
|
1358 |
-
shutil.copy(file_path,f'./weights/{model}.pth')
|
1359 |
-
shutil.rmtree("zips")
|
1360 |
-
shutil.rmtree("unzips")
|
1361 |
-
return "Success."
|
1362 |
-
except:
|
1363 |
-
return "There's been an error."
|
1364 |
-
def success_message(face):
|
1365 |
-
return f'{face.name} has been uploaded.', 'None'
|
1366 |
-
def mouth(size, face, voice, faces):
|
1367 |
-
if size == 'Half':
|
1368 |
-
size = 2
|
1369 |
-
else:
|
1370 |
-
size = 1
|
1371 |
-
if faces == 'None':
|
1372 |
-
character = face.name
|
1373 |
-
else:
|
1374 |
-
if faces == 'Ben Shapiro':
|
1375 |
-
character = '/content/wav2lip-HD/inputs/ben-shapiro-10.mp4'
|
1376 |
-
elif faces == 'Andrew Tate':
|
1377 |
-
character = '/content/wav2lip-HD/inputs/tate-7.mp4'
|
1378 |
-
command = "python inference.py " \
|
1379 |
-
"--checkpoint_path checkpoints/wav2lip.pth " \
|
1380 |
-
f"--face {character} " \
|
1381 |
-
f"--audio {voice} " \
|
1382 |
-
"--pads 0 20 0 0 " \
|
1383 |
-
"--outfile /content/wav2lip-HD/outputs/result.mp4 " \
|
1384 |
-
"--fps 24 " \
|
1385 |
-
f"--resize_factor {size}"
|
1386 |
-
process = subprocess.Popen(command, shell=True, cwd='/content/wav2lip-HD/Wav2Lip-master')
|
1387 |
-
stdout, stderr = process.communicate()
|
1388 |
-
return '/content/wav2lip-HD/outputs/result.mp4', 'Animation completed.'
|
1389 |
-
eleven_voices = ['Adam','Antoni','Josh','Arnold','Sam','Bella','Rachel','Domi','Elli']
|
1390 |
-
eleven_voices_ids=['pNInz6obpgDQGcFmaJgB','ErXwobaYiN019PkySvjV','TxGEqnHWrfWFTfGW9XjX','VR6AewLTigWG4xSOukaG','yoZ06aMxZJJ28mfd3POQ','EXAVITQu4vr4xnSDxMaL','21m00Tcm4TlvDq8ikWAM','AZnzlk1XvdvUeBnXmlld','MF3mGyEYCl7XYWbV9V6O']
|
1391 |
-
chosen_voice = dict(zip(eleven_voices, eleven_voices_ids))
|
1392 |
-
|
1393 |
-
def stoptraining(mim):
|
1394 |
-
if int(mim) == 1:
|
1395 |
-
try:
|
1396 |
-
CSVutil('csvdb/stop.csv', 'w+', 'stop', 'True')
|
1397 |
-
os.kill(PID, signal.SIGTERM)
|
1398 |
-
except Exception as e:
|
1399 |
-
print(f"Couldn't click due to {e}")
|
1400 |
-
return (
|
1401 |
-
{"visible": False, "__type__": "update"},
|
1402 |
-
{"visible": True, "__type__": "update"},
|
1403 |
-
)
|
1404 |
-
|
1405 |
-
|
1406 |
-
def elevenTTS(xiapi, text, id, lang):
|
1407 |
-
if xiapi!= '' and id !='':
|
1408 |
-
choice = chosen_voice[id]
|
1409 |
-
CHUNK_SIZE = 1024
|
1410 |
-
url = f"https://api.elevenlabs.io/v1/text-to-speech/{choice}"
|
1411 |
-
headers = {
|
1412 |
-
"Accept": "audio/mpeg",
|
1413 |
-
"Content-Type": "application/json",
|
1414 |
-
"xi-api-key": xiapi
|
1415 |
-
}
|
1416 |
-
if lang == 'en':
|
1417 |
-
data = {
|
1418 |
-
"text": text,
|
1419 |
-
"model_id": "eleven_monolingual_v1",
|
1420 |
-
"voice_settings": {
|
1421 |
-
"stability": 0.5,
|
1422 |
-
"similarity_boost": 0.5
|
1423 |
-
}
|
1424 |
-
}
|
1425 |
-
else:
|
1426 |
-
data = {
|
1427 |
-
"text": text,
|
1428 |
-
"model_id": "eleven_multilingual_v1",
|
1429 |
-
"voice_settings": {
|
1430 |
-
"stability": 0.5,
|
1431 |
-
"similarity_boost": 0.5
|
1432 |
-
}
|
1433 |
-
}
|
1434 |
-
|
1435 |
-
response = requests.post(url, json=data, headers=headers)
|
1436 |
-
with open('./temp_eleven.mp3', 'wb') as f:
|
1437 |
-
for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
|
1438 |
-
if chunk:
|
1439 |
-
f.write(chunk)
|
1440 |
-
aud_path = save_to_wav('./temp_eleven.mp3')
|
1441 |
-
return aud_path, aud_path
|
1442 |
-
else:
|
1443 |
-
tts = gTTS(text, lang=lang)
|
1444 |
-
tts.save('./temp_gTTS.mp3')
|
1445 |
-
aud_path = save_to_wav('./temp_gTTS.mp3')
|
1446 |
-
return aud_path, aud_path
|
1447 |
-
|
1448 |
-
def upload_to_dataset(files, dir):
|
1449 |
-
if dir == '':
|
1450 |
-
dir = './dataset'
|
1451 |
-
if not os.path.exists(dir):
|
1452 |
-
os.makedirs(dir)
|
1453 |
-
count = 0
|
1454 |
-
for file in files:
|
1455 |
-
path=file.name
|
1456 |
-
shutil.copy2(path,dir)
|
1457 |
-
count += 1
|
1458 |
-
return f' {count} files uploaded to {dir}.'
|
1459 |
-
|
1460 |
-
def zip_downloader(model):
|
1461 |
-
if not os.path.exists(f'./weights/{model}.pth'):
|
1462 |
-
return {"__type__": "update"}, f'Make sure the Voice Name is correct. I could not find {model}.pth'
|
1463 |
-
index_found = False
|
1464 |
-
for file in os.listdir(f'./logs/{model}'):
|
1465 |
-
if file.endswith('.index') and 'added' in file:
|
1466 |
-
log_file = file
|
1467 |
-
index_found = True
|
1468 |
-
if index_found:
|
1469 |
-
return [f'./weights/{model}.pth', f'./logs/{model}/{log_file}'], "Done"
|
1470 |
-
else:
|
1471 |
-
return f'./weights/{model}.pth', "Could not find Index file."
|
1472 |
-
|
1473 |
-
with gr.Blocks(theme=gr.themes.Base(), title='Mangio-RVC-Web 💻') as app:
|
1474 |
-
with gr.Tabs():
|
1475 |
-
with gr.TabItem("Inference"):
|
1476 |
-
gr.HTML("<h1> RVC V2 Huggingface Version </h1>")
|
1477 |
-
gr.HTML("<h4> Inference may take time because this space does not use GPU :( </h4>")
|
1478 |
-
gr.HTML("<h10> Huggingface version made by Clebersla </h10>")
|
1479 |
-
gr.HTML("<h10> Easy GUI coded by Rejekt's </h10>")
|
1480 |
-
gr.HTML("<h4> If you want to use this space privately, I recommend you duplicate the space. </h4>")
|
1481 |
-
|
1482 |
-
# Inference Preset Row
|
1483 |
-
# with gr.Row():
|
1484 |
-
# mangio_preset = gr.Dropdown(label="Inference Preset", choices=sorted(get_presets()))
|
1485 |
-
# mangio_preset_name_save = gr.Textbox(
|
1486 |
-
# label="Your preset name"
|
1487 |
-
# )
|
1488 |
-
# mangio_preset_save_btn = gr.Button('Save Preset', variant="primary")
|
1489 |
-
|
1490 |
-
# Other RVC stuff
|
1491 |
-
with gr.Row():
|
1492 |
-
sid0 = gr.Dropdown(label="1.Choose your Model.", choices=sorted(names), value=check_for_name())
|
1493 |
-
refresh_button = gr.Button("Refresh", variant="primary")
|
1494 |
-
if check_for_name() != '':
|
1495 |
-
get_vc(sorted(names)[0])
|
1496 |
-
vc_transform0 = gr.Number(label="Optional: You can change the pitch here or leave it at 0.", value=0)
|
1497 |
-
#clean_button = gr.Button(i18n("卸载音色省显存"), variant="primary")
|
1498 |
-
spk_item = gr.Slider(
|
1499 |
-
minimum=0,
|
1500 |
-
maximum=2333,
|
1501 |
-
step=1,
|
1502 |
-
label=i18n("请选择说话人id"),
|
1503 |
-
value=0,
|
1504 |
-
visible=False,
|
1505 |
-
interactive=True,
|
1506 |
-
)
|
1507 |
-
#clean_button.click(fn=clean, inputs=[], outputs=[sid0])
|
1508 |
-
sid0.change(
|
1509 |
-
fn=get_vc,
|
1510 |
-
inputs=[sid0],
|
1511 |
-
outputs=[spk_item],
|
1512 |
-
)
|
1513 |
-
but0 = gr.Button("Convert", variant="primary")
|
1514 |
-
with gr.Row():
|
1515 |
-
with gr.Column():
|
1516 |
-
with gr.Row():
|
1517 |
-
dropbox = gr.File(label="Drop your audio here & hit the Reload button.")
|
1518 |
-
with gr.Row():
|
1519 |
-
record_button=gr.Audio(source="microphone", label="OR Record audio.", type="filepath")
|
1520 |
-
with gr.Row():
|
1521 |
-
input_audio0 = gr.Dropdown(
|
1522 |
-
label="2.Choose your audio.",
|
1523 |
-
value="./audios/someguy.mp3",
|
1524 |
-
choices=audio_files
|
1525 |
-
)
|
1526 |
-
dropbox.upload(fn=save_to_wav2, inputs=[dropbox], outputs=[input_audio0])
|
1527 |
-
dropbox.upload(fn=change_choices2, inputs=[], outputs=[input_audio0])
|
1528 |
-
refresh_button2 = gr.Button("Refresh", variant="primary", size='sm')
|
1529 |
-
record_button.change(fn=save_to_wav, inputs=[record_button], outputs=[input_audio0])
|
1530 |
-
record_button.change(fn=change_choices2, inputs=[], outputs=[input_audio0])
|
1531 |
-
with gr.Row():
|
1532 |
-
with gr.Accordion('Text To Speech', open=False):
|
1533 |
-
with gr.Column():
|
1534 |
-
lang = gr.Radio(label='Chinese & Japanese do not work with ElevenLabs currently.',choices=['en','es','fr','pt','zh-CN','de','hi','ja'], value='en')
|
1535 |
-
api_box = gr.Textbox(label="Enter your API Key for ElevenLabs, or leave empty to use GoogleTTS", value='')
|
1536 |
-
elevenid=gr.Dropdown(label="Voice:", choices=eleven_voices)
|
1537 |
-
with gr.Column():
|
1538 |
-
tfs = gr.Textbox(label="Input your Text", interactive=True, value="This is a test.")
|
1539 |
-
tts_button = gr.Button(value="Speak")
|
1540 |
-
tts_button.click(fn=elevenTTS, inputs=[api_box,tfs, elevenid, lang], outputs=[record_button, input_audio0])
|
1541 |
-
with gr.Row():
|
1542 |
-
with gr.Accordion('Wav2Lip', open=False):
|
1543 |
-
with gr.Row():
|
1544 |
-
size = gr.Radio(label='Resolution:',choices=['Half','Full'])
|
1545 |
-
face = gr.UploadButton("Upload A Character",type='file')
|
1546 |
-
faces = gr.Dropdown(label="OR Choose one:", choices=['None','Ben Shapiro','Andrew Tate'])
|
1547 |
-
with gr.Row():
|
1548 |
-
preview = gr.Textbox(label="Status:",interactive=False)
|
1549 |
-
face.upload(fn=success_message,inputs=[face], outputs=[preview, faces])
|
1550 |
-
with gr.Row():
|
1551 |
-
animation = gr.Video(type='filepath')
|
1552 |
-
refresh_button2.click(fn=change_choices2, inputs=[], outputs=[input_audio0, animation])
|
1553 |
-
with gr.Row():
|
1554 |
-
animate_button = gr.Button('Animate')
|
1555 |
-
|
1556 |
-
with gr.Column():
|
1557 |
-
with gr.Accordion("Index Settings", open=False):
|
1558 |
-
file_index1 = gr.Dropdown(
|
1559 |
-
label="3. Path to your added.index file (if it didn't automatically find it.)",
|
1560 |
-
choices=get_indexes(),
|
1561 |
-
value=get_index(),
|
1562 |
-
interactive=True,
|
1563 |
-
)
|
1564 |
-
sid0.change(fn=match_index, inputs=[sid0],outputs=[file_index1])
|
1565 |
-
refresh_button.click(
|
1566 |
-
fn=change_choices, inputs=[], outputs=[sid0, file_index1]
|
1567 |
-
)
|
1568 |
-
# file_big_npy1 = gr.Textbox(
|
1569 |
-
# label=i18n("特征文件路径"),
|
1570 |
-
# value="E:\\codes\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
|
1571 |
-
# interactive=True,
|
1572 |
-
# )
|
1573 |
-
index_rate1 = gr.Slider(
|
1574 |
-
minimum=0,
|
1575 |
-
maximum=1,
|
1576 |
-
label=i18n("检索特征占比"),
|
1577 |
-
value=0.66,
|
1578 |
-
interactive=True,
|
1579 |
-
)
|
1580 |
-
vc_output2 = gr.Audio(
|
1581 |
-
label="Output Audio (Click on the Three Dots in the Right Corner to Download)",
|
1582 |
-
type='filepath',
|
1583 |
-
interactive=False,
|
1584 |
-
)
|
1585 |
-
animate_button.click(fn=mouth, inputs=[size, face, vc_output2, faces], outputs=[animation, preview])
|
1586 |
-
with gr.Accordion("Advanced Settings", open=False):
|
1587 |
-
f0method0 = gr.Radio(
|
1588 |
-
label="Optional: Change the Pitch Extraction Algorithm.\nExtraction methods are sorted from 'worst quality' to 'best quality'.\nmangio-crepe may or may not be better than rmvpe in cases where 'smoothness' is more important, but rmvpe is the best overall.",
|
1589 |
-
choices=["pm", "dio", "crepe-tiny", "mangio-crepe-tiny", "crepe", "harvest", "mangio-crepe", "rmvpe"], # Fork Feature. Add Crepe-Tiny
|
1590 |
-
value="rmvpe",
|
1591 |
-
interactive=True,
|
1592 |
-
)
|
1593 |
-
|
1594 |
-
crepe_hop_length = gr.Slider(
|
1595 |
-
minimum=1,
|
1596 |
-
maximum=512,
|
1597 |
-
step=1,
|
1598 |
-
label="Mangio-Crepe Hop Length. Higher numbers will reduce the chance of extreme pitch changes but lower numbers will increase accuracy. 64-192 is a good range to experiment with.",
|
1599 |
-
value=120,
|
1600 |
-
interactive=True,
|
1601 |
-
visible=False,
|
1602 |
-
)
|
1603 |
-
f0method0.change(fn=whethercrepeornah, inputs=[f0method0], outputs=[crepe_hop_length])
|
1604 |
-
filter_radius0 = gr.Slider(
|
1605 |
-
minimum=0,
|
1606 |
-
maximum=7,
|
1607 |
-
label=i18n(">=3则使用对harvest音高识别的结果使用中值滤波,数值为滤波半径,使用可以削弱哑音"),
|
1608 |
-
value=3,
|
1609 |
-
step=1,
|
1610 |
-
interactive=True,
|
1611 |
-
)
|
1612 |
-
resample_sr0 = gr.Slider(
|
1613 |
-
minimum=0,
|
1614 |
-
maximum=48000,
|
1615 |
-
label=i18n("后处理重采样至最终采样率,0为不进行重采样"),
|
1616 |
-
value=0,
|
1617 |
-
step=1,
|
1618 |
-
interactive=True,
|
1619 |
-
visible=False
|
1620 |
-
)
|
1621 |
-
rms_mix_rate0 = gr.Slider(
|
1622 |
-
minimum=0,
|
1623 |
-
maximum=1,
|
1624 |
-
label=i18n("输入源音量包络替换输出音量包络融合比例,越靠近1越使用输出包络"),
|
1625 |
-
value=0.21,
|
1626 |
-
interactive=True,
|
1627 |
-
)
|
1628 |
-
protect0 = gr.Slider(
|
1629 |
-
minimum=0,
|
1630 |
-
maximum=0.5,
|
1631 |
-
label=i18n("保护清辅音和呼吸声,防止电音撕裂等artifact,拉满0.5不开启,调低加大保护力度但可能降低索引效果"),
|
1632 |
-
value=0.33,
|
1633 |
-
step=0.01,
|
1634 |
-
interactive=True,
|
1635 |
-
)
|
1636 |
-
formanting = gr.Checkbox(
|
1637 |
-
value=bool(DoFormant),
|
1638 |
-
label="[EXPERIMENTAL] Formant shift inference audio",
|
1639 |
-
info="Used for male to female and vice-versa conversions",
|
1640 |
-
interactive=True,
|
1641 |
-
visible=True,
|
1642 |
-
)
|
1643 |
-
|
1644 |
-
formant_preset = gr.Dropdown(
|
1645 |
-
value='',
|
1646 |
-
choices=get_fshift_presets(),
|
1647 |
-
label="browse presets for formanting",
|
1648 |
-
visible=bool(DoFormant),
|
1649 |
-
)
|
1650 |
-
formant_refresh_button = gr.Button(
|
1651 |
-
value='\U0001f504',
|
1652 |
-
visible=bool(DoFormant),
|
1653 |
-
variant='primary',
|
1654 |
-
)
|
1655 |
-
#formant_refresh_button = ToolButton( elem_id='1')
|
1656 |
-
#create_refresh_button(formant_preset, lambda: {"choices": formant_preset}, "refresh_list_shiftpresets")
|
1657 |
-
|
1658 |
-
qfrency = gr.Slider(
|
1659 |
-
value=Quefrency,
|
1660 |
-
info="Default value is 1.0",
|
1661 |
-
label="Quefrency for formant shifting",
|
1662 |
-
minimum=0.0,
|
1663 |
-
maximum=16.0,
|
1664 |
-
step=0.1,
|
1665 |
-
visible=bool(DoFormant),
|
1666 |
-
interactive=True,
|
1667 |
-
)
|
1668 |
-
tmbre = gr.Slider(
|
1669 |
-
value=Timbre,
|
1670 |
-
info="Default value is 1.0",
|
1671 |
-
label="Timbre for formant shifting",
|
1672 |
-
minimum=0.0,
|
1673 |
-
maximum=16.0,
|
1674 |
-
step=0.1,
|
1675 |
-
visible=bool(DoFormant),
|
1676 |
-
interactive=True,
|
1677 |
-
)
|
1678 |
-
|
1679 |
-
formant_preset.change(fn=preset_apply, inputs=[formant_preset, qfrency, tmbre], outputs=[qfrency, tmbre])
|
1680 |
-
frmntbut = gr.Button("Apply", variant="primary", visible=bool(DoFormant))
|
1681 |
-
formanting.change(fn=formant_enabled,inputs=[formanting,qfrency,tmbre,frmntbut,formant_preset,formant_refresh_button],outputs=[formanting,qfrency,tmbre,frmntbut,formant_preset,formant_refresh_button])
|
1682 |
-
frmntbut.click(fn=formant_apply,inputs=[qfrency, tmbre], outputs=[qfrency, tmbre])
|
1683 |
-
formant_refresh_button.click(fn=update_fshift_presets,inputs=[formant_preset, qfrency, tmbre],outputs=[formant_preset, qfrency, tmbre])
|
1684 |
-
with gr.Row():
|
1685 |
-
vc_output1 = gr.Textbox("")
|
1686 |
-
f0_file = gr.File(label=i18n("F0曲线文件, 可选, 一行一个音高, 代替默认F0及升降调"), visible=False)
|
1687 |
-
|
1688 |
-
but0.click(
|
1689 |
-
vc_single,
|
1690 |
-
[
|
1691 |
-
spk_item,
|
1692 |
-
input_audio0,
|
1693 |
-
vc_transform0,
|
1694 |
-
f0_file,
|
1695 |
-
f0method0,
|
1696 |
-
file_index1,
|
1697 |
-
# file_index2,
|
1698 |
-
# file_big_npy1,
|
1699 |
-
index_rate1,
|
1700 |
-
filter_radius0,
|
1701 |
-
resample_sr0,
|
1702 |
-
rms_mix_rate0,
|
1703 |
-
protect0,
|
1704 |
-
crepe_hop_length
|
1705 |
-
],
|
1706 |
-
[vc_output1, vc_output2],
|
1707 |
-
)
|
1708 |
-
|
1709 |
-
with gr.Accordion("Batch Conversion",open=False):
|
1710 |
-
with gr.Row():
|
1711 |
-
with gr.Column():
|
1712 |
-
vc_transform1 = gr.Number(
|
1713 |
-
label=i18n("变调(整数, 半音数量, 升八度12降八度-12)"), value=0
|
1714 |
-
)
|
1715 |
-
opt_input = gr.Textbox(label=i18n("指定输出文件夹"), value="opt")
|
1716 |
-
f0method1 = gr.Radio(
|
1717 |
-
label=i18n(
|
1718 |
-
"选择音高提取算法,输入歌声可用pm提速,harvest低音好但巨慢无比,crepe效果好但吃GPU"
|
1719 |
-
),
|
1720 |
-
choices=["pm", "harvest", "crepe", "rmvpe"],
|
1721 |
-
value="rmvpe",
|
1722 |
-
interactive=True,
|
1723 |
-
)
|
1724 |
-
filter_radius1 = gr.Slider(
|
1725 |
-
minimum=0,
|
1726 |
-
maximum=7,
|
1727 |
-
label=i18n(">=3则使用对harvest音高识别的结果使用中值滤波,数值为滤波半径,使用可以削弱哑音"),
|
1728 |
-
value=3,
|
1729 |
-
step=1,
|
1730 |
-
interactive=True,
|
1731 |
-
)
|
1732 |
-
with gr.Column():
|
1733 |
-
file_index3 = gr.Textbox(
|
1734 |
-
label=i18n("特征检索库文件路径,为空则使用下拉的选择结果"),
|
1735 |
-
value="",
|
1736 |
-
interactive=True,
|
1737 |
-
)
|
1738 |
-
file_index4 = gr.Dropdown(
|
1739 |
-
label=i18n("自动检测index路径,下拉式选择(dropdown)"),
|
1740 |
-
choices=sorted(index_paths),
|
1741 |
-
interactive=True,
|
1742 |
-
)
|
1743 |
-
refresh_button.click(
|
1744 |
-
fn=lambda: change_choices()[1],
|
1745 |
-
inputs=[],
|
1746 |
-
outputs=file_index4,
|
1747 |
-
)
|
1748 |
-
# file_big_npy2 = gr.Textbox(
|
1749 |
-
# label=i18n("特征文件路径"),
|
1750 |
-
# value="E:\\codes\\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
|
1751 |
-
# interactive=True,
|
1752 |
-
# )
|
1753 |
-
index_rate2 = gr.Slider(
|
1754 |
-
minimum=0,
|
1755 |
-
maximum=1,
|
1756 |
-
label=i18n("检索特征占比"),
|
1757 |
-
value=1,
|
1758 |
-
interactive=True,
|
1759 |
-
)
|
1760 |
-
with gr.Column():
|
1761 |
-
resample_sr1 = gr.Slider(
|
1762 |
-
minimum=0,
|
1763 |
-
maximum=48000,
|
1764 |
-
label=i18n("后处理重采样至最终采样率,0为不进行重采样"),
|
1765 |
-
value=0,
|
1766 |
-
step=1,
|
1767 |
-
interactive=True,
|
1768 |
-
)
|
1769 |
-
rms_mix_rate1 = gr.Slider(
|
1770 |
-
minimum=0,
|
1771 |
-
maximum=1,
|
1772 |
-
label=i18n("输入源音量包络替换输出音量包络融合比例,越靠近1越使用输出包络"),
|
1773 |
-
value=1,
|
1774 |
-
interactive=True,
|
1775 |
-
)
|
1776 |
-
protect1 = gr.Slider(
|
1777 |
-
minimum=0,
|
1778 |
-
maximum=0.5,
|
1779 |
-
label=i18n(
|
1780 |
-
"保护清辅音和呼吸声,防止电音撕裂等artifact,拉满0.5不开启,调低加大保护力度但可能降低索引效果"
|
1781 |
-
),
|
1782 |
-
value=0.33,
|
1783 |
-
step=0.01,
|
1784 |
-
interactive=True,
|
1785 |
-
)
|
1786 |
-
with gr.Column():
|
1787 |
-
dir_input = gr.Textbox(
|
1788 |
-
label=i18n("输入待处理音频文件夹路径(去文件管理器地址栏拷就行了)"),
|
1789 |
-
value="E:\codes\py39\\test-20230416b\\todo-songs",
|
1790 |
-
)
|
1791 |
-
inputs = gr.File(
|
1792 |
-
file_count="multiple", label=i18n("也可批量输入音频文件, 二选一, 优先读文件夹")
|
1793 |
-
)
|
1794 |
-
with gr.Row():
|
1795 |
-
format1 = gr.Radio(
|
1796 |
-
label=i18n("导出文件格式"),
|
1797 |
-
choices=["wav", "flac", "mp3", "m4a"],
|
1798 |
-
value="flac",
|
1799 |
-
interactive=True,
|
1800 |
-
)
|
1801 |
-
but1 = gr.Button(i18n("转换"), variant="primary")
|
1802 |
-
vc_output3 = gr.Textbox(label=i18n("输出信息"))
|
1803 |
-
but1.click(
|
1804 |
-
vc_multi,
|
1805 |
-
[
|
1806 |
-
spk_item,
|
1807 |
-
dir_input,
|
1808 |
-
opt_input,
|
1809 |
-
inputs,
|
1810 |
-
vc_transform1,
|
1811 |
-
f0method1,
|
1812 |
-
file_index3,
|
1813 |
-
file_index4,
|
1814 |
-
# file_big_npy2,
|
1815 |
-
index_rate2,
|
1816 |
-
filter_radius1,
|
1817 |
-
resample_sr1,
|
1818 |
-
rms_mix_rate1,
|
1819 |
-
protect1,
|
1820 |
-
format1,
|
1821 |
-
crepe_hop_length,
|
1822 |
-
],
|
1823 |
-
[vc_output3],
|
1824 |
-
)
|
1825 |
-
but1.click(fn=lambda: easy_uploader.clear())
|
1826 |
-
with gr.TabItem("Download Model"):
|
1827 |
-
with gr.Row():
|
1828 |
-
url=gr.Textbox(label="Enter the URL to the Model:")
|
1829 |
-
with gr.Row():
|
1830 |
-
model = gr.Textbox(label="Name your model:")
|
1831 |
-
download_button=gr.Button("Download")
|
1832 |
-
with gr.Row():
|
1833 |
-
status_bar=gr.Textbox(label="")
|
1834 |
-
download_button.click(fn=download_from_url, inputs=[url, model], outputs=[status_bar])
|
1835 |
-
with gr.Row():
|
1836 |
-
gr.Markdown(
|
1837 |
-
"""
|
1838 |
-
Original RVC:https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI Mangio’s RVC Fork:https://github.com/Mangio621/Mangio-RVC-Fork ❤️ If you like the EasyGUI, help me keep it.❤️ https://paypal.me/lesantillan
|
1839 |
-
"""
|
1840 |
-
)
|
1841 |
-
|
1842 |
-
def has_two_files_in_pretrained_folder():
|
1843 |
-
pretrained_folder = "./pretrained/"
|
1844 |
-
if not os.path.exists(pretrained_folder):
|
1845 |
-
return False
|
1846 |
-
|
1847 |
-
files_in_folder = os.listdir(pretrained_folder)
|
1848 |
-
num_files = len(files_in_folder)
|
1849 |
-
return num_files >= 2
|
1850 |
-
|
1851 |
-
if has_two_files_in_pretrained_folder():
|
1852 |
-
print("Pretrained weights are downloaded. Training tab enabled!\n-------------------------------")
|
1853 |
-
with gr.TabItem("Train", visible=False):
|
1854 |
-
with gr.Row():
|
1855 |
-
with gr.Column():
|
1856 |
-
exp_dir1 = gr.Textbox(label="Voice Name:", value="My-Voice")
|
1857 |
-
sr2 = gr.Radio(
|
1858 |
-
label=i18n("目标采样率"),
|
1859 |
-
choices=["40k", "48k"],
|
1860 |
-
value="40k",
|
1861 |
-
interactive=True,
|
1862 |
-
visible=False
|
1863 |
-
)
|
1864 |
-
if_f0_3 = gr.Radio(
|
1865 |
-
label=i18n("模型是否带音高指导(唱歌一定要, 语音可以不要)"),
|
1866 |
-
choices=[True, False],
|
1867 |
-
value=True,
|
1868 |
-
interactive=True,
|
1869 |
-
visible=False
|
1870 |
-
)
|
1871 |
-
version19 = gr.Radio(
|
1872 |
-
label="RVC version",
|
1873 |
-
choices=["v1", "v2"],
|
1874 |
-
value="v2",
|
1875 |
-
interactive=True,
|
1876 |
-
visible=False,
|
1877 |
-
)
|
1878 |
-
np7 = gr.Slider(
|
1879 |
-
minimum=0,
|
1880 |
-
maximum=config.n_cpu,
|
1881 |
-
step=1,
|
1882 |
-
label="# of CPUs for data processing (Leave as it is)",
|
1883 |
-
value=config.n_cpu,
|
1884 |
-
interactive=True,
|
1885 |
-
visible=True
|
1886 |
-
)
|
1887 |
-
trainset_dir4 = gr.Textbox(label="Path to your dataset (audios, not zip):", value="./dataset")
|
1888 |
-
easy_uploader = gr.Files(label='OR Drop your audios here. They will be uploaded in your dataset path above.',file_types=['audio'])
|
1889 |
-
but1 = gr.Button("1. Process The Dataset", variant="primary")
|
1890 |
-
info1 = gr.Textbox(label="Status (wait until it says 'end preprocess'):", value="")
|
1891 |
-
easy_uploader.upload(fn=upload_to_dataset, inputs=[easy_uploader, trainset_dir4], outputs=[info1])
|
1892 |
-
but1.click(
|
1893 |
-
preprocess_dataset, [trainset_dir4, exp_dir1, sr2, np7], [info1]
|
1894 |
-
)
|
1895 |
-
with gr.Column():
|
1896 |
-
spk_id5 = gr.Slider(
|
1897 |
-
minimum=0,
|
1898 |
-
maximum=4,
|
1899 |
-
step=1,
|
1900 |
-
label=i18n("请指定说话人id"),
|
1901 |
-
value=0,
|
1902 |
-
interactive=True,
|
1903 |
-
visible=False
|
1904 |
-
)
|
1905 |
-
with gr.Accordion('GPU Settings', open=False, visible=False):
|
1906 |
-
gpus6 = gr.Textbox(
|
1907 |
-
label=i18n("以-分隔输入使用的卡号, 例如 0-1-2 使用卡0和卡1和卡2"),
|
1908 |
-
value=gpus,
|
1909 |
-
interactive=True,
|
1910 |
-
visible=False
|
1911 |
-
)
|
1912 |
-
gpu_info9 = gr.Textbox(label=i18n("显卡信息"), value=gpu_info)
|
1913 |
-
f0method8 = gr.Radio(
|
1914 |
-
label=i18n(
|
1915 |
-
"选择音高提取算法:输入歌声可用pm提速,高质量语音但CPU差可用dio提速,harvest质量更好但慢"
|
1916 |
-
),
|
1917 |
-
choices=["harvest","crepe", "mangio-crepe", "rmvpe"], # Fork feature: Crepe on f0 extraction for training.
|
1918 |
-
value="rmvpe",
|
1919 |
-
interactive=True,
|
1920 |
-
)
|
1921 |
-
|
1922 |
-
extraction_crepe_hop_length = gr.Slider(
|
1923 |
-
minimum=1,
|
1924 |
-
maximum=512,
|
1925 |
-
step=1,
|
1926 |
-
label=i18n("crepe_hop_length"),
|
1927 |
-
value=128,
|
1928 |
-
interactive=True,
|
1929 |
-
visible=False,
|
1930 |
-
)
|
1931 |
-
f0method8.change(fn=whethercrepeornah, inputs=[f0method8], outputs=[extraction_crepe_hop_length])
|
1932 |
-
but2 = gr.Button("2. Pitch Extraction", variant="primary")
|
1933 |
-
info2 = gr.Textbox(label="Status(Check the Colab Notebook's cell output):", value="", max_lines=8)
|
1934 |
-
but2.click(
|
1935 |
-
extract_f0_feature,
|
1936 |
-
[gpus6, np7, f0method8, if_f0_3, exp_dir1, version19, extraction_crepe_hop_length],
|
1937 |
-
[info2],
|
1938 |
-
)
|
1939 |
-
with gr.Row():
|
1940 |
-
with gr.Column():
|
1941 |
-
total_epoch11 = gr.Slider(
|
1942 |
-
minimum=1,
|
1943 |
-
maximum=5000,
|
1944 |
-
step=10,
|
1945 |
-
label="Total # of training epochs (IF you choose a value too high, your model will sound horribly overtrained.):",
|
1946 |
-
value=250,
|
1947 |
-
interactive=True,
|
1948 |
-
)
|
1949 |
-
butstop = gr.Button(
|
1950 |
-
"Stop Training",
|
1951 |
-
variant='primary',
|
1952 |
-
visible=False,
|
1953 |
-
)
|
1954 |
-
but3 = gr.Button("3. Train Model", variant="primary", visible=True)
|
1955 |
-
|
1956 |
-
but3.click(fn=stoptraining, inputs=[gr.Number(value=0, visible=False)], outputs=[but3, butstop])
|
1957 |
-
butstop.click(fn=stoptraining, inputs=[gr.Number(value=1, visible=False)], outputs=[butstop, but3])
|
1958 |
-
|
1959 |
-
|
1960 |
-
but4 = gr.Button("4.Train Index", variant="primary")
|
1961 |
-
info3 = gr.Textbox(label="Status(Check the Colab Notebook's cell output):", value="", max_lines=10)
|
1962 |
-
with gr.Accordion("Training Preferences (You can leave these as they are)", open=False):
|
1963 |
-
#gr.Markdown(value=i18n("step3: 填写训练设置, 开始训练模型和索引"))
|
1964 |
-
with gr.Column():
|
1965 |
-
save_epoch10 = gr.Slider(
|
1966 |
-
minimum=1,
|
1967 |
-
maximum=200,
|
1968 |
-
step=1,
|
1969 |
-
label="Backup every X amount of epochs:",
|
1970 |
-
value=10,
|
1971 |
-
interactive=True,
|
1972 |
-
)
|
1973 |
-
batch_size12 = gr.Slider(
|
1974 |
-
minimum=1,
|
1975 |
-
maximum=40,
|
1976 |
-
step=1,
|
1977 |
-
label="Batch Size (LEAVE IT unless you know what you're doing!):",
|
1978 |
-
value=default_batch_size,
|
1979 |
-
interactive=True,
|
1980 |
-
)
|
1981 |
-
if_save_latest13 = gr.Checkbox(
|
1982 |
-
label="Save only the latest '.ckpt' file to save disk space.",
|
1983 |
-
value=True,
|
1984 |
-
interactive=True,
|
1985 |
-
)
|
1986 |
-
if_cache_gpu17 = gr.Checkbox(
|
1987 |
-
label="Cache all training sets to GPU memory. Caching small datasets (less than 10 minutes) can speed up training, but caching large datasets will consume a lot of GPU memory and may not provide much speed improvement.",
|
1988 |
-
value=False,
|
1989 |
-
interactive=True,
|
1990 |
-
)
|
1991 |
-
if_save_every_weights18 = gr.Checkbox(
|
1992 |
-
label="Save a small final model to the 'weights' folder at each save point.",
|
1993 |
-
value=True,
|
1994 |
-
interactive=True,
|
1995 |
-
)
|
1996 |
-
zip_model = gr.Button('5. Download Model')
|
1997 |
-
zipped_model = gr.Files(label='Your Model and Index file can be downloaded here:')
|
1998 |
-
zip_model.click(fn=zip_downloader, inputs=[exp_dir1], outputs=[zipped_model, info3])
|
1999 |
-
with gr.Group():
|
2000 |
-
with gr.Accordion("Base Model Locations:", open=False, visible=False):
|
2001 |
-
pretrained_G14 = gr.Textbox(
|
2002 |
-
label=i18n("加载预训练底模G路径"),
|
2003 |
-
value="pretrained_v2/f0G40k.pth",
|
2004 |
-
interactive=True,
|
2005 |
-
)
|
2006 |
-
pretrained_D15 = gr.Textbox(
|
2007 |
-
label=i18n("加载预训练底模D路径"),
|
2008 |
-
value="pretrained_v2/f0D40k.pth",
|
2009 |
-
interactive=True,
|
2010 |
-
)
|
2011 |
-
gpus16 = gr.Textbox(
|
2012 |
-
label=i18n("以-分隔输入使用的卡号, 例如 0-1-2 使用卡0和卡1和卡2"),
|
2013 |
-
value=gpus,
|
2014 |
-
interactive=True,
|
2015 |
-
)
|
2016 |
-
sr2.change(
|
2017 |
-
change_sr2,
|
2018 |
-
[sr2, if_f0_3, version19],
|
2019 |
-
[pretrained_G14, pretrained_D15, version19],
|
2020 |
-
)
|
2021 |
-
version19.change(
|
2022 |
-
change_version19,
|
2023 |
-
[sr2, if_f0_3, version19],
|
2024 |
-
[pretrained_G14, pretrained_D15],
|
2025 |
-
)
|
2026 |
-
if_f0_3.change(
|
2027 |
-
change_f0,
|
2028 |
-
[if_f0_3, sr2, version19],
|
2029 |
-
[f0method8, pretrained_G14, pretrained_D15],
|
2030 |
-
)
|
2031 |
-
but5 = gr.Button(i18n("一键训练"), variant="primary", visible=False)
|
2032 |
-
but3.click(
|
2033 |
-
click_train,
|
2034 |
-
[
|
2035 |
-
exp_dir1,
|
2036 |
-
sr2,
|
2037 |
-
if_f0_3,
|
2038 |
-
spk_id5,
|
2039 |
-
save_epoch10,
|
2040 |
-
total_epoch11,
|
2041 |
-
batch_size12,
|
2042 |
-
if_save_latest13,
|
2043 |
-
pretrained_G14,
|
2044 |
-
pretrained_D15,
|
2045 |
-
gpus16,
|
2046 |
-
if_cache_gpu17,
|
2047 |
-
if_save_every_weights18,
|
2048 |
-
version19,
|
2049 |
-
],
|
2050 |
-
[
|
2051 |
-
info3,
|
2052 |
-
butstop,
|
2053 |
-
but3,
|
2054 |
-
],
|
2055 |
-
)
|
2056 |
-
but4.click(train_index, [exp_dir1, version19], info3)
|
2057 |
-
but5.click(
|
2058 |
-
train1key,
|
2059 |
-
[
|
2060 |
-
exp_dir1,
|
2061 |
-
sr2,
|
2062 |
-
if_f0_3,
|
2063 |
-
trainset_dir4,
|
2064 |
-
spk_id5,
|
2065 |
-
np7,
|
2066 |
-
f0method8,
|
2067 |
-
save_epoch10,
|
2068 |
-
total_epoch11,
|
2069 |
-
batch_size12,
|
2070 |
-
if_save_latest13,
|
2071 |
-
pretrained_G14,
|
2072 |
-
pretrained_D15,
|
2073 |
-
gpus16,
|
2074 |
-
if_cache_gpu17,
|
2075 |
-
if_save_every_weights18,
|
2076 |
-
version19,
|
2077 |
-
extraction_crepe_hop_length
|
2078 |
-
],
|
2079 |
-
info3,
|
2080 |
-
)
|
2081 |
-
|
2082 |
-
else:
|
2083 |
-
print(
|
2084 |
-
"Pretrained weights not downloaded. Disabling training tab.\n"
|
2085 |
-
"Wondering how to train a voice? Visit here for the RVC model training guide: https://t.ly/RVC_Training_Guide\n"
|
2086 |
-
"-------------------------------\n"
|
2087 |
-
)
|
2088 |
-
|
2089 |
-
app.queue(concurrency_count=511, max_size=1022).launch(share=False, quiet=True)
|
2090 |
-
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CofAI/chat.b4/client/js/icons.js
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
window.FontAwesomeKitConfig={asyncLoading:{enabled:!1},autoA11y:{enabled:!0},baseUrl:"https://ka-f.fontawesome.com",baseUrlKit:"https://kit-pro.fontawesome.com",detectConflictsUntil:null,iconUploads:{},id:96462084,license:"pro",method:"css",minify:{enabled:!0},token:"d0514f1901",v4FontFaceShim:{enabled:!0},v4shim:{enabled:!0},v5FontFaceShim:{enabled:!0},version:"6.1.1"},function(t){"function"==typeof define&&define.amd?define("kit-loader",t):t()}(function(){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}function e(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function n(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function o(t){for(var o=1;o<arguments.length;o++){var r=null!=arguments[o]?arguments[o]:{};o%2?n(Object(r),!0).forEach(function(n){e(t,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function r(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var n=[],o=!0,r=!1,i=void 0;try{for(var c,a=t[Symbol.iterator]();!(o=(c=a.next()).done)&&(n.push(c.value),!e||n.length!==e);o=!0);}catch(t){r=!0,i=t}finally{try{o||null==a.return||a.return()}finally{if(r)throw i}}return n}}(t,e)||function(t,e){if(t){if("string"==typeof t)return i(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n<e;n++)o[n]=t[n];return o}function c(t,e){var n=e&&e.addOn||"",o=e&&e.baseFilename||t.license+n,r=e&&e.minify?".min":"",i=e&&e.fileSuffix||t.method,c=e&&e.subdir||t.method;return t.baseUrl+"/releases/"+("latest"===t.version?"latest":"v".concat(t.version))+"/"+c+"/"+o+r+"."+i}function a(t,e){var n=e||["fa"],o="."+Array.prototype.join.call(n,",."),r=t.querySelectorAll(o);Array.prototype.forEach.call(r,function(e){var n=e.getAttribute("title");e.setAttribute("aria-hidden","true");var o=!e.nextElementSibling||!e.nextElementSibling.classList.contains("sr-only");if(n&&o){var r=t.createElement("span");r.innerHTML=n,r.classList.add("sr-only"),e.parentNode.insertBefore(r,e.nextSibling)}})}var u,f=function(){},s="undefined"!=typeof global&&void 0!==global.process&&"function"==typeof global.process.emit,d="undefined"==typeof setImmediate?setTimeout:setImmediate,l=[];function h(){for(var t=0;t<l.length;t++)l[t][0](l[t][1]);l=[],u=!1}function m(t,e){l.push([t,e]),u||(u=!0,d(h,0))}function p(t){var e=t.owner,n=e._state,o=e._data,r=t[n],i=t.then;if("function"==typeof r){n="fulfilled";try{o=r(o)}catch(t){g(i,t)}}v(i,o)||("fulfilled"===n&&b(i,o),"rejected"===n&&g(i,o))}function v(e,n){var o;try{if(e===n)throw new TypeError("A promises callback cannot return that same promise.");if(n&&("function"==typeof n||"object"===t(n))){var r=n.then;if("function"==typeof r)return r.call(n,function(t){o||(o=!0,n===t?y(e,t):b(e,t))},function(t){o||(o=!0,g(e,t))}),!0}}catch(t){return o||g(e,t),!0}return!1}function b(t,e){t!==e&&v(t,e)||y(t,e)}function y(t,e){"pending"===t._state&&(t._state="settled",t._data=e,m(A,t))}function g(t,e){"pending"===t._state&&(t._state="settled",t._data=e,m(S,t))}function w(t){t._then=t._then.forEach(p)}function A(t){t._state="fulfilled",w(t)}function S(t){t._state="rejected",w(t),!t._handled&&s&&global.process.emit("unhandledRejection",t._data,t)}function O(t){global.process.emit("rejectionHandled",t)}function j(t){if("function"!=typeof t)throw new TypeError("Promise resolver "+t+" is not a function");if(this instanceof j==0)throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");this._then=[],function(t,e){function n(t){g(e,t)}try{t(function(t){b(e,t)},n)}catch(t){n(t)}}(t,this)}j.prototype={constructor:j,_state:"pending",_then:null,_data:void 0,_handled:!1,then:function(t,e){var n={owner:this,then:new this.constructor(f),fulfilled:t,rejected:e};return!e&&!t||this._handled||(this._handled=!0,"rejected"===this._state&&s&&m(O,this)),"fulfilled"===this._state||"rejected"===this._state?m(p,n):this._then.push(n),n.then},catch:function(t){return this.then(null,t)}},j.all=function(t){if(!Array.isArray(t))throw new TypeError("You must pass an array to Promise.all().");return new j(function(e,n){var o=[],r=0;function i(t){return r++,function(n){o[t]=n,--r||e(o)}}for(var c,a=0;a<t.length;a++)(c=t[a])&&"function"==typeof c.then?c.then(i(a),n):o[a]=c;r||e(o)})},j.race=function(t){if(!Array.isArray(t))throw new TypeError("You must pass an array to Promise.race().");return new j(function(e,n){for(var o,r=0;r<t.length;r++)(o=t[r])&&"function"==typeof o.then?o.then(e,n):e(o)})},j.resolve=function(e){return e&&"object"===t(e)&&e.constructor===j?e:new j(function(t){t(e)})},j.reject=function(t){return new j(function(e,n){n(t)})};var F="function"==typeof Promise?Promise:j;function E(t,e){var n=e.fetch,o=e.XMLHttpRequest,r=e.token,i=t;return"URLSearchParams"in window?(i=new URL(t)).searchParams.set("token",r):i=i+"?token="+encodeURIComponent(r),i=i.toString(),new F(function(t,e){if("function"==typeof n)n(i,{mode:"cors",cache:"default"}).then(function(t){if(t.ok)return t.text();throw new Error("")}).then(function(e){t(e)}).catch(e);else if("function"==typeof o){var r=new o;r.addEventListener("loadend",function(){this.responseText?t(this.responseText):e(new Error(""))}),["abort","error","timeout"].map(function(t){r.addEventListener(t,function(){e(new Error(""))})}),r.open("GET",i),r.send()}else e(new Error(""))})}function _(t,e,n){var o=t;return[[/(url\("?)\.\.\/\.\.\/\.\./g,function(t,n){return"".concat(n).concat(e)}],[/(url\("?)\.\.\/webfonts/g,function(t,o){return"".concat(o).concat(e,"/releases/v").concat(n,"/webfonts")}],[/(url\("?)https:\/\/kit-free([^.])*\.fontawesome\.com/g,function(t,n){return"".concat(n).concat(e)}]].forEach(function(t){var e=r(t,2),n=e[0],i=e[1];o=o.replace(n,i)}),o}function C(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},r=e.document||r,i=a.bind(a,r,["fa","fab","fas","far","fal","fad","fak"]),u=Object.keys(t.iconUploads||{}).length>0;t.autoA11y.enabled&&n(i);var f=[{id:"fa-main",addOn:void 0}];t.v4shim&&t.v4shim.enabled&&f.push({id:"fa-v4-shims",addOn:"-v4-shims"}),t.v5FontFaceShim&&t.v5FontFaceShim.enabled&&f.push({id:"fa-v5-font-face",addOn:"-v5-font-face"}),t.v4FontFaceShim&&t.v4FontFaceShim.enabled&&f.push({id:"fa-v4-font-face",addOn:"-v4-font-face"}),u&&f.push({id:"fa-kit-upload",customCss:!0});var s=f.map(function(n){return new F(function(r,i){E(n.customCss?function(t){return t.baseUrlKit+"/"+t.token+"/"+t.id+"/kit-upload.css"}(t):c(t,{addOn:n.addOn,minify:t.minify.enabled}),e).then(function(i){r(function(t,e){var n=e.contentFilter||function(t,e){return t},o=document.createElement("style"),r=document.createTextNode(n(t,e));return o.appendChild(r),o.media="all",e.id&&o.setAttribute("id",e.id),e&&e.detectingConflicts&&e.detectionIgnoreAttr&&o.setAttributeNode(document.createAttribute(e.detectionIgnoreAttr)),o}(i,o(o({},e),{},{baseUrl:t.baseUrl,version:t.version,id:n.id,contentFilter:function(t,e){return _(t,e.baseUrl,e.version)}})))}).catch(i)})});return F.all(s)}function P(t,e){var n=document.createElement("SCRIPT"),o=document.createTextNode(t);return n.appendChild(o),n.referrerPolicy="strict-origin",e.id&&n.setAttribute("id",e.id),e&&e.detectingConflicts&&e.detectionIgnoreAttr&&n.setAttributeNode(document.createAttribute(e.detectionIgnoreAttr)),n}function U(t){var e,n=[],o=document,r=(o.documentElement.doScroll?/^loaded|^c/:/^loaded|^i|^c/).test(o.readyState);r||o.addEventListener("DOMContentLoaded",e=function(){for(o.removeEventListener("DOMContentLoaded",e),r=1;e=n.shift();)e()}),r?setTimeout(t,0):n.push(t)}try{if(window.FontAwesomeKitConfig){var k=window.FontAwesomeKitConfig,L={detectingConflicts:k.detectConflictsUntil&&new Date<=new Date(k.detectConflictsUntil),detectionIgnoreAttr:"data-fa-detection-ignore",fetch:window.fetch,token:k.token,XMLHttpRequest:window.XMLHttpRequest,document:document},I=document.currentScript,T=I?I.parentElement:document.head;(function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return"js"===t.method?function(t,e){e.autoA11y=t.autoA11y.enabled,"pro"===t.license&&(e.autoFetchSvg=!0,e.fetchSvgFrom=t.baseUrl+"/releases/"+("latest"===t.version?"latest":"v".concat(t.version))+"/svgs",e.fetchUploadedSvgFrom=t.uploadsUrl);var n=[];return t.v4shim.enabled&&n.push(new F(function(n,r){E(c(t,{addOn:"-v4-shims",minify:t.minify.enabled}),e).then(function(t){n(P(t,o(o({},e),{},{id:"fa-v4-shims"})))}).catch(r)})),n.push(new F(function(n,r){E(c(t,{minify:t.minify.enabled}),e).then(function(t){var r=P(t,o(o({},e),{},{id:"fa-main"}));n(function(t,e){var n=e&&void 0!==e.autoFetchSvg?e.autoFetchSvg:void 0,o=e&&void 0!==e.autoA11y?e.autoA11y:void 0;return void 0!==o&&t.setAttribute("data-auto-a11y",o?"true":"false"),n&&(t.setAttributeNode(document.createAttribute("data-auto-fetch-svg")),t.setAttribute("data-fetch-svg-from",e.fetchSvgFrom),t.setAttribute("data-fetch-uploaded-svg-from",e.fetchUploadedSvgFrom)),t}(r,e))}).catch(r)})),F.all(n)}(t,e):"css"===t.method?C(t,e,function(t){U(t),function(t){"undefined"!=typeof MutationObserver&&new MutationObserver(t).observe(document,{childList:!0,subtree:!0})}(t)}):void 0})(k,L).then(function(t){t.map(function(t){try{T.insertBefore(t,I?I.nextSibling:null)}catch(e){T.appendChild(t)}}),L.detectingConflicts&&I&&U(function(){I.setAttributeNode(document.createAttribute(L.detectionIgnoreAttr));var t=function(t,e){var n=document.createElement("script");return e&&e.detectionIgnoreAttr&&n.setAttributeNode(document.createAttribute(e.detectionIgnoreAttr)),n.src=c(t,{baseFilename:"conflict-detection",fileSuffix:"js",subdir:"js",minify:t.minify.enabled}),n}(k,L);document.body.appendChild(t)})}).catch(function(t){console.error("".concat("Font Awesome Kit:"," ").concat(t))})}}catch(t){console.error("".concat("Font Awesome Kit:"," ").concat(t))}});
|
|
|
|
spaces/DQChoi/gpt-demo/venv/lib/python3.11/site-packages/fontTools/otlLib/__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
"""OpenType Layout-related functionality."""
|
|
|
|
spaces/DQChoi/gpt-demo/venv/lib/python3.11/site-packages/gradio/templates/frontend/assets/index-322e8a8e.css
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
.gallery.svelte-1ayixqk,.gallery.svelte-1viwdyg{padding:var(--size-1) var(--size-2)}div.svelte-1viwdyg{overflow:hidden;min-width:var(--local-text-width);white-space:nowrap}video.svelte-1tntsc1{flex:none;border:2px solid var(--border-color-primary);border-radius:var(--radius-lg);max-width:none}video.svelte-1tntsc1:hover,video.selected.svelte-1tntsc1{border-color:var(--border-color-accent)}.table.svelte-1tntsc1{margin:0 auto;width:var(--size-20);height:var(--size-20);object-fit:cover}.gallery.svelte-1tntsc1{max-height:var(--size-20);object-fit:cover}div.svelte-rgtszb{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.gallery.svelte-rgtszb{display:flex;align-items:center;cursor:pointer;padding:var(--size-1) var(--size-2);text-align:left}table.svelte-1cib1xd.svelte-1cib1xd{position:relative}td.svelte-1cib1xd.svelte-1cib1xd{border:1px solid var(--table-border-color);padding:var(--size-2);font-size:var(--text-sm);font-family:var(--font-mono)}.selected.svelte-1cib1xd td.svelte-1cib1xd{border-color:var(--border-color-accent)}.table.svelte-1cib1xd.svelte-1cib1xd{display:inline-block;margin:0 auto}.gallery.svelte-1cib1xd td.svelte-1cib1xd:first-child{border-left:none}.gallery.svelte-1cib1xd tr:first-child td.svelte-1cib1xd{border-top:none}.gallery.svelte-1cib1xd td.svelte-1cib1xd:last-child{border-right:none}.gallery.svelte-1cib1xd tr:last-child td.svelte-1cib1xd{border-bottom:none}.overlay.svelte-1cib1xd.svelte-1cib1xd{--gradient-to:transparent;position:absolute;bottom:0;background:linear-gradient(to bottom,transparent,var(--gradient-to));width:var(--size-full);height:50%}.odd.svelte-1cib1xd.svelte-1cib1xd{--gradient-to:var(--table-even-background-fill)}.even.svelte-1cib1xd.svelte-1cib1xd{--gradient-to:var(--table-odd-background-fill)}.button.svelte-1cib1xd.svelte-1cib1xd{--gradient-to:var(--background-fill-primary)}div.svelte-h6ogpl{width:var(--size-10);height:var(--size-10)}.table.svelte-h6ogpl{margin:0 auto}.gallery.svelte-1ayixqk{padding:var(--size-1) var(--size-2)}.gallery.svelte-zvfedn{padding:var(--size-2)}pre.svelte-agpzo2{text-align:left}.gallery.svelte-agpzo2{padding:var(--size-1) var(--size-2)}.wrap.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno{display:inline-block;width:var(--size-full);max-width:var(--size-full);color:var(--body-text-color)}.hide.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno{display:none}.label.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno{display:flex;align-items:center;margin-bottom:var(--size-2);color:var(--block-label-text-color);font-weight:var(--block-label-text-weight);font-size:var(--block-label-text-size);line-height:var(--line-sm)}svg.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno{margin-right:var(--size-1)}.gallery.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno{display:flex;flex-wrap:wrap;gap:var(--spacing-lg)}.gallery-item.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno{border:1px solid var(--border-color-primary);border-radius:var(--button-large-radius);overflow:hidden}.gallery-item.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno:hover{border-color:var(--border-color-accent);background:var(--table-row-focus)}.table-wrap.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno{border:1px solid var(--border-color-primary);border-radius:var(--table-radius);width:var(--size-full);table-layout:auto;overflow-x:auto;line-height:var(--line-sm)}table.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno{width:var(--size-full)}.tr-head.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno{box-shadow:var(--shadow-drop-lg);border-bottom:1px solid var(--border-color-primary)}.tr-head.svelte-13hsdno>.svelte-13hsdno+.svelte-13hsdno{border-right-width:0px;border-left-width:1px;border-color:var(--border-color-primary)}th.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno{padding:var(--size-2);white-space:nowrap}.tr-body.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno{cursor:pointer;border-bottom:1px solid var(--border-color-primary);background:var(--table-even-background-fill)}.tr-body.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno:last-child{border:none}.tr-body.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno:nth-child(odd){background:var(--table-odd-background-fill)}.tr-body.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno:hover{background:var(--table-row-focus)}.tr-body.svelte-13hsdno>.svelte-13hsdno+.svelte-13hsdno{border-right-width:0px;border-left-width:1px;border-color:var(--border-color-primary)}.tr-body.svelte-13hsdno:hover>.svelte-13hsdno+.svelte-13hsdno{border-color:var(--border-color-accent)}td.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno{padding:var(--size-2);text-align:center}.paginate.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno{display:flex;justify-content:center;align-items:center;gap:var(--spacing-sm);margin-top:var(--size-2);color:var(--block-label-text-color);font-size:var(--text-sm)}button.current-page.svelte-13hsdno.svelte-13hsdno.svelte-13hsdno{font-weight:var(--weight-bold)}
|
|
|
|
spaces/DQChoi/gpt-demo/venv/lib/python3.11/site-packages/gradio/themes/utils/sizes.py
DELETED
@@ -1,132 +0,0 @@
|
|
1 |
-
from __future__ import annotations
|
2 |
-
|
3 |
-
|
4 |
-
class Size:
|
5 |
-
all = []
|
6 |
-
|
7 |
-
def __init__(
|
8 |
-
self, xxs: str, xs: str, sm: str, md: str, lg: str, xl: str, xxl: str, name=None
|
9 |
-
):
|
10 |
-
self.xxs = xxs
|
11 |
-
self.xs = xs
|
12 |
-
self.sm = sm
|
13 |
-
self.md = md
|
14 |
-
self.lg = lg
|
15 |
-
self.xl = xl
|
16 |
-
self.xxl = xxl
|
17 |
-
self.name = name
|
18 |
-
Size.all.append(self)
|
19 |
-
|
20 |
-
def expand(self) -> list[str]:
|
21 |
-
return [self.xxs, self.xs, self.sm, self.md, self.lg, self.xl, self.xxl]
|
22 |
-
|
23 |
-
|
24 |
-
radius_none = Size(
|
25 |
-
name="radius_none",
|
26 |
-
xxs="0px",
|
27 |
-
xs="0px",
|
28 |
-
sm="0px",
|
29 |
-
md="0px",
|
30 |
-
lg="0px",
|
31 |
-
xl="0px",
|
32 |
-
xxl="0px",
|
33 |
-
)
|
34 |
-
|
35 |
-
radius_sm = Size(
|
36 |
-
name="radius_sm",
|
37 |
-
xxs="1px",
|
38 |
-
xs="1px",
|
39 |
-
sm="2px",
|
40 |
-
md="4px",
|
41 |
-
lg="6px",
|
42 |
-
xl="8px",
|
43 |
-
xxl="12px",
|
44 |
-
)
|
45 |
-
|
46 |
-
radius_md = Size(
|
47 |
-
name="radius_md",
|
48 |
-
xxs="1px",
|
49 |
-
xs="2px",
|
50 |
-
sm="4px",
|
51 |
-
md="6px",
|
52 |
-
lg="8px",
|
53 |
-
xl="12px",
|
54 |
-
xxl="22px",
|
55 |
-
)
|
56 |
-
|
57 |
-
radius_lg = Size(
|
58 |
-
name="radius_lg",
|
59 |
-
xxs="2px",
|
60 |
-
xs="4px",
|
61 |
-
sm="6px",
|
62 |
-
md="8px",
|
63 |
-
lg="12px",
|
64 |
-
xl="16px",
|
65 |
-
xxl="24px",
|
66 |
-
)
|
67 |
-
|
68 |
-
spacing_sm = Size(
|
69 |
-
name="spacing_sm",
|
70 |
-
xxs="1px",
|
71 |
-
xs="1px",
|
72 |
-
sm="2px",
|
73 |
-
md="4px",
|
74 |
-
lg="6px",
|
75 |
-
xl="9px",
|
76 |
-
xxl="12px",
|
77 |
-
)
|
78 |
-
|
79 |
-
spacing_md = Size(
|
80 |
-
name="spacing_md",
|
81 |
-
xxs="1px",
|
82 |
-
xs="2px",
|
83 |
-
sm="4px",
|
84 |
-
md="6px",
|
85 |
-
lg="8px",
|
86 |
-
xl="10px",
|
87 |
-
xxl="16px",
|
88 |
-
)
|
89 |
-
|
90 |
-
spacing_lg = Size(
|
91 |
-
name="spacing_lg",
|
92 |
-
xxs="2px",
|
93 |
-
xs="4px",
|
94 |
-
sm="6px",
|
95 |
-
md="8px",
|
96 |
-
lg="10px",
|
97 |
-
xl="14px",
|
98 |
-
xxl="28px",
|
99 |
-
)
|
100 |
-
|
101 |
-
text_sm = Size(
|
102 |
-
name="text_sm",
|
103 |
-
xxs="8px",
|
104 |
-
xs="9px",
|
105 |
-
sm="11px",
|
106 |
-
md="13px",
|
107 |
-
lg="16px",
|
108 |
-
xl="20px",
|
109 |
-
xxl="24px",
|
110 |
-
)
|
111 |
-
|
112 |
-
text_md = Size(
|
113 |
-
name="text_md",
|
114 |
-
xxs="9px",
|
115 |
-
xs="10px",
|
116 |
-
sm="12px",
|
117 |
-
md="14px",
|
118 |
-
lg="16px",
|
119 |
-
xl="22px",
|
120 |
-
xxl="26px",
|
121 |
-
)
|
122 |
-
|
123 |
-
text_lg = Size(
|
124 |
-
name="text_lg",
|
125 |
-
xxs="10px",
|
126 |
-
xs="12px",
|
127 |
-
sm="14px",
|
128 |
-
md="16px",
|
129 |
-
lg="20px",
|
130 |
-
xl="24px",
|
131 |
-
xxl="28px",
|
132 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Danielzero/GPT3.5/readme/README_en.md
DELETED
@@ -1,127 +0,0 @@
|
|
1 |
-
<div align="right">
|
2 |
-
<!-- Language: -->
|
3 |
-
<a title="Chinese" href="../README.md">简体中文</a> | English | <a title="Japanese" href="README_ja.md">日本語</a>
|
4 |
-
</div>
|
5 |
-
|
6 |
-
<h1 align="center">川虎 Chat 🐯 Chuanhu Chat</h1>
|
7 |
-
<div align="center">
|
8 |
-
<a href="https://github.com/GaiZhenBiao/ChuanhuChatGPT">
|
9 |
-
<img src="https://user-images.githubusercontent.com/70903329/227087087-93b37d64-7dc3-4738-a518-c1cf05591c8a.png" alt="Logo" height="156">
|
10 |
-
</a>
|
11 |
-
|
12 |
-
<p align="center">
|
13 |
-
<h3>Lightweight and User-friendly Web-UI for LLMs including ChatGPT/ChatGLM/LLaMA</h3>
|
14 |
-
<p align="center">
|
15 |
-
<a href="https://github.com/GaiZhenbiao/ChuanhuChatGPT/blob/main/LICENSE">
|
16 |
-
<img alt="Tests Passing" src="https://img.shields.io/github/license/GaiZhenbiao/ChuanhuChatGPT" />
|
17 |
-
</a>
|
18 |
-
<a href="https://gradio.app/">
|
19 |
-
<img alt="GitHub Contributors" src="https://img.shields.io/badge/Base-Gradio-fb7d1a?style=flat" />
|
20 |
-
</a>
|
21 |
-
<a href="https://t.me/tkdifferent">
|
22 |
-
<img alt="GitHub pull requests" src="https://img.shields.io/badge/Telegram-Group-blue.svg?logo=telegram" />
|
23 |
-
</a>
|
24 |
-
<p>
|
25 |
-
Streaming / Unlimited conversations / Save history / Preset prompts / Chat with files / Web search <br />
|
26 |
-
LaTeX rendering / Table rendering / Code highlighting <br />
|
27 |
-
Auto dark mode / Adaptive web interface / WeChat-like theme <br />
|
28 |
-
Multi-parameters tuning / Multi-API-Key support / Multi-user support <br />
|
29 |
-
Compatible with GPT-4 / Local deployment for LLMs
|
30 |
-
</p>
|
31 |
-
<a href="https://www.youtube.com/watch?v=MtxS4XZWbJE"><strong>Video Tutorial</strong></a>
|
32 |
-
·
|
33 |
-
<a href="https://www.youtube.com/watch?v=77nw7iimYDE"><strong>2.0 Introduction</strong></a>
|
34 |
-
·
|
35 |
-
<a href="https://www.youtube.com/watch?v=x-O1jjBqgu4"><strong>3.0 Introduction & Tutorial</strong></a>
|
36 |
-
||
|
37 |
-
<a href="https://huggingface.co/spaces/JohnSmith9982/ChuanhuChatGPT"><strong>Online trial</strong></a>
|
38 |
-
·
|
39 |
-
<a href="https://huggingface.co/login?next=%2Fspaces%2FJohnSmith9982%2FChuanhuChatGPT%3Fduplicate%3Dtrue"><strong>One-Click deployment</strong></a>
|
40 |
-
</p>
|
41 |
-
<p align="center">
|
42 |
-
<img alt="Animation Demo" src="https://user-images.githubusercontent.com/51039745/226255695-6b17ff1f-ea8d-464f-b69b-a7b6b68fffe8.gif" />
|
43 |
-
</p>
|
44 |
-
</p>
|
45 |
-
</div>
|
46 |
-
|
47 |
-
## Usage Tips
|
48 |
-
|
49 |
-
- To better control the ChatGPT, use System Prompt.
|
50 |
-
- To use a Prompt Template, select the Prompt Template Collection file first, and then choose certain prompt from the drop-down menu.
|
51 |
-
- To try again if the response is unsatisfactory, use `🔄 Regenerate` button.
|
52 |
-
- To start a new line in the input box, press <kbd>Shift</kbd> + <kbd>Enter</kbd> keys.
|
53 |
-
- To quickly switch between input history, press <kbd>↑</kbd> and <kbd>↓</kbd> key in the input box.
|
54 |
-
- To deploy the program onto a server, change the last line of the program to `demo.launch(server_name="0.0.0.0", server_port=<your port number>)`.
|
55 |
-
- To get a public shared link, change the last line of the program to `demo.launch(share=True)`. Please be noted that the program must be running in order to be accessed via a public link.
|
56 |
-
- To use it in Hugging Face Spaces: It is recommended to **Duplicate Space** and run the program in your own Space for a faster and more secure experience.
|
57 |
-
|
58 |
-
## Installation
|
59 |
-
|
60 |
-
```shell
|
61 |
-
git clone https://github.com/GaiZhenbiao/ChuanhuChatGPT.git
|
62 |
-
cd ChuanhuChatGPT
|
63 |
-
pip install -r requirements.txt
|
64 |
-
```
|
65 |
-
|
66 |
-
Then make a copy of `config_example.json`, rename it to `config.json`, and then fill in your API-Key and other settings in the file.
|
67 |
-
|
68 |
-
```shell
|
69 |
-
python ChuanhuChatbot.py
|
70 |
-
```
|
71 |
-
|
72 |
-
A browser window will open and you will be able to chat with ChatGPT.
|
73 |
-
|
74 |
-
> **Note**
|
75 |
-
>
|
76 |
-
> Please check our [wiki page](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/使用教程) for detailed instructions.
|
77 |
-
|
78 |
-
## Troubleshooting
|
79 |
-
|
80 |
-
When you encounter problems, you should try manually pulling the latest changes of this project first. The steps are as follows:
|
81 |
-
|
82 |
-
1. Download the latest code archive by clicking on `Download ZIP` on the webpage, or
|
83 |
-
```shell
|
84 |
-
git pull https://github.com/GaiZhenbiao/ChuanhuChatGPT.git main -f
|
85 |
-
```
|
86 |
-
2. Try installing the dependencies again (as this project may have introduced new dependencies)
|
87 |
-
```
|
88 |
-
pip install -r requirements.txt
|
89 |
-
```
|
90 |
-
3. Update Gradio
|
91 |
-
```
|
92 |
-
pip install gradio --upgrade --force-reinstall
|
93 |
-
```
|
94 |
-
|
95 |
-
Generally, you can solve most problems by following these steps.
|
96 |
-
|
97 |
-
If the problem still exists, please refer to this page: [Frequently Asked Questions (FAQ)](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/常见问题)
|
98 |
-
|
99 |
-
This page lists almost all the possible problems and solutions. Please read it carefully.
|
100 |
-
|
101 |
-
## More Information
|
102 |
-
|
103 |
-
More information could be found in our [wiki](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki):
|
104 |
-
|
105 |
-
- [How to contribute a translation](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/Localization)
|
106 |
-
- [How to make a contribution](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/��献指南)
|
107 |
-
- [How to cite the project](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/使用许可#如何引用该项目)
|
108 |
-
- [Project changelog](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/更新日志)
|
109 |
-
- [Project license](https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/使用许可)
|
110 |
-
|
111 |
-
## Starchart
|
112 |
-
|
113 |
-
[](https://star-history.com/#GaiZhenbiao/ChuanhuChatGPT&Date)
|
114 |
-
|
115 |
-
## Contributors
|
116 |
-
|
117 |
-
<a href="https://github.com/GaiZhenbiao/ChuanhuChatGPT/graphs/contributors">
|
118 |
-
<img src="https://contrib.rocks/image?repo=GaiZhenbiao/ChuanhuChatGPT" />
|
119 |
-
</a>
|
120 |
-
|
121 |
-
## Sponsor
|
122 |
-
|
123 |
-
🐯 If you find this project helpful, feel free to buy me a coke or a cup of coffee~
|
124 |
-
|
125 |
-
<a href="https://www.buymeacoffee.com/ChuanhuChat" ><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=ChuanhuChat&button_colour=219d53&font_colour=ffffff&font_family=Poppins&outline_colour=ffffff&coffee_colour=FFDD00" alt="Buy Me A Coffee" width="250"></a>
|
126 |
-
|
127 |
-
<img width="250" alt="image" src="https://user-images.githubusercontent.com/51039745/226920291-e8ec0b0a-400f-4c20-ac13-dafac0c3aeeb.JPG">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/DragGan/DragGan-Inversion/PTI/models/e4e/encoders/__init__.py
DELETED
File without changes
|
spaces/DragGan/DragGan-Inversion/stylegan_human/stylemixing_video.py
DELETED
@@ -1,167 +0,0 @@
|
|
1 |
-
|
2 |
-
# Copyright (c) SenseTime Research. All rights reserved.
|
3 |
-
|
4 |
-
"""Here we demo style-mixing results using StyleGAN2 pretrained model.
|
5 |
-
Script reference: https://github.com/PDillis/stylegan2-fun """
|
6 |
-
|
7 |
-
|
8 |
-
import moviepy.editor
|
9 |
-
import argparse
|
10 |
-
import legacy
|
11 |
-
|
12 |
-
import scipy
|
13 |
-
import numpy as np
|
14 |
-
import PIL.Image
|
15 |
-
|
16 |
-
import dnnlib
|
17 |
-
import dnnlib.tflib as tflib
|
18 |
-
from typing import List
|
19 |
-
import re
|
20 |
-
import sys
|
21 |
-
import os
|
22 |
-
import click
|
23 |
-
import torch
|
24 |
-
|
25 |
-
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
|
26 |
-
|
27 |
-
|
28 |
-
"""
|
29 |
-
Generate style mixing video.
|
30 |
-
Examples:
|
31 |
-
|
32 |
-
\b
|
33 |
-
python stylemixing_video.py --network=pretrained_models/stylegan_human_v2_1024.pkl --row-seed=3859 \\
|
34 |
-
--col-seeds=3098,31759,3791 --col-styles=8-12 --trunc=0.8 --outdir=outputs/stylemixing_video
|
35 |
-
"""
|
36 |
-
|
37 |
-
|
38 |
-
@click.command()
|
39 |
-
@click.option('--network', 'network_pkl', help='Path to network pickle filename', required=True)
|
40 |
-
@click.option('--row-seed', 'src_seed', type=legacy.num_range, help='Random seed to use for image source row', required=True)
|
41 |
-
@click.option('--col-seeds', 'dst_seeds', type=legacy.num_range, help='Random seeds to use for image columns (style)', required=True)
|
42 |
-
@click.option('--col-styles', 'col_styles', type=legacy.num_range, help='Style layer range (default: %(default)s)', default='0-6')
|
43 |
-
@click.option('--only-stylemix', 'only_stylemix', help='Add flag to only show the style mxied images in the video', default=False)
|
44 |
-
@click.option('--trunc', 'truncation_psi', type=float, help='Truncation psi (default: %(default)s)', default=1)
|
45 |
-
@click.option('--duration-sec', 'duration_sec', type=float, help='Duration of video (default: %(default)s)', default=10)
|
46 |
-
@click.option('--fps', 'mp4_fps', type=int, help='FPS of generated video (default: %(default)s)', default=10)
|
47 |
-
@click.option('--indent-range', 'indent_range', type=int, default=30)
|
48 |
-
@click.option('--outdir', help='Root directory for run results (default: %(default)s)', default='outputs/stylemixing_video', metavar='DIR')
|
49 |
-
def style_mixing_video(network_pkl: str,
|
50 |
-
# Seed of the source image style (row)
|
51 |
-
src_seed: List[int],
|
52 |
-
# Seeds of the destination image styles (columns)
|
53 |
-
dst_seeds: List[int],
|
54 |
-
# Styles to transfer from first row to first column
|
55 |
-
col_styles: List[int],
|
56 |
-
truncation_psi=float,
|
57 |
-
# True if user wishes to show only thre style transferred result
|
58 |
-
only_stylemix=bool,
|
59 |
-
duration_sec=float,
|
60 |
-
smoothing_sec=1.0,
|
61 |
-
mp4_fps=int,
|
62 |
-
mp4_codec="libx264",
|
63 |
-
mp4_bitrate="16M",
|
64 |
-
minibatch_size=8,
|
65 |
-
noise_mode='const',
|
66 |
-
indent_range=int,
|
67 |
-
outdir=str):
|
68 |
-
# Calculate the number of frames:
|
69 |
-
print('col_seeds: ', dst_seeds)
|
70 |
-
num_frames = int(np.rint(duration_sec * mp4_fps))
|
71 |
-
print('Loading networks from "%s"...' % network_pkl)
|
72 |
-
device = torch.device('cuda')
|
73 |
-
with dnnlib.util.open_url(network_pkl) as f:
|
74 |
-
Gs = legacy.load_network_pkl(f)['G_ema'].to(device)
|
75 |
-
|
76 |
-
print(Gs.num_ws, Gs.w_dim, Gs.img_resolution)
|
77 |
-
max_style = int(2 * np.log2(Gs.img_resolution)) - 3
|
78 |
-
assert max(
|
79 |
-
col_styles) <= max_style, f"Maximum col-style allowed: {max_style}"
|
80 |
-
|
81 |
-
# Left col latents
|
82 |
-
print('Generating Source W vectors...')
|
83 |
-
src_shape = [num_frames] + [Gs.z_dim]
|
84 |
-
src_z = np.random.RandomState(
|
85 |
-
*src_seed).randn(*src_shape).astype(np.float32) # [frames, src, component]
|
86 |
-
src_z = scipy.ndimage.gaussian_filter(
|
87 |
-
src_z, [smoothing_sec * mp4_fps] + [0] * (2 - 1), mode="wrap")
|
88 |
-
src_z /= np.sqrt(np.mean(np.square(src_z)))
|
89 |
-
# Map into the detangled latent space W and do truncation trick
|
90 |
-
src_w = Gs.mapping(torch.from_numpy(src_z).to(device), None)
|
91 |
-
w_avg = Gs.mapping.w_avg
|
92 |
-
src_w = w_avg + (src_w - w_avg) * truncation_psi
|
93 |
-
|
94 |
-
# Top row latents (fixed reference)
|
95 |
-
print('Generating Destination W vectors...')
|
96 |
-
dst_z = np.stack([np.random.RandomState(seed).randn(Gs.z_dim)
|
97 |
-
for seed in dst_seeds])
|
98 |
-
dst_w = Gs.mapping(torch.from_numpy(dst_z).to(device), None)
|
99 |
-
dst_w = w_avg + (dst_w - w_avg) * truncation_psi
|
100 |
-
# Get the width and height of each image:
|
101 |
-
H = Gs.img_resolution # 1024
|
102 |
-
W = Gs.img_resolution//2 # 512
|
103 |
-
|
104 |
-
# Generate ALL the source images:
|
105 |
-
src_images = Gs.synthesis(src_w, noise_mode=noise_mode)
|
106 |
-
src_images = (src_images.permute(0, 2, 3, 1) * 127.5 +
|
107 |
-
128).clamp(0, 255).to(torch.uint8)
|
108 |
-
|
109 |
-
# Generate the column images:
|
110 |
-
dst_images = Gs.synthesis(dst_w, noise_mode=noise_mode)
|
111 |
-
dst_images = (dst_images.permute(0, 2, 3, 1) * 127.5 +
|
112 |
-
128).clamp(0, 255).to(torch.uint8)
|
113 |
-
|
114 |
-
print('Generating full video (including source and destination images)')
|
115 |
-
# Generate our canvas where we will paste all the generated images:
|
116 |
-
canvas = PIL.Image.new("RGB", ((
|
117 |
-
W-indent_range) * (len(dst_seeds) + 1), H * (len(src_seed) + 1)), "white") # W, H
|
118 |
-
|
119 |
-
# dst_image:[3,1024,512]
|
120 |
-
for col, dst_image in enumerate(list(dst_images)):
|
121 |
-
canvas.paste(PIL.Image.fromarray(dst_image.cpu().numpy(),
|
122 |
-
"RGB"), ((col + 1) * (W-indent_range), 0)) # H
|
123 |
-
# Aux functions: Frame generation func for moviepy.
|
124 |
-
|
125 |
-
def make_frame(t):
|
126 |
-
# Get the frame number according to time t:
|
127 |
-
frame_idx = int(np.clip(np.round(t * mp4_fps), 0, num_frames - 1))
|
128 |
-
# We wish the image belonging to the frame at time t:
|
129 |
-
src_image = src_images[frame_idx] # always in the same place
|
130 |
-
canvas.paste(PIL.Image.fromarray(src_image.cpu().numpy(), "RGB"),
|
131 |
-
(0-indent_range, H)) # Paste it to the lower left
|
132 |
-
|
133 |
-
# Now, for each of the column images:
|
134 |
-
for col, dst_image in enumerate(list(dst_images)):
|
135 |
-
# Select the pertinent latent w column:
|
136 |
-
w_col = np.stack([dst_w[col].cpu()]) # [18, 512] -> [1, 18, 512]
|
137 |
-
w_col = torch.from_numpy(w_col).to(device)
|
138 |
-
# Replace the values defined by col_styles:
|
139 |
-
w_col[:, col_styles] = src_w[frame_idx, col_styles] # .cpu()
|
140 |
-
# Generate these synthesized images:
|
141 |
-
col_images = Gs.synthesis(w_col, noise_mode=noise_mode)
|
142 |
-
col_images = (col_images.permute(0, 2, 3, 1) *
|
143 |
-
127.5 + 128).clamp(0, 255).to(torch.uint8)
|
144 |
-
# Paste them in their respective spot:
|
145 |
-
for row, image in enumerate(list(col_images)):
|
146 |
-
canvas.paste(
|
147 |
-
PIL.Image.fromarray(image.cpu().numpy(), "RGB"),
|
148 |
-
((col + 1) * (W - indent_range), (row + 1) * H),
|
149 |
-
)
|
150 |
-
return np.array(canvas)
|
151 |
-
|
152 |
-
# Generate video using make_frame:
|
153 |
-
print('Generating style-mixed video...')
|
154 |
-
videoclip = moviepy.editor.VideoClip(make_frame, duration=duration_sec)
|
155 |
-
grid_size = [len(dst_seeds), len(src_seed)]
|
156 |
-
mp4 = "{}x{}-style-mixing_{}_{}.mp4".format(
|
157 |
-
*grid_size, min(col_styles), max(col_styles))
|
158 |
-
if not os.path.exists(outdir):
|
159 |
-
os.makedirs(outdir)
|
160 |
-
videoclip.write_videofile(os.path.join(outdir, mp4),
|
161 |
-
fps=mp4_fps,
|
162 |
-
codec=mp4_codec,
|
163 |
-
bitrate=mp4_bitrate)
|
164 |
-
|
165 |
-
|
166 |
-
if __name__ == "__main__":
|
167 |
-
style_mixing_video()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|