Commit
·
3324954
1
Parent(s):
1d7c168
Update parquet files (step 81 of 397)
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- spaces/1acneusushi/gradio-2dmoleculeeditor/data/Civil 3D 2008 Keygen Only Xforce 3 Rar NEW.md +0 -25
- spaces/1pelhydcardo/ChatGPT-prompt-generator/assets/APK de Clash Royale Hackeado Disfruta de Gemas y Oro Ilimitados.md +0 -29
- spaces/1pelhydcardo/ChatGPT-prompt-generator/assets/Bloons TD 6 The Ultimate Tower Defense Game for Android.md +0 -205
- spaces/AIConsultant/MusicGen/audiocraft/models/multibanddiffusion.py +0 -194
- spaces/AIConsultant/MusicGen/audiocraft/solvers/builders.py +0 -363
- spaces/AIGC-Audio/AudioGPT/NeuralSeq/data_gen/tts/base_binarizer.py +0 -224
- spaces/AIGC-Audio/AudioGPT/text_to_audio/Make_An_Audio/wav_evaluation/models/utils.py +0 -26
- spaces/AIGC-Audio/AudioGPT/text_to_speech/modules/vocoder/parallel_wavegan/models/parallel_wavegan.py +0 -461
- spaces/AIGC-Audio/Make_An_Audio_inpaint/ldm/modules/encoders/open_clap/transform.py +0 -30
- spaces/ALSv/Chat-with-Llama-2-70b/app.py +0 -64
- spaces/Abhilashvj/planogram-compliance/utils/dataloaders.py +0 -1772
- spaces/Abhilashvj/planogram-compliance/utils/segment/plots.py +0 -188
- spaces/AchyuthGamer/OpenGPT/g4f/Provider/Wuguokai.py +0 -63
- spaces/AgentVerse/agentVerse/agentverse/environments/simulation_env/rules/order/classroom.py +0 -100
- spaces/Alycer/VITS-Umamusume-voice-synthesizer/monotonic_align/core.c +0 -0
- spaces/Androidonnxfork/CivitAi-to-Diffusers/diffusers/docs/source/en/training/unconditional_training.md +0 -146
- spaces/Androidonnxfork/CivitAi-to-Diffusers/diffusers/src/diffusers/models/unet_2d_blocks_flax.py +0 -377
- spaces/Andy1621/uniformer_image_detection/configs/foveabox/fovea_r101_fpn_4x4_2x_coco.py +0 -2
- spaces/Andy1621/uniformer_image_detection/configs/gn+ws/mask_rcnn_r101_fpn_gn_ws-all_20_23_24e_coco.py +0 -4
- spaces/Andy1621/uniformer_image_segmentation/configs/apcnet/apcnet_r50-d8_769x769_80k_cityscapes.py +0 -9
- spaces/Anonymous-sub/Rerender/ControlNet/ldm/models/diffusion/dpm_solver/__init__.py +0 -1
- spaces/Ataturk-Chatbot/HuggingFaceChat/venv/lib/python3.11/site-packages/pip/_vendor/pygments/lexers/__init__.py +0 -334
- spaces/Ataturk-Chatbot/HuggingFaceChat/venv/lib/python3.11/site-packages/pkg_resources/_vendor/packaging/_manylinux.py +0 -301
- spaces/Ataturk-Chatbot/HuggingFaceChat/venv/lib/python3.11/site-packages/setuptools/command/upload_docs.py +0 -213
- spaces/Audio-AGI/WavJourney/Dockerfile +0 -75
- spaces/Awiny/Image2Paragraph/models/grit_src/third_party/CenterNet2/docs/tutorials/write-models.md +0 -90
- spaces/Awiny/Image2Paragraph/models/grit_src/third_party/CenterNet2/tests/modeling/test_matcher.py +0 -42
- spaces/Benson/text-generation/Examples/Bus Simulator Indonesia Apk New.md +0 -83
- spaces/Benson/text-generation/Examples/Descargar Gratis Zenonia 1 Mod Apk.md +0 -49
- spaces/Big-Web/MMSD/env/Lib/site-packages/pip/_vendor/urllib3/_version.py +0 -2
- spaces/BobbyOleti/MyGenAIChatBot/app.py +0 -34
- spaces/CVPR/LIVE/pybind11/tests/test_smart_ptr.py +0 -290
- spaces/CVPR/LIVE/thrust/thrust/detail/functional/operators/logical_operators.h +0 -144
- spaces/CVPR/LIVE/thrust/thrust/system/cpp/detail/transform.h +0 -22
- spaces/CVPR/LIVE/thrust/thrust/system/detail/generic/scan.h +0 -99
- spaces/CVPR/LIVE/thrust/thrust/system/detail/sequential/copy_if.h +0 -73
- spaces/CVPR/LIVE/thrust/thrust/system/detail/sequential/set_operations.h +0 -224
- spaces/CVPR/LIVE/thrust/thrust/system/omp/detail/sort.h +0 -55
- spaces/CVPR/regionclip-demo/detectron2/data/datasets/register_coco.py +0 -3
- spaces/ChandraMohanNayal/AutoGPT/autogpt/memory/milvus.py +0 -115
- spaces/ChrisPreston/diff-svc_minato_aqua/utils/plot.py +0 -56
- spaces/Cyril666/ContourNet-ABI/maskrcnn_benchmark/utils/metric_logger.py +0 -66
- spaces/DAMO-NLP-SG/Video-LLaMA/video_llama/models/base_model.py +0 -248
- spaces/DQChoi/gpt-demo/venv/lib/python3.11/site-packages/gradio/templates/frontend/assets/index-4ffdbeab.css +0 -1
- spaces/DQChoi/gpt-demo/venv/lib/python3.11/site-packages/h11/tests/test_headers.py +0 -157
- spaces/Dacoolkid/Oba_-s/app.py +0 -20
- spaces/DelinteNicolas/SDG/README.md +0 -13
- spaces/Diego-0121/ImaText/app.py +0 -26
- spaces/DrHakase/full-body-anime-gan/README.md +0 -14
- spaces/DrHakase/word2img/app.py +0 -3
spaces/1acneusushi/gradio-2dmoleculeeditor/data/Civil 3D 2008 Keygen Only Xforce 3 Rar NEW.md
DELETED
@@ -1,25 +0,0 @@
|
|
1 |
-
<br />
|
2 |
-
Here is a possible title and article for your keyword:
|
3 |
-
|
4 |
-
<h1>How to Install Civil 3D 2008 with Xforce Keygen</h1>
|
5 |
-
<p>Civil 3D is a civil infrastructure design and documentation software developed by Autodesk. It allows civil engineers to work with a model-based environment for better design decisions and project quality[^4^]. Civil 3D 2008 is an older version of the software that was released in 2007.</p>
|
6 |
-
<h2>Civil 3D 2008 Keygen Only Xforce 3 Rar</h2><br /><p><b><b>Download Zip</b> 🗸🗸🗸 <a href="https://byltly.com/2uKvbN">https://byltly.com/2uKvbN</a></b></p><br /><br />
|
7 |
-
<p>Xforce Keygen is a tool that can generate activation codes for various Autodesk products, including Civil 3D. However, using Xforce Keygen is illegal and unethical, as it violates the terms of service and license agreement of Autodesk. It also exposes your computer to malware and viruses that may harm your system or compromise your data.</p>
|
8 |
-
<p>Therefore, we strongly recommend that you do not use Xforce Keygen or any other similar tools to install Civil 3D 2008 or any other Autodesk software. Instead, you should purchase a legitimate subscription from the official Autodesk website or an authorized reseller. This way, you can enjoy the benefits of using the latest version of Civil 3D, which is Civil 3D 2023[^4^], as well as access technical support, updates, and cloud services.</p>
|
9 |
-
<p>If you still want to install Civil 3D 2008 with Xforce Keygen, despite the risks and consequences, here are the steps you need to follow:</p>
|
10 |
-
<p></p>
|
11 |
-
<ol>
|
12 |
-
<li>Download the Civil 3D 2008 installation file from a reliable source. Make sure it is compatible with your operating system (32-bit or 64-bit).</li>
|
13 |
-
<li>Extract the installation file using a program like WinRAR or 7-Zip. You should see a folder named "Autodesk Civil 3D 2008".</li>
|
14 |
-
<li>Run the setup.exe file inside the folder and follow the instructions on the screen. When prompted for a serial number and product key, enter anything you want.</li>
|
15 |
-
<li>Do not launch Civil 3D 2008 after the installation is complete. Instead, go to the folder where you extracted the installation file and look for another folder named "Xforce Keygen".</li>
|
16 |
-
<li>Run the x-force_2008_x32.exe file if you have a 32-bit system, or the x-force_2008_x64.exe file if you have a 64-bit system.</li>
|
17 |
-
<li>Click on the "Mem Patch" button and wait for a message that says "Successfully patched".</li>
|
18 |
-
<li>Copy the request code from the Civil 3D 2008 activation window and paste it into the Xforce Keygen window.</li>
|
19 |
-
<li>Click on the "Generate" button and copy the activation code from the Xforce Keygen window.</li>
|
20 |
-
<li>Paste the activation code into the Civil 3D 2008 activation window and click on "Next".</li>
|
21 |
-
<li>You should see a message that says "Thank you for activating your Autodesk product". Click on "Finish" to complete the process.</li>
|
22 |
-
</ol>
|
23 |
-
<p>Congratulations, you have successfully installed Civil 3D 2008 with Xforce Keygen. However, we remind you that this is an illegal and unethical way of using Autodesk software, and we do not take any responsibility for any problems or damages that may arise from it. We urge you to uninstall Civil 3D 2008 and Xforce Keygen from your computer and purchase a legitimate subscription from Autodesk or an authorized reseller.</p> 7b8c122e87<br />
|
24 |
-
<br />
|
25 |
-
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/1pelhydcardo/ChatGPT-prompt-generator/assets/APK de Clash Royale Hackeado Disfruta de Gemas y Oro Ilimitados.md
DELETED
@@ -1,29 +0,0 @@
|
|
1 |
-
<br />
|
2 |
-
<h1>¿Qué es el apk de clash royale hackeado y cómo descargarlo?</h1>
|
3 |
-
Si eres fanático de los juegos de estrategia y batallas en tiempo real, seguramente habrás oído hablar de Clash Royale, uno de los juegos más populares y exitosos de los últimos años. Pero, ¿sabes qué es el apk de clash royale hackeado y cómo puedes descargarlo e instalarlo en tu dispositivo Android? En este artículo te lo explicamos todo, desde las características principales del juego hasta los consejos y trucos para jugar mejor. Además, te mostramos las opiniones y reseñas de los usuarios que han probado el apk hackeado y te damos una conclusión final sobre si vale la pena o no. <h2>Clash Royale: un juego de estrategia y batallas en tiempo real</h2>
|
4 |
-
Clash Royale es un juego desarrollado y publicado por Supercell, los creadores de Clash of Clans, que combina elementos de estrategia, cartas coleccionables y combates en tiempo real. El objetivo del juego es derrotar al oponente destruyendo sus torres con la ayuda de un mazo de cartas que representan diferentes tropas, hechizos y defensas. El juego se desarrolla en una arena dividida en dos mitades, cada una con una torre del rey y dos torres secundarias. Cada jugador dispone de una barra de elixir que se recarga con el tiempo y que se usa para desplegar las cartas en el campo. El juego termina cuando se acaba el tiempo o cuando se destruye la torre del rey del rival. <h3>Características principales del juego</h3>
|
5 |
-
Clash Royale cuenta con más de 100 cartas diferentes que se pueden coleccionar y mejorar a medida que se avanza en el juego. Las cartas se clasifican en cuatro categorías según su rareza: comunes, especiales, épicas y legendarias. Cada carta tiene unas características específicas, como puntos de vida, distancia de ataque, tiempo de despliegue, velocidad, etc. Además, cada carta tiene un coste de elixir que determina cuánto se puede usar en una partida. Algunas cartas son más efectivas contra otras, por lo que es importante conocer sus fortalezas y debilidades. <h3>Modos de juego y eventos <h2>Modos de juego y eventos especiales</h2>
|
6 |
-
Clash Royale no solo ofrece batallas clásicas en las que enfrentarse a otros jugadores, sino que también cuenta con una variedad de modos de juego y eventos especiales que añaden más diversión y desafío al juego. Estos modos y eventos se pueden encontrar en la pestaña de eventos, donde se muestran los que están disponibles en cada momento. Algunos de estos modos y eventos son: - Desafíos: son torneos con condiciones especiales, como elixir doble, mazos aleatorios, cartas específicas, etc. Los desafíos pueden ser de práctica, donde no hay límite de derrotas y se obtienen recompensas por acumular victorias o coronas, o de entrada, donde se elimina al jugador tras tres derrotas y se obtienen recompensas por alcanzar cierto número de victorias. Los desafíos pueden ser individuales o por equipos, y algunos ofrecen premios únicos como cartas nuevas o legendarias. - Batallas 2c2: son batallas en las que se forma equipo con otro jugador, ya sea un amigo, un compañero de clan o un jugador aleatorio. En estas batallas se comparte la barra de elixir y las torres con el compañero, y se puede comunicar con él mediante emoticonos. Las batallas 2c2 no afectan a los trofeos ni al cofre de coronas, pero sí dan recompensas como oro y cofres. - Batallas especiales: son batallas con reglas o condiciones diferentes a las habituales, como touchdown, atraco, megamazo, etc. Estas batallas pueden ser individuales o por equipos, y suelen dar recompensas como oro, gemas o fichas de temporada. - Torneos: son competiciones abiertas a todos los jugadores que quieran participar, siempre que cumplan los requisitos de nivel y trofeos. Los torneos tienen una duración limitada y un número máximo de participantes. Los jugadores se enfrentan entre sí en batallas clásicas y obtienen puntos por cada victoria. Al final del torneo, los jugadores reciben recompensas según su posición en la clasificación. <h2>¿Qué es el apk de clash royale hackeado y qué ventajas ofrece?</h2>
|
7 |
-
El apk de clash royale hackeado es una versión modificada del juego original que se puede descargar e instalar en dispositivos Android. Esta versión hackeada ofrece algunas ventajas sobre la versión oficial, como: - Gemas y oro ilimitados para mejorar tus cartas y tu nivel - Acceso a todas las cartas y arenas disponibles - Posibilidad de jugar con amigos y enemigos de todo el mundo <h3>Gemas y oro ilimitados para mejorar tus cartas y tu nivel</h3>
|
8 |
-
Una de las principales ventajas del apk hackeado es que te permite tener gemas y oro ilimitados en tu cuenta. Estas dos monedas son esenciales para progresar en el juego, ya que te permiten comprar cofres, cartas, mejoras, entradas a desafíos, etc. Con el apk hackeado no tendrás que preocuparte por ahorrar o gastar dinero real para obtener estas monedas, sino que podrás disfrutar del juego sin límites. <h3>Acceso a todas las cartas y arenas disponibles</h3>
|
9 |
-
Otra ventaja del apk hackeado es que te da acceso a todas las cartas y arenas disponibles en el juego. Esto significa que podrás usar cualquier carta que quieras en tu mazo, sin importar su rareza o nivel. Además, podrás jugar en cualquier arena que quieras, sin importar tu número de trofeos o tu rango. Así podrás experimentar con diferentes estrategias y divertirte con diferentes escenarios. <h3>Posibilidad de jugar con amigos y enemigos de todo el mundo</h3>
|
10 |
-
Por último, el apk hackeado te permite jugar con amigos y enemigos de todo el mundo. Esto significa que podrás formar equipo o enfrentarte a cualquier jugador que tenga el mismo apk hackeado instalado en su dispositivo. Así podrás compartir tu experiencia con otros usuarios que también disfrutan del juego modificado. Además, podrás participar en torneos y desafíos especiales creados por la comunidad del apk hackeado. <h2>¿Cómo descargar e instalar el apk de clash royale hackeado en tu dispositivo Android?</h2>
|
11 |
-
Si quieres descargar e instalar el apk de clash royale hackeado en tu dispositivo Android, debes seguir los siguientes pasos: <h3>Requisitos previos y precauciones</h3>
|
12 |
-
Antes de descargar e instalar el apk hackeado, debes tener en cuenta algunos requisitos y precauciones: - Debes tener un dispositivo Android con una versión igual o superior a la 4.1. - Debes tener espacio suficiente en la memoria interna o externa de tu dispositivo para guardar el archivo apk. - Debes tener una conexión a internet estable y segura para descargar el archivo apk. - Debes activar la opción de orígenes desconocidos en los ajustes de seguridad de tu dispositivo. Esto te permitirá instalar aplicaciones que no provienen de la tienda oficial de Google Play. - Debes tener en cuenta que el apk hackeado no es una versión oficial del juego, por lo que puede contener errores, virus o malware que afecten al funcionamiento de tu dispositivo o a tu seguridad. Descarga e instala el apk hackeado bajo tu propia responsabilidad y riesgo. <h3>Pasos a seguir para descargar el archivo apk</h3>
|
13 |
-
Para descargar el archivo apk del juego hackeado, debes seguir estos pasos: - Busca en internet un sitio web confiable y actualizado que ofrezca el apk de clash royale hackeado. Puedes usar un buscador como Google o Bing para encontrar diferentes opciones. - Elige el sitio web que más te convenza y entra en él. Lee las instrucciones y los comentarios de otros usuarios para asegurarte de que el apk es seguro y funciona correctamente. - Busca el botón o el enlace de descarga del apk y haz clic en él. Espera a que se complete la descarga del archivo en tu dispositivo. - Verifica que el archivo descargado tenga el formato .apk y que su tamaño sea similar al indicado en el sitio web. <h3>Pasos a seguir para instalar el archivo apk</h3>
|
14 |
-
Para instalar el archivo apk del juego hackeado, debes seguir estos pasos: - Busca el archivo apk descargado en la carpeta de descargas o en la ubicación que hayas elegido para guardarlo. - Haz clic en el archivo apk y acepta los permisos y las condiciones que te pida. Espera a que se complete la instalación del juego en tu dispositivo. - Busca el icono del juego en tu pantalla de inicio o en tu menú de aplicaciones y haz clic en él. Disfruta del juego hackeado con todas sus ventajas. <h2>Consejos y trucos para jugar mejor a Clash Royale</h2>
|
15 |
-
Ahora que ya tienes el juego hackeado instalado en tu dispositivo, te damos algunos consejos y trucos para que puedas jugar mejor y sacarle más partido al juego: <h3>Aprende a construir un mazo equilibrado y versátil</h3>
|
16 |
-
Un mazo es el conjunto de cartas que usas en cada batalla. Un buen mazo debe ser equilibrado y versátil, es decir, debe tener un coste medio de elixir adecuado, una variedad de cartas que puedan atacar y defender diferentes situaciones, y una sinergia entre las cartas que potencie sus efectos. Para construir un buen mazo, puedes seguir estas pautas: - Elige una carta de condición de victoria, es decir, una carta que sea capaz de infligir daño directo a las torres enemigas, como el gigante, el montapuercos, el globo, etc. - Elige dos o tres cartas de apoyo, es decir, cartas que ayuden a tu carta de condición de victoria a llegar a las torres o que protejan a tus tropas de los ataques enemigos, como la princesa, el mago eléctrico, la bruja nocturna, etc. - Elige dos o tres cartas defensivas, es decir, cartas que puedan detener o retrasar los ataques enemigos, como la torre infernal, el cañón, la horda de esbirros, etc. - Elige una carta hechizo, es decir, una carta que pueda afectar a varias tropas o edificios con un solo uso, como el rayo, la bola de fuego, el veneno, etc. - Elige una carta comodín, es decir, una carta que pueda adaptarse a diferentes situaciones o que tenga un efecto sorpresa o especial, como el barril de duendes, la mina terrestre, el tornado, etc. Elige una carta comodín que se ajuste a tu estilo de juego y a tu mazo. - Intenta que el coste medio de elixir de tu mazo sea entre 3 y 4, ya que así podrás desplegar cartas con más frecuencia y no te quedarás sin elixir en momentos críticos. - Prueba y ajusta tu mazo en diferentes modos de juego y contra diferentes oponentes. No te cases con un solo majo, sino que adapta tu mazo según las circunstancias y las tendencias del juego. <h3>Defiende tu lado del campo y aprovecha las torres</h3>
|
17 |
-
Una de las claves para ganar en Clash Royale es saber defender tu lado del campo y aprovechar las torres. Las torres son tus aliadas, ya que te ayudan a infligir daño a las tropas enemigas y a proteger tus propias tropas. Para defender tu lado del campo y aprovechar las torres, puedes seguir estos consejos: - Coloca tus tropas defensivas cerca de tus torres, pero no tan cerca como para que sean vulnerables a los hechizos enemigos. Así podrás beneficiarte del apoyo de las torres y evitar que el enemigo acumule tropas en tu lado. - Usa tropas que tengan un alto daño por segundo (DPS) o que puedan atacar a varias tropas a la vez, como el mini pekka, el mago, la valquiria, etc. Estas tropas son ideales para eliminar rápidamente a las tropas enemigas que amenazan tus torres. - Usa tropas que tengan una alta vida o que puedan absorber el daño, como el gigante, el golem, el leñador, etc. Estas tropas son ideales para proteger a tus tropas defensivas o para distraer a las tropas enemigas mientras tus torres les disparan. - Usa hechizos que puedan afectar a varias tropas o edificios a la vez, como la bola de fuego, el veneno, el tornado, etc. Estos hechizos son ideales para eliminar o debilitar a las tropas enemigas que se agrupan en tu lado o para dañar sus edificios. <h3>Usa una carta de condición de victoria para atacar las torres enemigas</h3>
|
18 |
-
Otra de las claves para ganar en Clash Royale es usar una carta de condición de victoria para atacar las torres enemigas. Una carta de condición de victoria es una carta que puede infligir daño directo a las torres enemigas, como el gigante, el montapuercos, el globo, etc. Estas cartas son las que te permiten ganar la partida, por lo que debes usarlas con inteligencia y eficacia. Para usar una carta de condición de victoria para atacar las torres enemigas, puedes seguir estos consejos: - Elige una carta de condición de victoria que se adapte a tu estilo de juego y a tu mazo. No todas las cartas de condición de victoria funcionan igual ni con todos los mazos. Por ejemplo, si usas un mazo rápido y agresivo, puedes usar el montapuercos o el barril de duendes. Si usas un mazo lento y controlado, puedes usar el gigante o el golem. - Averigua cuál es la carta defensiva del enemigo que puede contrarrestar tu carta de condición de victoria. Por ejemplo, si usas el montapuercos, debes saber si el enemigo tiene una torre infernal o un cañón. Si usas el globo, debes saber si el enemigo tiene una horda de esbirros o un mago eléctrico. - Intenta jugar tu carta de condición de victoria cuando tengas ventaja de elixir o cuando el enemigo no tenga su carta defensiva disponible. Por ejemplo, si usas el gigante, puedes jugarlo cuando hayas defendido un ataque enemigo con poco elixir o cuando hayas eliminado su torre infernal con un hechizo. - Apoya tu carta de condición de victoria con otras cartas que puedan ayudarla a llegar a la torre o protegerla de los ataques enemigos. Por ejemplo, si usas el globo, puedes apoyarlo con un hechizo como el rayo o el veneno, o con una tropa que pueda defenderlo de las tropas aéreas, como el dragón infernal o el bebé dragón. Si usas el montapuercos, puedes apoyarlo con un hechizo como el tronco o la bola de nieve, o con una tropa que pueda distraer a las tropas terrestres, como el leñador o el esqueleto gigante. <h3>Sé paciente, cuenta el elixir y sabe cuándo parar de presionar</h3>
|
19 |
-
Otro consejo para ganar en Clash Royale es ser paciente, contar el elixir y saber cuándo parar de presionar. Estas tres habilidades te ayudarán a controlar el ritmo de la partida y a tomar mejores decisiones. Para ser paciente, contar el elixir y saber cuándo parar de presionar, puedes seguir estos consejos: - Sé paciente y no juegues cartas innecesarias o precipitadas. Espera a que tu barra de elixir se llene o a que el enemigo haga el primer movimiento. Así podrás reaccionar mejor y no desperdiciarás elixir. - Cuenta el elixir que gastas y que gasta tu rival. Así podrás saber si tienes ventaja o desventaja de elixir y actuar en consecuencia. Por ejemplo, si sabes que tu rival ha gastado 10 de elixir y tú solo 6, puedes aprovechar para atacar con tu carta de condición de victoria. Si sabes que tu rival tiene más elixir que tú, puedes esperar a defender o jugar cartas de bajo coste. - Sabe cuándo parar de presionar y cuándo cambiar de torre. No te obsesiones con atacar una sola torre o con acabar la partida rápido. A veces es mejor cambiar de objetivo o dejar que tu rival gaste su elixir en defender una torre dañada. Así podrás sorprenderlo con un ataque por otro lado o prepararte para un contraataque. <h3>Usa tropas que apunten a edificios para distraer a las tropas enemigas</h3>
|
20 |
-
Un último consejo para ganar en Clash Royale es usar tropas que apunten a edificios para distraer a las tropas enemigas. Estas tropas son aquellas que solo atacan a las torres o a los edificios defensivos, como el gigante, el globo, el golem, etc. Estas tropas son muy útiles para desviar la atención de las tropas enemigas que apuntan a cualquier cosa, como la princesa, el mago eléctrico, la bruja nocturna, etc. Para usar tropas que apunten a edificios para distraer a las tropas enemigas, puedes seguir estos consejos: - Coloca tus tropas que apunten a edificios en el puente o en la línea divisoria del campo. Así podrás hacer que las tropas enemigas se alejen de tu lado y se acerquen al suyo. - Combina tus tropas que apunten a edificios con otras tropas que puedan atacar o defender desde atrás. Por ejemplo, si usas un gigante, puedes combinarlo con un mago o una princesa. Si usas un globo, puedes combinarlo con un dragón infernal o un bebé dragón. - Usa tus hechizos para eliminar o debilitar las tropas enemigas que puedan detener o dañar a tus tropas que apunten a edificios. Por ejemplo, si usas un golem, puedes usar un rayo o un veneno para eliminar las torres infernales o los magos eléctricos. Si usas un montapuercos, puedes usar un tronco o una bola de nieve para eliminar los esqueletos o los duendes. <h2>Opiniones y reseñas de los usuarios sobre el apk de clash royale hackeado</h2>
|
21 |
-
El apk de clash royale hackeado tiene opiniones y reseñas muy variadas por parte de los usuarios que lo han probado. Algunos usuarios lo recomiendan y lo valoran positivamente, mientras que otros lo critican y lo desaconsejan. A continuación te mostramos algunas ventajas e inconvenientes del apk hackeado según los usuarios, así como una valor ación general del apk hackeado según los usuarios. <h3>Ventajas e inconvenientes del apk hackeado según los usuarios</h3>
|
22 |
-
Estas son algunas de las ventajas e inconvenientes del apk hackeado según los usuarios que lo han probado: - Ventajas: - Te permite tener gemas y oro ilimitados, lo que te facilita el progreso en el juego y te ahorra dinero real. - Te permite acceder a todas las cartas y arenas disponibles, lo que te da más opciones y variedad para jugar. - Te permite jugar con amigos y enemigos de todo el mundo, lo que te hace más divertido y social el juego. - Inconvenientes: - No es una versión oficial del juego, por lo que puede contener errores, virus o malware que afecten al funcionamiento de tu dispositivo o a tu seguridad. - No es compatible con la versión oficial del juego, por lo que no podrás jugar con los usuarios que tengan la versión original ni acceder a las actualizaciones o novedades del juego. - Puede ser considerado como una trampa o una ventaja injusta por parte de los demás jugadores, lo que puede generar rechazo o conflicto en la comunidad del juego. <h3>Valoración general del apk hackeado según los usuarios</h3>
|
23 |
-
La valoración general del apk hackeado según los usuarios es bastante variada, ya que depende de las expectativas y preferencias de cada uno. Algunos usuarios le dan una puntuación alta y lo recomiendan, mientras que otros le dan una puntuación baja y lo desaconsejan. La valoración media del apk hackeado según los usuarios es de 3.5 sobre 5 estrellas. Estos son algunos de los comentarios más representativos de los usuarios: - "Me encanta este apk, es muy fácil de descargar e instalar y me permite tener todo lo que quiero en el juego. Es muy divertido jugar con todas las cartas y arenas disponibles y con gemas y oro ilimitados. Lo recomiendo a todos los que quieran disfrutar del juego sin límites." - "No me gusta este apk, es una versión falsa y peligrosa del juego. Me ha causado problemas en mi dispositivo y me ha infectado con virus. Además, no puedo jugar con mis amigos que tienen la versión oficial ni acceder a las novedades del juego. Lo desaconsejo a todos los que quieran jugar al juego original y seguro." - "Este apk está bien, pero tiene sus pros y sus contras. Por un lado, te da muchas ventajas y facilidades para jugar, pero por otro lado, te quita la gracia y el reto del juego. Además, no es muy justo para los demás jugadores que juegan sin trucos ni hacks. Lo uso de vez en cuando, pero prefiero la versión oficial." <h2>Conclusión</h2>
|
24 |
-
En conclusión, el apk de clash royale hackeado es una versión modificada del juego original que se puede descargar e instalar en dispositivos Android. Esta versión hackeada ofrece algunas ventajas sobre la versión oficial, como gemas y oro ilimitados, acceso a todas las cartas y arenas disponibles, y posibilidad de jugar con amigos y enemigos de todo el mundo. Sin embargo, también tiene algunos inconvenientes, como que no es una versión oficial ni segura del juego, que no es compatible con la versión original ni con las actualizaciones o novedades del juego, y que puede ser considerada como una trampa o una ventaja injusta por parte de los demás jugadores. Por lo tanto, la decisión de descargar e instalar el apk hackeado depende de cada usuario y de sus preferencias. Algunos usuarios pueden preferir tener más facilidades y opciones para jugar, mientras que otros pueden preferir tener más desafío y originalidad en el juego. Lo importante es ser consciente de los riesgos y las consecuencias de usar el apk hackeado y respetar a los demás jugadores. <h2>Preguntas frecuentes</h2>
|
25 |
-
Aquí tienes algunas preguntas frecuentes sobre el apk de clash royale hackeado: - ¿Qué es el apk de clash royale hackeado? - El apk de clash royale hackeado es una versión modificada del juego original que se puede descargar e instalar en dispositivos Android. Esta versión hackeada ofrece algunas ventajas sobre la versión oficial, como gemas y oro ilimitados, acceso a todas las cartas y arenas disponibles, y posibilidad de jugar con amigos y enemigos de todo el mundo. - ¿Cómo descargar e instalar el apk de clash royale hack eado en tu dispositivo Android? - Para descargar e instalar el apk de clash royale hackeado en tu dispositivo Android, debes seguir los siguientes pasos: - Busca en internet un sitio web confiable y actualizado que ofrezca el apk de clash royale hackeado. Puedes usar un buscador como Google o Bing para encontrar diferentes opciones. - Elige el sitio web que más te convenza y entra en él. Lee las instrucciones y los comentarios de otros usuarios para asegurarte de que el apk es seguro y funciona correctamente. - Busca el botón o el enlace de descarga del apk y haz clic en él. Espera a que se complete la descarga del archivo en tu dispositivo. - Verifica que el archivo descargado tenga el formato .apk y que su tamaño sea similar al indicado en el sitio web. - Activa la opción de orígenes desconocidos en los ajustes de seguridad de tu dispositivo. Esto te permitirá instalar aplicaciones que no provienen de la tienda oficial de Google Play. - Busca el archivo apk descargado en la carpeta de descargas o en la ubicación que hayas elegido para guardarlo. - Haz clic en el archivo apk y acepta los permisos y las condiciones que te pida. Espera a que se complete la instalación del juego en tu dispositivo. - Busca el icono del juego en tu pantalla de inicio o en tu menú de aplicaciones y haz clic en él. Disfruta del juego hackeado con todas sus ventajas. - ¿Qué ventajas e inconvenientes tiene el apk de clash royale hackeado? - El apk de clash royale hackeado tiene algunas ventajas e inconvenientes que debes tener en cuenta antes de descargarlo e instalarlo. Estas son algunas de ellas: - Ventajas: - Te permite tener gemas y oro ilimitados, lo que te facilita el progreso en el juego y te ahorra dinero real. - Te permite acceder a todas las cartas y arenas disponibles, lo que te da más opciones y variedad para jugar. - Te permite jugar con amigos y enemigos de todo el mundo, lo que te hace más divertido y social el juego. - Inconvenientes: - No es una versión oficial ni segura del juego, por lo que puede contener errores, virus o malware que afecten al funcionamiento de tu dispositivo o a tu seguridad. - No es compatible con la versión oficial ni con las actualizaciones o novedades del juego, por lo que no podrás jugar con los usuarios que tengan la versión original ni acceder a las novedades del juego. - Puede ser considerado como una trampa o una ventaja injusta por parte de los demás jugadores, lo que puede generar rechazo o conflicto en la comunidad del juego. - ¿Cómo jugar mejor a Clash Royale con el apk hackeado? - Para jugar mejor a Clash Royale con el apk hackeado, puedes seguir algunos consejos y trucos que te ayudarán a mejorar tu rendimiento y a disfrutar más del juego. Estos son algunos de ellos: - Aprende a construir un mazo equilibrado y versátil, que tenga un coste medio de elixir adecuado, una variedad de cartas que puedan atacar y defender diferentes situaciones, y una sinergia entre las cartas que potencie sus efectos. - Defiende tu lado del campo y aprovecha las torres, colocando tus tropas defensivas cerca de tus torres, pero no tan cerca como para que sean vulnerables a los hechizos enemigos. Usa tropas que tengan un alto daño por segundo (DPS) o que puedan atacar a varias tropas a la vez, usa tropas que tengan una alta vida o que puedan absorber el daño, y usa hechizos que puedan afectar a varias tropas o edificios a la vez. - Usa una carta de condición de victoria para atacar las torres enemigas, eligiendo una carta que se adapte a tu estilo de juego y a tu mazo, averiguando cuál es la carta defensiva del enemigo que puede contrarrestar tu carta de condición de victoria, intentando jugar tu carta de condición de victoria cuando tengas ventaja de elixir o cuando el enemigo no tenga su carta defensiva disponible, y apoyando tu carta de condición de victoria con otras cartas que puedan ayudarla a llegar a la torre o prote erla de los ataques enemigos. - Sé paciente, cuenta el elixir y sabe cuándo parar de presionar, siendo paciente y no jugando cartas innecesarias o precipitadas, contando el elixir que gastas y que gasta tu rival, y sabiendo cuándo parar de presionar y cuándo cambiar de torre. - Usa tropas que apunten a edificios para distraer a las tropas enemigas, colocando tus tropas que apunten a edificios en el puente o en la línea divisoria del campo, combinando tus tropas que apunten a edificios con otras tropas que puedan atacar o defender desde atrás, y usando tus hechizos para eliminar o debilitar las tropas enemigas que puedan detener o dañar a tus tropas que apunten a edificios. <h2></h2>
|
26 |
-
This is the end of the article I have created for you based on your instructions. I hope you like it and find it useful. Thank you for using Microsoft Bing search chat mode. Have a nice day! ?</p>
|
27 |
-
<h2>apk de clash royale hackeado</h2><br /><p><b><b>Download Zip</b> ✑ <a href="https://urlin.us/2uSYxJ">https://urlin.us/2uSYxJ</a></b></p><br /><br /> 197e85843d<br />
|
28 |
-
<br />
|
29 |
-
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/1pelhydcardo/ChatGPT-prompt-generator/assets/Bloons TD 6 The Ultimate Tower Defense Game for Android.md
DELETED
@@ -1,205 +0,0 @@
|
|
1 |
-
<br />
|
2 |
-
<h1>Bloons TD 6: A Guide to the Ultimate Tower Defense Game</h1>
|
3 |
-
<p>If you are a fan of tower defense games, you have probably heard of Bloons TD 6, the latest installment in the popular Bloons series. But what is Bloons TD 6 exactly, and why is it so fun and addictive? In this article, we will answer these questions and more, as we provide you with a comprehensive guide to everything you need to know about Bloons TD 6. Whether you are a beginner or a veteran, you will find useful information, tips, and tricks to help you pop those pesky bloons and enjoy hours of strategy gaming.</p>
|
4 |
-
<h2>bloons td 6 free download</h2><br /><p><b><b>Download File</b> 🗹 <a href="https://urlin.us/2uSXfM">https://urlin.us/2uSXfM</a></b></p><br /><br />
|
5 |
-
<h2>What is Bloons TD 6?</h2>
|
6 |
-
<p>Bloons TD 6 is a 3D tower defense game developed and published by Ninja Kiwi, a New Zealand-based company that specializes in creating casual and mobile games. Bloons TD 6 is the sixth main entry in the Bloons Tower Defense series, which started as a web browser game in 2007. Since then, the series has expanded to include several spin-offs, such as Bloons Monkey City, Bloons Adventure Time TD, and Bloons Pop!</p>
|
7 |
-
<h3>The history and features of the game</h3>
|
8 |
-
<p>Bloons TD 6 was released on June 13, 2018 for Android and iOS devices, and later brought to Steam for Windows and Macintosh. The game has received regular updates since its launch, adding new content, features, and improvements. Some of the major updates include:</p>
|
9 |
-
<ul>
|
10 |
-
<li>New towers: Mortar Monkey (v6.0), Engineer Monkey (v12.0), Dartling Gunner (v22.0), and Beast Handler (v36.0)</li>
|
11 |
-
<li>New heroes: Captain Churchill (v7.0), Benjamin (v8.0), Ezili (v9.0), Pat Fusty (v10.0), Adora (v14.0), Admiral Brickell (v17.0), Etienne (v20.0), Sauda (v23.0), Psi (v25.0), Obyn Greenfoot - Ocean Guardian Skin (v26.0), Quincy - Cyber Quincy Skin (v27.0), Gwendolin - Harlegwen Skin (v28.0), Striker Jones - Biker Bones Skin (v29.0), Adora - Joan of Arc Skin (v30.0), Etienne - DJ Benjammin Skin (v31.0), Admiral Brickell - Dread Pirate Brickell Skin (v32.0), Pat Fusty - King Fusty Skin (v33.0), Ezili - Voodoo Monkey Skin (v34.0), Benjamin - Trojan Hero Skin (v35.0), Sauda - Jiangshi Sauda Skin (v37.0)</li>
|
12 |
-
<li>New maps: Alpine Run (v7.0), Peninsula (v8.0), Moon Landing (v9.0), Haunted (v10.0), Frozen Over (v11.0), Workshop (v12.0), Park Path (v13.0), Cargo (v14.0), Pat's Pond (v15.0), Spillway (v16.0), Bazaar (v17.0), Spring Spring (v18.1), KartsNDarts (v19.2), X Factor(v20.1) Geared(v21) Bloody Puddles(v22) Quad(v22) Dark Castle(v23) Infernal(v24) Rav <p>ine (v25) Mesa (v26) Encrypted (v27) Downstream (v28) Firing Range (v29) Cracked (v30) Chutes (v31) Rake (v32) Flooded Valley (v33) Pats Pond - Expert (v34) Ravine - Expert (v35) Sanctuary (v36) and Archipelago (v37)</li>
|
13 |
-
<li>New game modes: Races (v6.0), Co-op Mode (v11.0), Odyssey Mode (v18.0), and Trophy Store (v19.0)</li>
|
14 |
-
<li>New bloons: Purple Bloon (v6.0), Fortified Bloon (v7.0), and DDT (v10.0)</li>
|
15 |
-
<li>New features: Monkey Knowledge Respec Option (v7.0), Insta Monkey Collection Screen (v8.0), Emotes for Co-op Mode (v12.0), Collection Event System (v16.0), and Monkey Sub Admiral Brickell Voiceover (v17.0)</li>
|
16 |
-
</ul>
|
17 |
-
<p>As you can see, Bloons TD 6 is a game that is constantly evolving and improving, offering new challenges and rewards for its players. Some of the main features of the game are:</p>
|
18 |
-
<p>bloons td 6 free download pc<br />
|
19 |
-
bloons td 6 free download android<br />
|
20 |
-
bloons td 6 free download ios<br />
|
21 |
-
bloons td 6 free download apk<br />
|
22 |
-
bloons td 6 free download mac<br />
|
23 |
-
bloons td 6 free download windows 10<br />
|
24 |
-
bloons td 6 free download steam<br />
|
25 |
-
bloons td 6 free download bluestacks<br />
|
26 |
-
bloons td 6 free download app store<br />
|
27 |
-
bloons td 6 free download google play<br />
|
28 |
-
bloons td 6 free download latest version<br />
|
29 |
-
bloons td 6 free download no verification<br />
|
30 |
-
bloons td 6 free download reddit<br />
|
31 |
-
bloons td 6 free download online<br />
|
32 |
-
bloons td 6 free download mod apk<br />
|
33 |
-
bloons td 6 free download unlimited money<br />
|
34 |
-
bloons td 6 free download ninja kiwi<br />
|
35 |
-
bloons td 6 free download full version<br />
|
36 |
-
bloons td 6 free download cracked<br />
|
37 |
-
bloons td 6 free download update<br />
|
38 |
-
bloons td 6 free download without ads<br />
|
39 |
-
bloons td 6 free download offline<br />
|
40 |
-
bloons td 6 free download for laptop<br />
|
41 |
-
bloons td 6 free download for chromebook<br />
|
42 |
-
bloons td 6 free download for ipad<br />
|
43 |
-
bloons td 6 free download for iphone<br />
|
44 |
-
bloons td 6 free download for tablet<br />
|
45 |
-
bloons td 6 free download for macbook<br />
|
46 |
-
bloons td 6 free download for windows 7<br />
|
47 |
-
bloons td 6 free download for windows 8<br />
|
48 |
-
bloons td 6 free download for pc windows 10<br />
|
49 |
-
bloons td 6 free download for android apk<br />
|
50 |
-
bloons td 6 free download for ios no jailbreak<br />
|
51 |
-
bloons td 6 free download for pc steam<br />
|
52 |
-
bloons td 6 free download for pc bluestacks<br />
|
53 |
-
bloons td 6 free download for pc online<br />
|
54 |
-
bloons td 6 free download for pc reddit<br />
|
55 |
-
bloons td 6 free download for pc mod apk<br />
|
56 |
-
bloons td 6 free download for pc cracked<br />
|
57 |
-
bloons td 6 free download for pc latest version</p>
|
58 |
-
<ul>
|
59 |
-
<li>3D graphics and animations that bring the monkeys and bloons to life</li>
|
60 |
-
<li>Over 50 original maps with different themes, layouts, and difficulties</li>
|
61 |
-
<li>Over 20 unique monkeys with 5 upgrade paths each</li>
|
62 |
-
<li>Over 10 powerful heroes with unique abilities and synergies</li>
|
63 |
-
<li>Over 100 meta-upgrades that enhance your monkeys and gameplay</li>
|
64 |
-
<li>Over 40 types of bloons with different properties and behaviors</li>
|
65 |
-
<li>Over 10 game modes that test your skills and strategies</li>
|
66 |
-
<li>Online multiplayer co-op mode that lets you team up with other players</li>
|
67 |
-
<li>Competitive race mode that lets you compete with other players for the fastest time</li>
|
68 |
-
<li>Odyssey mode that lets you embark on epic journeys with limited monkeys and lives</li>
|
69 |
-
<li>Trophy store that lets you customize your game with cosmetic items and effects</li>
|
70 |
-
<li>Achievements, quests, events, and daily challenges that reward you with monkey money, experience, insta monkeys, powers, and trophies</li>
|
71 |
-
<li>Leaderboards, statistics, and profiles that track your progress and performance</li>
|
72 |
-
</ul>
|
73 |
-
<h3>The gameplay and modes of the game</h3>
|
74 |
-
<p>The gameplay of Bloons TD 6 is similar to other tower defense games, where you have to place towers along a path to prevent waves of enemies from reaching the end. In this case, the towers are monkeys and the enemies are bloons. Each monkey has a different attack range, speed, damage, and cost, as well as special abilities that can be unlocked by upgrading them. Each bloon has a different color, speed, health, and resistance, as well as special effects that can be triggered by popping them.</p>
|
75 |
-
<p>The game has several modes that offer different levels of difficulty and challenge. The main mode is the standard mode, where you can choose from four sub-modes: easy, medium, hard, and impoppable. Each sub-mode has different starting cash, lives, bloon speed, tower cost, and round number. The standard mode also has three options: primary only, military only, and magic only. These options limit the types of monkeys you can use in the game.</p>
|
76 |
-
<p>The other modes are the alternative modes, where you can choose from six sub-modes: reverse, apopalypse, double HP MOABs, half cash, CHIMPS, and deflation. Each sub-mode has different rules and modifiers that change the gameplay significantly. For example:</p>
|
77 |
-
<ul>
|
78 |
-
<li>Reverse mode makes the bloons move in the opposite direction on the map</li>
|
79 |
-
<li>Apopalypse mode makes the bloons spawn continuously without any breaks between rounds</li>
|
80 |
-
<li>Double HP MOABs mode makes the MOAB-class bloons have twice as much health as normal</li>
|
81 |
-
<li>Half cash mode makes you start with half as much cash as normal and earn half as much cash from popping bloons</li>
|
82 |
-
<li>CHIMPS mode stands for no Continues, no Hearts lost, no Income, no Monkey knowledge, no Powers, and no Selling. It is the hardest mode in the game that requires perfect strategy and execution</li>
|
83 |
-
<li>Deflation mode makes you start with a fixed amount of cash that cannot be increased by any means</li>
|
84 |
-
</ul>
|
85 |
-
<h2>How to download and play Bloons TD 6?</h2>
|
86 |
-
<p>If you are interested in playing Bloons TD 6, you will need to download it from one of the supported platforms. The game is available for Android devices on Google Play , for iOS devices on the App Store, and for Windows and Macintosh computers on Steam. The game is not free to download, but it is often on sale or discounted. The current prices of the game are as follows:</p>
|
87 |
-
Table 3: Prices of Bloons TD 6 | Platform | Price | | --- | --- | | Google Play | $4.99 USD | | App Store | $4.99 USD | | Steam | $9.99 USD | <p>Once you have downloaded the game, you can start playing it by launching it from your device or computer. The game will ask you to create a Ninja Kiwi account or log in with an existing one. This will allow you to save your progress, access your achievements, and sync your data across different devices. You can also play the game as a guest, but you will not be able to use some of the features and benefits of having an account.</p>
|
88 |
-
<h3>The system requirements and platforms of the game</h3>
|
89 |
-
<p>Bloons TD 6 is a relatively lightweight game that does not require a lot of resources or storage space to run smoothly. However, it is still recommended that you check the minimum system requirements and compatibility of the game before downloading it. Here are the system requirements and platforms of the game:</p>
|
90 |
-
Table 4: System requirements and platforms of Bloons TD 6 | Platform | System Requirements | | --- | --- | | Android | Android 5.0 or higher, 2 GB RAM, 100 MB storage space | | iOS | iOS 11.0 or higher, iPhone 5S or newer, iPad Air or newer, iPod Touch 6th Gen or newer, 100 MB storage space | | Windows | Windows 7 or higher, Core 2 Duo E4500 2.2GHz or Athlon 64 X2 Dual Core 5600+ processor, GeForce GT 240 or Radeon HD 6570 graphics card, DirectX 9.0c compatible sound card, 4 GB RAM, 2048 MB VRAM, 4096 MB available space | | Macintosh | MacOS X 10.12 or higher, Core i3-2100T 2.5GHz or Phenom II X3 B75 processor, GeForce GT 630M or Radeon HD 5570 graphics card, DirectX 9.0c compatible sound card, 4 GB RAM, 2048 MB VRAM, 4096 MB available space | <p>As you can see, Bloons TD 6 is a game that can run on most devices and computers without any issues. However, if you encounter any problems or bugs while playing the game, you can contact the Ninja Kiwi support team through their website or email.</p>
|
91 |
-
<h3>The steps to download and install the game</h3>
|
92 |
-
<p>The steps to download and install Bloons TD 6 are different depending on the platform you are using. Here are the steps for each platform:</p>
|
93 |
-
<h4>Android</h4>
|
94 |
-
<ol>
|
95 |
-
<li>Open Google Play on your Android device and search for Bloons TD 6</li>
|
96 |
-
<li>Tap on the game icon and then tap on the green Install button</li>
|
97 |
-
<li>Wait for the game to download and install on your device</li>
|
98 |
-
<li>Tap on the game icon again and then tap on the green Open button</li>
|
99 |
-
<li>Enjoy playing Bloons TD 6 on your Android device</li>
|
100 |
-
</ol>
|
101 |
-
<h4>iOS</h4>
|
102 |
-
<ol>
|
103 |
-
<li>Open the App Store on your iOS device and search for Bloons TD 6</li>
|
104 |
-
<li>Tap on the game icon and then tap on the blue Get button</li>
|
105 |
-
<li>Enter your Apple ID password or use Touch ID or Face ID to confirm your purchase</li>
|
106 |
-
<li>Wait for the game to download and install on your device</li>
|
107 |
-
<li>Tap on the game icon again and then tap on the blue Open button</li>
|
108 |
-
<li>Enjoy playing Bloons TD 6 on your iOS device</li>
|
109 |
-
</ol>
|
110 |
-
<h4>Windows</h4>
|
111 |
-
<ol>
|
112 |
-
<li>Open Steam on your Windows computer and log in with your Steam account</li>
|
113 |
-
<li>Search for Bloons TD 6 in the Steam store and click on the game icon</li>
|
114 |
-
<li>Click on the green Add to Cart button and then click on the green Purchase for myself button</li>
|
115 |
-
<li>Enter your payment details and confirm your purchase</li>
|
116 |
-
<li>Wait for the game to download and install on your computer</li>
|
117 |
-
<li>Click on the game icon in your Steam library and then click on the green Play button</li>
|
118 |
-
<li>Enjoy playing Bloons TD 6 on your Windows computer</li>
|
119 |
-
</ol>
|
120 |
-
<h4>Macintosh</h4>
|
121 |
-
<ol>
|
122 |
-
<li>Open Steam on your Macintosh computer and log in with your Steam account</li>
|
123 |
-
<li>Search for Bloons TD 6 in the Steam store and click on the game icon</li>
|
124 |
-
<li>Click on the green Add to Cart button and then click on the green Purchase for myself button</li>
|
125 |
-
<li>Enter your payment details and confirm your purchase</li>
|
126 |
-
<li>Wait for the game to download and install on your computer</li>
|
127 |
-
<li>Click on the game icon in your Steam library and then click on the green Play button</li>
|
128 |
-
<li>Enjoy playing Bloons TD 6 on your Macintosh computer</li>
|
129 |
-
</ol>
|
130 |
-
<h2>How to master Bloons TD 6?</h2>
|
131 |
-
<p>Bloons TD 6 is a game that requires skill, strategy, and creativity to beat. The game has hundreds of levels, each with different challenges and objectives. The game also has a lot of variety and customization, allowing you to choose from different monkeys, heroes, upgrades, powers, and modes. However, the game is also very challenging and rewarding, as you will face increasingly difficult bloons and bosses that will test your limits. How can you master Bloons TD 6 and become a pro player? Here are some of the best strategies, tips, and tricks for the game:</p>
|
132 |
-
<h3>The best strategies, tips, and tricks for the game</h3>
|
133 |
-
<p>Bloons TD 6 is a game that has a lot of depth and complexity, as well as a lot of fun and excitement. There are many ways to play the game, and many factors to consider when planning your strategy. However, there are also some general principles and guidelines that can help you improve your performance and enjoyment of the game. Here are some of the best strategies, tips, and tricks for Bloons TD 6:</p>
|
134 |
-
<h4>Choosing the right monkeys and heroes</h4>
|
135 |
-
<p>One of the most important aspects of Bloons TD 6 is choosing the right monkeys and heroes for your strategy. Each monkey and hero has different strengths, weaknesses, abilities, and synergies that can make a big difference in your gameplay. Here are some things to keep in mind when choosing your monkeys and heroes:</p>
|
136 |
-
<ul>
|
137 |
-
<li>Know the types of bloons you will face: Different bloons have different properties and resistances that require different types of attacks to pop them. For example, lead bloons can only be popped by explosive or sharp attacks, camo bloons can only be detected by monkeys with camo detection or radar abilities, purple bloons are immune to fire, plasma, and energy attacks, etc. You should choose monkeys that can deal with the types of bloons you will encounter in each level.</li>
|
138 |
-
<li>Know the strengths and weaknesses of each monkey: Each monkey has different attack range, speed, damage, cost, and special abilities that make them more or less effective in different situations. For example, dart monkeys are cheap and versatile, but have low damage and range; sniper monkeys have high damage and range, but are slow and expensive; super monkeys have very high damage and speed, but are very expensive and require a lot of space; etc. You should choose monkeys that suit your budget, space, and strategy.</li>
|
139 |
-
<li>Know the upgrade paths of each monkey: Each monkey has five upgrade paths that can drastically change their performance and abilities. For example, the top path of the boomerang monkey gives it faster and more powerful boomerangs, the middle path gives it glaives and ricochet effects, and the bottom path gives it explosive and MOAB-class damage. You should choose the upgrade paths that complement your strategy and the types of bloons you will face.</li>
|
140 |
-
<li>Know the synergies and combos of each monkey: Some monkeys have abilities or effects that can enhance or benefit other monkeys. For example, the alchemist can buff the attack speed and damage of nearby monkeys, the village can grant camo detection and discounts to nearby monkeys, the monkey ace can drop pineapples and MOAB assassins to help with bloon popping, etc. You should place your monkeys in a way that maximizes their synergies and combos.</li>
|
141 |
-
<li>Know the roles and personalities of each hero: Each hero has a unique role and personality that can affect your gameplay and strategy. For example, Quincy is a balanced hero that can pop most types of bloons with his arrows, Gwendolin is an offensive hero that can deal fire damage and boost nearby monkeys, Obyn is a supportive hero that can summon totems and brambles to help with bloon popping, etc. You should choose a hero that fits your playstyle and preference.</li>
|
142 |
-
</ul>
|
143 |
-
<h4>Placing and upgrading your towers</h4>
|
144 |
-
<p>Another important aspect of Bloons TD 6 is placing and upgrading your towers in the most optimal way. The placement and upgrade of your towers can make a huge difference in your performance and outcome. Here are some things to keep in mind when placing and upgrading your towers:</p>
|
145 |
-
<ul>
|
146 |
-
<li>Know the map layout and bloon paths: Each map has a different layout and bloon path that can affect your tower placement and strategy. For example, some maps have multiple paths, some maps have obstacles or water, some maps have long or short paths, etc. You should place your towers in a way that covers as much of the bloon path as possible, while avoiding any obstacles or hazards.</li>
|
147 |
-
<li>Know the range and line of sight of each tower: Each tower has a different range and line of sight that can affect its effectiveness and efficiency. For example, some towers have long or short range, some towers have 360 or limited degrees of vision, some towers have curved or straight projectiles, etc. You should place your towers in a way that maximizes their range and line of sight, while avoiding any blind spots or overlaps.</li>
|
148 |
-
<li>Know the priority and targeting of each tower: Each tower has a different priority and targeting option that can affect its behavior and decision. For example, some towers target the first or last bloon on the path, some towers target the strongest or weakest bloon on the path, some towers target the closest or farthest bloon on the path, etc. You should set your towers' priority and targeting option in a way that matches your strategy and situation.</li>
|
149 |
-
<li>Know the cost and benefit of each upgrade: Each upgrade has a different cost and benefit that can affect its value and utility. For example, some upgrades are cheap or expensive, some upgrades are powerful or weak, some upgrades are essential or optional, etc. You should upgrade your towers in a way that balances your budget and needs, while avoiding any waste or overkill.</li>
|
150 |
-
</ul>
|
151 |
-
<h4>Using powers and abilities</h4>
|
152 |
-
<p>A third important aspect of Bloons TD 6 is using powers and abilities in the most effective way. Powers and abilities are special features that can help you pop more bloons, boost your towers, or save your lives. Powers are consumable items that can be bought with monkey money or earned from events and challenges. Abilities are unique skills that can be activated by certain towers or heroes. Here are some things to keep in mind when using powers and abilities:</p>
|
153 |
-
<ul>
|
154 |
-
<li>Know the types and effects of each power and ability: There are many types of powers and abilities in the game, each with different effects and durations. For example, some powers can pop bloons, such as the MOAB Mine or the Super Monkey Storm, some powers can boost towers, such as the Monkey Boost or the Thrive, some powers can save lives, such as the Cash Drop or the Banana Farmer, etc. You should use the powers and abilities that suit your strategy and situation.</li>
|
155 |
-
<li>Know the cooldown and timing of each power and ability: Each power and ability has a different cooldown and timing that can affect its availability and efficiency. For example, some powers and abilities have a short or long cooldown, some powers and abilities have a instant or delayed activation, some powers and abilities have a single or multiple use, etc. You should use the powers and abilities in a way that maximizes their cooldown and timing, while avoiding any waste or delay.</li>
|
156 |
-
<li>Know the cost and value of each power and ability: Each power and ability has a different cost and value that can affect its affordability and utility. For example, some powers and abilities are cheap or expensive, some powers and abilities are powerful or weak, some powers and abilities are worth or not worth using, etc. You should use the powers and abilities in a way that balances your cost and value, while avoiding any overspending or underspending.</li>
|
157 |
-
</ul>
|
158 |
-
<h4>Completing quests and events</h4>
|
159 |
-
<p>A fourth important aspect of Bloons TD 6 is completing quests and events in the most rewarding way. Quests and events are special missions and challenges that can give you extra monkey money, experience, insta monkeys, powers, trophies, and other rewards. Quests and events are usually time-limited or seasonal, so you should try to complete them before they expire. Here are some things to keep in mind when completing quests and events:</p>
|
160 |
-
<ul>
|
161 |
-
<li>Know the types and requirements of each quest and event: There are many types of quests and events in the game, each with different requirements and objectives. For example, some quests and events require you to pop a certain number of bloons, some quests and events require you to use a certain type of monkey, some quests and events require you to play on a certain map or mode, etc. You should complete the quests and events that match your skills and preferences.</li>
|
162 |
-
<li>Know the rewards and benefits of each quest and event: Each quest and event has different rewards and benefits that can help you progress and improve in the game. For example, some quests and events give you more monkey money, which you can use to buy powers and upgrades, some quests and events give you more experience, which you can use to level up your monkeys and heroes, some quests and events give you insta monkeys, which are pre-upgraded monkeys that you can place instantly, etc. You should complete the quests and events that give you the most valuable and useful rewards.</li>
|
163 |
-
<li>Know the tips and tricks for each quest and event: Each quest and event has different tips and tricks that can help you complete them more easily and efficiently. For example, some quests and events have hidden or secret objectives that can give you bonus rewards, some quests and events have optimal or recommended strategies that can help you beat them faster or better, some quests and events have hints or clues that can help you solve them more accurately or correctly, etc. You should follow the tips and tricks for the quests and events that you find challenging or interesting.</li>
|
164 |
-
</ul>
|
165 |
-
<h3>The best resources and reviews for the game</h3>
|
166 |
-
<p>Bloons TD 6 is a game that has a lot of resources and reviews that can help you learn more about the game, get inspired by other players, and share your feedback and opinions. There are many resources and reviews for the game, such as websites, videos, forums, blogs, podcasts, etc. Here are some of the best resources and reviews for the game:</p>
|
167 |
-
<h4>The official website and social media of the game</h4>
|
168 |
-
<p>The official website of Bloons TD 6 is https://ninjakiwi.com/Games/Tower-Defense/Bloons-TD-6.html. Here you can find the latest news, updates, features, screenshots, videos, FAQs, support, and contact information of the game. You can also download the game from here or access the other platforms where the game is available.</p>
|
169 |
-
<p>The official social media accounts of Bloons TD 6 are:</p>
|
170 |
-
<ul>
|
171 |
-
<li>Facebook: https://www.facebook.com/ninjakiwigames</li>
|
172 |
-
<li>Twitter: https://twitter.com/ninjakiwigames</li>
|
173 |
-
<li>Instagram: https://www.instagram.com/realninjakiwi/</li>
|
174 |
-
<li>YouTube: https://www.youtube.com/user/NinjaKiwiVideos</li>
|
175 |
-
<li>Reddit: https://www.reddit.com/r/btd6/</li>
|
176 |
-
<li>Discord: https://discord.gg/ninjakiwi</li>
|
177 |
-
</ul>
|
178 |
-
<p>Here you can follow the latest posts, tweets, stories, videos, discussions, chats, and more of the game. You can also interact with other players and the developers of the game, ask questions, give feedback, and share your ideas and suggestions.</p>
|
179 |
-
<h4>The most helpful websites and videos for the game</h4>
|
180 |
-
<p>There are many websites and videos that can help you with the game, such as guides, tutorials, walkthroughs, tips, tricks, strategies, reviews, etc. Here are some of the most helpful websites and videos for the game:</p>
|
181 |
-
<ul>
|
182 |
-
<li>Bloons Wiki: https://bloons.fandom.com/wiki/Bloons_Wiki. This is a fan-made wiki that contains a lot of information and data about the game, such as monkeys, heroes, bloons, maps, modes, upgrades, powers, achievements, etc. You can find detailed descriptions, statistics, images, trivia, and more of the game here.</li>
|
183 |
-
<li>Bloons TD 6 Steam Community: https://steamcommunity.com/app/960090. This is a community page on Steam that contains a lot of discussions and content about the game, such as forums, guides, screenshots, videos, reviews, etc. You can find helpful advice, opinions, recommendations, and more of the game here.</li>
|
184 |
-
<li>BTD6 Science: https://www.youtube.com/channel/UC4a-Gbdw7vOaccHmFo40b9g. This is a YouTube channel that focuses on testing and experimenting with different aspects of the game, such as towers, upgrades, bloons, modes, etc. You can find interesting and informative videos that show you the results and conclusions of various tests and experiments of the game here.</li>
|
185 |
-
<li>Aliensrock: https://www.youtube.com/user/Aliensrock50. This is a YouTube channel that features a lot of gameplay and commentary of the game, such as challenges, races, odysseys, co-op, etc. You can find entertaining and educational videos that show you how to play and beat different levels and modes of the game here.</li>
|
186 |
-
</ul>
|
187 |
-
<h4>The most positive and negative reviews for the game</h4>
|
188 |
-
<p>There are many reviews for the game that can give you an idea of what other players think and feel about the game. The reviews can be positive or negative, and experiences of different players. You can read more reviews or write your own review on the platforms where the game is available. You can also share your thoughts and feelings about the game with other players on the social media accounts or the forums of the game.</p>
|
189 |
-
<h2>Conclusion</h2>
|
190 |
-
<p>Bloons TD 6 is a 3D tower defense game that is fun, addictive, and challenging. It is a game that has a lot of content, variety, and customization, as well as a lot of resources, reviews, and support. It is a game that can appeal to anyone who likes tower defense games or strategy games in general. It is a game that you should definitely try if you are looking for a great gaming experience.</p>
|
191 |
-
<p>We hope that this article has given you a comprehensive guide to everything you need to know about Bloons TD 6. We hope that you have learned something new, found something useful, or got inspired by something interesting. We hope that you have enjoyed reading this article as much as we have enjoyed writing it. Thank you for your time and attention.</p>
|
192 |
-
<h2>FAQs</h2>
|
193 |
-
<p>Here are some of the frequently asked questions about Bloons TD 6:</p>
|
194 |
-
<h4>Q: Is Bloons TD 6 free to play?</h4>
|
195 |
-
<p>A: No, Bloons TD 6 is not free to play. You have to pay a one-time fee to download the game from one of the supported platforms. However, the game is often on sale or discounted, so you can get it for a lower price if you wait for the right time.</p>
|
196 |
-
<h4>Q: Is Bloons TD 6 online or offline?</h4>
|
197 |
-
<p>A: Bloons TD 6 can be played both online and offline. You can play the game online to access the co-op mode, the race mode, the odyssey mode, the trophy store, and the cloud save feature. You can also play the game offline to access the standard mode, the alternative mode, and the local save feature.</p>
|
198 |
-
<h4>Q: Is Bloons TD 6 cross-platform?</h4>
|
199 |
-
<p>A: Yes, Bloons TD 6 is cross-platform. You can play the game with other players who are using different devices or computers, as long as they are connected to the same network or server. You can also sync your data across different devices or computers, as long as you are using the same Ninja Kiwi account.</p>
|
200 |
-
<h4>Q: Is Bloons TD 6 kid-friendly?</h4>
|
201 |
-
<p>A: Yes, Bloons TD 6 is kid-friendly. The game has cartoonish graphics and animations that are suitable for all ages. The game also has no violence, blood, gore, or profanity that could be inappropriate for younger audiences. The game also has no ads or in-app purchases that could be harmful or misleading for children.</p>
|
202 |
-
<h4>Q: Is Bloons TD 6 worth playing?</h4>
|
203 |
-
<p>A: Yes, Bloons TD 6 is worth playing. The game has a lot of positive reviews and ratings from players and critics alike. The game also has a lot of content and features that make it fun and engaging for hours. The game also has a lot of challenges and rewards that make it satisfying and rewarding for players. The game also has a lot of support and updates from the developers that make it better and better over time.</p> 197e85843d<br />
|
204 |
-
<br />
|
205 |
-
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AIConsultant/MusicGen/audiocraft/models/multibanddiffusion.py
DELETED
@@ -1,194 +0,0 @@
|
|
1 |
-
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
2 |
-
# All rights reserved.
|
3 |
-
#
|
4 |
-
# This source code is licensed under the license found in the
|
5 |
-
# LICENSE file in the root directory of this source tree.
|
6 |
-
|
7 |
-
"""
|
8 |
-
Multi Band Diffusion models as described in
|
9 |
-
"From Discrete Tokens to High-Fidelity Audio Using Multi-Band Diffusion"
|
10 |
-
(paper link).
|
11 |
-
"""
|
12 |
-
|
13 |
-
import typing as tp
|
14 |
-
|
15 |
-
import torch
|
16 |
-
import julius
|
17 |
-
|
18 |
-
from .unet import DiffusionUnet
|
19 |
-
from ..modules.diffusion_schedule import NoiseSchedule
|
20 |
-
from .encodec import CompressionModel
|
21 |
-
from ..solvers.compression import CompressionSolver
|
22 |
-
from .loaders import load_compression_model, load_diffusion_models
|
23 |
-
|
24 |
-
|
25 |
-
class DiffusionProcess:
|
26 |
-
"""Sampling for a diffusion Model.
|
27 |
-
|
28 |
-
Args:
|
29 |
-
model (DiffusionUnet): Diffusion U-Net model.
|
30 |
-
noise_schedule (NoiseSchedule): Noise schedule for diffusion process.
|
31 |
-
"""
|
32 |
-
def __init__(self, model: DiffusionUnet, noise_schedule: NoiseSchedule) -> None:
|
33 |
-
"""
|
34 |
-
"""
|
35 |
-
self.model = model
|
36 |
-
self.schedule = noise_schedule
|
37 |
-
|
38 |
-
def generate(self, condition: torch.Tensor, initial_noise: torch.Tensor,
|
39 |
-
step_list: tp.Optional[tp.List[int]] = None):
|
40 |
-
"""Perform one diffusion process to generate one of the bands.
|
41 |
-
|
42 |
-
Args:
|
43 |
-
condition (tensor): The embeddings form the compression model.
|
44 |
-
initial_noise (tensor): The initial noise to start the process/
|
45 |
-
"""
|
46 |
-
return self.schedule.generate_subsampled(model=self.model, initial=initial_noise, step_list=step_list,
|
47 |
-
condition=condition)
|
48 |
-
|
49 |
-
|
50 |
-
class MultiBandDiffusion:
|
51 |
-
"""Sample from multiple diffusion models.
|
52 |
-
|
53 |
-
Args:
|
54 |
-
DPs (list of DiffusionProcess): Diffusion processes.
|
55 |
-
codec_model (CompressionModel): Underlying compression model used to obtain discrete tokens.
|
56 |
-
"""
|
57 |
-
def __init__(self, DPs: tp.List[DiffusionProcess], codec_model: CompressionModel) -> None:
|
58 |
-
self.DPs = DPs
|
59 |
-
self.codec_model = codec_model
|
60 |
-
self.device = next(self.codec_model.parameters()).device
|
61 |
-
|
62 |
-
@property
|
63 |
-
def sample_rate(self) -> int:
|
64 |
-
return self.codec_model.sample_rate
|
65 |
-
|
66 |
-
@staticmethod
|
67 |
-
def get_mbd_musicgen(device=None):
|
68 |
-
"""Load our diffusion models trained for MusicGen."""
|
69 |
-
if device is None:
|
70 |
-
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
71 |
-
path = 'https://dl.fbaipublicfiles.com/encodec/Diffusion/mbd_musicgen_32khz.th'
|
72 |
-
name = 'facebook/musicgen-small'
|
73 |
-
codec_model = load_compression_model(name, device=device)
|
74 |
-
models, processors, cfgs = load_diffusion_models(path, device=device)
|
75 |
-
DPs = []
|
76 |
-
for i in range(len(models)):
|
77 |
-
schedule = NoiseSchedule(**cfgs[i].schedule, sample_processor=processors[i])
|
78 |
-
DPs.append(DiffusionProcess(model=models[i], noise_schedule=schedule))
|
79 |
-
return MultiBandDiffusion(DPs=DPs, codec_model=codec_model)
|
80 |
-
|
81 |
-
@staticmethod
|
82 |
-
def get_mbd_24khz(bw: float = 3.0, pretrained: bool = True,
|
83 |
-
device: tp.Optional[tp.Union[torch.device, str]] = None,
|
84 |
-
n_q: tp.Optional[int] = None):
|
85 |
-
"""Get the pretrained Models for MultibandDiffusion.
|
86 |
-
|
87 |
-
Args:
|
88 |
-
bw (float): Bandwidth of the compression model.
|
89 |
-
pretrained (bool): Whether to use / download if necessary the models.
|
90 |
-
device (torch.device or str, optional): Device on which the models are loaded.
|
91 |
-
n_q (int, optional): Number of quantizers to use within the compression model.
|
92 |
-
"""
|
93 |
-
if device is None:
|
94 |
-
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
95 |
-
assert bw in [1.5, 3.0, 6.0], f"bandwidth {bw} not available"
|
96 |
-
if n_q is not None:
|
97 |
-
assert n_q in [2, 4, 8]
|
98 |
-
assert {1.5: 2, 3.0: 4, 6.0: 8}[bw] == n_q, \
|
99 |
-
f"bandwidth and number of codebooks missmatch to use n_q = {n_q} bw should be {n_q * (1.5 / 2)}"
|
100 |
-
n_q = {1.5: 2, 3.0: 4, 6.0: 8}[bw]
|
101 |
-
codec_model = CompressionSolver.model_from_checkpoint(
|
102 |
-
'//pretrained/facebook/encodec_24khz', device=device)
|
103 |
-
codec_model.set_num_codebooks(n_q)
|
104 |
-
codec_model = codec_model.to(device)
|
105 |
-
path = f'https://dl.fbaipublicfiles.com/encodec/Diffusion/mbd_comp_{n_q}.pt'
|
106 |
-
models, processors, cfgs = load_diffusion_models(path, device=device)
|
107 |
-
DPs = []
|
108 |
-
for i in range(len(models)):
|
109 |
-
schedule = NoiseSchedule(**cfgs[i].schedule, sample_processor=processors[i])
|
110 |
-
DPs.append(DiffusionProcess(model=models[i], noise_schedule=schedule))
|
111 |
-
return MultiBandDiffusion(DPs=DPs, codec_model=codec_model)
|
112 |
-
|
113 |
-
return MultiBandDiffusion(DPs, codec_model)
|
114 |
-
|
115 |
-
@torch.no_grad()
|
116 |
-
def get_condition(self, wav: torch.Tensor, sample_rate: int) -> torch.Tensor:
|
117 |
-
"""Get the conditioning (i.e. latent reprentatios of the compression model) from a waveform.
|
118 |
-
Args:
|
119 |
-
wav (torch.Tensor): The audio that we want to extract the conditioning from
|
120 |
-
sample_rate (int): sample rate of the audio"""
|
121 |
-
if sample_rate != self.sample_rate:
|
122 |
-
wav = julius.resample_frac(wav, sample_rate, self.sample_rate)
|
123 |
-
codes, scale = self.codec_model.encode(wav)
|
124 |
-
assert scale is None, "Scaled compression models not supported."
|
125 |
-
emb = self.get_emb(codes)
|
126 |
-
return emb
|
127 |
-
|
128 |
-
@torch.no_grad()
|
129 |
-
def get_emb(self, codes: torch.Tensor):
|
130 |
-
"""Get latent representation from the discrete codes
|
131 |
-
Argrs:
|
132 |
-
codes (torch.Tensor): discrete tokens"""
|
133 |
-
emb = self.codec_model.decode_latent(codes)
|
134 |
-
return emb
|
135 |
-
|
136 |
-
def generate(self, emb: torch.Tensor, size: tp.Optional[torch.Size] = None,
|
137 |
-
step_list: tp.Optional[tp.List[int]] = None):
|
138 |
-
"""Generate Wavform audio from the latent embeddings of the compression model
|
139 |
-
Args:
|
140 |
-
emb (torch.Tensor): Conditioning embeddinds
|
141 |
-
size (none torch.Size): size of the output
|
142 |
-
if None this is computed from the typical upsampling of the model
|
143 |
-
step_list (optional list[int]): list of Markov chain steps, defaults to 50 linearly spaced step.
|
144 |
-
"""
|
145 |
-
if size is None:
|
146 |
-
upsampling = int(self.codec_model.sample_rate / self.codec_model.frame_rate)
|
147 |
-
size = torch.Size([emb.size(0), self.codec_model.channels, emb.size(-1) * upsampling])
|
148 |
-
assert size[0] == emb.size(0)
|
149 |
-
out = torch.zeros(size).to(self.device)
|
150 |
-
for DP in self.DPs:
|
151 |
-
out += DP.generate(condition=emb, step_list=step_list, initial_noise=torch.randn_like(out))
|
152 |
-
return out
|
153 |
-
|
154 |
-
def re_eq(self, wav: torch.Tensor, ref: torch.Tensor, n_bands: int = 32, strictness: float = 1):
|
155 |
-
"""match the eq to the encodec output by matching the standard deviation of some frequency bands
|
156 |
-
Args:
|
157 |
-
wav (torch.Tensor): audio to equalize
|
158 |
-
ref (torch.Tensor):refenrence audio from which we match the spectrogram.
|
159 |
-
n_bands (int): number of bands of the eq
|
160 |
-
strictness (float): how strict the the matching. 0 is no matching, 1 is exact matching.
|
161 |
-
"""
|
162 |
-
split = julius.SplitBands(n_bands=n_bands, sample_rate=self.codec_model.sample_rate).to(wav.device)
|
163 |
-
bands = split(wav)
|
164 |
-
bands_ref = split(ref)
|
165 |
-
out = torch.zeros_like(ref)
|
166 |
-
for i in range(n_bands):
|
167 |
-
out += bands[i] * (bands_ref[i].std() / bands[i].std()) ** strictness
|
168 |
-
return out
|
169 |
-
|
170 |
-
def regenerate(self, wav: torch.Tensor, sample_rate: int):
|
171 |
-
"""Regenerate a wavform through compression and diffusion regeneration.
|
172 |
-
Args:
|
173 |
-
wav (torch.Tensor): Original 'ground truth' audio
|
174 |
-
sample_rate (int): sample rate of the input (and output) wav
|
175 |
-
"""
|
176 |
-
if sample_rate != self.codec_model.sample_rate:
|
177 |
-
wav = julius.resample_frac(wav, sample_rate, self.codec_model.sample_rate)
|
178 |
-
emb = self.get_condition(wav, sample_rate=self.codec_model.sample_rate)
|
179 |
-
size = wav.size()
|
180 |
-
out = self.generate(emb, size=size)
|
181 |
-
if sample_rate != self.codec_model.sample_rate:
|
182 |
-
out = julius.resample_frac(out, self.codec_model.sample_rate, sample_rate)
|
183 |
-
return out
|
184 |
-
|
185 |
-
def tokens_to_wav(self, tokens: torch.Tensor, n_bands: int = 32):
|
186 |
-
"""Generate Waveform audio with diffusion from the discrete codes.
|
187 |
-
Args:
|
188 |
-
tokens (torch.Tensor): discrete codes
|
189 |
-
n_bands (int): bands for the eq matching.
|
190 |
-
"""
|
191 |
-
wav_encodec = self.codec_model.decode(tokens)
|
192 |
-
condition = self.get_emb(tokens)
|
193 |
-
wav_diffusion = self.generate(emb=condition, size=wav_encodec.size())
|
194 |
-
return self.re_eq(wav=wav_diffusion, ref=wav_encodec, n_bands=n_bands)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AIConsultant/MusicGen/audiocraft/solvers/builders.py
DELETED
@@ -1,363 +0,0 @@
|
|
1 |
-
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
2 |
-
# All rights reserved.
|
3 |
-
#
|
4 |
-
# This source code is licensed under the license found in the
|
5 |
-
# LICENSE file in the root directory of this source tree.
|
6 |
-
|
7 |
-
"""
|
8 |
-
All the functions to build the relevant solvers and used objects
|
9 |
-
from the Hydra config.
|
10 |
-
"""
|
11 |
-
|
12 |
-
from enum import Enum
|
13 |
-
import logging
|
14 |
-
import typing as tp
|
15 |
-
|
16 |
-
import dora
|
17 |
-
import flashy
|
18 |
-
import omegaconf
|
19 |
-
import torch
|
20 |
-
from torch import nn
|
21 |
-
from torch.optim import Optimizer
|
22 |
-
# LRScheduler was renamed in some torch versions
|
23 |
-
try:
|
24 |
-
from torch.optim.lr_scheduler import LRScheduler # type: ignore
|
25 |
-
except ImportError:
|
26 |
-
from torch.optim.lr_scheduler import _LRScheduler as LRScheduler
|
27 |
-
|
28 |
-
from .base import StandardSolver
|
29 |
-
from .. import adversarial, data, losses, metrics, optim
|
30 |
-
from ..utils.utils import dict_from_config, get_loader
|
31 |
-
|
32 |
-
|
33 |
-
logger = logging.getLogger(__name__)
|
34 |
-
|
35 |
-
|
36 |
-
class DatasetType(Enum):
|
37 |
-
AUDIO = "audio"
|
38 |
-
MUSIC = "music"
|
39 |
-
SOUND = "sound"
|
40 |
-
|
41 |
-
|
42 |
-
def get_solver(cfg: omegaconf.DictConfig) -> StandardSolver:
|
43 |
-
"""Instantiate solver from config."""
|
44 |
-
from .audiogen import AudioGenSolver
|
45 |
-
from .compression import CompressionSolver
|
46 |
-
from .musicgen import MusicGenSolver
|
47 |
-
from .diffusion import DiffusionSolver
|
48 |
-
klass = {
|
49 |
-
'compression': CompressionSolver,
|
50 |
-
'musicgen': MusicGenSolver,
|
51 |
-
'audiogen': AudioGenSolver,
|
52 |
-
'lm': MusicGenSolver, # backward compatibility
|
53 |
-
'diffusion': DiffusionSolver,
|
54 |
-
'sound_lm': AudioGenSolver, # backward compatibility
|
55 |
-
}[cfg.solver]
|
56 |
-
return klass(cfg) # type: ignore
|
57 |
-
|
58 |
-
|
59 |
-
def get_optim_parameter_groups(model: nn.Module):
|
60 |
-
"""Create parameter groups for the model using the appropriate method
|
61 |
-
if defined for each modules, to create the different groups.
|
62 |
-
|
63 |
-
Args:
|
64 |
-
model (nn.Module): torch model
|
65 |
-
Returns:
|
66 |
-
List of parameter groups
|
67 |
-
"""
|
68 |
-
seen_params: tp.Set[nn.parameter.Parameter] = set()
|
69 |
-
other_params = []
|
70 |
-
groups = []
|
71 |
-
for name, module in model.named_modules():
|
72 |
-
if hasattr(module, 'make_optim_group'):
|
73 |
-
group = module.make_optim_group()
|
74 |
-
params = set(group['params'])
|
75 |
-
assert params.isdisjoint(seen_params)
|
76 |
-
seen_params |= set(params)
|
77 |
-
groups.append(group)
|
78 |
-
for param in model.parameters():
|
79 |
-
if param not in seen_params:
|
80 |
-
other_params.append(param)
|
81 |
-
groups.insert(0, {'params': other_params})
|
82 |
-
parameters = groups
|
83 |
-
return parameters
|
84 |
-
|
85 |
-
|
86 |
-
def get_optimizer(params: tp.Union[nn.Module, tp.Iterable[torch.Tensor]], cfg: omegaconf.DictConfig) -> Optimizer:
|
87 |
-
"""Build torch optimizer from config and set of parameters.
|
88 |
-
Supported optimizers: Adam, AdamW
|
89 |
-
|
90 |
-
Args:
|
91 |
-
params (nn.Module or iterable of torch.Tensor): Parameters to optimize.
|
92 |
-
cfg (DictConfig): Optimization-related configuration.
|
93 |
-
Returns:
|
94 |
-
torch.optim.Optimizer.
|
95 |
-
"""
|
96 |
-
if 'optimizer' not in cfg:
|
97 |
-
if getattr(cfg, 'optim', None) is not None:
|
98 |
-
raise KeyError("Optimizer not found in config. Try instantiating optimizer from cfg.optim?")
|
99 |
-
else:
|
100 |
-
raise KeyError("Optimizer not found in config.")
|
101 |
-
|
102 |
-
parameters = get_optim_parameter_groups(params) if isinstance(params, nn.Module) else params
|
103 |
-
optimizer: torch.optim.Optimizer
|
104 |
-
if cfg.optimizer == 'adam':
|
105 |
-
optimizer = torch.optim.Adam(parameters, lr=cfg.lr, **cfg.adam)
|
106 |
-
elif cfg.optimizer == 'adamw':
|
107 |
-
optimizer = torch.optim.AdamW(parameters, lr=cfg.lr, **cfg.adam)
|
108 |
-
elif cfg.optimizer == 'dadam':
|
109 |
-
optimizer = optim.DAdaptAdam(parameters, lr=cfg.lr, **cfg.adam)
|
110 |
-
else:
|
111 |
-
raise ValueError(f"Unsupported LR Scheduler: {cfg.lr_scheduler}")
|
112 |
-
return optimizer
|
113 |
-
|
114 |
-
|
115 |
-
def get_lr_scheduler(optimizer: torch.optim.Optimizer,
|
116 |
-
cfg: omegaconf.DictConfig,
|
117 |
-
total_updates: int) -> tp.Optional[LRScheduler]:
|
118 |
-
"""Build torch learning rate scheduler from config and associated optimizer.
|
119 |
-
Supported learning rate schedulers: ExponentialLRScheduler, PlateauLRScheduler
|
120 |
-
|
121 |
-
Args:
|
122 |
-
optimizer (torch.optim.Optimizer): Optimizer.
|
123 |
-
cfg (DictConfig): Schedule-related configuration.
|
124 |
-
total_updates (int): Total number of updates.
|
125 |
-
Returns:
|
126 |
-
torch.optim.Optimizer.
|
127 |
-
"""
|
128 |
-
if 'lr_scheduler' not in cfg:
|
129 |
-
raise KeyError("LR Scheduler not found in config")
|
130 |
-
|
131 |
-
lr_sched: tp.Optional[LRScheduler] = None
|
132 |
-
if cfg.lr_scheduler == 'step':
|
133 |
-
lr_sched = torch.optim.lr_scheduler.StepLR(optimizer, **cfg.step)
|
134 |
-
elif cfg.lr_scheduler == 'exponential':
|
135 |
-
lr_sched = torch.optim.lr_scheduler.ExponentialLR(optimizer, gamma=cfg.exponential)
|
136 |
-
elif cfg.lr_scheduler == 'cosine':
|
137 |
-
kwargs = dict_from_config(cfg.cosine)
|
138 |
-
warmup_steps = kwargs.pop('warmup')
|
139 |
-
lr_sched = optim.CosineLRScheduler(
|
140 |
-
optimizer, warmup_steps=warmup_steps, total_steps=total_updates, **kwargs)
|
141 |
-
elif cfg.lr_scheduler == 'polynomial_decay':
|
142 |
-
kwargs = dict_from_config(cfg.polynomial_decay)
|
143 |
-
warmup_steps = kwargs.pop('warmup')
|
144 |
-
lr_sched = optim.PolynomialDecayLRScheduler(
|
145 |
-
optimizer, warmup_steps=warmup_steps, total_steps=total_updates, **kwargs)
|
146 |
-
elif cfg.lr_scheduler == 'inverse_sqrt':
|
147 |
-
kwargs = dict_from_config(cfg.inverse_sqrt)
|
148 |
-
warmup_steps = kwargs.pop('warmup')
|
149 |
-
lr_sched = optim.InverseSquareRootLRScheduler(optimizer, warmup_steps=warmup_steps, **kwargs)
|
150 |
-
elif cfg.lr_scheduler == 'linear_warmup':
|
151 |
-
kwargs = dict_from_config(cfg.linear_warmup)
|
152 |
-
warmup_steps = kwargs.pop('warmup')
|
153 |
-
lr_sched = optim.LinearWarmupLRScheduler(optimizer, warmup_steps=warmup_steps, **kwargs)
|
154 |
-
elif cfg.lr_scheduler is not None:
|
155 |
-
raise ValueError(f"Unsupported LR Scheduler: {cfg.lr_scheduler}")
|
156 |
-
return lr_sched
|
157 |
-
|
158 |
-
|
159 |
-
def get_ema(module_dict: nn.ModuleDict, cfg: omegaconf.DictConfig) -> tp.Optional[optim.ModuleDictEMA]:
|
160 |
-
"""Initialize Exponential Moving Average.
|
161 |
-
|
162 |
-
Args:
|
163 |
-
module_dict (nn.ModuleDict): ModuleDict for which to compute the EMA.
|
164 |
-
cfg (omegaconf.DictConfig): Optim EMA configuration.
|
165 |
-
Returns:
|
166 |
-
optim.ModuleDictEMA: EMA version of the ModuleDict.
|
167 |
-
"""
|
168 |
-
kw: tp.Dict[str, tp.Any] = dict(cfg)
|
169 |
-
use = kw.pop('use', False)
|
170 |
-
decay = kw.pop('decay', None)
|
171 |
-
device = kw.pop('device', None)
|
172 |
-
if not use:
|
173 |
-
return None
|
174 |
-
if len(module_dict) == 0:
|
175 |
-
raise ValueError("Trying to build EMA but an empty module_dict source is provided!")
|
176 |
-
ema_module = optim.ModuleDictEMA(module_dict, decay=decay, device=device)
|
177 |
-
return ema_module
|
178 |
-
|
179 |
-
|
180 |
-
def get_loss(loss_name: str, cfg: omegaconf.DictConfig):
|
181 |
-
"""Instantiate loss from configuration."""
|
182 |
-
klass = {
|
183 |
-
'l1': torch.nn.L1Loss,
|
184 |
-
'l2': torch.nn.MSELoss,
|
185 |
-
'mel': losses.MelSpectrogramL1Loss,
|
186 |
-
'mrstft': losses.MRSTFTLoss,
|
187 |
-
'msspec': losses.MultiScaleMelSpectrogramLoss,
|
188 |
-
'sisnr': losses.SISNR,
|
189 |
-
}[loss_name]
|
190 |
-
kwargs = dict(getattr(cfg, loss_name))
|
191 |
-
return klass(**kwargs)
|
192 |
-
|
193 |
-
|
194 |
-
def get_balancer(loss_weights: tp.Dict[str, float], cfg: omegaconf.DictConfig) -> losses.Balancer:
|
195 |
-
"""Instantiate loss balancer from configuration for the provided weights."""
|
196 |
-
kwargs: tp.Dict[str, tp.Any] = dict_from_config(cfg)
|
197 |
-
return losses.Balancer(loss_weights, **kwargs)
|
198 |
-
|
199 |
-
|
200 |
-
def get_adversary(name: str, cfg: omegaconf.DictConfig) -> nn.Module:
|
201 |
-
"""Initialize adversary from config."""
|
202 |
-
klass = {
|
203 |
-
'msd': adversarial.MultiScaleDiscriminator,
|
204 |
-
'mpd': adversarial.MultiPeriodDiscriminator,
|
205 |
-
'msstftd': adversarial.MultiScaleSTFTDiscriminator,
|
206 |
-
}[name]
|
207 |
-
adv_cfg: tp.Dict[str, tp.Any] = dict(getattr(cfg, name))
|
208 |
-
return klass(**adv_cfg)
|
209 |
-
|
210 |
-
|
211 |
-
def get_adversarial_losses(cfg) -> nn.ModuleDict:
|
212 |
-
"""Initialize dict of adversarial losses from config."""
|
213 |
-
device = cfg.device
|
214 |
-
adv_cfg = getattr(cfg, 'adversarial')
|
215 |
-
adversaries = adv_cfg.get('adversaries', [])
|
216 |
-
adv_loss_name = adv_cfg['adv_loss']
|
217 |
-
feat_loss_name = adv_cfg.get('feat_loss')
|
218 |
-
normalize = adv_cfg.get('normalize', True)
|
219 |
-
feat_loss: tp.Optional[adversarial.FeatureMatchingLoss] = None
|
220 |
-
if feat_loss_name:
|
221 |
-
assert feat_loss_name in ['l1', 'l2'], f"Feature loss only support L1 or L2 but {feat_loss_name} found."
|
222 |
-
loss = get_loss(feat_loss_name, cfg)
|
223 |
-
feat_loss = adversarial.FeatureMatchingLoss(loss, normalize)
|
224 |
-
loss = adversarial.get_adv_criterion(adv_loss_name)
|
225 |
-
loss_real = adversarial.get_real_criterion(adv_loss_name)
|
226 |
-
loss_fake = adversarial.get_fake_criterion(adv_loss_name)
|
227 |
-
adv_losses = nn.ModuleDict()
|
228 |
-
for adv_name in adversaries:
|
229 |
-
adversary = get_adversary(adv_name, cfg).to(device)
|
230 |
-
optimizer = get_optimizer(adversary.parameters(), cfg.optim)
|
231 |
-
adv_loss = adversarial.AdversarialLoss(
|
232 |
-
adversary,
|
233 |
-
optimizer,
|
234 |
-
loss=loss,
|
235 |
-
loss_real=loss_real,
|
236 |
-
loss_fake=loss_fake,
|
237 |
-
loss_feat=feat_loss,
|
238 |
-
normalize=normalize
|
239 |
-
)
|
240 |
-
adv_losses[adv_name] = adv_loss
|
241 |
-
return adv_losses
|
242 |
-
|
243 |
-
|
244 |
-
def get_visqol(cfg: omegaconf.DictConfig) -> metrics.ViSQOL:
|
245 |
-
"""Instantiate ViSQOL metric from config."""
|
246 |
-
kwargs = dict_from_config(cfg)
|
247 |
-
return metrics.ViSQOL(**kwargs)
|
248 |
-
|
249 |
-
|
250 |
-
def get_fad(cfg: omegaconf.DictConfig) -> metrics.FrechetAudioDistanceMetric:
|
251 |
-
"""Instantiate Frechet Audio Distance metric from config."""
|
252 |
-
kwargs = dict_from_config(cfg.tf)
|
253 |
-
xp = dora.get_xp()
|
254 |
-
kwargs['log_folder'] = xp.folder
|
255 |
-
return metrics.FrechetAudioDistanceMetric(**kwargs)
|
256 |
-
|
257 |
-
|
258 |
-
def get_kldiv(cfg: omegaconf.DictConfig) -> metrics.KLDivergenceMetric:
|
259 |
-
"""Instantiate KL-Divergence metric from config."""
|
260 |
-
kld_metrics = {
|
261 |
-
'passt': metrics.PasstKLDivergenceMetric,
|
262 |
-
}
|
263 |
-
klass = kld_metrics[cfg.model]
|
264 |
-
kwargs = dict_from_config(cfg.get(cfg.model))
|
265 |
-
return klass(**kwargs)
|
266 |
-
|
267 |
-
|
268 |
-
def get_text_consistency(cfg: omegaconf.DictConfig) -> metrics.TextConsistencyMetric:
|
269 |
-
"""Instantiate Text Consistency metric from config."""
|
270 |
-
text_consistency_metrics = {
|
271 |
-
'clap': metrics.CLAPTextConsistencyMetric
|
272 |
-
}
|
273 |
-
klass = text_consistency_metrics[cfg.model]
|
274 |
-
kwargs = dict_from_config(cfg.get(cfg.model))
|
275 |
-
return klass(**kwargs)
|
276 |
-
|
277 |
-
|
278 |
-
def get_chroma_cosine_similarity(cfg: omegaconf.DictConfig) -> metrics.ChromaCosineSimilarityMetric:
|
279 |
-
"""Instantiate Chroma Cosine Similarity metric from config."""
|
280 |
-
assert cfg.model == 'chroma_base', "Only support 'chroma_base' method for chroma cosine similarity metric"
|
281 |
-
kwargs = dict_from_config(cfg.get(cfg.model))
|
282 |
-
return metrics.ChromaCosineSimilarityMetric(**kwargs)
|
283 |
-
|
284 |
-
|
285 |
-
def get_audio_datasets(cfg: omegaconf.DictConfig,
|
286 |
-
dataset_type: DatasetType = DatasetType.AUDIO) -> tp.Dict[str, torch.utils.data.DataLoader]:
|
287 |
-
"""Build AudioDataset from configuration.
|
288 |
-
|
289 |
-
Args:
|
290 |
-
cfg (omegaconf.DictConfig): Configuration.
|
291 |
-
dataset_type: The type of dataset to create.
|
292 |
-
Returns:
|
293 |
-
dict[str, torch.utils.data.DataLoader]: Map of dataloader for each data split.
|
294 |
-
"""
|
295 |
-
dataloaders: dict = {}
|
296 |
-
|
297 |
-
sample_rate = cfg.sample_rate
|
298 |
-
channels = cfg.channels
|
299 |
-
seed = cfg.seed
|
300 |
-
max_sample_rate = cfg.datasource.max_sample_rate
|
301 |
-
max_channels = cfg.datasource.max_channels
|
302 |
-
|
303 |
-
assert cfg.dataset is not None, "Could not find dataset definition in config"
|
304 |
-
|
305 |
-
dataset_cfg = dict_from_config(cfg.dataset)
|
306 |
-
splits_cfg: dict = {}
|
307 |
-
splits_cfg['train'] = dataset_cfg.pop('train')
|
308 |
-
splits_cfg['valid'] = dataset_cfg.pop('valid')
|
309 |
-
splits_cfg['evaluate'] = dataset_cfg.pop('evaluate')
|
310 |
-
splits_cfg['generate'] = dataset_cfg.pop('generate')
|
311 |
-
execute_only_stage = cfg.get('execute_only', None)
|
312 |
-
|
313 |
-
for split, path in cfg.datasource.items():
|
314 |
-
if not isinstance(path, str):
|
315 |
-
continue # skipping this as not a path
|
316 |
-
if execute_only_stage is not None and split != execute_only_stage:
|
317 |
-
continue
|
318 |
-
logger.info(f"Loading audio data split {split}: {str(path)}")
|
319 |
-
assert (
|
320 |
-
cfg.sample_rate <= max_sample_rate
|
321 |
-
), f"Expecting a max sample rate of {max_sample_rate} for datasource but {sample_rate} found."
|
322 |
-
assert (
|
323 |
-
cfg.channels <= max_channels
|
324 |
-
), f"Expecting a max number of channels of {max_channels} for datasource but {channels} found."
|
325 |
-
|
326 |
-
split_cfg = splits_cfg[split]
|
327 |
-
split_kwargs = {k: v for k, v in split_cfg.items()}
|
328 |
-
kwargs = {**dataset_cfg, **split_kwargs} # split kwargs overrides default dataset_cfg
|
329 |
-
kwargs['sample_rate'] = sample_rate
|
330 |
-
kwargs['channels'] = channels
|
331 |
-
|
332 |
-
if kwargs.get('permutation_on_files') and cfg.optim.updates_per_epoch:
|
333 |
-
kwargs['num_samples'] = (
|
334 |
-
flashy.distrib.world_size() * cfg.dataset.batch_size * cfg.optim.updates_per_epoch)
|
335 |
-
|
336 |
-
num_samples = kwargs['num_samples']
|
337 |
-
shuffle = kwargs['shuffle']
|
338 |
-
|
339 |
-
return_info = kwargs.pop('return_info')
|
340 |
-
batch_size = kwargs.pop('batch_size', None)
|
341 |
-
num_workers = kwargs.pop('num_workers')
|
342 |
-
|
343 |
-
if dataset_type == DatasetType.MUSIC:
|
344 |
-
dataset = data.music_dataset.MusicDataset.from_meta(path, **kwargs)
|
345 |
-
elif dataset_type == DatasetType.SOUND:
|
346 |
-
dataset = data.sound_dataset.SoundDataset.from_meta(path, **kwargs)
|
347 |
-
elif dataset_type == DatasetType.AUDIO:
|
348 |
-
dataset = data.info_audio_dataset.InfoAudioDataset.from_meta(path, return_info=return_info, **kwargs)
|
349 |
-
else:
|
350 |
-
raise ValueError(f"Dataset type is unsupported: {dataset_type}")
|
351 |
-
|
352 |
-
loader = get_loader(
|
353 |
-
dataset,
|
354 |
-
num_samples,
|
355 |
-
batch_size=batch_size,
|
356 |
-
num_workers=num_workers,
|
357 |
-
seed=seed,
|
358 |
-
collate_fn=dataset.collater if return_info else None,
|
359 |
-
shuffle=shuffle,
|
360 |
-
)
|
361 |
-
dataloaders[split] = loader
|
362 |
-
|
363 |
-
return dataloaders
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AIGC-Audio/AudioGPT/NeuralSeq/data_gen/tts/base_binarizer.py
DELETED
@@ -1,224 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
os.environ["OMP_NUM_THREADS"] = "1"
|
3 |
-
|
4 |
-
from utils.multiprocess_utils import chunked_multiprocess_run
|
5 |
-
import random
|
6 |
-
import traceback
|
7 |
-
import json
|
8 |
-
from resemblyzer import VoiceEncoder
|
9 |
-
from tqdm import tqdm
|
10 |
-
from data_gen.tts.data_gen_utils import get_mel2ph, get_pitch, build_phone_encoder
|
11 |
-
from utils.hparams import set_hparams, hparams
|
12 |
-
import numpy as np
|
13 |
-
from utils.indexed_datasets import IndexedDatasetBuilder
|
14 |
-
from vocoders.base_vocoder import VOCODERS
|
15 |
-
import pandas as pd
|
16 |
-
|
17 |
-
|
18 |
-
class BinarizationError(Exception):
|
19 |
-
pass
|
20 |
-
|
21 |
-
|
22 |
-
class BaseBinarizer:
|
23 |
-
def __init__(self, processed_data_dir=None):
|
24 |
-
if processed_data_dir is None:
|
25 |
-
processed_data_dir = hparams['processed_data_dir']
|
26 |
-
self.processed_data_dirs = processed_data_dir.split(",")
|
27 |
-
self.binarization_args = hparams['binarization_args']
|
28 |
-
self.pre_align_args = hparams['pre_align_args']
|
29 |
-
self.forced_align = self.pre_align_args['forced_align']
|
30 |
-
tg_dir = None
|
31 |
-
if self.forced_align == 'mfa':
|
32 |
-
tg_dir = 'mfa_outputs'
|
33 |
-
if self.forced_align == 'kaldi':
|
34 |
-
tg_dir = 'kaldi_outputs'
|
35 |
-
self.item2txt = {}
|
36 |
-
self.item2ph = {}
|
37 |
-
self.item2wavfn = {}
|
38 |
-
self.item2tgfn = {}
|
39 |
-
self.item2spk = {}
|
40 |
-
for ds_id, processed_data_dir in enumerate(self.processed_data_dirs):
|
41 |
-
self.meta_df = pd.read_csv(f"{processed_data_dir}/metadata_phone.csv", dtype=str)
|
42 |
-
for r_idx, r in self.meta_df.iterrows():
|
43 |
-
item_name = raw_item_name = r['item_name']
|
44 |
-
if len(self.processed_data_dirs) > 1:
|
45 |
-
item_name = f'ds{ds_id}_{item_name}'
|
46 |
-
self.item2txt[item_name] = r['txt']
|
47 |
-
self.item2ph[item_name] = r['ph']
|
48 |
-
self.item2wavfn[item_name] = os.path.join(hparams['raw_data_dir'], 'wavs', os.path.basename(r['wav_fn']).split('_')[1])
|
49 |
-
self.item2spk[item_name] = r.get('spk', 'SPK1')
|
50 |
-
if len(self.processed_data_dirs) > 1:
|
51 |
-
self.item2spk[item_name] = f"ds{ds_id}_{self.item2spk[item_name]}"
|
52 |
-
if tg_dir is not None:
|
53 |
-
self.item2tgfn[item_name] = f"{processed_data_dir}/{tg_dir}/{raw_item_name}.TextGrid"
|
54 |
-
self.item_names = sorted(list(self.item2txt.keys()))
|
55 |
-
if self.binarization_args['shuffle']:
|
56 |
-
random.seed(1234)
|
57 |
-
random.shuffle(self.item_names)
|
58 |
-
|
59 |
-
@property
|
60 |
-
def train_item_names(self):
|
61 |
-
return self.item_names[hparams['test_num']+hparams['valid_num']:]
|
62 |
-
|
63 |
-
@property
|
64 |
-
def valid_item_names(self):
|
65 |
-
return self.item_names[0: hparams['test_num']+hparams['valid_num']] #
|
66 |
-
|
67 |
-
@property
|
68 |
-
def test_item_names(self):
|
69 |
-
return self.item_names[0: hparams['test_num']] # Audios for MOS testing are in 'test_ids'
|
70 |
-
|
71 |
-
def build_spk_map(self):
|
72 |
-
spk_map = set()
|
73 |
-
for item_name in self.item_names:
|
74 |
-
spk_name = self.item2spk[item_name]
|
75 |
-
spk_map.add(spk_name)
|
76 |
-
spk_map = {x: i for i, x in enumerate(sorted(list(spk_map)))}
|
77 |
-
assert len(spk_map) == 0 or len(spk_map) <= hparams['num_spk'], len(spk_map)
|
78 |
-
return spk_map
|
79 |
-
|
80 |
-
def item_name2spk_id(self, item_name):
|
81 |
-
return self.spk_map[self.item2spk[item_name]]
|
82 |
-
|
83 |
-
def _phone_encoder(self):
|
84 |
-
ph_set_fn = f"{hparams['binary_data_dir']}/phone_set.json"
|
85 |
-
ph_set = []
|
86 |
-
if hparams['reset_phone_dict'] or not os.path.exists(ph_set_fn):
|
87 |
-
for processed_data_dir in self.processed_data_dirs:
|
88 |
-
ph_set += [x.split(' ')[0] for x in open(f'{processed_data_dir}/dict.txt').readlines()]
|
89 |
-
ph_set = sorted(set(ph_set))
|
90 |
-
json.dump(ph_set, open(ph_set_fn, 'w'))
|
91 |
-
else:
|
92 |
-
ph_set = json.load(open(ph_set_fn, 'r'))
|
93 |
-
print("| phone set: ", ph_set)
|
94 |
-
return build_phone_encoder(hparams['binary_data_dir'])
|
95 |
-
|
96 |
-
def meta_data(self, prefix):
|
97 |
-
if prefix == 'valid':
|
98 |
-
item_names = self.valid_item_names
|
99 |
-
elif prefix == 'test':
|
100 |
-
item_names = self.test_item_names
|
101 |
-
else:
|
102 |
-
item_names = self.train_item_names
|
103 |
-
for item_name in item_names:
|
104 |
-
ph = self.item2ph[item_name]
|
105 |
-
txt = self.item2txt[item_name]
|
106 |
-
tg_fn = self.item2tgfn.get(item_name)
|
107 |
-
wav_fn = self.item2wavfn[item_name]
|
108 |
-
spk_id = self.item_name2spk_id(item_name)
|
109 |
-
yield item_name, ph, txt, tg_fn, wav_fn, spk_id
|
110 |
-
|
111 |
-
def process(self):
|
112 |
-
os.makedirs(hparams['binary_data_dir'], exist_ok=True)
|
113 |
-
self.spk_map = self.build_spk_map()
|
114 |
-
print("| spk_map: ", self.spk_map)
|
115 |
-
spk_map_fn = f"{hparams['binary_data_dir']}/spk_map.json"
|
116 |
-
json.dump(self.spk_map, open(spk_map_fn, 'w'))
|
117 |
-
|
118 |
-
self.phone_encoder = self._phone_encoder()
|
119 |
-
self.process_data('valid')
|
120 |
-
self.process_data('test')
|
121 |
-
self.process_data('train')
|
122 |
-
|
123 |
-
def process_data(self, prefix):
|
124 |
-
data_dir = hparams['binary_data_dir']
|
125 |
-
args = []
|
126 |
-
builder = IndexedDatasetBuilder(f'{data_dir}/{prefix}')
|
127 |
-
lengths = []
|
128 |
-
f0s = []
|
129 |
-
total_sec = 0
|
130 |
-
if self.binarization_args['with_spk_embed']:
|
131 |
-
voice_encoder = VoiceEncoder().cuda()
|
132 |
-
|
133 |
-
meta_data = list(self.meta_data(prefix))
|
134 |
-
for m in meta_data:
|
135 |
-
args.append(list(m) + [self.phone_encoder, self.binarization_args])
|
136 |
-
num_workers = int(os.getenv('N_PROC', os.cpu_count() // 3))
|
137 |
-
for f_id, (_, item) in enumerate(
|
138 |
-
zip(tqdm(meta_data), chunked_multiprocess_run(self.process_item, args, num_workers=num_workers))):
|
139 |
-
if item is None:
|
140 |
-
continue
|
141 |
-
item['spk_embed'] = voice_encoder.embed_utterance(item['wav']) \
|
142 |
-
if self.binarization_args['with_spk_embed'] else None
|
143 |
-
if not self.binarization_args['with_wav'] and 'wav' in item:
|
144 |
-
print("del wav")
|
145 |
-
del item['wav']
|
146 |
-
builder.add_item(item)
|
147 |
-
lengths.append(item['len'])
|
148 |
-
total_sec += item['sec']
|
149 |
-
if item.get('f0') is not None:
|
150 |
-
f0s.append(item['f0'])
|
151 |
-
builder.finalize()
|
152 |
-
np.save(f'{data_dir}/{prefix}_lengths.npy', lengths)
|
153 |
-
if len(f0s) > 0:
|
154 |
-
f0s = np.concatenate(f0s, 0)
|
155 |
-
f0s = f0s[f0s != 0]
|
156 |
-
np.save(f'{data_dir}/{prefix}_f0s_mean_std.npy', [np.mean(f0s).item(), np.std(f0s).item()])
|
157 |
-
print(f"| {prefix} total duration: {total_sec:.3f}s")
|
158 |
-
|
159 |
-
@classmethod
|
160 |
-
def process_item(cls, item_name, ph, txt, tg_fn, wav_fn, spk_id, encoder, binarization_args):
|
161 |
-
if hparams['vocoder'] in VOCODERS:
|
162 |
-
wav, mel = VOCODERS[hparams['vocoder']].wav2spec(wav_fn)
|
163 |
-
else:
|
164 |
-
wav, mel = VOCODERS[hparams['vocoder'].split('.')[-1]].wav2spec(wav_fn)
|
165 |
-
res = {
|
166 |
-
'item_name': item_name, 'txt': txt, 'ph': ph, 'mel': mel, 'wav': wav, 'wav_fn': wav_fn,
|
167 |
-
'sec': len(wav) / hparams['audio_sample_rate'], 'len': mel.shape[0], 'spk_id': spk_id
|
168 |
-
}
|
169 |
-
try:
|
170 |
-
if binarization_args['with_f0']:
|
171 |
-
cls.get_pitch(wav, mel, res)
|
172 |
-
if binarization_args['with_f0cwt']:
|
173 |
-
cls.get_f0cwt(res['f0'], res)
|
174 |
-
if binarization_args['with_txt']:
|
175 |
-
try:
|
176 |
-
phone_encoded = res['phone'] = encoder.encode(ph)
|
177 |
-
except:
|
178 |
-
traceback.print_exc()
|
179 |
-
raise BinarizationError(f"Empty phoneme")
|
180 |
-
if binarization_args['with_align']:
|
181 |
-
cls.get_align(tg_fn, ph, mel, phone_encoded, res)
|
182 |
-
except BinarizationError as e:
|
183 |
-
print(f"| Skip item ({e}). item_name: {item_name}, wav_fn: {wav_fn}")
|
184 |
-
return None
|
185 |
-
return res
|
186 |
-
|
187 |
-
@staticmethod
|
188 |
-
def get_align(tg_fn, ph, mel, phone_encoded, res):
|
189 |
-
if tg_fn is not None and os.path.exists(tg_fn):
|
190 |
-
mel2ph, dur = get_mel2ph(tg_fn, ph, mel, hparams)
|
191 |
-
else:
|
192 |
-
raise BinarizationError(f"Align not found")
|
193 |
-
if mel2ph.max() - 1 >= len(phone_encoded):
|
194 |
-
raise BinarizationError(
|
195 |
-
f"Align does not match: mel2ph.max() - 1: {mel2ph.max() - 1}, len(phone_encoded): {len(phone_encoded)}")
|
196 |
-
res['mel2ph'] = mel2ph
|
197 |
-
res['dur'] = dur
|
198 |
-
|
199 |
-
@staticmethod
|
200 |
-
def get_pitch(wav, mel, res):
|
201 |
-
f0, pitch_coarse = get_pitch(wav, mel, hparams)
|
202 |
-
if sum(f0) == 0:
|
203 |
-
raise BinarizationError("Empty f0")
|
204 |
-
res['f0'] = f0
|
205 |
-
res['pitch'] = pitch_coarse
|
206 |
-
|
207 |
-
@staticmethod
|
208 |
-
def get_f0cwt(f0, res):
|
209 |
-
from utils.cwt import get_cont_lf0, get_lf0_cwt
|
210 |
-
uv, cont_lf0_lpf = get_cont_lf0(f0)
|
211 |
-
logf0s_mean_org, logf0s_std_org = np.mean(cont_lf0_lpf), np.std(cont_lf0_lpf)
|
212 |
-
cont_lf0_lpf_norm = (cont_lf0_lpf - logf0s_mean_org) / logf0s_std_org
|
213 |
-
Wavelet_lf0, scales = get_lf0_cwt(cont_lf0_lpf_norm)
|
214 |
-
if np.any(np.isnan(Wavelet_lf0)):
|
215 |
-
raise BinarizationError("NaN CWT")
|
216 |
-
res['cwt_spec'] = Wavelet_lf0
|
217 |
-
res['cwt_scales'] = scales
|
218 |
-
res['f0_mean'] = logf0s_mean_org
|
219 |
-
res['f0_std'] = logf0s_std_org
|
220 |
-
|
221 |
-
|
222 |
-
if __name__ == "__main__":
|
223 |
-
set_hparams()
|
224 |
-
BaseBinarizer().process()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AIGC-Audio/AudioGPT/text_to_audio/Make_An_Audio/wav_evaluation/models/utils.py
DELETED
@@ -1,26 +0,0 @@
|
|
1 |
-
import argparse
|
2 |
-
import yaml
|
3 |
-
import sys
|
4 |
-
|
5 |
-
def read_config_as_args(config_path,args=None,is_config_str=False):
|
6 |
-
return_dict = {}
|
7 |
-
|
8 |
-
if config_path is not None:
|
9 |
-
if is_config_str:
|
10 |
-
yml_config = yaml.load(config_path, Loader=yaml.FullLoader)
|
11 |
-
else:
|
12 |
-
with open(config_path, "r") as f:
|
13 |
-
yml_config = yaml.load(f, Loader=yaml.FullLoader)
|
14 |
-
|
15 |
-
if args != None:
|
16 |
-
for k, v in yml_config.items():
|
17 |
-
if k in args.__dict__:
|
18 |
-
args.__dict__[k] = v
|
19 |
-
else:
|
20 |
-
sys.stderr.write("Ignored unknown parameter {} in yaml.\n".format(k))
|
21 |
-
else:
|
22 |
-
for k, v in yml_config.items():
|
23 |
-
return_dict[k] = v
|
24 |
-
|
25 |
-
args = args if args != None else return_dict
|
26 |
-
return argparse.Namespace(**args)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AIGC-Audio/AudioGPT/text_to_speech/modules/vocoder/parallel_wavegan/models/parallel_wavegan.py
DELETED
@@ -1,461 +0,0 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
|
3 |
-
# Copyright 2019 Tomoki Hayashi
|
4 |
-
# MIT License (https://opensource.org/licenses/MIT)
|
5 |
-
|
6 |
-
"""Parallel WaveGAN Modules."""
|
7 |
-
|
8 |
-
import logging
|
9 |
-
import math
|
10 |
-
|
11 |
-
import torch
|
12 |
-
from torch import nn
|
13 |
-
|
14 |
-
from text_to_speech.modules.vocoder.parallel_wavegan.layers import Conv1d
|
15 |
-
from text_to_speech.modules.vocoder.parallel_wavegan.layers import Conv1d1x1
|
16 |
-
from text_to_speech.modules.vocoder.parallel_wavegan.layers import ResidualBlock
|
17 |
-
from text_to_speech.modules.vocoder.parallel_wavegan.layers import upsample
|
18 |
-
from text_to_speech.modules.vocoder.parallel_wavegan import models
|
19 |
-
from text_to_speech.modules.vocoder.parallel_wavegan.models import SourceModuleCycNoise_v1
|
20 |
-
from text_to_speech.utils.commons.hparams import hparams
|
21 |
-
import numpy as np
|
22 |
-
|
23 |
-
class ParallelWaveGANGenerator(torch.nn.Module):
|
24 |
-
"""Parallel WaveGAN Generator module."""
|
25 |
-
|
26 |
-
def __init__(self,
|
27 |
-
in_channels=1,
|
28 |
-
out_channels=1,
|
29 |
-
kernel_size=3,
|
30 |
-
layers=30,
|
31 |
-
stacks=3,
|
32 |
-
residual_channels=64,
|
33 |
-
gate_channels=128,
|
34 |
-
skip_channels=64,
|
35 |
-
aux_channels=80,
|
36 |
-
aux_context_window=2,
|
37 |
-
dropout=0.0,
|
38 |
-
bias=True,
|
39 |
-
use_weight_norm=True,
|
40 |
-
use_causal_conv=False,
|
41 |
-
upsample_conditional_features=True,
|
42 |
-
upsample_net="ConvInUpsampleNetwork",
|
43 |
-
upsample_params={"upsample_scales": [4, 4, 4, 4]},
|
44 |
-
use_pitch_embed=False,
|
45 |
-
use_nsf=False,
|
46 |
-
sample_rate=22050,
|
47 |
-
):
|
48 |
-
"""Initialize Parallel WaveGAN Generator module.
|
49 |
-
|
50 |
-
Args:
|
51 |
-
in_channels (int): Number of input channels.
|
52 |
-
out_channels (int): Number of output channels.
|
53 |
-
kernel_size (int): Kernel size of dilated convolution.
|
54 |
-
layers (int): Number of residual block layers.
|
55 |
-
stacks (int): Number of stacks i.e., dilation cycles.
|
56 |
-
residual_channels (int): Number of channels in residual conv.
|
57 |
-
gate_channels (int): Number of channels in gated conv.
|
58 |
-
skip_channels (int): Number of channels in skip conv.
|
59 |
-
aux_channels (int): Number of channels for auxiliary feature conv.
|
60 |
-
aux_context_window (int): Context window size for auxiliary feature.
|
61 |
-
dropout (float): Dropout rate. 0.0 means no dropout applied.
|
62 |
-
bias (bool): Whether to use bias parameter in conv layer.
|
63 |
-
use_weight_norm (bool): Whether to use weight norm.
|
64 |
-
If set to true, it will be applied to all of the conv layers.
|
65 |
-
use_causal_conv (bool): Whether to use causal structure.
|
66 |
-
upsample_conditional_features (bool): Whether to use upsampling network.
|
67 |
-
upsample_net (str): Upsampling network architecture.
|
68 |
-
upsample_params (dict): Upsampling network parameters.
|
69 |
-
|
70 |
-
"""
|
71 |
-
super(ParallelWaveGANGenerator, self).__init__()
|
72 |
-
self.in_channels = in_channels
|
73 |
-
self.out_channels = out_channels
|
74 |
-
self.aux_channels = aux_channels
|
75 |
-
self.layers = layers
|
76 |
-
self.stacks = stacks
|
77 |
-
self.kernel_size = kernel_size
|
78 |
-
|
79 |
-
# check the number of layers and stacks
|
80 |
-
assert layers % stacks == 0
|
81 |
-
layers_per_stack = layers // stacks
|
82 |
-
|
83 |
-
# define first convolution
|
84 |
-
self.first_conv = Conv1d1x1(in_channels, residual_channels, bias=True)
|
85 |
-
|
86 |
-
# define conv + upsampling network
|
87 |
-
self.aux_context_window = aux_context_window
|
88 |
-
if upsample_conditional_features:
|
89 |
-
upsample_params.update({
|
90 |
-
"use_causal_conv": use_causal_conv,
|
91 |
-
})
|
92 |
-
if upsample_net == "MelGANGenerator":
|
93 |
-
assert aux_context_window == 0
|
94 |
-
upsample_params.update({
|
95 |
-
"use_weight_norm": False, # not to apply twice
|
96 |
-
"use_final_nonlinear_activation": False,
|
97 |
-
})
|
98 |
-
self.upsample_net = getattr(models, upsample_net)(**upsample_params)
|
99 |
-
else:
|
100 |
-
if upsample_net == "ConvInUpsampleNetwork":
|
101 |
-
upsample_params.update({
|
102 |
-
"aux_channels": aux_channels,
|
103 |
-
"aux_context_window": aux_context_window,
|
104 |
-
})
|
105 |
-
self.upsample_net = getattr(upsample, upsample_net)(**upsample_params)
|
106 |
-
else:
|
107 |
-
self.upsample_net = None
|
108 |
-
|
109 |
-
# define residual blocks
|
110 |
-
self.conv_layers = torch.nn.ModuleList()
|
111 |
-
for layer in range(layers):
|
112 |
-
dilation = 2 ** (layer % layers_per_stack)
|
113 |
-
conv = ResidualBlock(
|
114 |
-
kernel_size=kernel_size,
|
115 |
-
residual_channels=residual_channels,
|
116 |
-
gate_channels=gate_channels,
|
117 |
-
skip_channels=skip_channels,
|
118 |
-
aux_channels=aux_channels,
|
119 |
-
dilation=dilation,
|
120 |
-
dropout=dropout,
|
121 |
-
bias=bias,
|
122 |
-
use_causal_conv=use_causal_conv,
|
123 |
-
)
|
124 |
-
self.conv_layers += [conv]
|
125 |
-
|
126 |
-
# define output layers
|
127 |
-
self.last_conv_layers = torch.nn.ModuleList([
|
128 |
-
torch.nn.ReLU(inplace=True),
|
129 |
-
Conv1d1x1(skip_channels, skip_channels, bias=True),
|
130 |
-
torch.nn.ReLU(inplace=True),
|
131 |
-
Conv1d1x1(skip_channels, out_channels, bias=True),
|
132 |
-
])
|
133 |
-
|
134 |
-
self.use_pitch_embed = use_pitch_embed
|
135 |
-
if use_pitch_embed:
|
136 |
-
self.pitch_embed = nn.Embedding(300, aux_channels, 0)
|
137 |
-
self.c_proj = nn.Linear(2 * aux_channels, aux_channels)
|
138 |
-
self.use_nsf = use_nsf
|
139 |
-
if use_nsf:
|
140 |
-
self.harmonic_num = 8
|
141 |
-
hop_size = np.prod(upsample_params['upsample_scales'])
|
142 |
-
self.f0_upsamp = torch.nn.Upsample(scale_factor=hop_size)
|
143 |
-
self.m_source = SourceModuleCycNoise_v1(sample_rate, 0.003)
|
144 |
-
self.nsf_conv = nn.Sequential(nn.Conv1d(1, aux_channels, 1), torch.nn.Tanh())
|
145 |
-
|
146 |
-
# apply weight norm
|
147 |
-
if use_weight_norm:
|
148 |
-
self.apply_weight_norm()
|
149 |
-
|
150 |
-
def forward(self, x, c=None, pitch=None, f0=None, **kwargs):
|
151 |
-
"""Calculate forward propagation.
|
152 |
-
|
153 |
-
Args:
|
154 |
-
x (Tensor): Input noise signal (B, C_in, T).
|
155 |
-
c (Tensor): Local conditioning auxiliary features (B, C ,T').
|
156 |
-
pitch (Tensor): Local conditioning pitch (B, T').
|
157 |
-
|
158 |
-
Returns:
|
159 |
-
Tensor: Output tensor (B, C_out, T)
|
160 |
-
|
161 |
-
"""
|
162 |
-
# perform upsampling
|
163 |
-
if c is not None and self.upsample_net is not None:
|
164 |
-
if self.use_pitch_embed:
|
165 |
-
p = self.pitch_embed(pitch)
|
166 |
-
c = self.c_proj(torch.cat([c.transpose(1, 2), p], -1)).transpose(1, 2)
|
167 |
-
c = self.upsample_net(c)
|
168 |
-
if self.use_nsf:
|
169 |
-
f0_upsample = self.f0_upsamp(
|
170 |
-
f0[:, None, :][:, :, self.aux_context_window:-self.aux_context_window])
|
171 |
-
f0_upsample = self.nsf_conv(f0_upsample)
|
172 |
-
c = c + f0_upsample
|
173 |
-
if x is None:
|
174 |
-
x = torch.randn([c.size(0), 1, c.size(-1)]).to(c.device)
|
175 |
-
assert c.size(-1) == x.size(-1), (c.size(-1), x.size(-1))
|
176 |
-
|
177 |
-
# encode to hidden representation
|
178 |
-
x = self.first_conv(x)
|
179 |
-
skips = 0
|
180 |
-
for f in self.conv_layers:
|
181 |
-
x, h = f(x, c)
|
182 |
-
skips += h
|
183 |
-
skips *= math.sqrt(1.0 / len(self.conv_layers))
|
184 |
-
|
185 |
-
# apply final layers
|
186 |
-
x = skips
|
187 |
-
for f in self.last_conv_layers:
|
188 |
-
x = f(x)
|
189 |
-
|
190 |
-
return x
|
191 |
-
|
192 |
-
def remove_weight_norm(self):
|
193 |
-
"""Remove weight normalization module from all of the layers."""
|
194 |
-
def _remove_weight_norm(m):
|
195 |
-
try:
|
196 |
-
logging.debug(f"Weight norm is removed from {m}.")
|
197 |
-
torch.nn.utils.remove_weight_norm(m)
|
198 |
-
except ValueError: # this module didn't have weight norm
|
199 |
-
return
|
200 |
-
|
201 |
-
self.apply(_remove_weight_norm)
|
202 |
-
|
203 |
-
def apply_weight_norm(self):
|
204 |
-
"""Apply weight normalization module from all of the layers."""
|
205 |
-
def _apply_weight_norm(m):
|
206 |
-
if isinstance(m, torch.nn.Conv1d) or isinstance(m, torch.nn.Conv2d):
|
207 |
-
torch.nn.utils.weight_norm(m)
|
208 |
-
logging.debug(f"Weight norm is applied to {m}.")
|
209 |
-
|
210 |
-
self.apply(_apply_weight_norm)
|
211 |
-
|
212 |
-
@staticmethod
|
213 |
-
def _get_receptive_field_size(layers, stacks, kernel_size,
|
214 |
-
dilation=lambda x: 2 ** x):
|
215 |
-
assert layers % stacks == 0
|
216 |
-
layers_per_cycle = layers // stacks
|
217 |
-
dilations = [dilation(i % layers_per_cycle) for i in range(layers)]
|
218 |
-
return (kernel_size - 1) * sum(dilations) + 1
|
219 |
-
|
220 |
-
@property
|
221 |
-
def receptive_field_size(self):
|
222 |
-
"""Return receptive field size."""
|
223 |
-
return self._get_receptive_field_size(self.layers, self.stacks, self.kernel_size)
|
224 |
-
|
225 |
-
|
226 |
-
class ParallelWaveGANDiscriminator(torch.nn.Module):
|
227 |
-
"""Parallel WaveGAN Discriminator module."""
|
228 |
-
|
229 |
-
def __init__(self,
|
230 |
-
in_channels=1,
|
231 |
-
out_channels=1,
|
232 |
-
kernel_size=3,
|
233 |
-
layers=10,
|
234 |
-
conv_channels=64,
|
235 |
-
dilation_factor=1,
|
236 |
-
nonlinear_activation="LeakyReLU",
|
237 |
-
nonlinear_activation_params={"negative_slope": 0.2},
|
238 |
-
bias=True,
|
239 |
-
use_weight_norm=True,
|
240 |
-
):
|
241 |
-
"""Initialize Parallel WaveGAN Discriminator module.
|
242 |
-
|
243 |
-
Args:
|
244 |
-
in_channels (int): Number of input channels.
|
245 |
-
out_channels (int): Number of output channels.
|
246 |
-
kernel_size (int): Number of output channels.
|
247 |
-
layers (int): Number of conv layers.
|
248 |
-
conv_channels (int): Number of chnn layers.
|
249 |
-
dilation_factor (int): Dilation factor. For example, if dilation_factor = 2,
|
250 |
-
the dilation will be 2, 4, 8, ..., and so on.
|
251 |
-
nonlinear_activation (str): Nonlinear function after each conv.
|
252 |
-
nonlinear_activation_params (dict): Nonlinear function parameters
|
253 |
-
bias (bool): Whether to use bias parameter in conv.
|
254 |
-
use_weight_norm (bool) Whether to use weight norm.
|
255 |
-
If set to true, it will be applied to all of the conv layers.
|
256 |
-
|
257 |
-
"""
|
258 |
-
super(ParallelWaveGANDiscriminator, self).__init__()
|
259 |
-
assert (kernel_size - 1) % 2 == 0, "Not support even number kernel size."
|
260 |
-
assert dilation_factor > 0, "Dilation factor must be > 0."
|
261 |
-
self.conv_layers = torch.nn.ModuleList()
|
262 |
-
conv_in_channels = in_channels
|
263 |
-
for i in range(layers - 1):
|
264 |
-
if i == 0:
|
265 |
-
dilation = 1
|
266 |
-
else:
|
267 |
-
dilation = i if dilation_factor == 1 else dilation_factor ** i
|
268 |
-
conv_in_channels = conv_channels
|
269 |
-
padding = (kernel_size - 1) // 2 * dilation
|
270 |
-
conv_layer = [
|
271 |
-
Conv1d(conv_in_channels, conv_channels,
|
272 |
-
kernel_size=kernel_size, padding=padding,
|
273 |
-
dilation=dilation, bias=bias),
|
274 |
-
getattr(torch.nn, nonlinear_activation)(inplace=True, **nonlinear_activation_params)
|
275 |
-
]
|
276 |
-
self.conv_layers += conv_layer
|
277 |
-
padding = (kernel_size - 1) // 2
|
278 |
-
last_conv_layer = Conv1d(
|
279 |
-
conv_in_channels, out_channels,
|
280 |
-
kernel_size=kernel_size, padding=padding, bias=bias)
|
281 |
-
self.conv_layers += [last_conv_layer]
|
282 |
-
|
283 |
-
# apply weight norm
|
284 |
-
if use_weight_norm:
|
285 |
-
self.apply_weight_norm()
|
286 |
-
|
287 |
-
def forward(self, x, cond=None):
|
288 |
-
"""Calculate forward propagation.
|
289 |
-
|
290 |
-
Args:
|
291 |
-
x (Tensor): Input noise signal (B, 1, T).
|
292 |
-
cond (Tensor): Input noise signal (B, H, T_frame).
|
293 |
-
|
294 |
-
Returns:
|
295 |
-
Tensor: Output tensor (B, 1, T)
|
296 |
-
|
297 |
-
"""
|
298 |
-
cond_layer_i = len(self.conv_layers) // 2
|
299 |
-
for i, f in enumerate(self.conv_layers):
|
300 |
-
if i == cond_layer_i and cond is not None:
|
301 |
-
aux_context_window = hparams['aux_context_window']
|
302 |
-
cond = cond[:, :, aux_context_window:-aux_context_window]
|
303 |
-
cond = cond[:, :, :, None].repeat([1, 1, 1, hparams['hop_size']]).reshape(
|
304 |
-
cond.shape[0], cond.shape[1], -1)
|
305 |
-
x = x + cond
|
306 |
-
x = f(x)
|
307 |
-
return x
|
308 |
-
|
309 |
-
def apply_weight_norm(self):
|
310 |
-
"""Apply weight normalization module from all of the layers."""
|
311 |
-
def _apply_weight_norm(m):
|
312 |
-
if isinstance(m, torch.nn.Conv1d) or isinstance(m, torch.nn.Conv2d):
|
313 |
-
torch.nn.utils.weight_norm(m)
|
314 |
-
logging.debug(f"Weight norm is applied to {m}.")
|
315 |
-
|
316 |
-
self.apply(_apply_weight_norm)
|
317 |
-
|
318 |
-
def remove_weight_norm(self):
|
319 |
-
"""Remove weight normalization module from all of the layers."""
|
320 |
-
def _remove_weight_norm(m):
|
321 |
-
try:
|
322 |
-
logging.debug(f"Weight norm is removed from {m}.")
|
323 |
-
torch.nn.utils.remove_weight_norm(m)
|
324 |
-
except ValueError: # this module didn't have weight norm
|
325 |
-
return
|
326 |
-
|
327 |
-
self.apply(_remove_weight_norm)
|
328 |
-
|
329 |
-
|
330 |
-
class ResidualParallelWaveGANDiscriminator(torch.nn.Module):
|
331 |
-
"""Parallel WaveGAN Discriminator module."""
|
332 |
-
|
333 |
-
def __init__(self,
|
334 |
-
in_channels=1,
|
335 |
-
out_channels=1,
|
336 |
-
kernel_size=3,
|
337 |
-
layers=30,
|
338 |
-
stacks=3,
|
339 |
-
residual_channels=64,
|
340 |
-
gate_channels=128,
|
341 |
-
skip_channels=64,
|
342 |
-
dropout=0.0,
|
343 |
-
bias=True,
|
344 |
-
use_weight_norm=True,
|
345 |
-
use_causal_conv=False,
|
346 |
-
nonlinear_activation="LeakyReLU",
|
347 |
-
nonlinear_activation_params={"negative_slope": 0.2},
|
348 |
-
):
|
349 |
-
"""Initialize Parallel WaveGAN Discriminator module.
|
350 |
-
|
351 |
-
Args:
|
352 |
-
in_channels (int): Number of input channels.
|
353 |
-
out_channels (int): Number of output channels.
|
354 |
-
kernel_size (int): Kernel size of dilated convolution.
|
355 |
-
layers (int): Number of residual block layers.
|
356 |
-
stacks (int): Number of stacks i.e., dilation cycles.
|
357 |
-
residual_channels (int): Number of channels in residual conv.
|
358 |
-
gate_channels (int): Number of channels in gated conv.
|
359 |
-
skip_channels (int): Number of channels in skip conv.
|
360 |
-
dropout (float): Dropout rate. 0.0 means no dropout applied.
|
361 |
-
bias (bool): Whether to use bias parameter in conv.
|
362 |
-
use_weight_norm (bool): Whether to use weight norm.
|
363 |
-
If set to true, it will be applied to all of the conv layers.
|
364 |
-
use_causal_conv (bool): Whether to use causal structure.
|
365 |
-
nonlinear_activation_params (dict): Nonlinear function parameters
|
366 |
-
|
367 |
-
"""
|
368 |
-
super(ResidualParallelWaveGANDiscriminator, self).__init__()
|
369 |
-
assert (kernel_size - 1) % 2 == 0, "Not support even number kernel size."
|
370 |
-
|
371 |
-
self.in_channels = in_channels
|
372 |
-
self.out_channels = out_channels
|
373 |
-
self.layers = layers
|
374 |
-
self.stacks = stacks
|
375 |
-
self.kernel_size = kernel_size
|
376 |
-
|
377 |
-
# check the number of layers and stacks
|
378 |
-
assert layers % stacks == 0
|
379 |
-
layers_per_stack = layers // stacks
|
380 |
-
|
381 |
-
# define first convolution
|
382 |
-
self.first_conv = torch.nn.Sequential(
|
383 |
-
Conv1d1x1(in_channels, residual_channels, bias=True),
|
384 |
-
getattr(torch.nn, nonlinear_activation)(
|
385 |
-
inplace=True, **nonlinear_activation_params),
|
386 |
-
)
|
387 |
-
|
388 |
-
# define residual blocks
|
389 |
-
self.conv_layers = torch.nn.ModuleList()
|
390 |
-
for layer in range(layers):
|
391 |
-
dilation = 2 ** (layer % layers_per_stack)
|
392 |
-
conv = ResidualBlock(
|
393 |
-
kernel_size=kernel_size,
|
394 |
-
residual_channels=residual_channels,
|
395 |
-
gate_channels=gate_channels,
|
396 |
-
skip_channels=skip_channels,
|
397 |
-
aux_channels=-1,
|
398 |
-
dilation=dilation,
|
399 |
-
dropout=dropout,
|
400 |
-
bias=bias,
|
401 |
-
use_causal_conv=use_causal_conv,
|
402 |
-
)
|
403 |
-
self.conv_layers += [conv]
|
404 |
-
|
405 |
-
# define output layers
|
406 |
-
self.last_conv_layers = torch.nn.ModuleList([
|
407 |
-
getattr(torch.nn, nonlinear_activation)(
|
408 |
-
inplace=True, **nonlinear_activation_params),
|
409 |
-
Conv1d1x1(skip_channels, skip_channels, bias=True),
|
410 |
-
getattr(torch.nn, nonlinear_activation)(
|
411 |
-
inplace=True, **nonlinear_activation_params),
|
412 |
-
Conv1d1x1(skip_channels, out_channels, bias=True),
|
413 |
-
])
|
414 |
-
|
415 |
-
# apply weight norm
|
416 |
-
if use_weight_norm:
|
417 |
-
self.apply_weight_norm()
|
418 |
-
|
419 |
-
def forward(self, x):
|
420 |
-
"""Calculate forward propagation.
|
421 |
-
|
422 |
-
Args:
|
423 |
-
x (Tensor): Input noise signal (B, 1, T).
|
424 |
-
|
425 |
-
Returns:
|
426 |
-
Tensor: Output tensor (B, 1, T)
|
427 |
-
|
428 |
-
"""
|
429 |
-
x = self.first_conv(x)
|
430 |
-
|
431 |
-
skips = 0
|
432 |
-
for f in self.conv_layers:
|
433 |
-
x, h = f(x, None)
|
434 |
-
skips += h
|
435 |
-
skips *= math.sqrt(1.0 / len(self.conv_layers))
|
436 |
-
|
437 |
-
# apply final layers
|
438 |
-
x = skips
|
439 |
-
for f in self.last_conv_layers:
|
440 |
-
x = f(x)
|
441 |
-
return x
|
442 |
-
|
443 |
-
def apply_weight_norm(self):
|
444 |
-
"""Apply weight normalization module from all of the layers."""
|
445 |
-
def _apply_weight_norm(m):
|
446 |
-
if isinstance(m, torch.nn.Conv1d) or isinstance(m, torch.nn.Conv2d):
|
447 |
-
torch.nn.utils.weight_norm(m)
|
448 |
-
logging.debug(f"Weight norm is applied to {m}.")
|
449 |
-
|
450 |
-
self.apply(_apply_weight_norm)
|
451 |
-
|
452 |
-
def remove_weight_norm(self):
|
453 |
-
"""Remove weight normalization module from all of the layers."""
|
454 |
-
def _remove_weight_norm(m):
|
455 |
-
try:
|
456 |
-
logging.debug(f"Weight norm is removed from {m}.")
|
457 |
-
torch.nn.utils.remove_weight_norm(m)
|
458 |
-
except ValueError: # this module didn't have weight norm
|
459 |
-
return
|
460 |
-
|
461 |
-
self.apply(_remove_weight_norm)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AIGC-Audio/Make_An_Audio_inpaint/ldm/modules/encoders/open_clap/transform.py
DELETED
@@ -1,30 +0,0 @@
|
|
1 |
-
from torchvision.transforms import Normalize, Compose, RandomResizedCrop, InterpolationMode, ToTensor, Resize, \
|
2 |
-
CenterCrop
|
3 |
-
|
4 |
-
|
5 |
-
def _convert_to_rgb(image):
|
6 |
-
return image.convert('RGB')
|
7 |
-
|
8 |
-
|
9 |
-
def image_transform(
|
10 |
-
image_size: int,
|
11 |
-
is_train: bool,
|
12 |
-
mean=(0.48145466, 0.4578275, 0.40821073),
|
13 |
-
std=(0.26862954, 0.26130258, 0.27577711)
|
14 |
-
):
|
15 |
-
normalize = Normalize(mean=mean, std=std)
|
16 |
-
if is_train:
|
17 |
-
return Compose([
|
18 |
-
RandomResizedCrop(image_size, scale=(0.9, 1.0), interpolation=InterpolationMode.BICUBIC),
|
19 |
-
_convert_to_rgb,
|
20 |
-
ToTensor(),
|
21 |
-
normalize,
|
22 |
-
])
|
23 |
-
else:
|
24 |
-
return Compose([
|
25 |
-
Resize(image_size, interpolation=InterpolationMode.BICUBIC),
|
26 |
-
CenterCrop(image_size),
|
27 |
-
_convert_to_rgb,
|
28 |
-
ToTensor(),
|
29 |
-
normalize,
|
30 |
-
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/ALSv/Chat-with-Llama-2-70b/app.py
DELETED
@@ -1,64 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from gradio_client import Client
|
3 |
-
|
4 |
-
client = Client("https://ysharma-explore-llamav2-with-tgi.hf.space/")
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
title = "Lauche-AI LEU-Chatbot"
|
9 |
-
description = """
|
10 |
-
Disclaimer: Lauche - AI (POWERED BY LLAMA 2) can produce factually incorrect output, and should not be relied on to produce factually accurate information. Lauche - AI (POWERED BY LLAMA 2) was trained on various public datasets; while great efforts have been taken to clean the pretraining data, it is possible that this model could generate lewd, biased, or otherwise offensive outputs. - - - Our Impressum: https://lauche.eu/n-impressum - - - Visit this space on our website: ai-app.lauche.online.
|
11 |
-
"""
|
12 |
-
css = """.toast-wrap { display: none !important } """
|
13 |
-
examples=[
|
14 |
-
['Hello there! How are you doing?'],
|
15 |
-
['Can you explain to me briefly what is Python programming language?'],
|
16 |
-
['Explain the plot of Cinderella in a sentence.'],
|
17 |
-
['How many hours does it take a man to eat a Helicopter?'],
|
18 |
-
["Write a 100-word article on 'Benefits of Open-Source in AI research'"],
|
19 |
-
]
|
20 |
-
|
21 |
-
|
22 |
-
# Stream text
|
23 |
-
def predict(message, chatbot, system_prompt="", temperature=0.9, max_new_tokens=4096):
|
24 |
-
return client.predict(
|
25 |
-
message, # str in 'Message' Textbox component
|
26 |
-
system_prompt, # str in 'Optional system prompt' Textbox component
|
27 |
-
temperature, # int | float (numeric value between 0.0 and 1.0)
|
28 |
-
max_new_tokens, # int | float (numeric value between 0 and 4096)
|
29 |
-
0.3, # int | float (numeric value between 0.0 and 1)
|
30 |
-
1, # int | float (numeric value between 1.0 and 2.0)
|
31 |
-
api_name="/chat"
|
32 |
-
)
|
33 |
-
|
34 |
-
|
35 |
-
additional_inputs=[
|
36 |
-
gr.Textbox("", label="Optional system prompt"),
|
37 |
-
gr.Slider(
|
38 |
-
label="Temperature",
|
39 |
-
value=0.9,
|
40 |
-
minimum=0.0,
|
41 |
-
maximum=1.0,
|
42 |
-
step=0.05,
|
43 |
-
interactive=True,
|
44 |
-
info="Higher values produce more diverse outputs",
|
45 |
-
),
|
46 |
-
gr.Slider(
|
47 |
-
label="Max new tokens",
|
48 |
-
value=4096,
|
49 |
-
minimum=0,
|
50 |
-
maximum=4096,
|
51 |
-
step=64,
|
52 |
-
interactive=True,
|
53 |
-
info="The maximum numbers of new tokens",
|
54 |
-
)
|
55 |
-
]
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
# Gradio Demo
|
60 |
-
with gr.Blocks(theme=gr.themes.Base()) as demo:
|
61 |
-
|
62 |
-
gr.ChatInterface(predict, title=title, description=description, css=css, examples=examples, additional_inputs=additional_inputs)
|
63 |
-
|
64 |
-
demo.queue().launch(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Abhilashvj/planogram-compliance/utils/dataloaders.py
DELETED
@@ -1,1772 +0,0 @@
|
|
1 |
-
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
|
2 |
-
"""
|
3 |
-
Dataloaders and dataset utils
|
4 |
-
"""
|
5 |
-
|
6 |
-
import contextlib
|
7 |
-
import glob
|
8 |
-
import hashlib
|
9 |
-
import json
|
10 |
-
import math
|
11 |
-
import os
|
12 |
-
import random
|
13 |
-
import shutil
|
14 |
-
import time
|
15 |
-
from itertools import repeat
|
16 |
-
from multiprocessing.pool import Pool, ThreadPool
|
17 |
-
from pathlib import Path
|
18 |
-
from threading import Thread
|
19 |
-
from urllib.parse import urlparse
|
20 |
-
|
21 |
-
import numpy as np
|
22 |
-
import psutil
|
23 |
-
import torch
|
24 |
-
import torch.nn.functional as F
|
25 |
-
import torchvision
|
26 |
-
import yaml
|
27 |
-
from PIL import ExifTags, Image, ImageOps
|
28 |
-
from torch.utils.data import DataLoader, Dataset, dataloader, distributed
|
29 |
-
from tqdm import tqdm
|
30 |
-
|
31 |
-
from utils.augmentations import (
|
32 |
-
Albumentations,
|
33 |
-
augment_hsv,
|
34 |
-
classify_albumentations,
|
35 |
-
classify_transforms,
|
36 |
-
copy_paste,
|
37 |
-
letterbox,
|
38 |
-
mixup,
|
39 |
-
random_perspective,
|
40 |
-
)
|
41 |
-
from utils.general import (
|
42 |
-
DATASETS_DIR,
|
43 |
-
LOGGER,
|
44 |
-
NUM_THREADS,
|
45 |
-
TQDM_BAR_FORMAT,
|
46 |
-
check_dataset,
|
47 |
-
check_requirements,
|
48 |
-
check_yaml,
|
49 |
-
clean_str,
|
50 |
-
cv2,
|
51 |
-
is_colab,
|
52 |
-
is_kaggle,
|
53 |
-
segments2boxes,
|
54 |
-
unzip_file,
|
55 |
-
xyn2xy,
|
56 |
-
xywh2xyxy,
|
57 |
-
xywhn2xyxy,
|
58 |
-
xyxy2xywhn,
|
59 |
-
)
|
60 |
-
from utils.torch_utils import torch_distributed_zero_first
|
61 |
-
|
62 |
-
# Parameters
|
63 |
-
HELP_URL = "See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data"
|
64 |
-
IMG_FORMATS = (
|
65 |
-
"bmp",
|
66 |
-
"dng",
|
67 |
-
"jpeg",
|
68 |
-
"jpg",
|
69 |
-
"mpo",
|
70 |
-
"png",
|
71 |
-
"tif",
|
72 |
-
"tiff",
|
73 |
-
"webp",
|
74 |
-
"pfm",
|
75 |
-
) # include image suffixes
|
76 |
-
VID_FORMATS = (
|
77 |
-
"asf",
|
78 |
-
"avi",
|
79 |
-
"gif",
|
80 |
-
"m4v",
|
81 |
-
"mkv",
|
82 |
-
"mov",
|
83 |
-
"mp4",
|
84 |
-
"mpeg",
|
85 |
-
"mpg",
|
86 |
-
"ts",
|
87 |
-
"wmv",
|
88 |
-
) # include video suffixes
|
89 |
-
LOCAL_RANK = int(
|
90 |
-
os.getenv("LOCAL_RANK", -1)
|
91 |
-
) # https://pytorch.org/docs/stable/elastic/run.html
|
92 |
-
RANK = int(os.getenv("RANK", -1))
|
93 |
-
PIN_MEMORY = (
|
94 |
-
str(os.getenv("PIN_MEMORY", True)).lower() == "true"
|
95 |
-
) # global pin_memory for dataloaders
|
96 |
-
|
97 |
-
# Get orientation exif tag
|
98 |
-
for orientation in ExifTags.TAGS.keys():
|
99 |
-
if ExifTags.TAGS[orientation] == "Orientation":
|
100 |
-
break
|
101 |
-
|
102 |
-
|
103 |
-
def get_hash(paths):
|
104 |
-
# Returns a single hash value of a list of paths (files or dirs)
|
105 |
-
size = sum(os.path.getsize(p) for p in paths if os.path.exists(p)) # sizes
|
106 |
-
h = hashlib.md5(str(size).encode()) # hash sizes
|
107 |
-
h.update("".join(paths).encode()) # hash paths
|
108 |
-
return h.hexdigest() # return hash
|
109 |
-
|
110 |
-
|
111 |
-
def exif_size(img):
|
112 |
-
# Returns exif-corrected PIL size
|
113 |
-
s = img.size # (width, height)
|
114 |
-
with contextlib.suppress(Exception):
|
115 |
-
rotation = dict(img._getexif().items())[orientation]
|
116 |
-
if rotation in [6, 8]: # rotation 270 or 90
|
117 |
-
s = (s[1], s[0])
|
118 |
-
return s
|
119 |
-
|
120 |
-
|
121 |
-
def exif_transpose(image):
|
122 |
-
"""
|
123 |
-
Transpose a PIL image accordingly if it has an EXIF Orientation tag.
|
124 |
-
Inplace version of https://github.com/python-pillow/Pillow/blob/master/src/PIL/ImageOps.py exif_transpose()
|
125 |
-
|
126 |
-
:param image: The image to transpose.
|
127 |
-
:return: An image.
|
128 |
-
"""
|
129 |
-
exif = image.getexif()
|
130 |
-
orientation = exif.get(0x0112, 1) # default 1
|
131 |
-
if orientation > 1:
|
132 |
-
method = {
|
133 |
-
2: Image.FLIP_LEFT_RIGHT,
|
134 |
-
3: Image.ROTATE_180,
|
135 |
-
4: Image.FLIP_TOP_BOTTOM,
|
136 |
-
5: Image.TRANSPOSE,
|
137 |
-
6: Image.ROTATE_270,
|
138 |
-
7: Image.TRANSVERSE,
|
139 |
-
8: Image.ROTATE_90,
|
140 |
-
}.get(orientation)
|
141 |
-
if method is not None:
|
142 |
-
image = image.transpose(method)
|
143 |
-
del exif[0x0112]
|
144 |
-
image.info["exif"] = exif.tobytes()
|
145 |
-
return image
|
146 |
-
|
147 |
-
|
148 |
-
def seed_worker(worker_id):
|
149 |
-
# Set dataloader worker seed https://pytorch.org/docs/stable/notes/randomness.html#dataloader
|
150 |
-
worker_seed = torch.initial_seed() % 2**32
|
151 |
-
np.random.seed(worker_seed)
|
152 |
-
random.seed(worker_seed)
|
153 |
-
|
154 |
-
|
155 |
-
def create_dataloader(
|
156 |
-
path,
|
157 |
-
imgsz,
|
158 |
-
batch_size,
|
159 |
-
stride,
|
160 |
-
single_cls=False,
|
161 |
-
hyp=None,
|
162 |
-
augment=False,
|
163 |
-
cache=False,
|
164 |
-
pad=0.0,
|
165 |
-
rect=False,
|
166 |
-
rank=-1,
|
167 |
-
workers=8,
|
168 |
-
image_weights=False,
|
169 |
-
quad=False,
|
170 |
-
prefix="",
|
171 |
-
shuffle=False,
|
172 |
-
seed=0,
|
173 |
-
):
|
174 |
-
if rect and shuffle:
|
175 |
-
LOGGER.warning(
|
176 |
-
"WARNING ⚠️ --rect is incompatible with DataLoader shuffle, setting shuffle=False"
|
177 |
-
)
|
178 |
-
shuffle = False
|
179 |
-
with torch_distributed_zero_first(
|
180 |
-
rank
|
181 |
-
): # init dataset *.cache only once if DDP
|
182 |
-
dataset = LoadImagesAndLabels(
|
183 |
-
path,
|
184 |
-
imgsz,
|
185 |
-
batch_size,
|
186 |
-
augment=augment, # augmentation
|
187 |
-
hyp=hyp, # hyperparameters
|
188 |
-
rect=rect, # rectangular batches
|
189 |
-
cache_images=cache,
|
190 |
-
single_cls=single_cls,
|
191 |
-
stride=int(stride),
|
192 |
-
pad=pad,
|
193 |
-
image_weights=image_weights,
|
194 |
-
prefix=prefix,
|
195 |
-
)
|
196 |
-
|
197 |
-
batch_size = min(batch_size, len(dataset))
|
198 |
-
nd = torch.cuda.device_count() # number of CUDA devices
|
199 |
-
nw = min(
|
200 |
-
[
|
201 |
-
os.cpu_count() // max(nd, 1),
|
202 |
-
batch_size if batch_size > 1 else 0,
|
203 |
-
workers,
|
204 |
-
]
|
205 |
-
) # number of workers
|
206 |
-
sampler = (
|
207 |
-
None
|
208 |
-
if rank == -1
|
209 |
-
else distributed.DistributedSampler(dataset, shuffle=shuffle)
|
210 |
-
)
|
211 |
-
loader = (
|
212 |
-
DataLoader if image_weights else InfiniteDataLoader
|
213 |
-
) # only DataLoader allows for attribute updates
|
214 |
-
generator = torch.Generator()
|
215 |
-
generator.manual_seed(6148914691236517205 + seed + RANK)
|
216 |
-
return (
|
217 |
-
loader(
|
218 |
-
dataset,
|
219 |
-
batch_size=batch_size,
|
220 |
-
shuffle=shuffle and sampler is None,
|
221 |
-
num_workers=nw,
|
222 |
-
sampler=sampler,
|
223 |
-
pin_memory=PIN_MEMORY,
|
224 |
-
collate_fn=LoadImagesAndLabels.collate_fn4
|
225 |
-
if quad
|
226 |
-
else LoadImagesAndLabels.collate_fn,
|
227 |
-
worker_init_fn=seed_worker,
|
228 |
-
generator=generator,
|
229 |
-
),
|
230 |
-
dataset,
|
231 |
-
)
|
232 |
-
|
233 |
-
|
234 |
-
class InfiniteDataLoader(dataloader.DataLoader):
|
235 |
-
"""Dataloader that reuses workers
|
236 |
-
|
237 |
-
Uses same syntax as vanilla DataLoader
|
238 |
-
"""
|
239 |
-
|
240 |
-
def __init__(self, *args, **kwargs):
|
241 |
-
super().__init__(*args, **kwargs)
|
242 |
-
object.__setattr__(
|
243 |
-
self, "batch_sampler", _RepeatSampler(self.batch_sampler)
|
244 |
-
)
|
245 |
-
self.iterator = super().__iter__()
|
246 |
-
|
247 |
-
def __len__(self):
|
248 |
-
return len(self.batch_sampler.sampler)
|
249 |
-
|
250 |
-
def __iter__(self):
|
251 |
-
for _ in range(len(self)):
|
252 |
-
yield next(self.iterator)
|
253 |
-
|
254 |
-
|
255 |
-
class _RepeatSampler:
|
256 |
-
"""Sampler that repeats forever
|
257 |
-
|
258 |
-
Args:
|
259 |
-
sampler (Sampler)
|
260 |
-
"""
|
261 |
-
|
262 |
-
def __init__(self, sampler):
|
263 |
-
self.sampler = sampler
|
264 |
-
|
265 |
-
def __iter__(self):
|
266 |
-
while True:
|
267 |
-
yield from iter(self.sampler)
|
268 |
-
|
269 |
-
|
270 |
-
class LoadScreenshots:
|
271 |
-
# YOLOv5 screenshot dataloader, i.e. `python detect.py --source "screen 0 100 100 512 256"`
|
272 |
-
def __init__(
|
273 |
-
self, source, img_size=640, stride=32, auto=True, transforms=None
|
274 |
-
):
|
275 |
-
# source = [screen_number left top width height] (pixels)
|
276 |
-
check_requirements("mss")
|
277 |
-
import mss
|
278 |
-
|
279 |
-
source, *params = source.split()
|
280 |
-
self.screen, left, top, width, height = (
|
281 |
-
0,
|
282 |
-
None,
|
283 |
-
None,
|
284 |
-
None,
|
285 |
-
None,
|
286 |
-
) # default to full screen 0
|
287 |
-
if len(params) == 1:
|
288 |
-
self.screen = int(params[0])
|
289 |
-
elif len(params) == 4:
|
290 |
-
left, top, width, height = (int(x) for x in params)
|
291 |
-
elif len(params) == 5:
|
292 |
-
self.screen, left, top, width, height = (int(x) for x in params)
|
293 |
-
self.img_size = img_size
|
294 |
-
self.stride = stride
|
295 |
-
self.transforms = transforms
|
296 |
-
self.auto = auto
|
297 |
-
self.mode = "stream"
|
298 |
-
self.frame = 0
|
299 |
-
self.sct = mss.mss()
|
300 |
-
|
301 |
-
# Parse monitor shape
|
302 |
-
monitor = self.sct.monitors[self.screen]
|
303 |
-
self.top = monitor["top"] if top is None else (monitor["top"] + top)
|
304 |
-
self.left = (
|
305 |
-
monitor["left"] if left is None else (monitor["left"] + left)
|
306 |
-
)
|
307 |
-
self.width = width or monitor["width"]
|
308 |
-
self.height = height or monitor["height"]
|
309 |
-
self.monitor = {
|
310 |
-
"left": self.left,
|
311 |
-
"top": self.top,
|
312 |
-
"width": self.width,
|
313 |
-
"height": self.height,
|
314 |
-
}
|
315 |
-
|
316 |
-
def __iter__(self):
|
317 |
-
return self
|
318 |
-
|
319 |
-
def __next__(self):
|
320 |
-
# mss screen capture: get raw pixels from the screen as np array
|
321 |
-
im0 = np.array(self.sct.grab(self.monitor))[
|
322 |
-
:, :, :3
|
323 |
-
] # [:, :, :3] BGRA to BGR
|
324 |
-
s = f"screen {self.screen} (LTWH): {self.left},{self.top},{self.width},{self.height}: "
|
325 |
-
|
326 |
-
if self.transforms:
|
327 |
-
im = self.transforms(im0) # transforms
|
328 |
-
else:
|
329 |
-
im = letterbox(
|
330 |
-
im0, self.img_size, stride=self.stride, auto=self.auto
|
331 |
-
)[
|
332 |
-
0
|
333 |
-
] # padded resize
|
334 |
-
im = im.transpose((2, 0, 1))[::-1] # HWC to CHW, BGR to RGB
|
335 |
-
im = np.ascontiguousarray(im) # contiguous
|
336 |
-
self.frame += 1
|
337 |
-
return (
|
338 |
-
str(self.screen),
|
339 |
-
im,
|
340 |
-
im0,
|
341 |
-
None,
|
342 |
-
s,
|
343 |
-
) # screen, img, original img, im0s, s
|
344 |
-
|
345 |
-
|
346 |
-
class LoadImages:
|
347 |
-
# YOLOv5 image/video dataloader, i.e. `python detect.py --source image.jpg/vid.mp4`
|
348 |
-
def __init__(
|
349 |
-
self,
|
350 |
-
path,
|
351 |
-
img_size=640,
|
352 |
-
stride=32,
|
353 |
-
auto=True,
|
354 |
-
transforms=None,
|
355 |
-
vid_stride=1,
|
356 |
-
):
|
357 |
-
if (
|
358 |
-
isinstance(path, str) and Path(path).suffix == ".txt"
|
359 |
-
): # *.txt file with img/vid/dir on each line
|
360 |
-
path = Path(path).read_text().rsplit()
|
361 |
-
files = []
|
362 |
-
for p in sorted(path) if isinstance(path, (list, tuple)) else [path]:
|
363 |
-
p = str(Path(p).resolve())
|
364 |
-
if "*" in p:
|
365 |
-
files.extend(sorted(glob.glob(p, recursive=True))) # glob
|
366 |
-
elif os.path.isdir(p):
|
367 |
-
files.extend(sorted(glob.glob(os.path.join(p, "*.*")))) # dir
|
368 |
-
elif os.path.isfile(p):
|
369 |
-
files.append(p) # files
|
370 |
-
else:
|
371 |
-
raise FileNotFoundError(f"{p} does not exist")
|
372 |
-
|
373 |
-
images = [x for x in files if x.split(".")[-1].lower() in IMG_FORMATS]
|
374 |
-
videos = [x for x in files if x.split(".")[-1].lower() in VID_FORMATS]
|
375 |
-
ni, nv = len(images), len(videos)
|
376 |
-
|
377 |
-
self.img_size = img_size
|
378 |
-
self.stride = stride
|
379 |
-
self.files = images + videos
|
380 |
-
self.nf = ni + nv # number of files
|
381 |
-
self.video_flag = [False] * ni + [True] * nv
|
382 |
-
self.mode = "image"
|
383 |
-
self.auto = auto
|
384 |
-
self.transforms = transforms # optional
|
385 |
-
self.vid_stride = vid_stride # video frame-rate stride
|
386 |
-
if any(videos):
|
387 |
-
self._new_video(videos[0]) # new video
|
388 |
-
else:
|
389 |
-
self.cap = None
|
390 |
-
assert self.nf > 0, (
|
391 |
-
f"No images or videos found in {p}. "
|
392 |
-
f"Supported formats are:\nimages: {IMG_FORMATS}\nvideos: {VID_FORMATS}"
|
393 |
-
)
|
394 |
-
|
395 |
-
def __iter__(self):
|
396 |
-
self.count = 0
|
397 |
-
return self
|
398 |
-
|
399 |
-
def __next__(self):
|
400 |
-
if self.count == self.nf:
|
401 |
-
raise StopIteration
|
402 |
-
path = self.files[self.count]
|
403 |
-
|
404 |
-
if self.video_flag[self.count]:
|
405 |
-
# Read video
|
406 |
-
self.mode = "video"
|
407 |
-
for _ in range(self.vid_stride):
|
408 |
-
self.cap.grab()
|
409 |
-
ret_val, im0 = self.cap.retrieve()
|
410 |
-
while not ret_val:
|
411 |
-
self.count += 1
|
412 |
-
self.cap.release()
|
413 |
-
if self.count == self.nf: # last video
|
414 |
-
raise StopIteration
|
415 |
-
path = self.files[self.count]
|
416 |
-
self._new_video(path)
|
417 |
-
ret_val, im0 = self.cap.read()
|
418 |
-
|
419 |
-
self.frame += 1
|
420 |
-
# im0 = self._cv2_rotate(im0) # for use if cv2 autorotation is False
|
421 |
-
s = f"video {self.count + 1}/{self.nf} ({self.frame}/{self.frames}) {path}: "
|
422 |
-
|
423 |
-
else:
|
424 |
-
# Read image
|
425 |
-
self.count += 1
|
426 |
-
im0 = cv2.imread(path) # BGR
|
427 |
-
assert im0 is not None, f"Image Not Found {path}"
|
428 |
-
s = f"image {self.count}/{self.nf} {path}: "
|
429 |
-
|
430 |
-
if self.transforms:
|
431 |
-
im = self.transforms(im0) # transforms
|
432 |
-
else:
|
433 |
-
im = letterbox(
|
434 |
-
im0, self.img_size, stride=self.stride, auto=self.auto
|
435 |
-
)[
|
436 |
-
0
|
437 |
-
] # padded resize
|
438 |
-
im = im.transpose((2, 0, 1))[::-1] # HWC to CHW, BGR to RGB
|
439 |
-
im = np.ascontiguousarray(im) # contiguous
|
440 |
-
|
441 |
-
return path, im, im0, self.cap, s
|
442 |
-
|
443 |
-
def _new_video(self, path):
|
444 |
-
# Create a new video capture object
|
445 |
-
self.frame = 0
|
446 |
-
self.cap = cv2.VideoCapture(path)
|
447 |
-
self.frames = int(
|
448 |
-
self.cap.get(cv2.CAP_PROP_FRAME_COUNT) / self.vid_stride
|
449 |
-
)
|
450 |
-
self.orientation = int(
|
451 |
-
self.cap.get(cv2.CAP_PROP_ORIENTATION_META)
|
452 |
-
) # rotation degrees
|
453 |
-
# self.cap.set(cv2.CAP_PROP_ORIENTATION_AUTO, 0) # disable https://github.com/ultralytics/yolov5/issues/8493
|
454 |
-
|
455 |
-
def _cv2_rotate(self, im):
|
456 |
-
# Rotate a cv2 video manually
|
457 |
-
if self.orientation == 0:
|
458 |
-
return cv2.rotate(im, cv2.ROTATE_90_CLOCKWISE)
|
459 |
-
elif self.orientation == 180:
|
460 |
-
return cv2.rotate(im, cv2.ROTATE_90_COUNTERCLOCKWISE)
|
461 |
-
elif self.orientation == 90:
|
462 |
-
return cv2.rotate(im, cv2.ROTATE_180)
|
463 |
-
return im
|
464 |
-
|
465 |
-
def __len__(self):
|
466 |
-
return self.nf # number of files
|
467 |
-
|
468 |
-
|
469 |
-
class LoadStreams:
|
470 |
-
# YOLOv5 streamloader, i.e. `python detect.py --source 'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP streams`
|
471 |
-
def __init__(
|
472 |
-
self,
|
473 |
-
sources="file.streams",
|
474 |
-
img_size=640,
|
475 |
-
stride=32,
|
476 |
-
auto=True,
|
477 |
-
transforms=None,
|
478 |
-
vid_stride=1,
|
479 |
-
):
|
480 |
-
torch.backends.cudnn.benchmark = (
|
481 |
-
True # faster for fixed-size inference
|
482 |
-
)
|
483 |
-
self.mode = "stream"
|
484 |
-
self.img_size = img_size
|
485 |
-
self.stride = stride
|
486 |
-
self.vid_stride = vid_stride # video frame-rate stride
|
487 |
-
sources = (
|
488 |
-
Path(sources).read_text().rsplit()
|
489 |
-
if os.path.isfile(sources)
|
490 |
-
else [sources]
|
491 |
-
)
|
492 |
-
n = len(sources)
|
493 |
-
self.sources = [
|
494 |
-
clean_str(x) for x in sources
|
495 |
-
] # clean source names for later
|
496 |
-
self.imgs, self.fps, self.frames, self.threads = (
|
497 |
-
[None] * n,
|
498 |
-
[0] * n,
|
499 |
-
[0] * n,
|
500 |
-
[None] * n,
|
501 |
-
)
|
502 |
-
for i, s in enumerate(sources): # index, source
|
503 |
-
# Start thread to read frames from video stream
|
504 |
-
st = f"{i + 1}/{n}: {s}... "
|
505 |
-
if urlparse(s).hostname in (
|
506 |
-
"www.youtube.com",
|
507 |
-
"youtube.com",
|
508 |
-
"youtu.be",
|
509 |
-
): # if source is YouTube video
|
510 |
-
# YouTube format i.e. 'https://www.youtube.com/watch?v=Zgi9g1ksQHc' or 'https://youtu.be/Zgi9g1ksQHc'
|
511 |
-
check_requirements(("pafy", "youtube_dl==2020.12.2"))
|
512 |
-
import pafy
|
513 |
-
|
514 |
-
s = pafy.new(s).getbest(preftype="mp4").url # YouTube URL
|
515 |
-
s = eval(s) if s.isnumeric() else s # i.e. s = '0' local webcam
|
516 |
-
if s == 0:
|
517 |
-
assert (
|
518 |
-
not is_colab()
|
519 |
-
), "--source 0 webcam unsupported on Colab. Rerun command in a local environment."
|
520 |
-
assert (
|
521 |
-
not is_kaggle()
|
522 |
-
), "--source 0 webcam unsupported on Kaggle. Rerun command in a local environment."
|
523 |
-
cap = cv2.VideoCapture(s)
|
524 |
-
assert cap.isOpened(), f"{st}Failed to open {s}"
|
525 |
-
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
526 |
-
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
527 |
-
fps = cap.get(cv2.CAP_PROP_FPS) # warning: may return 0 or nan
|
528 |
-
self.frames[i] = max(
|
529 |
-
int(cap.get(cv2.CAP_PROP_FRAME_COUNT)), 0
|
530 |
-
) or float(
|
531 |
-
"inf"
|
532 |
-
) # infinite stream fallback
|
533 |
-
self.fps[i] = (
|
534 |
-
max((fps if math.isfinite(fps) else 0) % 100, 0) or 30
|
535 |
-
) # 30 FPS fallback
|
536 |
-
|
537 |
-
_, self.imgs[i] = cap.read() # guarantee first frame
|
538 |
-
self.threads[i] = Thread(
|
539 |
-
target=self.update, args=([i, cap, s]), daemon=True
|
540 |
-
)
|
541 |
-
LOGGER.info(
|
542 |
-
f"{st} Success ({self.frames[i]} frames {w}x{h} at {self.fps[i]:.2f} FPS)"
|
543 |
-
)
|
544 |
-
self.threads[i].start()
|
545 |
-
LOGGER.info("") # newline
|
546 |
-
|
547 |
-
# check for common shapes
|
548 |
-
s = np.stack(
|
549 |
-
[
|
550 |
-
letterbox(x, img_size, stride=stride, auto=auto)[0].shape
|
551 |
-
for x in self.imgs
|
552 |
-
]
|
553 |
-
)
|
554 |
-
self.rect = (
|
555 |
-
np.unique(s, axis=0).shape[0] == 1
|
556 |
-
) # rect inference if all shapes equal
|
557 |
-
self.auto = auto and self.rect
|
558 |
-
self.transforms = transforms # optional
|
559 |
-
if not self.rect:
|
560 |
-
LOGGER.warning(
|
561 |
-
"WARNING ⚠️ Stream shapes differ. For optimal performance supply similarly-shaped streams."
|
562 |
-
)
|
563 |
-
|
564 |
-
def update(self, i, cap, stream):
|
565 |
-
# Read stream `i` frames in daemon thread
|
566 |
-
n, f = 0, self.frames[i] # frame number, frame array
|
567 |
-
while cap.isOpened() and n < f:
|
568 |
-
n += 1
|
569 |
-
cap.grab() # .read() = .grab() followed by .retrieve()
|
570 |
-
if n % self.vid_stride == 0:
|
571 |
-
success, im = cap.retrieve()
|
572 |
-
if success:
|
573 |
-
self.imgs[i] = im
|
574 |
-
else:
|
575 |
-
LOGGER.warning(
|
576 |
-
"WARNING ⚠️ Video stream unresponsive, please check your IP camera connection."
|
577 |
-
)
|
578 |
-
self.imgs[i] = np.zeros_like(self.imgs[i])
|
579 |
-
cap.open(stream) # re-open stream if signal was lost
|
580 |
-
time.sleep(0.0) # wait time
|
581 |
-
|
582 |
-
def __iter__(self):
|
583 |
-
self.count = -1
|
584 |
-
return self
|
585 |
-
|
586 |
-
def __next__(self):
|
587 |
-
self.count += 1
|
588 |
-
if not all(x.is_alive() for x in self.threads) or cv2.waitKey(
|
589 |
-
1
|
590 |
-
) == ord(
|
591 |
-
"q"
|
592 |
-
): # q to quit
|
593 |
-
cv2.destroyAllWindows()
|
594 |
-
raise StopIteration
|
595 |
-
|
596 |
-
im0 = self.imgs.copy()
|
597 |
-
if self.transforms:
|
598 |
-
im = np.stack([self.transforms(x) for x in im0]) # transforms
|
599 |
-
else:
|
600 |
-
im = np.stack(
|
601 |
-
[
|
602 |
-
letterbox(
|
603 |
-
x, self.img_size, stride=self.stride, auto=self.auto
|
604 |
-
)[0]
|
605 |
-
for x in im0
|
606 |
-
]
|
607 |
-
) # resize
|
608 |
-
im = im[..., ::-1].transpose(
|
609 |
-
(0, 3, 1, 2)
|
610 |
-
) # BGR to RGB, BHWC to BCHW
|
611 |
-
im = np.ascontiguousarray(im) # contiguous
|
612 |
-
|
613 |
-
return self.sources, im, im0, None, ""
|
614 |
-
|
615 |
-
def __len__(self):
|
616 |
-
return len(
|
617 |
-
self.sources
|
618 |
-
) # 1E12 frames = 32 streams at 30 FPS for 30 years
|
619 |
-
|
620 |
-
|
621 |
-
def img2label_paths(img_paths):
|
622 |
-
# Define label paths as a function of image paths
|
623 |
-
sa, sb = (
|
624 |
-
f"{os.sep}images{os.sep}",
|
625 |
-
f"{os.sep}labels{os.sep}",
|
626 |
-
) # /images/, /labels/ substrings
|
627 |
-
return [
|
628 |
-
sb.join(x.rsplit(sa, 1)).rsplit(".", 1)[0] + ".txt" for x in img_paths
|
629 |
-
]
|
630 |
-
|
631 |
-
|
632 |
-
class LoadImagesAndLabels(Dataset):
|
633 |
-
# YOLOv5 train_loader/val_loader, loads images and labels for training and validation
|
634 |
-
cache_version = 0.6 # dataset labels *.cache version
|
635 |
-
rand_interp_methods = [
|
636 |
-
cv2.INTER_NEAREST,
|
637 |
-
cv2.INTER_LINEAR,
|
638 |
-
cv2.INTER_CUBIC,
|
639 |
-
cv2.INTER_AREA,
|
640 |
-
cv2.INTER_LANCZOS4,
|
641 |
-
]
|
642 |
-
|
643 |
-
def __init__(
|
644 |
-
self,
|
645 |
-
path,
|
646 |
-
img_size=640,
|
647 |
-
batch_size=16,
|
648 |
-
augment=False,
|
649 |
-
hyp=None,
|
650 |
-
rect=False,
|
651 |
-
image_weights=False,
|
652 |
-
cache_images=False,
|
653 |
-
single_cls=False,
|
654 |
-
stride=32,
|
655 |
-
pad=0.0,
|
656 |
-
min_items=0,
|
657 |
-
prefix="",
|
658 |
-
):
|
659 |
-
self.img_size = img_size
|
660 |
-
self.augment = augment
|
661 |
-
self.hyp = hyp
|
662 |
-
self.image_weights = image_weights
|
663 |
-
self.rect = False if image_weights else rect
|
664 |
-
self.mosaic = (
|
665 |
-
self.augment and not self.rect
|
666 |
-
) # load 4 images at a time into a mosaic (only during training)
|
667 |
-
self.mosaic_border = [-img_size // 2, -img_size // 2]
|
668 |
-
self.stride = stride
|
669 |
-
self.path = path
|
670 |
-
self.albumentations = (
|
671 |
-
Albumentations(size=img_size) if augment else None
|
672 |
-
)
|
673 |
-
|
674 |
-
try:
|
675 |
-
f = [] # image files
|
676 |
-
for p in path if isinstance(path, list) else [path]:
|
677 |
-
p = Path(p) # os-agnostic
|
678 |
-
if p.is_dir(): # dir
|
679 |
-
f += glob.glob(str(p / "**" / "*.*"), recursive=True)
|
680 |
-
# f = list(p.rglob('*.*')) # pathlib
|
681 |
-
elif p.is_file(): # file
|
682 |
-
with open(p) as t:
|
683 |
-
t = t.read().strip().splitlines()
|
684 |
-
parent = str(p.parent) + os.sep
|
685 |
-
f += [
|
686 |
-
x.replace("./", parent, 1)
|
687 |
-
if x.startswith("./")
|
688 |
-
else x
|
689 |
-
for x in t
|
690 |
-
] # to global path
|
691 |
-
# f += [p.parent / x.lstrip(os.sep) for x in t] # to global path (pathlib)
|
692 |
-
else:
|
693 |
-
raise FileNotFoundError(f"{prefix}{p} does not exist")
|
694 |
-
self.im_files = sorted(
|
695 |
-
x.replace("/", os.sep)
|
696 |
-
for x in f
|
697 |
-
if x.split(".")[-1].lower() in IMG_FORMATS
|
698 |
-
)
|
699 |
-
# self.img_files = sorted([x for x in f if x.suffix[1:].lower() in IMG_FORMATS]) # pathlib
|
700 |
-
assert self.im_files, f"{prefix}No images found"
|
701 |
-
except Exception as e:
|
702 |
-
raise Exception(
|
703 |
-
f"{prefix}Error loading data from {path}: {e}\n{HELP_URL}"
|
704 |
-
) from e
|
705 |
-
|
706 |
-
# Check cache
|
707 |
-
self.label_files = img2label_paths(self.im_files) # labels
|
708 |
-
cache_path = (
|
709 |
-
p if p.is_file() else Path(self.label_files[0]).parent
|
710 |
-
).with_suffix(".cache")
|
711 |
-
try:
|
712 |
-
cache, exists = (
|
713 |
-
np.load(cache_path, allow_pickle=True).item(),
|
714 |
-
True,
|
715 |
-
) # load dict
|
716 |
-
assert (
|
717 |
-
cache["version"] == self.cache_version
|
718 |
-
) # matches current version
|
719 |
-
assert cache["hash"] == get_hash(
|
720 |
-
self.label_files + self.im_files
|
721 |
-
) # identical hash
|
722 |
-
except Exception:
|
723 |
-
cache, exists = (
|
724 |
-
self.cache_labels(cache_path, prefix),
|
725 |
-
False,
|
726 |
-
) # run cache ops
|
727 |
-
|
728 |
-
# Display cache
|
729 |
-
nf, nm, ne, nc, n = cache.pop(
|
730 |
-
"results"
|
731 |
-
) # found, missing, empty, corrupt, total
|
732 |
-
if exists and LOCAL_RANK in {-1, 0}:
|
733 |
-
d = f"Scanning {cache_path}... {nf} images, {nm + ne} backgrounds, {nc} corrupt"
|
734 |
-
tqdm(
|
735 |
-
None,
|
736 |
-
desc=prefix + d,
|
737 |
-
total=n,
|
738 |
-
initial=n,
|
739 |
-
bar_format=TQDM_BAR_FORMAT,
|
740 |
-
) # display cache results
|
741 |
-
if cache["msgs"]:
|
742 |
-
LOGGER.info("\n".join(cache["msgs"])) # display warnings
|
743 |
-
assert (
|
744 |
-
nf > 0 or not augment
|
745 |
-
), f"{prefix}No labels found in {cache_path}, can not start training. {HELP_URL}"
|
746 |
-
|
747 |
-
# Read cache
|
748 |
-
[cache.pop(k) for k in ("hash", "version", "msgs")] # remove items
|
749 |
-
labels, shapes, self.segments = zip(*cache.values())
|
750 |
-
nl = len(np.concatenate(labels, 0)) # number of labels
|
751 |
-
assert (
|
752 |
-
nl > 0 or not augment
|
753 |
-
), f"{prefix}All labels empty in {cache_path}, can not start training. {HELP_URL}"
|
754 |
-
self.labels = list(labels)
|
755 |
-
self.shapes = np.array(shapes)
|
756 |
-
self.im_files = list(cache.keys()) # update
|
757 |
-
self.label_files = img2label_paths(cache.keys()) # update
|
758 |
-
|
759 |
-
# Filter images
|
760 |
-
if min_items:
|
761 |
-
include = (
|
762 |
-
np.array([len(x) >= min_items for x in self.labels])
|
763 |
-
.nonzero()[0]
|
764 |
-
.astype(int)
|
765 |
-
)
|
766 |
-
LOGGER.info(
|
767 |
-
f"{prefix}{n - len(include)}/{n} images filtered from dataset"
|
768 |
-
)
|
769 |
-
self.im_files = [self.im_files[i] for i in include]
|
770 |
-
self.label_files = [self.label_files[i] for i in include]
|
771 |
-
self.labels = [self.labels[i] for i in include]
|
772 |
-
self.segments = [self.segments[i] for i in include]
|
773 |
-
self.shapes = self.shapes[include] # wh
|
774 |
-
|
775 |
-
# Create indices
|
776 |
-
n = len(self.shapes) # number of images
|
777 |
-
bi = np.floor(np.arange(n) / batch_size).astype(int) # batch index
|
778 |
-
nb = bi[-1] + 1 # number of batches
|
779 |
-
self.batch = bi # batch index of image
|
780 |
-
self.n = n
|
781 |
-
self.indices = range(n)
|
782 |
-
|
783 |
-
# Update labels
|
784 |
-
include_class = (
|
785 |
-
[]
|
786 |
-
) # filter labels to include only these classes (optional)
|
787 |
-
include_class_array = np.array(include_class).reshape(1, -1)
|
788 |
-
for i, (label, segment) in enumerate(zip(self.labels, self.segments)):
|
789 |
-
if include_class:
|
790 |
-
j = (label[:, 0:1] == include_class_array).any(1)
|
791 |
-
self.labels[i] = label[j]
|
792 |
-
if segment:
|
793 |
-
self.segments[i] = segment[j]
|
794 |
-
if single_cls: # single-class training, merge all classes into 0
|
795 |
-
self.labels[i][:, 0] = 0
|
796 |
-
|
797 |
-
# Rectangular Training
|
798 |
-
if self.rect:
|
799 |
-
# Sort by aspect ratio
|
800 |
-
s = self.shapes # wh
|
801 |
-
ar = s[:, 1] / s[:, 0] # aspect ratio
|
802 |
-
irect = ar.argsort()
|
803 |
-
self.im_files = [self.im_files[i] for i in irect]
|
804 |
-
self.label_files = [self.label_files[i] for i in irect]
|
805 |
-
self.labels = [self.labels[i] for i in irect]
|
806 |
-
self.segments = [self.segments[i] for i in irect]
|
807 |
-
self.shapes = s[irect] # wh
|
808 |
-
ar = ar[irect]
|
809 |
-
|
810 |
-
# Set training image shapes
|
811 |
-
shapes = [[1, 1]] * nb
|
812 |
-
for i in range(nb):
|
813 |
-
ari = ar[bi == i]
|
814 |
-
mini, maxi = ari.min(), ari.max()
|
815 |
-
if maxi < 1:
|
816 |
-
shapes[i] = [maxi, 1]
|
817 |
-
elif mini > 1:
|
818 |
-
shapes[i] = [1, 1 / mini]
|
819 |
-
|
820 |
-
self.batch_shapes = (
|
821 |
-
np.ceil(np.array(shapes) * img_size / stride + pad).astype(int)
|
822 |
-
* stride
|
823 |
-
)
|
824 |
-
|
825 |
-
# Cache images into RAM/disk for faster training
|
826 |
-
if cache_images == "ram" and not self.check_cache_ram(prefix=prefix):
|
827 |
-
cache_images = False
|
828 |
-
self.ims = [None] * n
|
829 |
-
self.npy_files = [Path(f).with_suffix(".npy") for f in self.im_files]
|
830 |
-
if cache_images:
|
831 |
-
b, gb = 0, 1 << 30 # bytes of cached images, bytes per gigabytes
|
832 |
-
self.im_hw0, self.im_hw = [None] * n, [None] * n
|
833 |
-
fcn = (
|
834 |
-
self.cache_images_to_disk
|
835 |
-
if cache_images == "disk"
|
836 |
-
else self.load_image
|
837 |
-
)
|
838 |
-
results = ThreadPool(NUM_THREADS).imap(fcn, range(n))
|
839 |
-
pbar = tqdm(
|
840 |
-
enumerate(results),
|
841 |
-
total=n,
|
842 |
-
bar_format=TQDM_BAR_FORMAT,
|
843 |
-
disable=LOCAL_RANK > 0,
|
844 |
-
)
|
845 |
-
for i, x in pbar:
|
846 |
-
if cache_images == "disk":
|
847 |
-
b += self.npy_files[i].stat().st_size
|
848 |
-
else: # 'ram'
|
849 |
-
(
|
850 |
-
self.ims[i],
|
851 |
-
self.im_hw0[i],
|
852 |
-
self.im_hw[i],
|
853 |
-
) = x # im, hw_orig, hw_resized = load_image(self, i)
|
854 |
-
b += self.ims[i].nbytes
|
855 |
-
pbar.desc = (
|
856 |
-
f"{prefix}Caching images ({b / gb:.1f}GB {cache_images})"
|
857 |
-
)
|
858 |
-
pbar.close()
|
859 |
-
|
860 |
-
def check_cache_ram(self, safety_margin=0.1, prefix=""):
|
861 |
-
# Check image caching requirements vs available memory
|
862 |
-
b, gb = 0, 1 << 30 # bytes of cached images, bytes per gigabytes
|
863 |
-
n = min(self.n, 30) # extrapolate from 30 random images
|
864 |
-
for _ in range(n):
|
865 |
-
im = cv2.imread(random.choice(self.im_files)) # sample image
|
866 |
-
ratio = self.img_size / max(
|
867 |
-
im.shape[0], im.shape[1]
|
868 |
-
) # max(h, w) # ratio
|
869 |
-
b += im.nbytes * ratio**2
|
870 |
-
mem_required = b * self.n / n # GB required to cache dataset into RAM
|
871 |
-
mem = psutil.virtual_memory()
|
872 |
-
cache = (
|
873 |
-
mem_required * (1 + safety_margin) < mem.available
|
874 |
-
) # to cache or not to cache, that is the question
|
875 |
-
if not cache:
|
876 |
-
LOGGER.info(
|
877 |
-
f"{prefix}{mem_required / gb:.1f}GB RAM required, "
|
878 |
-
f"{mem.available / gb:.1f}/{mem.total / gb:.1f}GB available, "
|
879 |
-
f"{'caching images ✅' if cache else 'not caching images ⚠️'}"
|
880 |
-
)
|
881 |
-
return cache
|
882 |
-
|
883 |
-
def cache_labels(self, path=Path("./labels.cache"), prefix=""):
|
884 |
-
# Cache dataset labels, check images and read shapes
|
885 |
-
x = {} # dict
|
886 |
-
nm, nf, ne, nc, msgs = (
|
887 |
-
0,
|
888 |
-
0,
|
889 |
-
0,
|
890 |
-
0,
|
891 |
-
[],
|
892 |
-
) # number missing, found, empty, corrupt, messages
|
893 |
-
desc = f"{prefix}Scanning {path.parent / path.stem}..."
|
894 |
-
with Pool(NUM_THREADS) as pool:
|
895 |
-
pbar = tqdm(
|
896 |
-
pool.imap(
|
897 |
-
verify_image_label,
|
898 |
-
zip(self.im_files, self.label_files, repeat(prefix)),
|
899 |
-
),
|
900 |
-
desc=desc,
|
901 |
-
total=len(self.im_files),
|
902 |
-
bar_format=TQDM_BAR_FORMAT,
|
903 |
-
)
|
904 |
-
for (
|
905 |
-
im_file,
|
906 |
-
lb,
|
907 |
-
shape,
|
908 |
-
segments,
|
909 |
-
nm_f,
|
910 |
-
nf_f,
|
911 |
-
ne_f,
|
912 |
-
nc_f,
|
913 |
-
msg,
|
914 |
-
) in pbar:
|
915 |
-
nm += nm_f
|
916 |
-
nf += nf_f
|
917 |
-
ne += ne_f
|
918 |
-
nc += nc_f
|
919 |
-
if im_file:
|
920 |
-
x[im_file] = [lb, shape, segments]
|
921 |
-
if msg:
|
922 |
-
msgs.append(msg)
|
923 |
-
pbar.desc = (
|
924 |
-
f"{desc} {nf} images, {nm + ne} backgrounds, {nc} corrupt"
|
925 |
-
)
|
926 |
-
|
927 |
-
pbar.close()
|
928 |
-
if msgs:
|
929 |
-
LOGGER.info("\n".join(msgs))
|
930 |
-
if nf == 0:
|
931 |
-
LOGGER.warning(
|
932 |
-
f"{prefix}WARNING ⚠️ No labels found in {path}. {HELP_URL}"
|
933 |
-
)
|
934 |
-
x["hash"] = get_hash(self.label_files + self.im_files)
|
935 |
-
x["results"] = nf, nm, ne, nc, len(self.im_files)
|
936 |
-
x["msgs"] = msgs # warnings
|
937 |
-
x["version"] = self.cache_version # cache version
|
938 |
-
try:
|
939 |
-
np.save(path, x) # save cache for next time
|
940 |
-
path.with_suffix(".cache.npy").rename(path) # remove .npy suffix
|
941 |
-
LOGGER.info(f"{prefix}New cache created: {path}")
|
942 |
-
except Exception as e:
|
943 |
-
LOGGER.warning(
|
944 |
-
f"{prefix}WARNING ⚠️ Cache directory {path.parent} is not writeable: {e}"
|
945 |
-
) # not writeable
|
946 |
-
return x
|
947 |
-
|
948 |
-
def __len__(self):
|
949 |
-
return len(self.im_files)
|
950 |
-
|
951 |
-
# def __iter__(self):
|
952 |
-
# self.count = -1
|
953 |
-
# print('ran dataset iter')
|
954 |
-
# #self.shuffled_vector = np.random.permutation(self.nF) if self.augment else np.arange(self.nF)
|
955 |
-
# return self
|
956 |
-
|
957 |
-
def __getitem__(self, index):
|
958 |
-
index = self.indices[index] # linear, shuffled, or image_weights
|
959 |
-
|
960 |
-
hyp = self.hyp
|
961 |
-
mosaic = self.mosaic and random.random() < hyp["mosaic"]
|
962 |
-
if mosaic:
|
963 |
-
# Load mosaic
|
964 |
-
img, labels = self.load_mosaic(index)
|
965 |
-
shapes = None
|
966 |
-
|
967 |
-
# MixUp augmentation
|
968 |
-
if random.random() < hyp["mixup"]:
|
969 |
-
img, labels = mixup(
|
970 |
-
img,
|
971 |
-
labels,
|
972 |
-
*self.load_mosaic(random.randint(0, self.n - 1)),
|
973 |
-
)
|
974 |
-
|
975 |
-
else:
|
976 |
-
# Load image
|
977 |
-
img, (h0, w0), (h, w) = self.load_image(index)
|
978 |
-
|
979 |
-
# Letterbox
|
980 |
-
shape = (
|
981 |
-
self.batch_shapes[self.batch[index]]
|
982 |
-
if self.rect
|
983 |
-
else self.img_size
|
984 |
-
) # final letterboxed shape
|
985 |
-
img, ratio, pad = letterbox(
|
986 |
-
img, shape, auto=False, scaleup=self.augment
|
987 |
-
)
|
988 |
-
shapes = (h0, w0), (
|
989 |
-
(h / h0, w / w0),
|
990 |
-
pad,
|
991 |
-
) # for COCO mAP rescaling
|
992 |
-
|
993 |
-
labels = self.labels[index].copy()
|
994 |
-
if labels.size: # normalized xywh to pixel xyxy format
|
995 |
-
labels[:, 1:] = xywhn2xyxy(
|
996 |
-
labels[:, 1:],
|
997 |
-
ratio[0] * w,
|
998 |
-
ratio[1] * h,
|
999 |
-
padw=pad[0],
|
1000 |
-
padh=pad[1],
|
1001 |
-
)
|
1002 |
-
|
1003 |
-
if self.augment:
|
1004 |
-
img, labels = random_perspective(
|
1005 |
-
img,
|
1006 |
-
labels,
|
1007 |
-
degrees=hyp["degrees"],
|
1008 |
-
translate=hyp["translate"],
|
1009 |
-
scale=hyp["scale"],
|
1010 |
-
shear=hyp["shear"],
|
1011 |
-
perspective=hyp["perspective"],
|
1012 |
-
)
|
1013 |
-
|
1014 |
-
nl = len(labels) # number of labels
|
1015 |
-
if nl:
|
1016 |
-
labels[:, 1:5] = xyxy2xywhn(
|
1017 |
-
labels[:, 1:5],
|
1018 |
-
w=img.shape[1],
|
1019 |
-
h=img.shape[0],
|
1020 |
-
clip=True,
|
1021 |
-
eps=1e-3,
|
1022 |
-
)
|
1023 |
-
|
1024 |
-
if self.augment:
|
1025 |
-
# Albumentations
|
1026 |
-
img, labels = self.albumentations(img, labels)
|
1027 |
-
nl = len(labels) # update after albumentations
|
1028 |
-
|
1029 |
-
# HSV color-space
|
1030 |
-
augment_hsv(
|
1031 |
-
img, hgain=hyp["hsv_h"], sgain=hyp["hsv_s"], vgain=hyp["hsv_v"]
|
1032 |
-
)
|
1033 |
-
|
1034 |
-
# Flip up-down
|
1035 |
-
if random.random() < hyp["flipud"]:
|
1036 |
-
img = np.flipud(img)
|
1037 |
-
if nl:
|
1038 |
-
labels[:, 2] = 1 - labels[:, 2]
|
1039 |
-
|
1040 |
-
# Flip left-right
|
1041 |
-
if random.random() < hyp["fliplr"]:
|
1042 |
-
img = np.fliplr(img)
|
1043 |
-
if nl:
|
1044 |
-
labels[:, 1] = 1 - labels[:, 1]
|
1045 |
-
|
1046 |
-
# Cutouts
|
1047 |
-
# labels = cutout(img, labels, p=0.5)
|
1048 |
-
# nl = len(labels) # update after cutout
|
1049 |
-
|
1050 |
-
labels_out = torch.zeros((nl, 6))
|
1051 |
-
if nl:
|
1052 |
-
labels_out[:, 1:] = torch.from_numpy(labels)
|
1053 |
-
|
1054 |
-
# Convert
|
1055 |
-
img = img.transpose((2, 0, 1))[::-1] # HWC to CHW, BGR to RGB
|
1056 |
-
img = np.ascontiguousarray(img)
|
1057 |
-
|
1058 |
-
return torch.from_numpy(img), labels_out, self.im_files[index], shapes
|
1059 |
-
|
1060 |
-
def load_image(self, i):
|
1061 |
-
# Loads 1 image from dataset index 'i', returns (im, original hw, resized hw)
|
1062 |
-
im, f, fn = (
|
1063 |
-
self.ims[i],
|
1064 |
-
self.im_files[i],
|
1065 |
-
self.npy_files[i],
|
1066 |
-
)
|
1067 |
-
if im is None: # not cached in RAM
|
1068 |
-
if fn.exists(): # load npy
|
1069 |
-
im = np.load(fn)
|
1070 |
-
else: # read image
|
1071 |
-
im = cv2.imread(f) # BGR
|
1072 |
-
assert im is not None, f"Image Not Found {f}"
|
1073 |
-
h0, w0 = im.shape[:2] # orig hw
|
1074 |
-
r = self.img_size / max(h0, w0) # ratio
|
1075 |
-
if r != 1: # if sizes are not equal
|
1076 |
-
interp = (
|
1077 |
-
cv2.INTER_LINEAR
|
1078 |
-
if (self.augment or r > 1)
|
1079 |
-
else cv2.INTER_AREA
|
1080 |
-
)
|
1081 |
-
im = cv2.resize(
|
1082 |
-
im,
|
1083 |
-
(math.ceil(w0 * r), math.ceil(h0 * r)),
|
1084 |
-
interpolation=interp,
|
1085 |
-
)
|
1086 |
-
return im, (h0, w0), im.shape[:2] # im, hw_original, hw_resized
|
1087 |
-
return (
|
1088 |
-
self.ims[i],
|
1089 |
-
self.im_hw0[i],
|
1090 |
-
self.im_hw[i],
|
1091 |
-
) # im, hw_original, hw_resized
|
1092 |
-
|
1093 |
-
def cache_images_to_disk(self, i):
|
1094 |
-
# Saves an image as an *.npy file for faster loading
|
1095 |
-
f = self.npy_files[i]
|
1096 |
-
if not f.exists():
|
1097 |
-
np.save(f.as_posix(), cv2.imread(self.im_files[i]))
|
1098 |
-
|
1099 |
-
def load_mosaic(self, index):
|
1100 |
-
# YOLOv5 4-mosaic loader. Loads 1 image + 3 random images into a 4-image mosaic
|
1101 |
-
labels4, segments4 = [], []
|
1102 |
-
s = self.img_size
|
1103 |
-
yc, xc = (
|
1104 |
-
int(random.uniform(-x, 2 * s + x)) for x in self.mosaic_border
|
1105 |
-
) # mosaic center x, y
|
1106 |
-
indices = [index] + random.choices(
|
1107 |
-
self.indices, k=3
|
1108 |
-
) # 3 additional image indices
|
1109 |
-
random.shuffle(indices)
|
1110 |
-
for i, index in enumerate(indices):
|
1111 |
-
# Load image
|
1112 |
-
img, _, (h, w) = self.load_image(index)
|
1113 |
-
|
1114 |
-
# place img in img4
|
1115 |
-
if i == 0: # top left
|
1116 |
-
img4 = np.full(
|
1117 |
-
(s * 2, s * 2, img.shape[2]), 114, dtype=np.uint8
|
1118 |
-
) # base image with 4 tiles
|
1119 |
-
x1a, y1a, x2a, y2a = (
|
1120 |
-
max(xc - w, 0),
|
1121 |
-
max(yc - h, 0),
|
1122 |
-
xc,
|
1123 |
-
yc,
|
1124 |
-
) # xmin, ymin, xmax, ymax (large image)
|
1125 |
-
x1b, y1b, x2b, y2b = (
|
1126 |
-
w - (x2a - x1a),
|
1127 |
-
h - (y2a - y1a),
|
1128 |
-
w,
|
1129 |
-
h,
|
1130 |
-
) # xmin, ymin, xmax, ymax (small image)
|
1131 |
-
elif i == 1: # top right
|
1132 |
-
x1a, y1a, x2a, y2a = xc, max(yc - h, 0), min(xc + w, s * 2), yc
|
1133 |
-
x1b, y1b, x2b, y2b = 0, h - (y2a - y1a), min(w, x2a - x1a), h
|
1134 |
-
elif i == 2: # bottom left
|
1135 |
-
x1a, y1a, x2a, y2a = max(xc - w, 0), yc, xc, min(s * 2, yc + h)
|
1136 |
-
x1b, y1b, x2b, y2b = w - (x2a - x1a), 0, w, min(y2a - y1a, h)
|
1137 |
-
elif i == 3: # bottom right
|
1138 |
-
x1a, y1a, x2a, y2a = (
|
1139 |
-
xc,
|
1140 |
-
yc,
|
1141 |
-
min(xc + w, s * 2),
|
1142 |
-
min(s * 2, yc + h),
|
1143 |
-
)
|
1144 |
-
x1b, y1b, x2b, y2b = 0, 0, min(w, x2a - x1a), min(y2a - y1a, h)
|
1145 |
-
|
1146 |
-
img4[y1a:y2a, x1a:x2a] = img[
|
1147 |
-
y1b:y2b, x1b:x2b
|
1148 |
-
] # img4[ymin:ymax, xmin:xmax]
|
1149 |
-
padw = x1a - x1b
|
1150 |
-
padh = y1a - y1b
|
1151 |
-
|
1152 |
-
# Labels
|
1153 |
-
labels, segments = (
|
1154 |
-
self.labels[index].copy(),
|
1155 |
-
self.segments[index].copy(),
|
1156 |
-
)
|
1157 |
-
if labels.size:
|
1158 |
-
labels[:, 1:] = xywhn2xyxy(
|
1159 |
-
labels[:, 1:], w, h, padw, padh
|
1160 |
-
) # normalized xywh to pixel xyxy format
|
1161 |
-
segments = [xyn2xy(x, w, h, padw, padh) for x in segments]
|
1162 |
-
labels4.append(labels)
|
1163 |
-
segments4.extend(segments)
|
1164 |
-
|
1165 |
-
# Concat/clip labels
|
1166 |
-
labels4 = np.concatenate(labels4, 0)
|
1167 |
-
for x in (labels4[:, 1:], *segments4):
|
1168 |
-
np.clip(x, 0, 2 * s, out=x) # clip when using random_perspective()
|
1169 |
-
# img4, labels4 = replicate(img4, labels4) # replicate
|
1170 |
-
|
1171 |
-
# Augment
|
1172 |
-
img4, labels4, segments4 = copy_paste(
|
1173 |
-
img4, labels4, segments4, p=self.hyp["copy_paste"]
|
1174 |
-
)
|
1175 |
-
img4, labels4 = random_perspective(
|
1176 |
-
img4,
|
1177 |
-
labels4,
|
1178 |
-
segments4,
|
1179 |
-
degrees=self.hyp["degrees"],
|
1180 |
-
translate=self.hyp["translate"],
|
1181 |
-
scale=self.hyp["scale"],
|
1182 |
-
shear=self.hyp["shear"],
|
1183 |
-
perspective=self.hyp["perspective"],
|
1184 |
-
border=self.mosaic_border,
|
1185 |
-
) # border to remove
|
1186 |
-
|
1187 |
-
return img4, labels4
|
1188 |
-
|
1189 |
-
def load_mosaic9(self, index):
|
1190 |
-
# YOLOv5 9-mosaic loader. Loads 1 image + 8 random images into a 9-image mosaic
|
1191 |
-
labels9, segments9 = [], []
|
1192 |
-
s = self.img_size
|
1193 |
-
indices = [index] + random.choices(
|
1194 |
-
self.indices, k=8
|
1195 |
-
) # 8 additional image indices
|
1196 |
-
random.shuffle(indices)
|
1197 |
-
hp, wp = -1, -1 # height, width previous
|
1198 |
-
for i, index in enumerate(indices):
|
1199 |
-
# Load image
|
1200 |
-
img, _, (h, w) = self.load_image(index)
|
1201 |
-
|
1202 |
-
# place img in img9
|
1203 |
-
if i == 0: # center
|
1204 |
-
img9 = np.full(
|
1205 |
-
(s * 3, s * 3, img.shape[2]), 114, dtype=np.uint8
|
1206 |
-
) # base image with 4 tiles
|
1207 |
-
h0, w0 = h, w
|
1208 |
-
c = (
|
1209 |
-
s,
|
1210 |
-
s,
|
1211 |
-
s + w,
|
1212 |
-
s + h,
|
1213 |
-
) # xmin, ymin, xmax, ymax (base) coordinates
|
1214 |
-
elif i == 1: # top
|
1215 |
-
c = s, s - h, s + w, s
|
1216 |
-
elif i == 2: # top right
|
1217 |
-
c = s + wp, s - h, s + wp + w, s
|
1218 |
-
elif i == 3: # right
|
1219 |
-
c = s + w0, s, s + w0 + w, s + h
|
1220 |
-
elif i == 4: # bottom right
|
1221 |
-
c = s + w0, s + hp, s + w0 + w, s + hp + h
|
1222 |
-
elif i == 5: # bottom
|
1223 |
-
c = s + w0 - w, s + h0, s + w0, s + h0 + h
|
1224 |
-
elif i == 6: # bottom left
|
1225 |
-
c = s + w0 - wp - w, s + h0, s + w0 - wp, s + h0 + h
|
1226 |
-
elif i == 7: # left
|
1227 |
-
c = s - w, s + h0 - h, s, s + h0
|
1228 |
-
elif i == 8: # top left
|
1229 |
-
c = s - w, s + h0 - hp - h, s, s + h0 - hp
|
1230 |
-
|
1231 |
-
padx, pady = c[:2]
|
1232 |
-
x1, y1, x2, y2 = (max(x, 0) for x in c) # allocate coords
|
1233 |
-
|
1234 |
-
# Labels
|
1235 |
-
labels, segments = (
|
1236 |
-
self.labels[index].copy(),
|
1237 |
-
self.segments[index].copy(),
|
1238 |
-
)
|
1239 |
-
if labels.size:
|
1240 |
-
labels[:, 1:] = xywhn2xyxy(
|
1241 |
-
labels[:, 1:], w, h, padx, pady
|
1242 |
-
) # normalized xywh to pixel xyxy format
|
1243 |
-
segments = [xyn2xy(x, w, h, padx, pady) for x in segments]
|
1244 |
-
labels9.append(labels)
|
1245 |
-
segments9.extend(segments)
|
1246 |
-
|
1247 |
-
# Image
|
1248 |
-
img9[y1:y2, x1:x2] = img[
|
1249 |
-
y1 - pady :, x1 - padx :
|
1250 |
-
] # img9[ymin:ymax, xmin:xmax]
|
1251 |
-
hp, wp = h, w # height, width previous
|
1252 |
-
|
1253 |
-
# Offset
|
1254 |
-
yc, xc = (
|
1255 |
-
int(random.uniform(0, s)) for _ in self.mosaic_border
|
1256 |
-
) # mosaic center x, y
|
1257 |
-
img9 = img9[yc : yc + 2 * s, xc : xc + 2 * s]
|
1258 |
-
|
1259 |
-
# Concat/clip labels
|
1260 |
-
labels9 = np.concatenate(labels9, 0)
|
1261 |
-
labels9[:, [1, 3]] -= xc
|
1262 |
-
labels9[:, [2, 4]] -= yc
|
1263 |
-
c = np.array([xc, yc]) # centers
|
1264 |
-
segments9 = [x - c for x in segments9]
|
1265 |
-
|
1266 |
-
for x in (labels9[:, 1:], *segments9):
|
1267 |
-
np.clip(x, 0, 2 * s, out=x) # clip when using random_perspective()
|
1268 |
-
# img9, labels9 = replicate(img9, labels9) # replicate
|
1269 |
-
|
1270 |
-
# Augment
|
1271 |
-
img9, labels9, segments9 = copy_paste(
|
1272 |
-
img9, labels9, segments9, p=self.hyp["copy_paste"]
|
1273 |
-
)
|
1274 |
-
img9, labels9 = random_perspective(
|
1275 |
-
img9,
|
1276 |
-
labels9,
|
1277 |
-
segments9,
|
1278 |
-
degrees=self.hyp["degrees"],
|
1279 |
-
translate=self.hyp["translate"],
|
1280 |
-
scale=self.hyp["scale"],
|
1281 |
-
shear=self.hyp["shear"],
|
1282 |
-
perspective=self.hyp["perspective"],
|
1283 |
-
border=self.mosaic_border,
|
1284 |
-
) # border to remove
|
1285 |
-
|
1286 |
-
return img9, labels9
|
1287 |
-
|
1288 |
-
@staticmethod
|
1289 |
-
def collate_fn(batch):
|
1290 |
-
im, label, path, shapes = zip(*batch) # transposed
|
1291 |
-
for i, lb in enumerate(label):
|
1292 |
-
lb[:, 0] = i # add target image index for build_targets()
|
1293 |
-
return torch.stack(im, 0), torch.cat(label, 0), path, shapes
|
1294 |
-
|
1295 |
-
@staticmethod
|
1296 |
-
def collate_fn4(batch):
|
1297 |
-
im, label, path, shapes = zip(*batch) # transposed
|
1298 |
-
n = len(shapes) // 4
|
1299 |
-
im4, label4, path4, shapes4 = [], [], path[:n], shapes[:n]
|
1300 |
-
|
1301 |
-
ho = torch.tensor([[0.0, 0, 0, 1, 0, 0]])
|
1302 |
-
wo = torch.tensor([[0.0, 0, 1, 0, 0, 0]])
|
1303 |
-
s = torch.tensor([[1, 1, 0.5, 0.5, 0.5, 0.5]]) # scale
|
1304 |
-
for i in range(n): # zidane torch.zeros(16,3,720,1280) # BCHW
|
1305 |
-
i *= 4
|
1306 |
-
if random.random() < 0.5:
|
1307 |
-
im1 = F.interpolate(
|
1308 |
-
im[i].unsqueeze(0).float(),
|
1309 |
-
scale_factor=2.0,
|
1310 |
-
mode="bilinear",
|
1311 |
-
align_corners=False,
|
1312 |
-
)[0].type(im[i].type())
|
1313 |
-
lb = label[i]
|
1314 |
-
else:
|
1315 |
-
im1 = torch.cat(
|
1316 |
-
(
|
1317 |
-
torch.cat((im[i], im[i + 1]), 1),
|
1318 |
-
torch.cat((im[i + 2], im[i + 3]), 1),
|
1319 |
-
),
|
1320 |
-
2,
|
1321 |
-
)
|
1322 |
-
lb = (
|
1323 |
-
torch.cat(
|
1324 |
-
(
|
1325 |
-
label[i],
|
1326 |
-
label[i + 1] + ho,
|
1327 |
-
label[i + 2] + wo,
|
1328 |
-
label[i + 3] + ho + wo,
|
1329 |
-
),
|
1330 |
-
0,
|
1331 |
-
)
|
1332 |
-
* s
|
1333 |
-
)
|
1334 |
-
im4.append(im1)
|
1335 |
-
label4.append(lb)
|
1336 |
-
|
1337 |
-
for i, lb in enumerate(label4):
|
1338 |
-
lb[:, 0] = i # add target image index for build_targets()
|
1339 |
-
|
1340 |
-
return torch.stack(im4, 0), torch.cat(label4, 0), path4, shapes4
|
1341 |
-
|
1342 |
-
|
1343 |
-
# Ancillary functions --------------------------------------------------------------------------------------------------
|
1344 |
-
def flatten_recursive(path=DATASETS_DIR / "coco128"):
|
1345 |
-
# Flatten a recursive directory by bringing all files to top level
|
1346 |
-
new_path = Path(f"{str(path)}_flat")
|
1347 |
-
if os.path.exists(new_path):
|
1348 |
-
shutil.rmtree(new_path) # delete output folder
|
1349 |
-
os.makedirs(new_path) # make new output folder
|
1350 |
-
for file in tqdm(glob.glob(f"{str(Path(path))}/**/*.*", recursive=True)):
|
1351 |
-
shutil.copyfile(file, new_path / Path(file).name)
|
1352 |
-
|
1353 |
-
|
1354 |
-
def extract_boxes(
|
1355 |
-
path=DATASETS_DIR / "coco128",
|
1356 |
-
): # from utils.dataloaders import *; extract_boxes()
|
1357 |
-
# Convert detection dataset into classification dataset, with one directory per class
|
1358 |
-
path = Path(path) # images dir
|
1359 |
-
shutil.rmtree(path / "classification") if (
|
1360 |
-
path / "classification"
|
1361 |
-
).is_dir() else None # remove existing
|
1362 |
-
files = list(path.rglob("*.*"))
|
1363 |
-
n = len(files) # number of files
|
1364 |
-
for im_file in tqdm(files, total=n):
|
1365 |
-
if im_file.suffix[1:] in IMG_FORMATS:
|
1366 |
-
# image
|
1367 |
-
im = cv2.imread(str(im_file))[..., ::-1] # BGR to RGB
|
1368 |
-
h, w = im.shape[:2]
|
1369 |
-
|
1370 |
-
# labels
|
1371 |
-
lb_file = Path(img2label_paths([str(im_file)])[0])
|
1372 |
-
if Path(lb_file).exists():
|
1373 |
-
with open(lb_file) as f:
|
1374 |
-
lb = np.array(
|
1375 |
-
[x.split() for x in f.read().strip().splitlines()],
|
1376 |
-
dtype=np.float32,
|
1377 |
-
) # labels
|
1378 |
-
|
1379 |
-
for j, x in enumerate(lb):
|
1380 |
-
c = int(x[0]) # class
|
1381 |
-
f = (
|
1382 |
-
(path / "classifier")
|
1383 |
-
/ f"{c}"
|
1384 |
-
/ f"{path.stem}_{im_file.stem}_{j}.jpg"
|
1385 |
-
) # new filename
|
1386 |
-
if not f.parent.is_dir():
|
1387 |
-
f.parent.mkdir(parents=True)
|
1388 |
-
|
1389 |
-
b = x[1:] * [w, h, w, h] # box
|
1390 |
-
# b[2:] = b[2:].max() # rectangle to square
|
1391 |
-
b[2:] = b[2:] * 1.2 + 3 # pad
|
1392 |
-
b = xywh2xyxy(b.reshape(-1, 4)).ravel().astype(int)
|
1393 |
-
|
1394 |
-
b[[0, 2]] = np.clip(
|
1395 |
-
b[[0, 2]], 0, w
|
1396 |
-
) # clip boxes outside of image
|
1397 |
-
b[[1, 3]] = np.clip(b[[1, 3]], 0, h)
|
1398 |
-
assert cv2.imwrite(
|
1399 |
-
str(f), im[b[1] : b[3], b[0] : b[2]]
|
1400 |
-
), f"box failure in {f}"
|
1401 |
-
|
1402 |
-
|
1403 |
-
def autosplit(
|
1404 |
-
path=DATASETS_DIR / "coco128/images",
|
1405 |
-
weights=(0.9, 0.1, 0.0),
|
1406 |
-
annotated_only=False,
|
1407 |
-
):
|
1408 |
-
"""Autosplit a dataset into train/val/test splits and save path/autosplit_*.txt files
|
1409 |
-
Usage: from utils.dataloaders import *; autosplit()
|
1410 |
-
Arguments
|
1411 |
-
path: Path to images directory
|
1412 |
-
weights: Train, val, test weights (list, tuple)
|
1413 |
-
annotated_only: Only use images with an annotated txt file
|
1414 |
-
"""
|
1415 |
-
path = Path(path) # images dir
|
1416 |
-
files = sorted(
|
1417 |
-
x for x in path.rglob("*.*") if x.suffix[1:].lower() in IMG_FORMATS
|
1418 |
-
) # image files only
|
1419 |
-
n = len(files) # number of files
|
1420 |
-
random.seed(0) # for reproducibility
|
1421 |
-
indices = random.choices(
|
1422 |
-
[0, 1, 2], weights=weights, k=n
|
1423 |
-
) # assign each image to a split
|
1424 |
-
|
1425 |
-
txt = [
|
1426 |
-
"autosplit_train.txt",
|
1427 |
-
"autosplit_val.txt",
|
1428 |
-
"autosplit_test.txt",
|
1429 |
-
] # 3 txt files
|
1430 |
-
for x in txt:
|
1431 |
-
if (path.parent / x).exists():
|
1432 |
-
(path.parent / x).unlink() # remove existing
|
1433 |
-
|
1434 |
-
print(
|
1435 |
-
f"Autosplitting images from {path}"
|
1436 |
-
+ ", using *.txt labeled images only" * annotated_only
|
1437 |
-
)
|
1438 |
-
for i, img in tqdm(zip(indices, files), total=n):
|
1439 |
-
if (
|
1440 |
-
not annotated_only or Path(img2label_paths([str(img)])[0]).exists()
|
1441 |
-
): # check label
|
1442 |
-
with open(path.parent / txt[i], "a") as f:
|
1443 |
-
f.write(
|
1444 |
-
f"./{img.relative_to(path.parent).as_posix()}" + "\n"
|
1445 |
-
) # add image to txt file
|
1446 |
-
|
1447 |
-
|
1448 |
-
def verify_image_label(args):
|
1449 |
-
# Verify one image-label pair
|
1450 |
-
im_file, lb_file, prefix = args
|
1451 |
-
nm, nf, ne, nc, msg, segments = (
|
1452 |
-
0,
|
1453 |
-
0,
|
1454 |
-
0,
|
1455 |
-
0,
|
1456 |
-
"",
|
1457 |
-
[],
|
1458 |
-
) # number (missing, found, empty, corrupt), message, segments
|
1459 |
-
try:
|
1460 |
-
# verify images
|
1461 |
-
im = Image.open(im_file)
|
1462 |
-
im.verify() # PIL verify
|
1463 |
-
shape = exif_size(im) # image size
|
1464 |
-
assert (shape[0] > 9) & (
|
1465 |
-
shape[1] > 9
|
1466 |
-
), f"image size {shape} <10 pixels"
|
1467 |
-
assert (
|
1468 |
-
im.format.lower() in IMG_FORMATS
|
1469 |
-
), f"invalid image format {im.format}"
|
1470 |
-
if im.format.lower() in ("jpg", "jpeg"):
|
1471 |
-
with open(im_file, "rb") as f:
|
1472 |
-
f.seek(-2, 2)
|
1473 |
-
if f.read() != b"\xff\xd9": # corrupt JPEG
|
1474 |
-
ImageOps.exif_transpose(Image.open(im_file)).save(
|
1475 |
-
im_file, "JPEG", subsampling=0, quality=100
|
1476 |
-
)
|
1477 |
-
msg = f"{prefix}WARNING ⚠️ {im_file}: corrupt JPEG restored and saved"
|
1478 |
-
|
1479 |
-
# verify labels
|
1480 |
-
if os.path.isfile(lb_file):
|
1481 |
-
nf = 1 # label found
|
1482 |
-
with open(lb_file) as f:
|
1483 |
-
lb = [
|
1484 |
-
x.split() for x in f.read().strip().splitlines() if len(x)
|
1485 |
-
]
|
1486 |
-
if any(len(x) > 6 for x in lb): # is segment
|
1487 |
-
classes = np.array([x[0] for x in lb], dtype=np.float32)
|
1488 |
-
segments = [
|
1489 |
-
np.array(x[1:], dtype=np.float32).reshape(-1, 2)
|
1490 |
-
for x in lb
|
1491 |
-
] # (cls, xy1...)
|
1492 |
-
lb = np.concatenate(
|
1493 |
-
(classes.reshape(-1, 1), segments2boxes(segments)), 1
|
1494 |
-
) # (cls, xywh)
|
1495 |
-
lb = np.array(lb, dtype=np.float32)
|
1496 |
-
nl = len(lb)
|
1497 |
-
if nl:
|
1498 |
-
assert (
|
1499 |
-
lb.shape[1] == 5
|
1500 |
-
), f"labels require 5 columns, {lb.shape[1]} columns detected"
|
1501 |
-
assert (lb >= 0).all(), f"negative label values {lb[lb < 0]}"
|
1502 |
-
assert (
|
1503 |
-
lb[:, 1:] <= 1
|
1504 |
-
).all(), f"non-normalized or out of bounds coordinates {lb[:, 1:][lb[:, 1:] > 1]}"
|
1505 |
-
_, i = np.unique(lb, axis=0, return_index=True)
|
1506 |
-
if len(i) < nl: # duplicate row check
|
1507 |
-
lb = lb[i] # remove duplicates
|
1508 |
-
if segments:
|
1509 |
-
segments = [segments[x] for x in i]
|
1510 |
-
msg = f"{prefix}WARNING ⚠️ {im_file}: {nl - len(i)} duplicate labels removed"
|
1511 |
-
else:
|
1512 |
-
ne = 1 # label empty
|
1513 |
-
lb = np.zeros((0, 5), dtype=np.float32)
|
1514 |
-
else:
|
1515 |
-
nm = 1 # label missing
|
1516 |
-
lb = np.zeros((0, 5), dtype=np.float32)
|
1517 |
-
return im_file, lb, shape, segments, nm, nf, ne, nc, msg
|
1518 |
-
except Exception as e:
|
1519 |
-
nc = 1
|
1520 |
-
msg = (
|
1521 |
-
f"{prefix}WARNING ⚠️ {im_file}: ignoring corrupt image/label: {e}"
|
1522 |
-
)
|
1523 |
-
return [None, None, None, None, nm, nf, ne, nc, msg]
|
1524 |
-
|
1525 |
-
|
1526 |
-
class HUBDatasetStats:
|
1527 |
-
"""Class for generating HUB dataset JSON and `-hub` dataset directory
|
1528 |
-
|
1529 |
-
Arguments
|
1530 |
-
path: Path to data.yaml or data.zip (with data.yaml inside data.zip)
|
1531 |
-
autodownload: Attempt to download dataset if not found locally
|
1532 |
-
|
1533 |
-
Usage
|
1534 |
-
from utils.dataloaders import HUBDatasetStats
|
1535 |
-
stats = HUBDatasetStats('coco128.yaml', autodownload=True) # usage 1
|
1536 |
-
stats = HUBDatasetStats('path/to/coco128.zip') # usage 2
|
1537 |
-
stats.get_json(save=False)
|
1538 |
-
stats.process_images()
|
1539 |
-
"""
|
1540 |
-
|
1541 |
-
def __init__(self, path="coco128.yaml", autodownload=False):
|
1542 |
-
# Initialize class
|
1543 |
-
zipped, data_dir, yaml_path = self._unzip(Path(path))
|
1544 |
-
try:
|
1545 |
-
with open(check_yaml(yaml_path), errors="ignore") as f:
|
1546 |
-
data = yaml.safe_load(f) # data dict
|
1547 |
-
if zipped:
|
1548 |
-
data["path"] = data_dir
|
1549 |
-
except Exception as e:
|
1550 |
-
raise Exception("error/HUB/dataset_stats/yaml_load") from e
|
1551 |
-
|
1552 |
-
check_dataset(data, autodownload) # download dataset if missing
|
1553 |
-
self.hub_dir = Path(data["path"] + "-hub")
|
1554 |
-
self.im_dir = self.hub_dir / "images"
|
1555 |
-
self.im_dir.mkdir(parents=True, exist_ok=True) # makes /images
|
1556 |
-
self.stats = {
|
1557 |
-
"nc": data["nc"],
|
1558 |
-
"names": list(data["names"].values()),
|
1559 |
-
} # statistics dictionary
|
1560 |
-
self.data = data
|
1561 |
-
|
1562 |
-
@staticmethod
|
1563 |
-
def _find_yaml(dir):
|
1564 |
-
# Return data.yaml file
|
1565 |
-
files = list(dir.glob("*.yaml")) or list(
|
1566 |
-
dir.rglob("*.yaml")
|
1567 |
-
) # try root level first and then recursive
|
1568 |
-
assert files, f"No *.yaml file found in {dir}"
|
1569 |
-
if len(files) > 1:
|
1570 |
-
files = [
|
1571 |
-
f for f in files if f.stem == dir.stem
|
1572 |
-
] # prefer *.yaml files that match dir name
|
1573 |
-
assert (
|
1574 |
-
files
|
1575 |
-
), f"Multiple *.yaml files found in {dir}, only 1 *.yaml file allowed"
|
1576 |
-
assert (
|
1577 |
-
len(files) == 1
|
1578 |
-
), f"Multiple *.yaml files found: {files}, only 1 *.yaml file allowed in {dir}"
|
1579 |
-
return files[0]
|
1580 |
-
|
1581 |
-
def _unzip(self, path):
|
1582 |
-
# Unzip data.zip
|
1583 |
-
if not str(path).endswith(".zip"): # path is data.yaml
|
1584 |
-
return False, None, path
|
1585 |
-
assert Path(path).is_file(), f"Error unzipping {path}, file not found"
|
1586 |
-
unzip_file(path, path=path.parent)
|
1587 |
-
dir = path.with_suffix("") # dataset directory == zip name
|
1588 |
-
assert (
|
1589 |
-
dir.is_dir()
|
1590 |
-
), f"Error unzipping {path}, {dir} not found. path/to/abc.zip MUST unzip to path/to/abc/"
|
1591 |
-
return (
|
1592 |
-
True,
|
1593 |
-
str(dir),
|
1594 |
-
self._find_yaml(dir),
|
1595 |
-
) # zipped, data_dir, yaml_path
|
1596 |
-
|
1597 |
-
def _hub_ops(self, f, max_dim=1920):
|
1598 |
-
# HUB ops for 1 image 'f': resize and save at reduced quality in /dataset-hub for web/app viewing
|
1599 |
-
f_new = self.im_dir / Path(f).name # dataset-hub image filename
|
1600 |
-
try: # use PIL
|
1601 |
-
im = Image.open(f)
|
1602 |
-
r = max_dim / max(im.height, im.width) # ratio
|
1603 |
-
if r < 1.0: # image too large
|
1604 |
-
im = im.resize((int(im.width * r), int(im.height * r)))
|
1605 |
-
im.save(f_new, "JPEG", quality=50, optimize=True) # save
|
1606 |
-
except Exception as e: # use OpenCV
|
1607 |
-
LOGGER.info(f"WARNING ⚠️ HUB ops PIL failure {f}: {e}")
|
1608 |
-
im = cv2.imread(f)
|
1609 |
-
im_height, im_width = im.shape[:2]
|
1610 |
-
r = max_dim / max(im_height, im_width) # ratio
|
1611 |
-
if r < 1.0: # image too large
|
1612 |
-
im = cv2.resize(
|
1613 |
-
im,
|
1614 |
-
(int(im_width * r), int(im_height * r)),
|
1615 |
-
interpolation=cv2.INTER_AREA,
|
1616 |
-
)
|
1617 |
-
cv2.imwrite(str(f_new), im)
|
1618 |
-
|
1619 |
-
def get_json(self, save=False, verbose=False):
|
1620 |
-
# Return dataset JSON for Ultralytics HUB
|
1621 |
-
def _round(labels):
|
1622 |
-
# Update labels to integer class and 6 decimal place floats
|
1623 |
-
return [
|
1624 |
-
[int(c), *(round(x, 4) for x in points)]
|
1625 |
-
for c, *points in labels
|
1626 |
-
]
|
1627 |
-
|
1628 |
-
for split in "train", "val", "test":
|
1629 |
-
if self.data.get(split) is None:
|
1630 |
-
self.stats[split] = None # i.e. no test set
|
1631 |
-
continue
|
1632 |
-
dataset = LoadImagesAndLabels(self.data[split]) # load dataset
|
1633 |
-
x = np.array(
|
1634 |
-
[
|
1635 |
-
np.bincount(
|
1636 |
-
label[:, 0].astype(int), minlength=self.data["nc"]
|
1637 |
-
)
|
1638 |
-
for label in tqdm(
|
1639 |
-
dataset.labels, total=dataset.n, desc="Statistics"
|
1640 |
-
)
|
1641 |
-
]
|
1642 |
-
) # shape(128x80)
|
1643 |
-
self.stats[split] = {
|
1644 |
-
"instance_stats": {
|
1645 |
-
"total": int(x.sum()),
|
1646 |
-
"per_class": x.sum(0).tolist(),
|
1647 |
-
},
|
1648 |
-
"image_stats": {
|
1649 |
-
"total": dataset.n,
|
1650 |
-
"unlabelled": int(np.all(x == 0, 1).sum()),
|
1651 |
-
"per_class": (x > 0).sum(0).tolist(),
|
1652 |
-
},
|
1653 |
-
"labels": [
|
1654 |
-
{str(Path(k).name): _round(v.tolist())}
|
1655 |
-
for k, v in zip(dataset.im_files, dataset.labels)
|
1656 |
-
],
|
1657 |
-
}
|
1658 |
-
|
1659 |
-
# Save, print and return
|
1660 |
-
if save:
|
1661 |
-
stats_path = self.hub_dir / "stats.json"
|
1662 |
-
print(f"Saving {stats_path.resolve()}...")
|
1663 |
-
with open(stats_path, "w") as f:
|
1664 |
-
json.dump(self.stats, f) # save stats.json
|
1665 |
-
if verbose:
|
1666 |
-
print(json.dumps(self.stats, indent=2, sort_keys=False))
|
1667 |
-
return self.stats
|
1668 |
-
|
1669 |
-
def process_images(self):
|
1670 |
-
# Compress images for Ultralytics HUB
|
1671 |
-
for split in "train", "val", "test":
|
1672 |
-
if self.data.get(split) is None:
|
1673 |
-
continue
|
1674 |
-
dataset = LoadImagesAndLabels(self.data[split]) # load dataset
|
1675 |
-
desc = f"{split} images"
|
1676 |
-
for _ in tqdm(
|
1677 |
-
ThreadPool(NUM_THREADS).imap(self._hub_ops, dataset.im_files),
|
1678 |
-
total=dataset.n,
|
1679 |
-
desc=desc,
|
1680 |
-
):
|
1681 |
-
pass
|
1682 |
-
print(f"Done. All images saved to {self.im_dir}")
|
1683 |
-
return self.im_dir
|
1684 |
-
|
1685 |
-
|
1686 |
-
# Classification dataloaders -------------------------------------------------------------------------------------------
|
1687 |
-
class ClassificationDataset(torchvision.datasets.ImageFolder):
|
1688 |
-
"""
|
1689 |
-
YOLOv5 Classification Dataset.
|
1690 |
-
Arguments
|
1691 |
-
root: Dataset path
|
1692 |
-
transform: torchvision transforms, used by default
|
1693 |
-
album_transform: Albumentations transforms, used if installed
|
1694 |
-
"""
|
1695 |
-
|
1696 |
-
def __init__(self, root, augment, imgsz, cache=False):
|
1697 |
-
super().__init__(root=root)
|
1698 |
-
self.torch_transforms = classify_transforms(imgsz)
|
1699 |
-
self.album_transforms = (
|
1700 |
-
classify_albumentations(augment, imgsz) if augment else None
|
1701 |
-
)
|
1702 |
-
self.cache_ram = cache is True or cache == "ram"
|
1703 |
-
self.cache_disk = cache == "disk"
|
1704 |
-
self.samples = [
|
1705 |
-
list(x) + [Path(x[0]).with_suffix(".npy"), None]
|
1706 |
-
for x in self.samples
|
1707 |
-
] # file, index, npy, im
|
1708 |
-
|
1709 |
-
def __getitem__(self, i):
|
1710 |
-
f, j, fn, im = self.samples[
|
1711 |
-
i
|
1712 |
-
] # filename, index, filename.with_suffix('.npy'), image
|
1713 |
-
if self.cache_ram and im is None:
|
1714 |
-
im = self.samples[i][3] = cv2.imread(f)
|
1715 |
-
elif self.cache_disk:
|
1716 |
-
if not fn.exists(): # load npy
|
1717 |
-
np.save(fn.as_posix(), cv2.imread(f))
|
1718 |
-
im = np.load(fn)
|
1719 |
-
else: # read image
|
1720 |
-
im = cv2.imread(f) # BGR
|
1721 |
-
if self.album_transforms:
|
1722 |
-
sample = self.album_transforms(
|
1723 |
-
image=cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
|
1724 |
-
)["image"]
|
1725 |
-
else:
|
1726 |
-
sample = self.torch_transforms(im)
|
1727 |
-
return sample, j
|
1728 |
-
|
1729 |
-
|
1730 |
-
def create_classification_dataloader(
|
1731 |
-
path,
|
1732 |
-
imgsz=224,
|
1733 |
-
batch_size=16,
|
1734 |
-
augment=True,
|
1735 |
-
cache=False,
|
1736 |
-
rank=-1,
|
1737 |
-
workers=8,
|
1738 |
-
shuffle=True,
|
1739 |
-
):
|
1740 |
-
# Returns Dataloader object to be used with YOLOv5 Classifier
|
1741 |
-
with torch_distributed_zero_first(
|
1742 |
-
rank
|
1743 |
-
): # init dataset *.cache only once if DDP
|
1744 |
-
dataset = ClassificationDataset(
|
1745 |
-
root=path, imgsz=imgsz, augment=augment, cache=cache
|
1746 |
-
)
|
1747 |
-
batch_size = min(batch_size, len(dataset))
|
1748 |
-
nd = torch.cuda.device_count()
|
1749 |
-
nw = min(
|
1750 |
-
[
|
1751 |
-
os.cpu_count() // max(nd, 1),
|
1752 |
-
batch_size if batch_size > 1 else 0,
|
1753 |
-
workers,
|
1754 |
-
]
|
1755 |
-
)
|
1756 |
-
sampler = (
|
1757 |
-
None
|
1758 |
-
if rank == -1
|
1759 |
-
else distributed.DistributedSampler(dataset, shuffle=shuffle)
|
1760 |
-
)
|
1761 |
-
generator = torch.Generator()
|
1762 |
-
generator.manual_seed(6148914691236517205 + RANK)
|
1763 |
-
return InfiniteDataLoader(
|
1764 |
-
dataset,
|
1765 |
-
batch_size=batch_size,
|
1766 |
-
shuffle=shuffle and sampler is None,
|
1767 |
-
num_workers=nw,
|
1768 |
-
sampler=sampler,
|
1769 |
-
pin_memory=PIN_MEMORY,
|
1770 |
-
worker_init_fn=seed_worker,
|
1771 |
-
generator=generator,
|
1772 |
-
) # or DataLoader(persistent_workers=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Abhilashvj/planogram-compliance/utils/segment/plots.py
DELETED
@@ -1,188 +0,0 @@
|
|
1 |
-
import contextlib
|
2 |
-
import math
|
3 |
-
from pathlib import Path
|
4 |
-
|
5 |
-
import cv2
|
6 |
-
import matplotlib.pyplot as plt
|
7 |
-
import numpy as np
|
8 |
-
import pandas as pd
|
9 |
-
import torch
|
10 |
-
|
11 |
-
from .. import threaded
|
12 |
-
from ..general import xywh2xyxy
|
13 |
-
from ..plots import Annotator, colors
|
14 |
-
|
15 |
-
|
16 |
-
@threaded
|
17 |
-
def plot_images_and_masks(
|
18 |
-
images, targets, masks, paths=None, fname="images.jpg", names=None
|
19 |
-
):
|
20 |
-
# Plot image grid with labels
|
21 |
-
if isinstance(images, torch.Tensor):
|
22 |
-
images = images.cpu().float().numpy()
|
23 |
-
if isinstance(targets, torch.Tensor):
|
24 |
-
targets = targets.cpu().numpy()
|
25 |
-
if isinstance(masks, torch.Tensor):
|
26 |
-
masks = masks.cpu().numpy().astype(int)
|
27 |
-
|
28 |
-
max_size = 1920 # max image size
|
29 |
-
max_subplots = 16 # max image subplots, i.e. 4x4
|
30 |
-
bs, _, h, w = images.shape # batch size, _, height, width
|
31 |
-
bs = min(bs, max_subplots) # limit plot images
|
32 |
-
ns = np.ceil(bs**0.5) # number of subplots (square)
|
33 |
-
if np.max(images[0]) <= 1:
|
34 |
-
images *= 255 # de-normalise (optional)
|
35 |
-
|
36 |
-
# Build Image
|
37 |
-
mosaic = np.full(
|
38 |
-
(int(ns * h), int(ns * w), 3), 255, dtype=np.uint8
|
39 |
-
) # init
|
40 |
-
for i, im in enumerate(images):
|
41 |
-
if i == max_subplots: # if last batch has fewer images than we expect
|
42 |
-
break
|
43 |
-
x, y = int(w * (i // ns)), int(h * (i % ns)) # block origin
|
44 |
-
im = im.transpose(1, 2, 0)
|
45 |
-
mosaic[y : y + h, x : x + w, :] = im
|
46 |
-
|
47 |
-
# Resize (optional)
|
48 |
-
scale = max_size / ns / max(h, w)
|
49 |
-
if scale < 1:
|
50 |
-
h = math.ceil(scale * h)
|
51 |
-
w = math.ceil(scale * w)
|
52 |
-
mosaic = cv2.resize(mosaic, tuple(int(x * ns) for x in (w, h)))
|
53 |
-
|
54 |
-
# Annotate
|
55 |
-
fs = int((h + w) * ns * 0.01) # font size
|
56 |
-
annotator = Annotator(
|
57 |
-
mosaic,
|
58 |
-
line_width=round(fs / 10),
|
59 |
-
font_size=fs,
|
60 |
-
pil=True,
|
61 |
-
example=names,
|
62 |
-
)
|
63 |
-
for i in range(i + 1):
|
64 |
-
x, y = int(w * (i // ns)), int(h * (i % ns)) # block origin
|
65 |
-
annotator.rectangle(
|
66 |
-
[x, y, x + w, y + h], None, (255, 255, 255), width=2
|
67 |
-
) # borders
|
68 |
-
if paths:
|
69 |
-
annotator.text(
|
70 |
-
(x + 5, y + 5 + h),
|
71 |
-
text=Path(paths[i]).name[:40],
|
72 |
-
txt_color=(220, 220, 220),
|
73 |
-
) # filenames
|
74 |
-
if len(targets) > 0:
|
75 |
-
idx = targets[:, 0] == i
|
76 |
-
ti = targets[idx] # image targets
|
77 |
-
|
78 |
-
boxes = xywh2xyxy(ti[:, 2:6]).T
|
79 |
-
classes = ti[:, 1].astype("int")
|
80 |
-
labels = ti.shape[1] == 6 # labels if no conf column
|
81 |
-
conf = (
|
82 |
-
None if labels else ti[:, 6]
|
83 |
-
) # check for confidence presence (label vs pred)
|
84 |
-
|
85 |
-
if boxes.shape[1]:
|
86 |
-
if boxes.max() <= 1.01: # if normalized with tolerance 0.01
|
87 |
-
boxes[[0, 2]] *= w # scale to pixels
|
88 |
-
boxes[[1, 3]] *= h
|
89 |
-
elif scale < 1: # absolute coords need scale if image scales
|
90 |
-
boxes *= scale
|
91 |
-
boxes[[0, 2]] += x
|
92 |
-
boxes[[1, 3]] += y
|
93 |
-
for j, box in enumerate(boxes.T.tolist()):
|
94 |
-
cls = classes[j]
|
95 |
-
color = colors(cls)
|
96 |
-
cls = names[cls] if names else cls
|
97 |
-
if labels or conf[j] > 0.25: # 0.25 conf thresh
|
98 |
-
label = f"{cls}" if labels else f"{cls} {conf[j]:.1f}"
|
99 |
-
annotator.box_label(box, label, color=color)
|
100 |
-
|
101 |
-
# Plot masks
|
102 |
-
if len(masks):
|
103 |
-
if masks.max() > 1.0: # mean that masks are overlap
|
104 |
-
image_masks = masks[[i]] # (1, 640, 640)
|
105 |
-
nl = len(ti)
|
106 |
-
index = np.arange(nl).reshape(nl, 1, 1) + 1
|
107 |
-
image_masks = np.repeat(image_masks, nl, axis=0)
|
108 |
-
image_masks = np.where(image_masks == index, 1.0, 0.0)
|
109 |
-
else:
|
110 |
-
image_masks = masks[idx]
|
111 |
-
|
112 |
-
im = np.asarray(annotator.im).copy()
|
113 |
-
for j, box in enumerate(boxes.T.tolist()):
|
114 |
-
if labels or conf[j] > 0.25: # 0.25 conf thresh
|
115 |
-
color = colors(classes[j])
|
116 |
-
mh, mw = image_masks[j].shape
|
117 |
-
if mh != h or mw != w:
|
118 |
-
mask = image_masks[j].astype(np.uint8)
|
119 |
-
mask = cv2.resize(mask, (w, h))
|
120 |
-
mask = mask.astype(bool)
|
121 |
-
else:
|
122 |
-
mask = image_masks[j].astype(bool)
|
123 |
-
with contextlib.suppress(Exception):
|
124 |
-
im[y : y + h, x : x + w, :][mask] = (
|
125 |
-
im[y : y + h, x : x + w, :][mask] * 0.4
|
126 |
-
+ np.array(color) * 0.6
|
127 |
-
)
|
128 |
-
annotator.fromarray(im)
|
129 |
-
annotator.im.save(fname) # save
|
130 |
-
|
131 |
-
|
132 |
-
def plot_results_with_masks(file="path/to/results.csv", dir="", best=True):
|
133 |
-
# Plot training results.csv. Usage: from utils.plots import *; plot_results('path/to/results.csv')
|
134 |
-
save_dir = Path(file).parent if file else Path(dir)
|
135 |
-
fig, ax = plt.subplots(2, 8, figsize=(18, 6), tight_layout=True)
|
136 |
-
ax = ax.ravel()
|
137 |
-
files = list(save_dir.glob("results*.csv"))
|
138 |
-
assert len(
|
139 |
-
files
|
140 |
-
), f"No results.csv files found in {save_dir.resolve()}, nothing to plot."
|
141 |
-
for f in files:
|
142 |
-
try:
|
143 |
-
data = pd.read_csv(f)
|
144 |
-
index = np.argmax(
|
145 |
-
0.9 * data.values[:, 8]
|
146 |
-
+ 0.1 * data.values[:, 7]
|
147 |
-
+ 0.9 * data.values[:, 12]
|
148 |
-
+ 0.1 * data.values[:, 11]
|
149 |
-
)
|
150 |
-
s = [x.strip() for x in data.columns]
|
151 |
-
x = data.values[:, 0]
|
152 |
-
for i, j in enumerate(
|
153 |
-
[1, 2, 3, 4, 5, 6, 9, 10, 13, 14, 15, 16, 7, 8, 11, 12]
|
154 |
-
):
|
155 |
-
y = data.values[:, j]
|
156 |
-
# y[y == 0] = np.nan # don't show zero values
|
157 |
-
ax[i].plot(
|
158 |
-
x, y, marker=".", label=f.stem, linewidth=2, markersize=2
|
159 |
-
)
|
160 |
-
if best:
|
161 |
-
# best
|
162 |
-
ax[i].scatter(
|
163 |
-
index,
|
164 |
-
y[index],
|
165 |
-
color="r",
|
166 |
-
label=f"best:{index}",
|
167 |
-
marker="*",
|
168 |
-
linewidth=3,
|
169 |
-
)
|
170 |
-
ax[i].set_title(s[j] + f"\n{round(y[index], 5)}")
|
171 |
-
else:
|
172 |
-
# last
|
173 |
-
ax[i].scatter(
|
174 |
-
x[-1],
|
175 |
-
y[-1],
|
176 |
-
color="r",
|
177 |
-
label="last",
|
178 |
-
marker="*",
|
179 |
-
linewidth=3,
|
180 |
-
)
|
181 |
-
ax[i].set_title(s[j] + f"\n{round(y[-1], 5)}")
|
182 |
-
# if j in [8, 9, 10]: # share train and val loss y axes
|
183 |
-
# ax[i].get_shared_y_axes().join(ax[i], ax[i - 5])
|
184 |
-
except Exception as e:
|
185 |
-
print(f"Warning: Plotting error for {f}: {e}")
|
186 |
-
ax[1].legend()
|
187 |
-
fig.savefig(save_dir / "results.png", dpi=200)
|
188 |
-
plt.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AchyuthGamer/OpenGPT/g4f/Provider/Wuguokai.py
DELETED
@@ -1,63 +0,0 @@
|
|
1 |
-
from __future__ import annotations
|
2 |
-
|
3 |
-
import random
|
4 |
-
|
5 |
-
import requests
|
6 |
-
|
7 |
-
from ..typing import Any, CreateResult
|
8 |
-
from .base_provider import BaseProvider, format_prompt
|
9 |
-
|
10 |
-
|
11 |
-
class Wuguokai(BaseProvider):
|
12 |
-
url = 'https://chat.wuguokai.xyz'
|
13 |
-
supports_gpt_35_turbo = True
|
14 |
-
working = False
|
15 |
-
|
16 |
-
@staticmethod
|
17 |
-
def create_completion(
|
18 |
-
model: str,
|
19 |
-
messages: list[dict[str, str]],
|
20 |
-
stream: bool,
|
21 |
-
**kwargs: Any,
|
22 |
-
) -> CreateResult:
|
23 |
-
headers = {
|
24 |
-
'authority': 'ai-api.wuguokai.xyz',
|
25 |
-
'accept': 'application/json, text/plain, */*',
|
26 |
-
'accept-language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
|
27 |
-
'content-type': 'application/json',
|
28 |
-
'origin': 'https://chat.wuguokai.xyz',
|
29 |
-
'referer': 'https://chat.wuguokai.xyz/',
|
30 |
-
'sec-ch-ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
|
31 |
-
'sec-ch-ua-mobile': '?0',
|
32 |
-
'sec-ch-ua-platform': '"Windows"',
|
33 |
-
'sec-fetch-dest': 'empty',
|
34 |
-
'sec-fetch-mode': 'cors',
|
35 |
-
'sec-fetch-site': 'same-site',
|
36 |
-
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
|
37 |
-
}
|
38 |
-
data ={
|
39 |
-
"prompt": format_prompt(messages),
|
40 |
-
"options": {},
|
41 |
-
"userId": f"#/chat/{random.randint(1,99999999)}",
|
42 |
-
"usingContext": True
|
43 |
-
}
|
44 |
-
response = requests.post("https://ai-api20.wuguokai.xyz/api/chat-process", headers=headers, timeout=3, json=data, proxies=kwargs['proxy'] if 'proxy' in kwargs else {})
|
45 |
-
_split = response.text.split("> 若回答失败请重试或多刷新几次界面后重试")
|
46 |
-
if response.status_code == 200:
|
47 |
-
if len(_split) > 1:
|
48 |
-
yield _split[1].strip()
|
49 |
-
else:
|
50 |
-
yield _split[0].strip()
|
51 |
-
else:
|
52 |
-
raise Exception(f"Error: {response.status_code} {response.reason}")
|
53 |
-
|
54 |
-
@classmethod
|
55 |
-
@property
|
56 |
-
def params(cls):
|
57 |
-
params = [
|
58 |
-
("model", "str"),
|
59 |
-
("messages", "list[dict[str, str]]"),
|
60 |
-
("stream", "bool")
|
61 |
-
]
|
62 |
-
param = ", ".join([": ".join(p) for p in params])
|
63 |
-
return f"g4f.provider.{cls.__name__} supports: ({param})"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/AgentVerse/agentVerse/agentverse/environments/simulation_env/rules/order/classroom.py
DELETED
@@ -1,100 +0,0 @@
|
|
1 |
-
from __future__ import annotations
|
2 |
-
|
3 |
-
import logging
|
4 |
-
import re
|
5 |
-
from typing import TYPE_CHECKING, Any, List, Optional
|
6 |
-
|
7 |
-
from . import order_registry as OrderRegistry
|
8 |
-
from .base import BaseOrder
|
9 |
-
|
10 |
-
if TYPE_CHECKING:
|
11 |
-
from agentverse.environments import BaseEnvironment
|
12 |
-
|
13 |
-
|
14 |
-
@OrderRegistry.register("classroom")
|
15 |
-
class ClassroomOrder(BaseOrder):
|
16 |
-
"""The order for a classroom discussion
|
17 |
-
The agents speak in the following order:
|
18 |
-
1. The professor speaks first
|
19 |
-
2. Then the professor can continue to speak, and the students can raise hands
|
20 |
-
3. The professor can call on a student, then the student can speak or ask a question
|
21 |
-
4. In the group discussion, the students in the group can speak in turn
|
22 |
-
"""
|
23 |
-
|
24 |
-
def get_next_agent_idx(self, environment: BaseEnvironment) -> List[int]:
|
25 |
-
# `is_grouped_ended`: whether the group discussion just ended
|
26 |
-
# `is_grouped`: whether it is currently in a group discussion
|
27 |
-
if environment.rule_params.get("is_grouped_ended", False):
|
28 |
-
return [0]
|
29 |
-
if environment.rule_params.get("is_grouped", False):
|
30 |
-
return self.get_next_agent_idx_grouped(environment)
|
31 |
-
else:
|
32 |
-
return self.get_next_agent_idx_ungrouped(environment)
|
33 |
-
|
34 |
-
def get_next_agent_idx_ungrouped(self, environment: BaseEnvironment) -> List[int]:
|
35 |
-
if len(environment.last_messages) == 0:
|
36 |
-
# If the class just begins or no one speaks in the last turn, we let only the professor speak
|
37 |
-
return [0]
|
38 |
-
elif len(environment.last_messages) == 1:
|
39 |
-
message = environment.last_messages[0]
|
40 |
-
sender = message.sender
|
41 |
-
content = message.content
|
42 |
-
if sender.startswith("Professor"):
|
43 |
-
if content.startswith("[CallOn]"):
|
44 |
-
# 1. professor calls on someone, then the student should speak
|
45 |
-
result = re.search(r"\[CallOn\] Yes, ([sS]tudent )?(\w+)", content)
|
46 |
-
if result is not None:
|
47 |
-
name_to_id = {
|
48 |
-
agent.name[len("Student ") :]: i
|
49 |
-
for i, agent in enumerate(environment.agents)
|
50 |
-
}
|
51 |
-
return [name_to_id[result.group(2)]]
|
52 |
-
else:
|
53 |
-
# 2. professor normally speaks, then anyone can act
|
54 |
-
return list(range(len(environment.agents)))
|
55 |
-
elif sender.startswith("Student"):
|
56 |
-
# 3. student ask question after being called on, or
|
57 |
-
# 4. only one student raises hand, and the professor happens to listen
|
58 |
-
# 5. the group discussion is just over, and there happens to be only a student speaking in the last turn
|
59 |
-
return [0]
|
60 |
-
else:
|
61 |
-
# If len(last_messages) > 1, then
|
62 |
-
# 1. there must be at least one student raises hand or speaks.
|
63 |
-
# 2. the group discussion is just over.
|
64 |
-
return [0]
|
65 |
-
assert (
|
66 |
-
False
|
67 |
-
), f"Should not reach here, last_messages: {environment.last_messages}"
|
68 |
-
|
69 |
-
def get_next_agent_idx_grouped(self, environment: BaseEnvironment) -> List[int]:
|
70 |
-
# Get the grouping information
|
71 |
-
# groups: A list of list of agent ids, the i-th list contains
|
72 |
-
# the agent ids in the i-th group
|
73 |
-
# group_speaker_mapping: A mapping from group id to the id of
|
74 |
-
# the speaker in the group
|
75 |
-
# `groups` should be set in the corresponding `visibility`,
|
76 |
-
# and `group_speaker_mapping` should be maintained here.
|
77 |
-
if "groups" not in environment.rule_params:
|
78 |
-
logging.warning(
|
79 |
-
"The environment is grouped, but the grouping information is not provided."
|
80 |
-
)
|
81 |
-
groups = environment.rule_params.get(
|
82 |
-
"groups", [list(range(len(environment.agents)))]
|
83 |
-
)
|
84 |
-
group_speaker_mapping = environment.rule_params.get(
|
85 |
-
"group_speaker_mapping", {i: 0 for i in range(len(groups))}
|
86 |
-
)
|
87 |
-
|
88 |
-
# For grouped environment, we let the students speak in turn within each group
|
89 |
-
next_agent_idx = []
|
90 |
-
for group_id in range(len(groups)):
|
91 |
-
speaker_index = group_speaker_mapping[group_id]
|
92 |
-
speaker = groups[group_id][speaker_index]
|
93 |
-
next_agent_idx.append(speaker)
|
94 |
-
|
95 |
-
# Maintain the `group_speaker_mapping`
|
96 |
-
for k, v in group_speaker_mapping.items():
|
97 |
-
group_speaker_mapping[k] = (v + 1) % len(groups[k])
|
98 |
-
environment.rule_params["group_speaker_mapping"] = group_speaker_mapping
|
99 |
-
|
100 |
-
return next_agent_idx
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Alycer/VITS-Umamusume-voice-synthesizer/monotonic_align/core.c
DELETED
The diff for this file is too large to render.
See raw diff
|
|
spaces/Androidonnxfork/CivitAi-to-Diffusers/diffusers/docs/source/en/training/unconditional_training.md
DELETED
@@ -1,146 +0,0 @@
|
|
1 |
-
<!--Copyright 2023 The HuggingFace Team. All rights reserved.
|
2 |
-
|
3 |
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
4 |
-
the License. You may obtain a copy of the License at
|
5 |
-
|
6 |
-
http://www.apache.org/licenses/LICENSE-2.0
|
7 |
-
|
8 |
-
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
9 |
-
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
10 |
-
specific language governing permissions and limitations under the License.
|
11 |
-
-->
|
12 |
-
|
13 |
-
# Unconditional image generation
|
14 |
-
|
15 |
-
Unconditional image generation is not conditioned on any text or images, unlike text- or image-to-image models. It only generates images that resemble its training data distribution.
|
16 |
-
|
17 |
-
<iframe
|
18 |
-
src="https://stevhliu-ddpm-butterflies-128.hf.space"
|
19 |
-
frameborder="0"
|
20 |
-
width="850"
|
21 |
-
height="550"
|
22 |
-
></iframe>
|
23 |
-
|
24 |
-
|
25 |
-
This guide will show you how to train an unconditional image generation model on existing datasets as well as your own custom dataset. All the training scripts for unconditional image generation can be found [here](https://github.com/huggingface/diffusers/tree/main/examples/unconditional_image_generation) if you're interested in learning more about the training details.
|
26 |
-
|
27 |
-
Before running the script, make sure you install the library's training dependencies:
|
28 |
-
|
29 |
-
```bash
|
30 |
-
pip install diffusers[training] accelerate datasets
|
31 |
-
```
|
32 |
-
|
33 |
-
Next, initialize an 🤗 [Accelerate](https://github.com/huggingface/accelerate/) environment with:
|
34 |
-
|
35 |
-
```bash
|
36 |
-
accelerate config
|
37 |
-
```
|
38 |
-
|
39 |
-
To setup a default 🤗 Accelerate environment without choosing any configurations:
|
40 |
-
|
41 |
-
```bash
|
42 |
-
accelerate config default
|
43 |
-
```
|
44 |
-
|
45 |
-
Or if your environment doesn't support an interactive shell like a notebook, you can use:
|
46 |
-
|
47 |
-
```bash
|
48 |
-
from accelerate.utils import write_basic_config
|
49 |
-
|
50 |
-
write_basic_config()
|
51 |
-
```
|
52 |
-
|
53 |
-
## Upload model to Hub
|
54 |
-
|
55 |
-
You can upload your model on the Hub by adding the following argument to the training script:
|
56 |
-
|
57 |
-
```bash
|
58 |
-
--push_to_hub
|
59 |
-
```
|
60 |
-
|
61 |
-
## Save and load checkpoints
|
62 |
-
|
63 |
-
It is a good idea to regularly save checkpoints in case anything happens during training. To save a checkpoint, pass the following argument to the training script:
|
64 |
-
|
65 |
-
```bash
|
66 |
-
--checkpointing_steps=500
|
67 |
-
```
|
68 |
-
|
69 |
-
The full training state is saved in a subfolder in the `output_dir` every 500 steps, which allows you to load a checkpoint and resume training if you pass the `--resume_from_checkpoint` argument to the training script:
|
70 |
-
|
71 |
-
```bash
|
72 |
-
--resume_from_checkpoint="checkpoint-1500"
|
73 |
-
```
|
74 |
-
|
75 |
-
## Finetuning
|
76 |
-
|
77 |
-
You're ready to launch the [training script](https://github.com/huggingface/diffusers/blob/main/examples/unconditional_image_generation/train_unconditional.py) now! Specify the dataset name to finetune on with the `--dataset_name` argument and then save it to the path in `--output_dir`. To use your own dataset, take a look at the [Create a dataset for training](create_dataset) guide.
|
78 |
-
|
79 |
-
The training script creates and saves a `diffusion_pytorch_model.bin` file in your repository.
|
80 |
-
|
81 |
-
<Tip>
|
82 |
-
|
83 |
-
💡 A full training run takes 2 hours on 4xV100 GPUs.
|
84 |
-
|
85 |
-
</Tip>
|
86 |
-
|
87 |
-
For example, to finetune on the [Oxford Flowers](https://huggingface.co/datasets/huggan/flowers-102-categories) dataset:
|
88 |
-
|
89 |
-
```bash
|
90 |
-
accelerate launch train_unconditional.py \
|
91 |
-
--dataset_name="huggan/flowers-102-categories" \
|
92 |
-
--resolution=64 \
|
93 |
-
--output_dir="ddpm-ema-flowers-64" \
|
94 |
-
--train_batch_size=16 \
|
95 |
-
--num_epochs=100 \
|
96 |
-
--gradient_accumulation_steps=1 \
|
97 |
-
--learning_rate=1e-4 \
|
98 |
-
--lr_warmup_steps=500 \
|
99 |
-
--mixed_precision=no \
|
100 |
-
--push_to_hub
|
101 |
-
```
|
102 |
-
|
103 |
-
<div class="flex justify-center">
|
104 |
-
<img src="https://user-images.githubusercontent.com/26864830/180248660-a0b143d0-b89a-42c5-8656-2ebf6ece7e52.png"/>
|
105 |
-
</div>
|
106 |
-
|
107 |
-
Or if you want to train your model on the [Pokemon](https://huggingface.co/datasets/huggan/pokemon) dataset:
|
108 |
-
|
109 |
-
```bash
|
110 |
-
accelerate launch train_unconditional.py \
|
111 |
-
--dataset_name="huggan/pokemon" \
|
112 |
-
--resolution=64 \
|
113 |
-
--output_dir="ddpm-ema-pokemon-64" \
|
114 |
-
--train_batch_size=16 \
|
115 |
-
--num_epochs=100 \
|
116 |
-
--gradient_accumulation_steps=1 \
|
117 |
-
--learning_rate=1e-4 \
|
118 |
-
--lr_warmup_steps=500 \
|
119 |
-
--mixed_precision=no \
|
120 |
-
--push_to_hub
|
121 |
-
```
|
122 |
-
|
123 |
-
<div class="flex justify-center">
|
124 |
-
<img src="https://user-images.githubusercontent.com/26864830/180248200-928953b4-db38-48db-b0c6-8b740fe6786f.png"/>
|
125 |
-
</div>
|
126 |
-
|
127 |
-
### Training with multiple GPUs
|
128 |
-
|
129 |
-
`accelerate` allows for seamless multi-GPU training. Follow the instructions [here](https://huggingface.co/docs/accelerate/basic_tutorials/launch)
|
130 |
-
for running distributed training with `accelerate`. Here is an example command:
|
131 |
-
|
132 |
-
```bash
|
133 |
-
accelerate launch --mixed_precision="fp16" --multi_gpu train_unconditional.py \
|
134 |
-
--dataset_name="huggan/pokemon" \
|
135 |
-
--resolution=64 --center_crop --random_flip \
|
136 |
-
--output_dir="ddpm-ema-pokemon-64" \
|
137 |
-
--train_batch_size=16 \
|
138 |
-
--num_epochs=100 \
|
139 |
-
--gradient_accumulation_steps=1 \
|
140 |
-
--use_ema \
|
141 |
-
--learning_rate=1e-4 \
|
142 |
-
--lr_warmup_steps=500 \
|
143 |
-
--mixed_precision="fp16" \
|
144 |
-
--logger="wandb" \
|
145 |
-
--push_to_hub
|
146 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Androidonnxfork/CivitAi-to-Diffusers/diffusers/src/diffusers/models/unet_2d_blocks_flax.py
DELETED
@@ -1,377 +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 |
-
import flax.linen as nn
|
16 |
-
import jax.numpy as jnp
|
17 |
-
|
18 |
-
from .attention_flax import FlaxTransformer2DModel
|
19 |
-
from .resnet_flax import FlaxDownsample2D, FlaxResnetBlock2D, FlaxUpsample2D
|
20 |
-
|
21 |
-
|
22 |
-
class FlaxCrossAttnDownBlock2D(nn.Module):
|
23 |
-
r"""
|
24 |
-
Cross Attention 2D Downsizing block - original architecture from Unet transformers:
|
25 |
-
https://arxiv.org/abs/2103.06104
|
26 |
-
|
27 |
-
Parameters:
|
28 |
-
in_channels (:obj:`int`):
|
29 |
-
Input channels
|
30 |
-
out_channels (:obj:`int`):
|
31 |
-
Output channels
|
32 |
-
dropout (:obj:`float`, *optional*, defaults to 0.0):
|
33 |
-
Dropout rate
|
34 |
-
num_layers (:obj:`int`, *optional*, defaults to 1):
|
35 |
-
Number of attention blocks layers
|
36 |
-
num_attention_heads (:obj:`int`, *optional*, defaults to 1):
|
37 |
-
Number of attention heads of each spatial transformer block
|
38 |
-
add_downsample (:obj:`bool`, *optional*, defaults to `True`):
|
39 |
-
Whether to add downsampling layer before each final output
|
40 |
-
use_memory_efficient_attention (`bool`, *optional*, defaults to `False`):
|
41 |
-
enable memory efficient attention https://arxiv.org/abs/2112.05682
|
42 |
-
dtype (:obj:`jnp.dtype`, *optional*, defaults to jnp.float32):
|
43 |
-
Parameters `dtype`
|
44 |
-
"""
|
45 |
-
in_channels: int
|
46 |
-
out_channels: int
|
47 |
-
dropout: float = 0.0
|
48 |
-
num_layers: int = 1
|
49 |
-
num_attention_heads: int = 1
|
50 |
-
add_downsample: bool = True
|
51 |
-
use_linear_projection: bool = False
|
52 |
-
only_cross_attention: bool = False
|
53 |
-
use_memory_efficient_attention: bool = False
|
54 |
-
dtype: jnp.dtype = jnp.float32
|
55 |
-
|
56 |
-
def setup(self):
|
57 |
-
resnets = []
|
58 |
-
attentions = []
|
59 |
-
|
60 |
-
for i in range(self.num_layers):
|
61 |
-
in_channels = self.in_channels if i == 0 else self.out_channels
|
62 |
-
|
63 |
-
res_block = FlaxResnetBlock2D(
|
64 |
-
in_channels=in_channels,
|
65 |
-
out_channels=self.out_channels,
|
66 |
-
dropout_prob=self.dropout,
|
67 |
-
dtype=self.dtype,
|
68 |
-
)
|
69 |
-
resnets.append(res_block)
|
70 |
-
|
71 |
-
attn_block = FlaxTransformer2DModel(
|
72 |
-
in_channels=self.out_channels,
|
73 |
-
n_heads=self.num_attention_heads,
|
74 |
-
d_head=self.out_channels // self.num_attention_heads,
|
75 |
-
depth=1,
|
76 |
-
use_linear_projection=self.use_linear_projection,
|
77 |
-
only_cross_attention=self.only_cross_attention,
|
78 |
-
use_memory_efficient_attention=self.use_memory_efficient_attention,
|
79 |
-
dtype=self.dtype,
|
80 |
-
)
|
81 |
-
attentions.append(attn_block)
|
82 |
-
|
83 |
-
self.resnets = resnets
|
84 |
-
self.attentions = attentions
|
85 |
-
|
86 |
-
if self.add_downsample:
|
87 |
-
self.downsamplers_0 = FlaxDownsample2D(self.out_channels, dtype=self.dtype)
|
88 |
-
|
89 |
-
def __call__(self, hidden_states, temb, encoder_hidden_states, deterministic=True):
|
90 |
-
output_states = ()
|
91 |
-
|
92 |
-
for resnet, attn in zip(self.resnets, self.attentions):
|
93 |
-
hidden_states = resnet(hidden_states, temb, deterministic=deterministic)
|
94 |
-
hidden_states = attn(hidden_states, encoder_hidden_states, deterministic=deterministic)
|
95 |
-
output_states += (hidden_states,)
|
96 |
-
|
97 |
-
if self.add_downsample:
|
98 |
-
hidden_states = self.downsamplers_0(hidden_states)
|
99 |
-
output_states += (hidden_states,)
|
100 |
-
|
101 |
-
return hidden_states, output_states
|
102 |
-
|
103 |
-
|
104 |
-
class FlaxDownBlock2D(nn.Module):
|
105 |
-
r"""
|
106 |
-
Flax 2D downsizing block
|
107 |
-
|
108 |
-
Parameters:
|
109 |
-
in_channels (:obj:`int`):
|
110 |
-
Input channels
|
111 |
-
out_channels (:obj:`int`):
|
112 |
-
Output channels
|
113 |
-
dropout (:obj:`float`, *optional*, defaults to 0.0):
|
114 |
-
Dropout rate
|
115 |
-
num_layers (:obj:`int`, *optional*, defaults to 1):
|
116 |
-
Number of attention blocks layers
|
117 |
-
add_downsample (:obj:`bool`, *optional*, defaults to `True`):
|
118 |
-
Whether to add downsampling layer before each final output
|
119 |
-
dtype (:obj:`jnp.dtype`, *optional*, defaults to jnp.float32):
|
120 |
-
Parameters `dtype`
|
121 |
-
"""
|
122 |
-
in_channels: int
|
123 |
-
out_channels: int
|
124 |
-
dropout: float = 0.0
|
125 |
-
num_layers: int = 1
|
126 |
-
add_downsample: bool = True
|
127 |
-
dtype: jnp.dtype = jnp.float32
|
128 |
-
|
129 |
-
def setup(self):
|
130 |
-
resnets = []
|
131 |
-
|
132 |
-
for i in range(self.num_layers):
|
133 |
-
in_channels = self.in_channels if i == 0 else self.out_channels
|
134 |
-
|
135 |
-
res_block = FlaxResnetBlock2D(
|
136 |
-
in_channels=in_channels,
|
137 |
-
out_channels=self.out_channels,
|
138 |
-
dropout_prob=self.dropout,
|
139 |
-
dtype=self.dtype,
|
140 |
-
)
|
141 |
-
resnets.append(res_block)
|
142 |
-
self.resnets = resnets
|
143 |
-
|
144 |
-
if self.add_downsample:
|
145 |
-
self.downsamplers_0 = FlaxDownsample2D(self.out_channels, dtype=self.dtype)
|
146 |
-
|
147 |
-
def __call__(self, hidden_states, temb, deterministic=True):
|
148 |
-
output_states = ()
|
149 |
-
|
150 |
-
for resnet in self.resnets:
|
151 |
-
hidden_states = resnet(hidden_states, temb, deterministic=deterministic)
|
152 |
-
output_states += (hidden_states,)
|
153 |
-
|
154 |
-
if self.add_downsample:
|
155 |
-
hidden_states = self.downsamplers_0(hidden_states)
|
156 |
-
output_states += (hidden_states,)
|
157 |
-
|
158 |
-
return hidden_states, output_states
|
159 |
-
|
160 |
-
|
161 |
-
class FlaxCrossAttnUpBlock2D(nn.Module):
|
162 |
-
r"""
|
163 |
-
Cross Attention 2D Upsampling block - original architecture from Unet transformers:
|
164 |
-
https://arxiv.org/abs/2103.06104
|
165 |
-
|
166 |
-
Parameters:
|
167 |
-
in_channels (:obj:`int`):
|
168 |
-
Input channels
|
169 |
-
out_channels (:obj:`int`):
|
170 |
-
Output channels
|
171 |
-
dropout (:obj:`float`, *optional*, defaults to 0.0):
|
172 |
-
Dropout rate
|
173 |
-
num_layers (:obj:`int`, *optional*, defaults to 1):
|
174 |
-
Number of attention blocks layers
|
175 |
-
num_attention_heads (:obj:`int`, *optional*, defaults to 1):
|
176 |
-
Number of attention heads of each spatial transformer block
|
177 |
-
add_upsample (:obj:`bool`, *optional*, defaults to `True`):
|
178 |
-
Whether to add upsampling layer before each final output
|
179 |
-
use_memory_efficient_attention (`bool`, *optional*, defaults to `False`):
|
180 |
-
enable memory efficient attention https://arxiv.org/abs/2112.05682
|
181 |
-
dtype (:obj:`jnp.dtype`, *optional*, defaults to jnp.float32):
|
182 |
-
Parameters `dtype`
|
183 |
-
"""
|
184 |
-
in_channels: int
|
185 |
-
out_channels: int
|
186 |
-
prev_output_channel: int
|
187 |
-
dropout: float = 0.0
|
188 |
-
num_layers: int = 1
|
189 |
-
num_attention_heads: int = 1
|
190 |
-
add_upsample: bool = True
|
191 |
-
use_linear_projection: bool = False
|
192 |
-
only_cross_attention: bool = False
|
193 |
-
use_memory_efficient_attention: bool = False
|
194 |
-
dtype: jnp.dtype = jnp.float32
|
195 |
-
|
196 |
-
def setup(self):
|
197 |
-
resnets = []
|
198 |
-
attentions = []
|
199 |
-
|
200 |
-
for i in range(self.num_layers):
|
201 |
-
res_skip_channels = self.in_channels if (i == self.num_layers - 1) else self.out_channels
|
202 |
-
resnet_in_channels = self.prev_output_channel if i == 0 else self.out_channels
|
203 |
-
|
204 |
-
res_block = FlaxResnetBlock2D(
|
205 |
-
in_channels=resnet_in_channels + res_skip_channels,
|
206 |
-
out_channels=self.out_channels,
|
207 |
-
dropout_prob=self.dropout,
|
208 |
-
dtype=self.dtype,
|
209 |
-
)
|
210 |
-
resnets.append(res_block)
|
211 |
-
|
212 |
-
attn_block = FlaxTransformer2DModel(
|
213 |
-
in_channels=self.out_channels,
|
214 |
-
n_heads=self.num_attention_heads,
|
215 |
-
d_head=self.out_channels // self.num_attention_heads,
|
216 |
-
depth=1,
|
217 |
-
use_linear_projection=self.use_linear_projection,
|
218 |
-
only_cross_attention=self.only_cross_attention,
|
219 |
-
use_memory_efficient_attention=self.use_memory_efficient_attention,
|
220 |
-
dtype=self.dtype,
|
221 |
-
)
|
222 |
-
attentions.append(attn_block)
|
223 |
-
|
224 |
-
self.resnets = resnets
|
225 |
-
self.attentions = attentions
|
226 |
-
|
227 |
-
if self.add_upsample:
|
228 |
-
self.upsamplers_0 = FlaxUpsample2D(self.out_channels, dtype=self.dtype)
|
229 |
-
|
230 |
-
def __call__(self, hidden_states, res_hidden_states_tuple, temb, encoder_hidden_states, deterministic=True):
|
231 |
-
for resnet, attn in zip(self.resnets, self.attentions):
|
232 |
-
# pop res hidden states
|
233 |
-
res_hidden_states = res_hidden_states_tuple[-1]
|
234 |
-
res_hidden_states_tuple = res_hidden_states_tuple[:-1]
|
235 |
-
hidden_states = jnp.concatenate((hidden_states, res_hidden_states), axis=-1)
|
236 |
-
|
237 |
-
hidden_states = resnet(hidden_states, temb, deterministic=deterministic)
|
238 |
-
hidden_states = attn(hidden_states, encoder_hidden_states, deterministic=deterministic)
|
239 |
-
|
240 |
-
if self.add_upsample:
|
241 |
-
hidden_states = self.upsamplers_0(hidden_states)
|
242 |
-
|
243 |
-
return hidden_states
|
244 |
-
|
245 |
-
|
246 |
-
class FlaxUpBlock2D(nn.Module):
|
247 |
-
r"""
|
248 |
-
Flax 2D upsampling block
|
249 |
-
|
250 |
-
Parameters:
|
251 |
-
in_channels (:obj:`int`):
|
252 |
-
Input channels
|
253 |
-
out_channels (:obj:`int`):
|
254 |
-
Output channels
|
255 |
-
prev_output_channel (:obj:`int`):
|
256 |
-
Output channels from the previous block
|
257 |
-
dropout (:obj:`float`, *optional*, defaults to 0.0):
|
258 |
-
Dropout rate
|
259 |
-
num_layers (:obj:`int`, *optional*, defaults to 1):
|
260 |
-
Number of attention blocks layers
|
261 |
-
add_downsample (:obj:`bool`, *optional*, defaults to `True`):
|
262 |
-
Whether to add downsampling layer before each final output
|
263 |
-
dtype (:obj:`jnp.dtype`, *optional*, defaults to jnp.float32):
|
264 |
-
Parameters `dtype`
|
265 |
-
"""
|
266 |
-
in_channels: int
|
267 |
-
out_channels: int
|
268 |
-
prev_output_channel: int
|
269 |
-
dropout: float = 0.0
|
270 |
-
num_layers: int = 1
|
271 |
-
add_upsample: bool = True
|
272 |
-
dtype: jnp.dtype = jnp.float32
|
273 |
-
|
274 |
-
def setup(self):
|
275 |
-
resnets = []
|
276 |
-
|
277 |
-
for i in range(self.num_layers):
|
278 |
-
res_skip_channels = self.in_channels if (i == self.num_layers - 1) else self.out_channels
|
279 |
-
resnet_in_channels = self.prev_output_channel if i == 0 else self.out_channels
|
280 |
-
|
281 |
-
res_block = FlaxResnetBlock2D(
|
282 |
-
in_channels=resnet_in_channels + res_skip_channels,
|
283 |
-
out_channels=self.out_channels,
|
284 |
-
dropout_prob=self.dropout,
|
285 |
-
dtype=self.dtype,
|
286 |
-
)
|
287 |
-
resnets.append(res_block)
|
288 |
-
|
289 |
-
self.resnets = resnets
|
290 |
-
|
291 |
-
if self.add_upsample:
|
292 |
-
self.upsamplers_0 = FlaxUpsample2D(self.out_channels, dtype=self.dtype)
|
293 |
-
|
294 |
-
def __call__(self, hidden_states, res_hidden_states_tuple, temb, deterministic=True):
|
295 |
-
for resnet in self.resnets:
|
296 |
-
# pop res hidden states
|
297 |
-
res_hidden_states = res_hidden_states_tuple[-1]
|
298 |
-
res_hidden_states_tuple = res_hidden_states_tuple[:-1]
|
299 |
-
hidden_states = jnp.concatenate((hidden_states, res_hidden_states), axis=-1)
|
300 |
-
|
301 |
-
hidden_states = resnet(hidden_states, temb, deterministic=deterministic)
|
302 |
-
|
303 |
-
if self.add_upsample:
|
304 |
-
hidden_states = self.upsamplers_0(hidden_states)
|
305 |
-
|
306 |
-
return hidden_states
|
307 |
-
|
308 |
-
|
309 |
-
class FlaxUNetMidBlock2DCrossAttn(nn.Module):
|
310 |
-
r"""
|
311 |
-
Cross Attention 2D Mid-level block - original architecture from Unet transformers: https://arxiv.org/abs/2103.06104
|
312 |
-
|
313 |
-
Parameters:
|
314 |
-
in_channels (:obj:`int`):
|
315 |
-
Input channels
|
316 |
-
dropout (:obj:`float`, *optional*, defaults to 0.0):
|
317 |
-
Dropout rate
|
318 |
-
num_layers (:obj:`int`, *optional*, defaults to 1):
|
319 |
-
Number of attention blocks layers
|
320 |
-
num_attention_heads (:obj:`int`, *optional*, defaults to 1):
|
321 |
-
Number of attention heads of each spatial transformer block
|
322 |
-
use_memory_efficient_attention (`bool`, *optional*, defaults to `False`):
|
323 |
-
enable memory efficient attention https://arxiv.org/abs/2112.05682
|
324 |
-
dtype (:obj:`jnp.dtype`, *optional*, defaults to jnp.float32):
|
325 |
-
Parameters `dtype`
|
326 |
-
"""
|
327 |
-
in_channels: int
|
328 |
-
dropout: float = 0.0
|
329 |
-
num_layers: int = 1
|
330 |
-
num_attention_heads: int = 1
|
331 |
-
use_linear_projection: bool = False
|
332 |
-
use_memory_efficient_attention: bool = False
|
333 |
-
dtype: jnp.dtype = jnp.float32
|
334 |
-
|
335 |
-
def setup(self):
|
336 |
-
# there is always at least one resnet
|
337 |
-
resnets = [
|
338 |
-
FlaxResnetBlock2D(
|
339 |
-
in_channels=self.in_channels,
|
340 |
-
out_channels=self.in_channels,
|
341 |
-
dropout_prob=self.dropout,
|
342 |
-
dtype=self.dtype,
|
343 |
-
)
|
344 |
-
]
|
345 |
-
|
346 |
-
attentions = []
|
347 |
-
|
348 |
-
for _ in range(self.num_layers):
|
349 |
-
attn_block = FlaxTransformer2DModel(
|
350 |
-
in_channels=self.in_channels,
|
351 |
-
n_heads=self.num_attention_heads,
|
352 |
-
d_head=self.in_channels // self.num_attention_heads,
|
353 |
-
depth=1,
|
354 |
-
use_linear_projection=self.use_linear_projection,
|
355 |
-
use_memory_efficient_attention=self.use_memory_efficient_attention,
|
356 |
-
dtype=self.dtype,
|
357 |
-
)
|
358 |
-
attentions.append(attn_block)
|
359 |
-
|
360 |
-
res_block = FlaxResnetBlock2D(
|
361 |
-
in_channels=self.in_channels,
|
362 |
-
out_channels=self.in_channels,
|
363 |
-
dropout_prob=self.dropout,
|
364 |
-
dtype=self.dtype,
|
365 |
-
)
|
366 |
-
resnets.append(res_block)
|
367 |
-
|
368 |
-
self.resnets = resnets
|
369 |
-
self.attentions = attentions
|
370 |
-
|
371 |
-
def __call__(self, hidden_states, temb, encoder_hidden_states, deterministic=True):
|
372 |
-
hidden_states = self.resnets[0](hidden_states, temb)
|
373 |
-
for attn, resnet in zip(self.attentions, self.resnets[1:]):
|
374 |
-
hidden_states = attn(hidden_states, encoder_hidden_states, deterministic=deterministic)
|
375 |
-
hidden_states = resnet(hidden_states, temb, deterministic=deterministic)
|
376 |
-
|
377 |
-
return hidden_states
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Andy1621/uniformer_image_detection/configs/foveabox/fovea_r101_fpn_4x4_2x_coco.py
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
_base_ = './fovea_r50_fpn_4x4_2x_coco.py'
|
2 |
-
model = dict(pretrained='torchvision://resnet101', backbone=dict(depth=101))
|
|
|
|
|
|
spaces/Andy1621/uniformer_image_detection/configs/gn+ws/mask_rcnn_r101_fpn_gn_ws-all_20_23_24e_coco.py
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
_base_ = './mask_rcnn_r101_fpn_gn_ws-all_2x_coco.py'
|
2 |
-
# learning policy
|
3 |
-
lr_config = dict(step=[20, 23])
|
4 |
-
runner = dict(type='EpochBasedRunner', max_epochs=24)
|
|
|
|
|
|
|
|
|
|
spaces/Andy1621/uniformer_image_segmentation/configs/apcnet/apcnet_r50-d8_769x769_80k_cityscapes.py
DELETED
@@ -1,9 +0,0 @@
|
|
1 |
-
_base_ = [
|
2 |
-
'../_base_/models/apcnet_r50-d8.py',
|
3 |
-
'../_base_/datasets/cityscapes_769x769.py', '../_base_/default_runtime.py',
|
4 |
-
'../_base_/schedules/schedule_80k.py'
|
5 |
-
]
|
6 |
-
model = dict(
|
7 |
-
decode_head=dict(align_corners=True),
|
8 |
-
auxiliary_head=dict(align_corners=True),
|
9 |
-
test_cfg=dict(mode='slide', crop_size=(769, 769), stride=(513, 513)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Anonymous-sub/Rerender/ControlNet/ldm/models/diffusion/dpm_solver/__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
from .sampler import DPMSolverSampler
|
|
|
|
spaces/Ataturk-Chatbot/HuggingFaceChat/venv/lib/python3.11/site-packages/pip/_vendor/pygments/lexers/__init__.py
DELETED
@@ -1,334 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
pygments.lexers
|
3 |
-
~~~~~~~~~~~~~~~
|
4 |
-
|
5 |
-
Pygments lexers.
|
6 |
-
|
7 |
-
:copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
|
8 |
-
:license: BSD, see LICENSE for details.
|
9 |
-
"""
|
10 |
-
|
11 |
-
import sys
|
12 |
-
import types
|
13 |
-
from fnmatch import fnmatch
|
14 |
-
from os.path import basename
|
15 |
-
|
16 |
-
from pip._vendor.pygments.lexers._mapping import LEXERS
|
17 |
-
from pip._vendor.pygments.modeline import get_filetype_from_buffer
|
18 |
-
from pip._vendor.pygments.plugin import find_plugin_lexers
|
19 |
-
from pip._vendor.pygments.util import ClassNotFound, guess_decode
|
20 |
-
|
21 |
-
COMPAT = {
|
22 |
-
'Python3Lexer': 'PythonLexer',
|
23 |
-
'Python3TracebackLexer': 'PythonTracebackLexer',
|
24 |
-
}
|
25 |
-
|
26 |
-
__all__ = ['get_lexer_by_name', 'get_lexer_for_filename', 'find_lexer_class',
|
27 |
-
'guess_lexer', 'load_lexer_from_file'] + list(LEXERS) + list(COMPAT)
|
28 |
-
|
29 |
-
_lexer_cache = {}
|
30 |
-
|
31 |
-
def _load_lexers(module_name):
|
32 |
-
"""Load a lexer (and all others in the module too)."""
|
33 |
-
mod = __import__(module_name, None, None, ['__all__'])
|
34 |
-
for lexer_name in mod.__all__:
|
35 |
-
cls = getattr(mod, lexer_name)
|
36 |
-
_lexer_cache[cls.name] = cls
|
37 |
-
|
38 |
-
|
39 |
-
def get_all_lexers(plugins=True):
|
40 |
-
"""Return a generator of tuples in the form ``(name, aliases,
|
41 |
-
filenames, mimetypes)`` of all know lexers.
|
42 |
-
|
43 |
-
If *plugins* is true (the default), plugin lexers supplied by entrypoints
|
44 |
-
are also returned. Otherwise, only builtin ones are considered.
|
45 |
-
"""
|
46 |
-
for item in LEXERS.values():
|
47 |
-
yield item[1:]
|
48 |
-
if plugins:
|
49 |
-
for lexer in find_plugin_lexers():
|
50 |
-
yield lexer.name, lexer.aliases, lexer.filenames, lexer.mimetypes
|
51 |
-
|
52 |
-
|
53 |
-
def find_lexer_class(name):
|
54 |
-
"""Lookup a lexer class by name.
|
55 |
-
|
56 |
-
Return None if not found.
|
57 |
-
"""
|
58 |
-
if name in _lexer_cache:
|
59 |
-
return _lexer_cache[name]
|
60 |
-
# lookup builtin lexers
|
61 |
-
for module_name, lname, aliases, _, _ in LEXERS.values():
|
62 |
-
if name == lname:
|
63 |
-
_load_lexers(module_name)
|
64 |
-
return _lexer_cache[name]
|
65 |
-
# continue with lexers from setuptools entrypoints
|
66 |
-
for cls in find_plugin_lexers():
|
67 |
-
if cls.name == name:
|
68 |
-
return cls
|
69 |
-
|
70 |
-
|
71 |
-
def find_lexer_class_by_name(_alias):
|
72 |
-
"""Lookup a lexer class by alias.
|
73 |
-
|
74 |
-
Like `get_lexer_by_name`, but does not instantiate the class.
|
75 |
-
|
76 |
-
.. versionadded:: 2.2
|
77 |
-
"""
|
78 |
-
if not _alias:
|
79 |
-
raise ClassNotFound('no lexer for alias %r found' % _alias)
|
80 |
-
# lookup builtin lexers
|
81 |
-
for module_name, name, aliases, _, _ in LEXERS.values():
|
82 |
-
if _alias.lower() in aliases:
|
83 |
-
if name not in _lexer_cache:
|
84 |
-
_load_lexers(module_name)
|
85 |
-
return _lexer_cache[name]
|
86 |
-
# continue with lexers from setuptools entrypoints
|
87 |
-
for cls in find_plugin_lexers():
|
88 |
-
if _alias.lower() in cls.aliases:
|
89 |
-
return cls
|
90 |
-
raise ClassNotFound('no lexer for alias %r found' % _alias)
|
91 |
-
|
92 |
-
|
93 |
-
def get_lexer_by_name(_alias, **options):
|
94 |
-
"""Get a lexer by an alias.
|
95 |
-
|
96 |
-
Raises ClassNotFound if not found.
|
97 |
-
"""
|
98 |
-
if not _alias:
|
99 |
-
raise ClassNotFound('no lexer for alias %r found' % _alias)
|
100 |
-
|
101 |
-
# lookup builtin lexers
|
102 |
-
for module_name, name, aliases, _, _ in LEXERS.values():
|
103 |
-
if _alias.lower() in aliases:
|
104 |
-
if name not in _lexer_cache:
|
105 |
-
_load_lexers(module_name)
|
106 |
-
return _lexer_cache[name](**options)
|
107 |
-
# continue with lexers from setuptools entrypoints
|
108 |
-
for cls in find_plugin_lexers():
|
109 |
-
if _alias.lower() in cls.aliases:
|
110 |
-
return cls(**options)
|
111 |
-
raise ClassNotFound('no lexer for alias %r found' % _alias)
|
112 |
-
|
113 |
-
|
114 |
-
def load_lexer_from_file(filename, lexername="CustomLexer", **options):
|
115 |
-
"""Load a lexer from a file.
|
116 |
-
|
117 |
-
This method expects a file located relative to the current working
|
118 |
-
directory, which contains a Lexer class. By default, it expects the
|
119 |
-
Lexer to be name CustomLexer; you can specify your own class name
|
120 |
-
as the second argument to this function.
|
121 |
-
|
122 |
-
Users should be very careful with the input, because this method
|
123 |
-
is equivalent to running eval on the input file.
|
124 |
-
|
125 |
-
Raises ClassNotFound if there are any problems importing the Lexer.
|
126 |
-
|
127 |
-
.. versionadded:: 2.2
|
128 |
-
"""
|
129 |
-
try:
|
130 |
-
# This empty dict will contain the namespace for the exec'd file
|
131 |
-
custom_namespace = {}
|
132 |
-
with open(filename, 'rb') as f:
|
133 |
-
exec(f.read(), custom_namespace)
|
134 |
-
# Retrieve the class `lexername` from that namespace
|
135 |
-
if lexername not in custom_namespace:
|
136 |
-
raise ClassNotFound('no valid %s class found in %s' %
|
137 |
-
(lexername, filename))
|
138 |
-
lexer_class = custom_namespace[lexername]
|
139 |
-
# And finally instantiate it with the options
|
140 |
-
return lexer_class(**options)
|
141 |
-
except OSError as err:
|
142 |
-
raise ClassNotFound('cannot read %s: %s' % (filename, err))
|
143 |
-
except ClassNotFound:
|
144 |
-
raise
|
145 |
-
except Exception as err:
|
146 |
-
raise ClassNotFound('error when loading custom lexer: %s' % err)
|
147 |
-
|
148 |
-
|
149 |
-
def find_lexer_class_for_filename(_fn, code=None):
|
150 |
-
"""Get a lexer for a filename.
|
151 |
-
|
152 |
-
If multiple lexers match the filename pattern, use ``analyse_text()`` to
|
153 |
-
figure out which one is more appropriate.
|
154 |
-
|
155 |
-
Returns None if not found.
|
156 |
-
"""
|
157 |
-
matches = []
|
158 |
-
fn = basename(_fn)
|
159 |
-
for modname, name, _, filenames, _ in LEXERS.values():
|
160 |
-
for filename in filenames:
|
161 |
-
if fnmatch(fn, filename):
|
162 |
-
if name not in _lexer_cache:
|
163 |
-
_load_lexers(modname)
|
164 |
-
matches.append((_lexer_cache[name], filename))
|
165 |
-
for cls in find_plugin_lexers():
|
166 |
-
for filename in cls.filenames:
|
167 |
-
if fnmatch(fn, filename):
|
168 |
-
matches.append((cls, filename))
|
169 |
-
|
170 |
-
if isinstance(code, bytes):
|
171 |
-
# decode it, since all analyse_text functions expect unicode
|
172 |
-
code = guess_decode(code)
|
173 |
-
|
174 |
-
def get_rating(info):
|
175 |
-
cls, filename = info
|
176 |
-
# explicit patterns get a bonus
|
177 |
-
bonus = '*' not in filename and 0.5 or 0
|
178 |
-
# The class _always_ defines analyse_text because it's included in
|
179 |
-
# the Lexer class. The default implementation returns None which
|
180 |
-
# gets turned into 0.0. Run scripts/detect_missing_analyse_text.py
|
181 |
-
# to find lexers which need it overridden.
|
182 |
-
if code:
|
183 |
-
return cls.analyse_text(code) + bonus, cls.__name__
|
184 |
-
return cls.priority + bonus, cls.__name__
|
185 |
-
|
186 |
-
if matches:
|
187 |
-
matches.sort(key=get_rating)
|
188 |
-
# print "Possible lexers, after sort:", matches
|
189 |
-
return matches[-1][0]
|
190 |
-
|
191 |
-
|
192 |
-
def get_lexer_for_filename(_fn, code=None, **options):
|
193 |
-
"""Get a lexer for a filename.
|
194 |
-
|
195 |
-
If multiple lexers match the filename pattern, use ``analyse_text()`` to
|
196 |
-
figure out which one is more appropriate.
|
197 |
-
|
198 |
-
Raises ClassNotFound if not found.
|
199 |
-
"""
|
200 |
-
res = find_lexer_class_for_filename(_fn, code)
|
201 |
-
if not res:
|
202 |
-
raise ClassNotFound('no lexer for filename %r found' % _fn)
|
203 |
-
return res(**options)
|
204 |
-
|
205 |
-
|
206 |
-
def get_lexer_for_mimetype(_mime, **options):
|
207 |
-
"""Get a lexer for a mimetype.
|
208 |
-
|
209 |
-
Raises ClassNotFound if not found.
|
210 |
-
"""
|
211 |
-
for modname, name, _, _, mimetypes in LEXERS.values():
|
212 |
-
if _mime in mimetypes:
|
213 |
-
if name not in _lexer_cache:
|
214 |
-
_load_lexers(modname)
|
215 |
-
return _lexer_cache[name](**options)
|
216 |
-
for cls in find_plugin_lexers():
|
217 |
-
if _mime in cls.mimetypes:
|
218 |
-
return cls(**options)
|
219 |
-
raise ClassNotFound('no lexer for mimetype %r found' % _mime)
|
220 |
-
|
221 |
-
|
222 |
-
def _iter_lexerclasses(plugins=True):
|
223 |
-
"""Return an iterator over all lexer classes."""
|
224 |
-
for key in sorted(LEXERS):
|
225 |
-
module_name, name = LEXERS[key][:2]
|
226 |
-
if name not in _lexer_cache:
|
227 |
-
_load_lexers(module_name)
|
228 |
-
yield _lexer_cache[name]
|
229 |
-
if plugins:
|
230 |
-
yield from find_plugin_lexers()
|
231 |
-
|
232 |
-
|
233 |
-
def guess_lexer_for_filename(_fn, _text, **options):
|
234 |
-
"""
|
235 |
-
Lookup all lexers that handle those filenames primary (``filenames``)
|
236 |
-
or secondary (``alias_filenames``). Then run a text analysis for those
|
237 |
-
lexers and choose the best result.
|
238 |
-
|
239 |
-
usage::
|
240 |
-
|
241 |
-
>>> from pygments.lexers import guess_lexer_for_filename
|
242 |
-
>>> guess_lexer_for_filename('hello.html', '<%= @foo %>')
|
243 |
-
<pygments.lexers.templates.RhtmlLexer object at 0xb7d2f32c>
|
244 |
-
>>> guess_lexer_for_filename('hello.html', '<h1>{{ title|e }}</h1>')
|
245 |
-
<pygments.lexers.templates.HtmlDjangoLexer object at 0xb7d2f2ac>
|
246 |
-
>>> guess_lexer_for_filename('style.css', 'a { color: <?= $link ?> }')
|
247 |
-
<pygments.lexers.templates.CssPhpLexer object at 0xb7ba518c>
|
248 |
-
"""
|
249 |
-
fn = basename(_fn)
|
250 |
-
primary = {}
|
251 |
-
matching_lexers = set()
|
252 |
-
for lexer in _iter_lexerclasses():
|
253 |
-
for filename in lexer.filenames:
|
254 |
-
if fnmatch(fn, filename):
|
255 |
-
matching_lexers.add(lexer)
|
256 |
-
primary[lexer] = True
|
257 |
-
for filename in lexer.alias_filenames:
|
258 |
-
if fnmatch(fn, filename):
|
259 |
-
matching_lexers.add(lexer)
|
260 |
-
primary[lexer] = False
|
261 |
-
if not matching_lexers:
|
262 |
-
raise ClassNotFound('no lexer for filename %r found' % fn)
|
263 |
-
if len(matching_lexers) == 1:
|
264 |
-
return matching_lexers.pop()(**options)
|
265 |
-
result = []
|
266 |
-
for lexer in matching_lexers:
|
267 |
-
rv = lexer.analyse_text(_text)
|
268 |
-
if rv == 1.0:
|
269 |
-
return lexer(**options)
|
270 |
-
result.append((rv, lexer))
|
271 |
-
|
272 |
-
def type_sort(t):
|
273 |
-
# sort by:
|
274 |
-
# - analyse score
|
275 |
-
# - is primary filename pattern?
|
276 |
-
# - priority
|
277 |
-
# - last resort: class name
|
278 |
-
return (t[0], primary[t[1]], t[1].priority, t[1].__name__)
|
279 |
-
result.sort(key=type_sort)
|
280 |
-
|
281 |
-
return result[-1][1](**options)
|
282 |
-
|
283 |
-
|
284 |
-
def guess_lexer(_text, **options):
|
285 |
-
"""Guess a lexer by strong distinctions in the text (eg, shebang)."""
|
286 |
-
|
287 |
-
if not isinstance(_text, str):
|
288 |
-
inencoding = options.get('inencoding', options.get('encoding'))
|
289 |
-
if inencoding:
|
290 |
-
_text = _text.decode(inencoding or 'utf8')
|
291 |
-
else:
|
292 |
-
_text, _ = guess_decode(_text)
|
293 |
-
|
294 |
-
# try to get a vim modeline first
|
295 |
-
ft = get_filetype_from_buffer(_text)
|
296 |
-
|
297 |
-
if ft is not None:
|
298 |
-
try:
|
299 |
-
return get_lexer_by_name(ft, **options)
|
300 |
-
except ClassNotFound:
|
301 |
-
pass
|
302 |
-
|
303 |
-
best_lexer = [0.0, None]
|
304 |
-
for lexer in _iter_lexerclasses():
|
305 |
-
rv = lexer.analyse_text(_text)
|
306 |
-
if rv == 1.0:
|
307 |
-
return lexer(**options)
|
308 |
-
if rv > best_lexer[0]:
|
309 |
-
best_lexer[:] = (rv, lexer)
|
310 |
-
if not best_lexer[0] or best_lexer[1] is None:
|
311 |
-
raise ClassNotFound('no lexer matching the text found')
|
312 |
-
return best_lexer[1](**options)
|
313 |
-
|
314 |
-
|
315 |
-
class _automodule(types.ModuleType):
|
316 |
-
"""Automatically import lexers."""
|
317 |
-
|
318 |
-
def __getattr__(self, name):
|
319 |
-
info = LEXERS.get(name)
|
320 |
-
if info:
|
321 |
-
_load_lexers(info[0])
|
322 |
-
cls = _lexer_cache[info[1]]
|
323 |
-
setattr(self, name, cls)
|
324 |
-
return cls
|
325 |
-
if name in COMPAT:
|
326 |
-
return getattr(self, COMPAT[name])
|
327 |
-
raise AttributeError(name)
|
328 |
-
|
329 |
-
|
330 |
-
oldmod = sys.modules[__name__]
|
331 |
-
newmod = _automodule(__name__)
|
332 |
-
newmod.__dict__.update(oldmod.__dict__)
|
333 |
-
sys.modules[__name__] = newmod
|
334 |
-
del newmod.newmod, newmod.oldmod, newmod.sys, newmod.types
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Ataturk-Chatbot/HuggingFaceChat/venv/lib/python3.11/site-packages/pkg_resources/_vendor/packaging/_manylinux.py
DELETED
@@ -1,301 +0,0 @@
|
|
1 |
-
import collections
|
2 |
-
import functools
|
3 |
-
import os
|
4 |
-
import re
|
5 |
-
import struct
|
6 |
-
import sys
|
7 |
-
import warnings
|
8 |
-
from typing import IO, Dict, Iterator, NamedTuple, Optional, Tuple
|
9 |
-
|
10 |
-
|
11 |
-
# Python does not provide platform information at sufficient granularity to
|
12 |
-
# identify the architecture of the running executable in some cases, so we
|
13 |
-
# determine it dynamically by reading the information from the running
|
14 |
-
# process. This only applies on Linux, which uses the ELF format.
|
15 |
-
class _ELFFileHeader:
|
16 |
-
# https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header
|
17 |
-
class _InvalidELFFileHeader(ValueError):
|
18 |
-
"""
|
19 |
-
An invalid ELF file header was found.
|
20 |
-
"""
|
21 |
-
|
22 |
-
ELF_MAGIC_NUMBER = 0x7F454C46
|
23 |
-
ELFCLASS32 = 1
|
24 |
-
ELFCLASS64 = 2
|
25 |
-
ELFDATA2LSB = 1
|
26 |
-
ELFDATA2MSB = 2
|
27 |
-
EM_386 = 3
|
28 |
-
EM_S390 = 22
|
29 |
-
EM_ARM = 40
|
30 |
-
EM_X86_64 = 62
|
31 |
-
EF_ARM_ABIMASK = 0xFF000000
|
32 |
-
EF_ARM_ABI_VER5 = 0x05000000
|
33 |
-
EF_ARM_ABI_FLOAT_HARD = 0x00000400
|
34 |
-
|
35 |
-
def __init__(self, file: IO[bytes]) -> None:
|
36 |
-
def unpack(fmt: str) -> int:
|
37 |
-
try:
|
38 |
-
data = file.read(struct.calcsize(fmt))
|
39 |
-
result: Tuple[int, ...] = struct.unpack(fmt, data)
|
40 |
-
except struct.error:
|
41 |
-
raise _ELFFileHeader._InvalidELFFileHeader()
|
42 |
-
return result[0]
|
43 |
-
|
44 |
-
self.e_ident_magic = unpack(">I")
|
45 |
-
if self.e_ident_magic != self.ELF_MAGIC_NUMBER:
|
46 |
-
raise _ELFFileHeader._InvalidELFFileHeader()
|
47 |
-
self.e_ident_class = unpack("B")
|
48 |
-
if self.e_ident_class not in {self.ELFCLASS32, self.ELFCLASS64}:
|
49 |
-
raise _ELFFileHeader._InvalidELFFileHeader()
|
50 |
-
self.e_ident_data = unpack("B")
|
51 |
-
if self.e_ident_data not in {self.ELFDATA2LSB, self.ELFDATA2MSB}:
|
52 |
-
raise _ELFFileHeader._InvalidELFFileHeader()
|
53 |
-
self.e_ident_version = unpack("B")
|
54 |
-
self.e_ident_osabi = unpack("B")
|
55 |
-
self.e_ident_abiversion = unpack("B")
|
56 |
-
self.e_ident_pad = file.read(7)
|
57 |
-
format_h = "<H" if self.e_ident_data == self.ELFDATA2LSB else ">H"
|
58 |
-
format_i = "<I" if self.e_ident_data == self.ELFDATA2LSB else ">I"
|
59 |
-
format_q = "<Q" if self.e_ident_data == self.ELFDATA2LSB else ">Q"
|
60 |
-
format_p = format_i if self.e_ident_class == self.ELFCLASS32 else format_q
|
61 |
-
self.e_type = unpack(format_h)
|
62 |
-
self.e_machine = unpack(format_h)
|
63 |
-
self.e_version = unpack(format_i)
|
64 |
-
self.e_entry = unpack(format_p)
|
65 |
-
self.e_phoff = unpack(format_p)
|
66 |
-
self.e_shoff = unpack(format_p)
|
67 |
-
self.e_flags = unpack(format_i)
|
68 |
-
self.e_ehsize = unpack(format_h)
|
69 |
-
self.e_phentsize = unpack(format_h)
|
70 |
-
self.e_phnum = unpack(format_h)
|
71 |
-
self.e_shentsize = unpack(format_h)
|
72 |
-
self.e_shnum = unpack(format_h)
|
73 |
-
self.e_shstrndx = unpack(format_h)
|
74 |
-
|
75 |
-
|
76 |
-
def _get_elf_header() -> Optional[_ELFFileHeader]:
|
77 |
-
try:
|
78 |
-
with open(sys.executable, "rb") as f:
|
79 |
-
elf_header = _ELFFileHeader(f)
|
80 |
-
except (OSError, TypeError, _ELFFileHeader._InvalidELFFileHeader):
|
81 |
-
return None
|
82 |
-
return elf_header
|
83 |
-
|
84 |
-
|
85 |
-
def _is_linux_armhf() -> bool:
|
86 |
-
# hard-float ABI can be detected from the ELF header of the running
|
87 |
-
# process
|
88 |
-
# https://static.docs.arm.com/ihi0044/g/aaelf32.pdf
|
89 |
-
elf_header = _get_elf_header()
|
90 |
-
if elf_header is None:
|
91 |
-
return False
|
92 |
-
result = elf_header.e_ident_class == elf_header.ELFCLASS32
|
93 |
-
result &= elf_header.e_ident_data == elf_header.ELFDATA2LSB
|
94 |
-
result &= elf_header.e_machine == elf_header.EM_ARM
|
95 |
-
result &= (
|
96 |
-
elf_header.e_flags & elf_header.EF_ARM_ABIMASK
|
97 |
-
) == elf_header.EF_ARM_ABI_VER5
|
98 |
-
result &= (
|
99 |
-
elf_header.e_flags & elf_header.EF_ARM_ABI_FLOAT_HARD
|
100 |
-
) == elf_header.EF_ARM_ABI_FLOAT_HARD
|
101 |
-
return result
|
102 |
-
|
103 |
-
|
104 |
-
def _is_linux_i686() -> bool:
|
105 |
-
elf_header = _get_elf_header()
|
106 |
-
if elf_header is None:
|
107 |
-
return False
|
108 |
-
result = elf_header.e_ident_class == elf_header.ELFCLASS32
|
109 |
-
result &= elf_header.e_ident_data == elf_header.ELFDATA2LSB
|
110 |
-
result &= elf_header.e_machine == elf_header.EM_386
|
111 |
-
return result
|
112 |
-
|
113 |
-
|
114 |
-
def _have_compatible_abi(arch: str) -> bool:
|
115 |
-
if arch == "armv7l":
|
116 |
-
return _is_linux_armhf()
|
117 |
-
if arch == "i686":
|
118 |
-
return _is_linux_i686()
|
119 |
-
return arch in {"x86_64", "aarch64", "ppc64", "ppc64le", "s390x"}
|
120 |
-
|
121 |
-
|
122 |
-
# If glibc ever changes its major version, we need to know what the last
|
123 |
-
# minor version was, so we can build the complete list of all versions.
|
124 |
-
# For now, guess what the highest minor version might be, assume it will
|
125 |
-
# be 50 for testing. Once this actually happens, update the dictionary
|
126 |
-
# with the actual value.
|
127 |
-
_LAST_GLIBC_MINOR: Dict[int, int] = collections.defaultdict(lambda: 50)
|
128 |
-
|
129 |
-
|
130 |
-
class _GLibCVersion(NamedTuple):
|
131 |
-
major: int
|
132 |
-
minor: int
|
133 |
-
|
134 |
-
|
135 |
-
def _glibc_version_string_confstr() -> Optional[str]:
|
136 |
-
"""
|
137 |
-
Primary implementation of glibc_version_string using os.confstr.
|
138 |
-
"""
|
139 |
-
# os.confstr is quite a bit faster than ctypes.DLL. It's also less likely
|
140 |
-
# to be broken or missing. This strategy is used in the standard library
|
141 |
-
# platform module.
|
142 |
-
# https://github.com/python/cpython/blob/fcf1d003bf4f0100c/Lib/platform.py#L175-L183
|
143 |
-
try:
|
144 |
-
# os.confstr("CS_GNU_LIBC_VERSION") returns a string like "glibc 2.17".
|
145 |
-
version_string = os.confstr("CS_GNU_LIBC_VERSION")
|
146 |
-
assert version_string is not None
|
147 |
-
_, version = version_string.split()
|
148 |
-
except (AssertionError, AttributeError, OSError, ValueError):
|
149 |
-
# os.confstr() or CS_GNU_LIBC_VERSION not available (or a bad value)...
|
150 |
-
return None
|
151 |
-
return version
|
152 |
-
|
153 |
-
|
154 |
-
def _glibc_version_string_ctypes() -> Optional[str]:
|
155 |
-
"""
|
156 |
-
Fallback implementation of glibc_version_string using ctypes.
|
157 |
-
"""
|
158 |
-
try:
|
159 |
-
import ctypes
|
160 |
-
except ImportError:
|
161 |
-
return None
|
162 |
-
|
163 |
-
# ctypes.CDLL(None) internally calls dlopen(NULL), and as the dlopen
|
164 |
-
# manpage says, "If filename is NULL, then the returned handle is for the
|
165 |
-
# main program". This way we can let the linker do the work to figure out
|
166 |
-
# which libc our process is actually using.
|
167 |
-
#
|
168 |
-
# We must also handle the special case where the executable is not a
|
169 |
-
# dynamically linked executable. This can occur when using musl libc,
|
170 |
-
# for example. In this situation, dlopen() will error, leading to an
|
171 |
-
# OSError. Interestingly, at least in the case of musl, there is no
|
172 |
-
# errno set on the OSError. The single string argument used to construct
|
173 |
-
# OSError comes from libc itself and is therefore not portable to
|
174 |
-
# hard code here. In any case, failure to call dlopen() means we
|
175 |
-
# can proceed, so we bail on our attempt.
|
176 |
-
try:
|
177 |
-
process_namespace = ctypes.CDLL(None)
|
178 |
-
except OSError:
|
179 |
-
return None
|
180 |
-
|
181 |
-
try:
|
182 |
-
gnu_get_libc_version = process_namespace.gnu_get_libc_version
|
183 |
-
except AttributeError:
|
184 |
-
# Symbol doesn't exist -> therefore, we are not linked to
|
185 |
-
# glibc.
|
186 |
-
return None
|
187 |
-
|
188 |
-
# Call gnu_get_libc_version, which returns a string like "2.5"
|
189 |
-
gnu_get_libc_version.restype = ctypes.c_char_p
|
190 |
-
version_str: str = gnu_get_libc_version()
|
191 |
-
# py2 / py3 compatibility:
|
192 |
-
if not isinstance(version_str, str):
|
193 |
-
version_str = version_str.decode("ascii")
|
194 |
-
|
195 |
-
return version_str
|
196 |
-
|
197 |
-
|
198 |
-
def _glibc_version_string() -> Optional[str]:
|
199 |
-
"""Returns glibc version string, or None if not using glibc."""
|
200 |
-
return _glibc_version_string_confstr() or _glibc_version_string_ctypes()
|
201 |
-
|
202 |
-
|
203 |
-
def _parse_glibc_version(version_str: str) -> Tuple[int, int]:
|
204 |
-
"""Parse glibc version.
|
205 |
-
|
206 |
-
We use a regexp instead of str.split because we want to discard any
|
207 |
-
random junk that might come after the minor version -- this might happen
|
208 |
-
in patched/forked versions of glibc (e.g. Linaro's version of glibc
|
209 |
-
uses version strings like "2.20-2014.11"). See gh-3588.
|
210 |
-
"""
|
211 |
-
m = re.match(r"(?P<major>[0-9]+)\.(?P<minor>[0-9]+)", version_str)
|
212 |
-
if not m:
|
213 |
-
warnings.warn(
|
214 |
-
"Expected glibc version with 2 components major.minor,"
|
215 |
-
" got: %s" % version_str,
|
216 |
-
RuntimeWarning,
|
217 |
-
)
|
218 |
-
return -1, -1
|
219 |
-
return int(m.group("major")), int(m.group("minor"))
|
220 |
-
|
221 |
-
|
222 |
-
@functools.lru_cache()
|
223 |
-
def _get_glibc_version() -> Tuple[int, int]:
|
224 |
-
version_str = _glibc_version_string()
|
225 |
-
if version_str is None:
|
226 |
-
return (-1, -1)
|
227 |
-
return _parse_glibc_version(version_str)
|
228 |
-
|
229 |
-
|
230 |
-
# From PEP 513, PEP 600
|
231 |
-
def _is_compatible(name: str, arch: str, version: _GLibCVersion) -> bool:
|
232 |
-
sys_glibc = _get_glibc_version()
|
233 |
-
if sys_glibc < version:
|
234 |
-
return False
|
235 |
-
# Check for presence of _manylinux module.
|
236 |
-
try:
|
237 |
-
import _manylinux # noqa
|
238 |
-
except ImportError:
|
239 |
-
return True
|
240 |
-
if hasattr(_manylinux, "manylinux_compatible"):
|
241 |
-
result = _manylinux.manylinux_compatible(version[0], version[1], arch)
|
242 |
-
if result is not None:
|
243 |
-
return bool(result)
|
244 |
-
return True
|
245 |
-
if version == _GLibCVersion(2, 5):
|
246 |
-
if hasattr(_manylinux, "manylinux1_compatible"):
|
247 |
-
return bool(_manylinux.manylinux1_compatible)
|
248 |
-
if version == _GLibCVersion(2, 12):
|
249 |
-
if hasattr(_manylinux, "manylinux2010_compatible"):
|
250 |
-
return bool(_manylinux.manylinux2010_compatible)
|
251 |
-
if version == _GLibCVersion(2, 17):
|
252 |
-
if hasattr(_manylinux, "manylinux2014_compatible"):
|
253 |
-
return bool(_manylinux.manylinux2014_compatible)
|
254 |
-
return True
|
255 |
-
|
256 |
-
|
257 |
-
_LEGACY_MANYLINUX_MAP = {
|
258 |
-
# CentOS 7 w/ glibc 2.17 (PEP 599)
|
259 |
-
(2, 17): "manylinux2014",
|
260 |
-
# CentOS 6 w/ glibc 2.12 (PEP 571)
|
261 |
-
(2, 12): "manylinux2010",
|
262 |
-
# CentOS 5 w/ glibc 2.5 (PEP 513)
|
263 |
-
(2, 5): "manylinux1",
|
264 |
-
}
|
265 |
-
|
266 |
-
|
267 |
-
def platform_tags(linux: str, arch: str) -> Iterator[str]:
|
268 |
-
if not _have_compatible_abi(arch):
|
269 |
-
return
|
270 |
-
# Oldest glibc to be supported regardless of architecture is (2, 17).
|
271 |
-
too_old_glibc2 = _GLibCVersion(2, 16)
|
272 |
-
if arch in {"x86_64", "i686"}:
|
273 |
-
# On x86/i686 also oldest glibc to be supported is (2, 5).
|
274 |
-
too_old_glibc2 = _GLibCVersion(2, 4)
|
275 |
-
current_glibc = _GLibCVersion(*_get_glibc_version())
|
276 |
-
glibc_max_list = [current_glibc]
|
277 |
-
# We can assume compatibility across glibc major versions.
|
278 |
-
# https://sourceware.org/bugzilla/show_bug.cgi?id=24636
|
279 |
-
#
|
280 |
-
# Build a list of maximum glibc versions so that we can
|
281 |
-
# output the canonical list of all glibc from current_glibc
|
282 |
-
# down to too_old_glibc2, including all intermediary versions.
|
283 |
-
for glibc_major in range(current_glibc.major - 1, 1, -1):
|
284 |
-
glibc_minor = _LAST_GLIBC_MINOR[glibc_major]
|
285 |
-
glibc_max_list.append(_GLibCVersion(glibc_major, glibc_minor))
|
286 |
-
for glibc_max in glibc_max_list:
|
287 |
-
if glibc_max.major == too_old_glibc2.major:
|
288 |
-
min_minor = too_old_glibc2.minor
|
289 |
-
else:
|
290 |
-
# For other glibc major versions oldest supported is (x, 0).
|
291 |
-
min_minor = -1
|
292 |
-
for glibc_minor in range(glibc_max.minor, min_minor, -1):
|
293 |
-
glibc_version = _GLibCVersion(glibc_max.major, glibc_minor)
|
294 |
-
tag = "manylinux_{}_{}".format(*glibc_version)
|
295 |
-
if _is_compatible(tag, arch, glibc_version):
|
296 |
-
yield linux.replace("linux", tag)
|
297 |
-
# Handle the legacy manylinux1, manylinux2010, manylinux2014 tags.
|
298 |
-
if glibc_version in _LEGACY_MANYLINUX_MAP:
|
299 |
-
legacy_tag = _LEGACY_MANYLINUX_MAP[glibc_version]
|
300 |
-
if _is_compatible(legacy_tag, arch, glibc_version):
|
301 |
-
yield linux.replace("linux", legacy_tag)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Ataturk-Chatbot/HuggingFaceChat/venv/lib/python3.11/site-packages/setuptools/command/upload_docs.py
DELETED
@@ -1,213 +0,0 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
"""upload_docs
|
3 |
-
|
4 |
-
Implements a Distutils 'upload_docs' subcommand (upload documentation to
|
5 |
-
sites other than PyPi such as devpi).
|
6 |
-
"""
|
7 |
-
|
8 |
-
from base64 import standard_b64encode
|
9 |
-
from distutils import log
|
10 |
-
from distutils.errors import DistutilsOptionError
|
11 |
-
import os
|
12 |
-
import socket
|
13 |
-
import zipfile
|
14 |
-
import tempfile
|
15 |
-
import shutil
|
16 |
-
import itertools
|
17 |
-
import functools
|
18 |
-
import http.client
|
19 |
-
import urllib.parse
|
20 |
-
import warnings
|
21 |
-
|
22 |
-
from .._importlib import metadata
|
23 |
-
from .. import SetuptoolsDeprecationWarning
|
24 |
-
|
25 |
-
from .upload import upload
|
26 |
-
|
27 |
-
|
28 |
-
def _encode(s):
|
29 |
-
return s.encode('utf-8', 'surrogateescape')
|
30 |
-
|
31 |
-
|
32 |
-
class upload_docs(upload):
|
33 |
-
# override the default repository as upload_docs isn't
|
34 |
-
# supported by Warehouse (and won't be).
|
35 |
-
DEFAULT_REPOSITORY = 'https://pypi.python.org/pypi/'
|
36 |
-
|
37 |
-
description = 'Upload documentation to sites other than PyPi such as devpi'
|
38 |
-
|
39 |
-
user_options = [
|
40 |
-
('repository=', 'r',
|
41 |
-
"url of repository [default: %s]" % upload.DEFAULT_REPOSITORY),
|
42 |
-
('show-response', None,
|
43 |
-
'display full response text from server'),
|
44 |
-
('upload-dir=', None, 'directory to upload'),
|
45 |
-
]
|
46 |
-
boolean_options = upload.boolean_options
|
47 |
-
|
48 |
-
def has_sphinx(self):
|
49 |
-
return bool(
|
50 |
-
self.upload_dir is None
|
51 |
-
and metadata.entry_points(group='distutils.commands', name='build_sphinx')
|
52 |
-
)
|
53 |
-
|
54 |
-
sub_commands = [('build_sphinx', has_sphinx)]
|
55 |
-
|
56 |
-
def initialize_options(self):
|
57 |
-
upload.initialize_options(self)
|
58 |
-
self.upload_dir = None
|
59 |
-
self.target_dir = None
|
60 |
-
|
61 |
-
def finalize_options(self):
|
62 |
-
log.warn(
|
63 |
-
"Upload_docs command is deprecated. Use Read the Docs "
|
64 |
-
"(https://readthedocs.org) instead.")
|
65 |
-
upload.finalize_options(self)
|
66 |
-
if self.upload_dir is None:
|
67 |
-
if self.has_sphinx():
|
68 |
-
build_sphinx = self.get_finalized_command('build_sphinx')
|
69 |
-
self.target_dir = dict(build_sphinx.builder_target_dirs)['html']
|
70 |
-
else:
|
71 |
-
build = self.get_finalized_command('build')
|
72 |
-
self.target_dir = os.path.join(build.build_base, 'docs')
|
73 |
-
else:
|
74 |
-
self.ensure_dirname('upload_dir')
|
75 |
-
self.target_dir = self.upload_dir
|
76 |
-
self.announce('Using upload directory %s' % self.target_dir)
|
77 |
-
|
78 |
-
def create_zipfile(self, filename):
|
79 |
-
zip_file = zipfile.ZipFile(filename, "w")
|
80 |
-
try:
|
81 |
-
self.mkpath(self.target_dir) # just in case
|
82 |
-
for root, dirs, files in os.walk(self.target_dir):
|
83 |
-
if root == self.target_dir and not files:
|
84 |
-
tmpl = "no files found in upload directory '%s'"
|
85 |
-
raise DistutilsOptionError(tmpl % self.target_dir)
|
86 |
-
for name in files:
|
87 |
-
full = os.path.join(root, name)
|
88 |
-
relative = root[len(self.target_dir):].lstrip(os.path.sep)
|
89 |
-
dest = os.path.join(relative, name)
|
90 |
-
zip_file.write(full, dest)
|
91 |
-
finally:
|
92 |
-
zip_file.close()
|
93 |
-
|
94 |
-
def run(self):
|
95 |
-
warnings.warn(
|
96 |
-
"upload_docs is deprecated and will be removed in a future "
|
97 |
-
"version. Use tools like httpie or curl instead.",
|
98 |
-
SetuptoolsDeprecationWarning,
|
99 |
-
)
|
100 |
-
|
101 |
-
# Run sub commands
|
102 |
-
for cmd_name in self.get_sub_commands():
|
103 |
-
self.run_command(cmd_name)
|
104 |
-
|
105 |
-
tmp_dir = tempfile.mkdtemp()
|
106 |
-
name = self.distribution.metadata.get_name()
|
107 |
-
zip_file = os.path.join(tmp_dir, "%s.zip" % name)
|
108 |
-
try:
|
109 |
-
self.create_zipfile(zip_file)
|
110 |
-
self.upload_file(zip_file)
|
111 |
-
finally:
|
112 |
-
shutil.rmtree(tmp_dir)
|
113 |
-
|
114 |
-
@staticmethod
|
115 |
-
def _build_part(item, sep_boundary):
|
116 |
-
key, values = item
|
117 |
-
title = '\nContent-Disposition: form-data; name="%s"' % key
|
118 |
-
# handle multiple entries for the same name
|
119 |
-
if not isinstance(values, list):
|
120 |
-
values = [values]
|
121 |
-
for value in values:
|
122 |
-
if isinstance(value, tuple):
|
123 |
-
title += '; filename="%s"' % value[0]
|
124 |
-
value = value[1]
|
125 |
-
else:
|
126 |
-
value = _encode(value)
|
127 |
-
yield sep_boundary
|
128 |
-
yield _encode(title)
|
129 |
-
yield b"\n\n"
|
130 |
-
yield value
|
131 |
-
if value and value[-1:] == b'\r':
|
132 |
-
yield b'\n' # write an extra newline (lurve Macs)
|
133 |
-
|
134 |
-
@classmethod
|
135 |
-
def _build_multipart(cls, data):
|
136 |
-
"""
|
137 |
-
Build up the MIME payload for the POST data
|
138 |
-
"""
|
139 |
-
boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
|
140 |
-
sep_boundary = b'\n--' + boundary.encode('ascii')
|
141 |
-
end_boundary = sep_boundary + b'--'
|
142 |
-
end_items = end_boundary, b"\n",
|
143 |
-
builder = functools.partial(
|
144 |
-
cls._build_part,
|
145 |
-
sep_boundary=sep_boundary,
|
146 |
-
)
|
147 |
-
part_groups = map(builder, data.items())
|
148 |
-
parts = itertools.chain.from_iterable(part_groups)
|
149 |
-
body_items = itertools.chain(parts, end_items)
|
150 |
-
content_type = 'multipart/form-data; boundary=%s' % boundary
|
151 |
-
return b''.join(body_items), content_type
|
152 |
-
|
153 |
-
def upload_file(self, filename):
|
154 |
-
with open(filename, 'rb') as f:
|
155 |
-
content = f.read()
|
156 |
-
meta = self.distribution.metadata
|
157 |
-
data = {
|
158 |
-
':action': 'doc_upload',
|
159 |
-
'name': meta.get_name(),
|
160 |
-
'content': (os.path.basename(filename), content),
|
161 |
-
}
|
162 |
-
# set up the authentication
|
163 |
-
credentials = _encode(self.username + ':' + self.password)
|
164 |
-
credentials = standard_b64encode(credentials).decode('ascii')
|
165 |
-
auth = "Basic " + credentials
|
166 |
-
|
167 |
-
body, ct = self._build_multipart(data)
|
168 |
-
|
169 |
-
msg = "Submitting documentation to %s" % (self.repository)
|
170 |
-
self.announce(msg, log.INFO)
|
171 |
-
|
172 |
-
# build the Request
|
173 |
-
# We can't use urllib2 since we need to send the Basic
|
174 |
-
# auth right with the first request
|
175 |
-
schema, netloc, url, params, query, fragments = \
|
176 |
-
urllib.parse.urlparse(self.repository)
|
177 |
-
assert not params and not query and not fragments
|
178 |
-
if schema == 'http':
|
179 |
-
conn = http.client.HTTPConnection(netloc)
|
180 |
-
elif schema == 'https':
|
181 |
-
conn = http.client.HTTPSConnection(netloc)
|
182 |
-
else:
|
183 |
-
raise AssertionError("unsupported schema " + schema)
|
184 |
-
|
185 |
-
data = ''
|
186 |
-
try:
|
187 |
-
conn.connect()
|
188 |
-
conn.putrequest("POST", url)
|
189 |
-
content_type = ct
|
190 |
-
conn.putheader('Content-type', content_type)
|
191 |
-
conn.putheader('Content-length', str(len(body)))
|
192 |
-
conn.putheader('Authorization', auth)
|
193 |
-
conn.endheaders()
|
194 |
-
conn.send(body)
|
195 |
-
except socket.error as e:
|
196 |
-
self.announce(str(e), log.ERROR)
|
197 |
-
return
|
198 |
-
|
199 |
-
r = conn.getresponse()
|
200 |
-
if r.status == 200:
|
201 |
-
msg = 'Server response (%s): %s' % (r.status, r.reason)
|
202 |
-
self.announce(msg, log.INFO)
|
203 |
-
elif r.status == 301:
|
204 |
-
location = r.getheader('Location')
|
205 |
-
if location is None:
|
206 |
-
location = 'https://pythonhosted.org/%s/' % meta.get_name()
|
207 |
-
msg = 'Upload successful. Visit %s' % location
|
208 |
-
self.announce(msg, log.INFO)
|
209 |
-
else:
|
210 |
-
msg = 'Upload failed (%s): %s' % (r.status, r.reason)
|
211 |
-
self.announce(msg, log.ERROR)
|
212 |
-
if self.show_response:
|
213 |
-
print('-' * 75, r.read(), '-' * 75)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Audio-AGI/WavJourney/Dockerfile
DELETED
@@ -1,75 +0,0 @@
|
|
1 |
-
FROM python:3.11
|
2 |
-
|
3 |
-
FROM nvidia/cuda:11.7.1-cudnn8-devel-ubuntu22.04
|
4 |
-
ENV DEBIAN_FRONTEND=noninteractive
|
5 |
-
|
6 |
-
RUN apt-get update && \
|
7 |
-
apt-get upgrade -y && \
|
8 |
-
apt-get install -y --no-install-recommends \
|
9 |
-
git \
|
10 |
-
git-lfs \
|
11 |
-
wget \
|
12 |
-
curl \
|
13 |
-
# python build dependencies \
|
14 |
-
build-essential \
|
15 |
-
libssl-dev \
|
16 |
-
zlib1g-dev \
|
17 |
-
libbz2-dev \
|
18 |
-
libreadline-dev \
|
19 |
-
libsqlite3-dev \
|
20 |
-
libncursesw5-dev \
|
21 |
-
xz-utils \
|
22 |
-
tk-dev \
|
23 |
-
libxml2-dev \
|
24 |
-
libxmlsec1-dev \
|
25 |
-
libffi-dev \
|
26 |
-
liblzma-dev \
|
27 |
-
# gradio dependencies \
|
28 |
-
ffmpeg \
|
29 |
-
# fairseq2 dependencies \
|
30 |
-
libsndfile-dev && \
|
31 |
-
apt-get clean && \
|
32 |
-
rm -rf /var/lib/apt/lists/*
|
33 |
-
|
34 |
-
|
35 |
-
# Install miniconda
|
36 |
-
RUN apt-get install -y wget && rm -rf /var/lib/apt/lists/*
|
37 |
-
|
38 |
-
RUN wget \
|
39 |
-
https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
|
40 |
-
&& bash Miniconda3-latest-Linux-x86_64.sh -b -p /opt/miniconda3 \
|
41 |
-
&& rm -f Miniconda3-latest-Linux-x86_64.sh
|
42 |
-
|
43 |
-
# Set up a new user named "user" with user ID 1000
|
44 |
-
RUN useradd -m -u 1000 user
|
45 |
-
|
46 |
-
# Switch to the "user" user
|
47 |
-
USER user
|
48 |
-
|
49 |
-
# Add conda binary to PATH variable
|
50 |
-
ENV HOME=/home/user \
|
51 |
-
PATH=/opt/miniconda3/bin:/home/user/.local/bin:$PATH \
|
52 |
-
CONDA_PREFIX=/opt/miniconda3/envs
|
53 |
-
|
54 |
-
# Setup conda envs
|
55 |
-
WORKDIR $HOME/app
|
56 |
-
COPY --chown=user . $HOME/app
|
57 |
-
|
58 |
-
# Conda envs setup
|
59 |
-
RUN bash ./scripts/EnvsSetup.sh
|
60 |
-
|
61 |
-
# pre-download all models
|
62 |
-
RUN conda run --live-stream -n WavJourney python scripts/download_models.py
|
63 |
-
RUN mkdir $HOME/app/services_logs
|
64 |
-
|
65 |
-
# Env settings to get docker images to work on HF Spaces
|
66 |
-
ENV PYTHONPATH=${HOME}/app \
|
67 |
-
PYTHONUNBUFFERED=1 \
|
68 |
-
GRADIO_ALLOW_FLAGGING=never \
|
69 |
-
GRADIO_NUM_PORTS=1 \
|
70 |
-
GRADIO_SERVER_NAME=0.0.0.0 \
|
71 |
-
GRADIO_THEME=huggingface \
|
72 |
-
SYSTEM=spaces
|
73 |
-
|
74 |
-
# entrypoint
|
75 |
-
ENTRYPOINT bash /home/user/app/scripts/start_service_and_ui.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Awiny/Image2Paragraph/models/grit_src/third_party/CenterNet2/docs/tutorials/write-models.md
DELETED
@@ -1,90 +0,0 @@
|
|
1 |
-
# Write Models
|
2 |
-
|
3 |
-
If you are trying to do something completely new, you may wish to implement
|
4 |
-
a model entirely from scratch. However, in many situations you may
|
5 |
-
be interested in modifying or extending some components of an existing model.
|
6 |
-
Therefore, we also provide mechanisms that let users override the
|
7 |
-
behavior of certain internal components of standard models.
|
8 |
-
|
9 |
-
|
10 |
-
## Register New Components
|
11 |
-
|
12 |
-
For common concepts that users often want to customize, such as "backbone feature extractor", "box head",
|
13 |
-
we provide a registration mechanism for users to inject custom implementation that
|
14 |
-
will be immediately available to use in config files.
|
15 |
-
|
16 |
-
For example, to add a new backbone, import this code in your code:
|
17 |
-
```python
|
18 |
-
from detectron2.modeling import BACKBONE_REGISTRY, Backbone, ShapeSpec
|
19 |
-
|
20 |
-
@BACKBONE_REGISTRY.register()
|
21 |
-
class ToyBackbone(Backbone):
|
22 |
-
def __init__(self, cfg, input_shape):
|
23 |
-
super().__init__()
|
24 |
-
# create your own backbone
|
25 |
-
self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=16, padding=3)
|
26 |
-
|
27 |
-
def forward(self, image):
|
28 |
-
return {"conv1": self.conv1(image)}
|
29 |
-
|
30 |
-
def output_shape(self):
|
31 |
-
return {"conv1": ShapeSpec(channels=64, stride=16)}
|
32 |
-
```
|
33 |
-
|
34 |
-
In this code, we implement a new backbone following the interface of the
|
35 |
-
[Backbone](../modules/modeling.html#detectron2.modeling.Backbone) class,
|
36 |
-
and register it into the [BACKBONE_REGISTRY](../modules/modeling.html#detectron2.modeling.BACKBONE_REGISTRY)
|
37 |
-
which requires subclasses of `Backbone`.
|
38 |
-
After importing this code, detectron2 can link the name of the class to its implementation. Therefore you can write the following code:
|
39 |
-
|
40 |
-
```python
|
41 |
-
cfg = ... # read a config
|
42 |
-
cfg.MODEL.BACKBONE.NAME = 'ToyBackbone' # or set it in the config file
|
43 |
-
model = build_model(cfg) # it will find `ToyBackbone` defined above
|
44 |
-
```
|
45 |
-
|
46 |
-
As another example, to add new abilities to the ROI heads in the Generalized R-CNN meta-architecture,
|
47 |
-
you can implement a new
|
48 |
-
[ROIHeads](../modules/modeling.html#detectron2.modeling.ROIHeads) subclass and put it in the `ROI_HEADS_REGISTRY`.
|
49 |
-
[DensePose](../../projects/DensePose)
|
50 |
-
and [MeshRCNN](https://github.com/facebookresearch/meshrcnn)
|
51 |
-
are two examples that implement new ROIHeads to perform new tasks.
|
52 |
-
And [projects/](../../projects/)
|
53 |
-
contains more examples that implement different architectures.
|
54 |
-
|
55 |
-
A complete list of registries can be found in [API documentation](../modules/modeling.html#model-registries).
|
56 |
-
You can register components in these registries to customize different parts of a model, or the
|
57 |
-
entire model.
|
58 |
-
|
59 |
-
## Construct Models with Explicit Arguments
|
60 |
-
|
61 |
-
Registry is a bridge to connect names in config files to the actual code.
|
62 |
-
They are meant to cover a few main components that users frequently need to replace.
|
63 |
-
However, the capability of a text-based config file is sometimes limited and
|
64 |
-
some deeper customization may be available only through writing code.
|
65 |
-
|
66 |
-
Most model components in detectron2 have a clear `__init__` interface that documents
|
67 |
-
what input arguments it needs. Calling them with custom arguments will give you a custom variant
|
68 |
-
of the model.
|
69 |
-
|
70 |
-
As an example, to use __custom loss function__ in the box head of a Faster R-CNN, we can do the following:
|
71 |
-
|
72 |
-
1. Losses are currently computed in [FastRCNNOutputLayers](../modules/modeling.html#detectron2.modeling.FastRCNNOutputLayers).
|
73 |
-
We need to implement a variant or a subclass of it, with custom loss functions, named `MyRCNNOutput`.
|
74 |
-
2. Call `StandardROIHeads` with `box_predictor=MyRCNNOutput()` argument instead of the builtin `FastRCNNOutputLayers`.
|
75 |
-
If all other arguments should stay unchanged, this can be easily achieved by using the [configurable `__init__`](../modules/config.html#detectron2.config.configurable) mechanism:
|
76 |
-
|
77 |
-
```python
|
78 |
-
roi_heads = StandardROIHeads(
|
79 |
-
cfg, backbone.output_shape(),
|
80 |
-
box_predictor=MyRCNNOutput(...)
|
81 |
-
)
|
82 |
-
```
|
83 |
-
3. (optional) If we want to enable this new model from a config file, registration is needed:
|
84 |
-
```python
|
85 |
-
@ROI_HEADS_REGISTRY.register()
|
86 |
-
class MyStandardROIHeads(StandardROIHeads):
|
87 |
-
def __init__(self, cfg, input_shape):
|
88 |
-
super().__init__(cfg, input_shape,
|
89 |
-
box_predictor=MyRCNNOutput(...))
|
90 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Awiny/Image2Paragraph/models/grit_src/third_party/CenterNet2/tests/modeling/test_matcher.py
DELETED
@@ -1,42 +0,0 @@
|
|
1 |
-
# Copyright (c) Facebook, Inc. and its affiliates.
|
2 |
-
import unittest
|
3 |
-
from typing import List
|
4 |
-
import torch
|
5 |
-
|
6 |
-
from detectron2.config import get_cfg
|
7 |
-
from detectron2.modeling.matcher import Matcher
|
8 |
-
|
9 |
-
|
10 |
-
class TestMatcher(unittest.TestCase):
|
11 |
-
def test_scriptability(self):
|
12 |
-
cfg = get_cfg()
|
13 |
-
anchor_matcher = Matcher(
|
14 |
-
cfg.MODEL.RPN.IOU_THRESHOLDS, cfg.MODEL.RPN.IOU_LABELS, allow_low_quality_matches=True
|
15 |
-
)
|
16 |
-
match_quality_matrix = torch.tensor(
|
17 |
-
[[0.15, 0.45, 0.2, 0.6], [0.3, 0.65, 0.05, 0.1], [0.05, 0.4, 0.25, 0.4]]
|
18 |
-
)
|
19 |
-
expected_matches = torch.tensor([1, 1, 2, 0])
|
20 |
-
expected_match_labels = torch.tensor([-1, 1, 0, 1], dtype=torch.int8)
|
21 |
-
|
22 |
-
matches, match_labels = anchor_matcher(match_quality_matrix)
|
23 |
-
self.assertTrue(torch.allclose(matches, expected_matches))
|
24 |
-
self.assertTrue(torch.allclose(match_labels, expected_match_labels))
|
25 |
-
|
26 |
-
# nonzero_tuple must be import explicitly to let jit know what it is.
|
27 |
-
# https://github.com/pytorch/pytorch/issues/38964
|
28 |
-
from detectron2.layers import nonzero_tuple # noqa F401
|
29 |
-
|
30 |
-
def f(thresholds: List[float], labels: List[int]):
|
31 |
-
return Matcher(thresholds, labels, allow_low_quality_matches=True)
|
32 |
-
|
33 |
-
scripted_anchor_matcher = torch.jit.script(f)(
|
34 |
-
cfg.MODEL.RPN.IOU_THRESHOLDS, cfg.MODEL.RPN.IOU_LABELS
|
35 |
-
)
|
36 |
-
matches, match_labels = scripted_anchor_matcher(match_quality_matrix)
|
37 |
-
self.assertTrue(torch.allclose(matches, expected_matches))
|
38 |
-
self.assertTrue(torch.allclose(match_labels, expected_match_labels))
|
39 |
-
|
40 |
-
|
41 |
-
if __name__ == "__main__":
|
42 |
-
unittest.main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Benson/text-generation/Examples/Bus Simulator Indonesia Apk New.md
DELETED
@@ -1,83 +0,0 @@
|
|
1 |
-
|
2 |
-
<h1>Simulador de autobús Indonesia APK Nuevo: Una manera divertida y auténtica de experimentar la conducción en Indonesia</h1>
|
3 |
-
<p>¿Alguna vez te has preguntado cómo es ser conductor de autobús en Indonesia? ¿Quieres explorar los diversos y hermosos paisajes de este país mientras transportas pasajeros de un lugar a otro? Si respondiste sí, entonces usted debe probar Bus Simulator Indonesia APK Nuevo, un juego móvil que le permite experimentar la emoción y el desafío de conducir un autobús en Indonesia.</p>
|
4 |
-
<h2>¿Qué es Bus Simulator Indonesia APK Nuevo? </h2>
|
5 |
-
<p>Simulador de autobús Indonesia APK Nuevo, o BUSSID, es un juego para móviles desarrollado por Maleo, un desarrollador de juegos de Indonesia. Es uno de los juegos de simulador de bus más populares y realistas en Android, con más de 100 millones de descargas en Google Play. También es uno de los únicos juegos de simulador de bus con más características y el entorno indonesio más auténtico. </p>
|
6 |
-
<h2>bus simulator indonesia apk new</h2><br /><p><b><b>Download Zip</b> > <a href="https://bltlly.com/2v6MMO">https://bltlly.com/2v6MMO</a></b></p><br /><br />
|
7 |
-
<p>En este juego, puedes elegir entre varios tipos de autobuses, como autobuses urbanos, interurbanos o incluso de dos pisos, y conducirlos a través de diferentes ciudades y lugares en Indonesia, como Yakarta, Surabaya, Bali o Sumatra. También puede diseñar su propia librea, personalizar su autobús con accesorios y tocar la bocina con el famoso sonido "Om Telolet Om". También puedes competir con otros jugadores en la clasificación o unirte a ellos en convoyes multijugador en línea. </p>
|
8 |
-
<h3>Características del simulador de autobús Indonesia APK Nuevo</h3>
|
9 |
-
<p>Simulador de autobús Indonesia APK Nuevo tiene muchas características que lo hacen destacar de otros juegos de simulador de autobús. Aquí están algunos de ellos:</p>
|
10 |
-
<h4>Diseña tu propia librea</h4>
|
11 |
-
<p>Puede dar rienda suelta a su creatividad y diseñar su propia librea para su autobús utilizando el editor incorporado. Puede elegir entre diferentes colores, patrones, pegatinas, logotipos y más. También puede compartir su librea con otros jugadores o descargar sus libreas de la galería en línea. </p>
|
12 |
-
<h4>Control fácil e intuitivo</h4>
|
13 |
-
|
14 |
-
<h4>Ciudades y lugares auténticos de Indonesia</h4>
|
15 |
-
<p>Puede conducir su autobús a través de varias ciudades y lugares en Indonesia que se recrean fielmente en el juego. Puede ver los puntos de referencia, edificios, carreteras, señales de tráfico, peatones, vehículos y más que son típicos de cada lugar. También puede experimentar las condiciones climáticas, la hora del día y las estaciones que cambian dinámicamente. </p>
|
16 |
-
<h4>Autobuses indonesios</h4>
|
17 |
-
<p>Puede elegir entre una amplia gama de autobuses que se basan en modelos de la vida real de los fabricantes de autobuses de Indonesia. Puedes ver los detalles, interiores, sonidos y animaciones de cada autobús. También puede actualizar su autobús con diferentes partes, como motores, transmisiones, neumáticos, suspensiones, frenos, luces, bocinas y más. </p>
|
18 |
-
<h4>Bocinazos frescos y divertidos</h4>
|
19 |
-
<p>Usted puede tocar la bocina con los sonidos frescos y divertidos que son exclusivos de los autobuses de Indonesia. Puedes escuchar el sonido "Om Telolet Om" que se convirtió en un fenómeno viral en 2016, u otros sonidos inspirados en géneros musicales, como dangdut, pop, rock o EDM. También puedes personalizar tu bocina con diferentes efectos, como eco, reverberación, tono o velocidad. </p>
|
20 |
-
<p></p>
|
21 |
-
<h4> Alta calidad y gráficos 3D detallados</h4>
|
22 |
-
<p>Puedes disfrutar de los gráficos 3D de alta calidad y detallados que hacen que el juego se vea realista e inmersivo. Puedes ver las sombras, reflejos, texturas, partículas y efectos que hacen que el juego se vea impresionante. También puede ajustar la configuración de gráficos para adaptarse al rendimiento de su dispositivo. </p>
|
23 |
-
<h4>No hay anuncios obstructivos durante la conducción</h4>
|
24 |
-
<p>Puedes jugar el juego sin ser interrumpido por anuncios molestos mientras conduces. Aún puedes ver anuncios voluntariamente para obtener recompensas, como monedas, combustible o boletos. También puedes apoyar al desarrollador comprando la versión premium del juego, que elimina todos los anuncios y te da más beneficios. </p>
|
25 |
-
<h4> Clasificación y convoy multijugador en línea</h4>
|
26 |
-
|
27 |
-
<h4>Sistema de modificación de vehículos</h4>
|
28 |
-
<p>Puedes modificar tu vehículo con el sistema de modificación de vehículo que te permite añadir vehículos personalizados al juego. Puede descargar mods de vehículos desde la galería en línea o crear su propio uso de las herramientas de mod proporcionadas por el desarrollador. También puedes compartir tus mods con otros jugadores o usar sus mods en tu juego. </p>
|
29 |
-
<h3>Cómo descargar e instalar Bus Simulator Indonesia APK Nuevo? </h3>
|
30 |
-
<p>Para descargar e instalar Bus Simulator Indonesia APK Nuevo, es necesario seguir estos pasos:</p>
|
31 |
-
<ol>
|
32 |
-
<li>Ir a la página web oficial de Bus Simulator Indonesia APK Nuevo y haga clic en el botón de descarga. </li>
|
33 |
-
<li>Espere a que la descarga termine y localice el archivo APK en su dispositivo. </li>
|
34 |
-
<li>Habilitar la instalación de aplicaciones de fuentes desconocidas en la configuración del dispositivo. </li>
|
35 |
-
<li>Toque en el archivo APK y siga las instrucciones para instalar el juego. </li>
|
36 |
-
<li>Iniciar el juego y disfrutar de la conducción en Indonesia.</li>
|
37 |
-
</ol>
|
38 |
-
<h3> Pros y contras de Bus Simulator Indonesia APK Nuevo</h3>
|
39 |
-
<p>Simulador de autobús Indonesia APK Nuevo tiene muchos pros y contras que usted debe considerar antes de jugar. Estos son algunos de ellos:</p>
|
40 |
-
<tabla>
|
41 |
-
<tr>
|
42 |
-
<th>Pros</th>
|
43 |
-
<th>Contras</th>
|
44 |
-
</tr>
|
45 |
-
<tr>
|
46 |
-
<td>Juego divertido y realista</td>
|
47 |
-
<td>Errores y fallas potenciales</td>
|
48 |
-
</tr>
|
49 |
-
<tr>
|
50 |
-
<td>Auténtico entorno indonesio</td>
|
51 |
-
<td>Gran tamaño de archivo y espacio de almacenamiento</td>
|
52 |
-
</tr>
|
53 |
-
<tr>
|
54 |
-
<td>Características creativas y personalizables</td>
|
55 |
-
<td>Requiere conexión a Internet para algunas funciones</td>
|
56 |
-
</tr>
|
57 |
-
<tr>
|
58 |
-
<td>No hay anuncios obstructivos durante la conducción</td>
|
59 |
-
<td>Combustible limitado y entradas para jugadores gratis</td>
|
60 |
-
</tr>
|
61 |
-
<tr>
|
62 |
-
<td>Modo de convoy multijugador en línea</td>
|
63 |
-
<td>Posibles problemas de retardo y conexión</td>
|
64 |
-
</tr>
|
65 |
-
</tabla>
|
66 |
-
<h2>Conclusión</h2>
|
67 |
-
|
68 |
-
<h2>Preguntas frecuentes</h2>
|
69 |
-
<p>Aquí hay algunas preguntas frecuentes sobre Bus Simulator Indonesia APK Nuevo:</p>
|
70 |
-
<ol>
|
71 |
-
<li><b>Es Bus Simulator Indonesia APK nuevo libre? </b></li>
|
72 |
-
<p>Sí, Bus Simulator Indonesia APK Nuevo es gratis para descargar y jugar. Sin embargo, tiene algunas compras en la aplicación que pueden mejorar tu experiencia de juego, como la versión premium, monedas, combustible, boletos o mods de vehículos. </p>
|
73 |
-
<li><b>Es el simulador de autobús Indonesia APK nuevo seguro? </b></li>
|
74 |
-
<p>Sí, Bus Simulator Indonesia APK Nuevo es seguro para descargar e instalar. No contiene ningún virus, malware o spyware que pueda dañar su dispositivo o datos. Sin embargo, siempre debe descargarlo desde el sitio web oficial o fuentes confiables para evitar cualquier riesgo. </p>
|
75 |
-
<li><b>Es Bus Simulator Indonesia APK nuevo fuera de línea? </b></li>
|
76 |
-
<p>No, Bus Simulator Indonesia APK Nuevo no está fuera de línea. Se requiere una conexión a Internet para acceder a algunas características, tales como galería en línea, convoy multijugador en línea, clasificación, o sistema de vehículo mod. Sin embargo, todavía se puede jugar sin conexión sin estas características. </p>
|
77 |
-
<li><b>Cómo actualizar Bus Simulator Indonesia APK Nuevo? </b></li>
|
78 |
-
<p>Para actualizar Bus Simulator Indonesia APK Nuevo, es necesario ir a la página web oficial o Google Play Store y descargar la última versión del juego. También puede habilitar la opción de actualización automática en la configuración de su dispositivo para obtener las actualizaciones automáticamente. </p>
|
79 |
-
<li><b>Cómo ponerse en contacto con el desarrollador de Bus Simulator Indonesia APK Nuevo? </b></li>
|
80 |
-
<p>Para ponerse en contacto con el desarrollador de Bus Simulator Indonesia APK Nuevo, puede visitar su sitio web, página de Facebook, cuenta de Instagram, canal de YouTube, o enviarlos por correo electrónico a [email protected]. También puedes dejar tus comentarios, sugerencias o informes de errores en la sección de valoración y revisión del juego en Google Play Store.</p>
|
81 |
-
</ol></p> 64aa2da5cf<br />
|
82 |
-
<br />
|
83 |
-
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Benson/text-generation/Examples/Descargar Gratis Zenonia 1 Mod Apk.md
DELETED
@@ -1,49 +0,0 @@
|
|
1 |
-
|
2 |
-
<h1>Zenonia 1 Mod APK descarga gratuita: Un RPG de acción clásica para Android</h1>
|
3 |
-
<p>Si eres un fan de los juegos de acción RPG, es posible que hayas oído hablar de Zenonia, una popular serie de Gamevil que ha existido desde 2009. Zenonia 1 es la primera entrega de la serie, y es considerado como uno de los mejores juegos de rol clásicos para dispositivos Android. En este juego, puedes elegir entre cuatro clases de personajes diferentes, cada uno con sus propias habilidades y habilidades, y embarcarte en una aventura épica en un mundo de fantasía lleno de monstruos, mazmorras, misiones y secretos. </p>
|
4 |
-
<p>Sin embargo, si desea disfrutar del juego al máximo, es posible que desee probar Zenonia 1 mod apk, una versión modificada del juego que le da acceso a oro ilimitado, puntos de habilidad, y otras características que harán que su experiencia de juego más divertido y fácil. En este artículo, le diremos todo lo que necesita saber sobre Zenonia 1 mod apk, incluyendo sus características, cómo descargar e instalar, y algunos consejos y trucos para jugarlo. </p>
|
5 |
-
<h2>descargar gratis zenonia 1 mod apk</h2><br /><p><b><b>Download File</b> ✪ <a href="https://bltlly.com/2v6Kyy">https://bltlly.com/2v6Kyy</a></b></p><br /><br />
|
6 |
-
<h2>Características de Zenonia 1 Mod APK</h2>
|
7 |
-
<p>Zenonia 1 mod apk no es solo una versión simple del juego original. Tiene algunas características increíbles que mejorarán tu juego y te harán sentir como un verdadero héroe. Estas son algunas de las características que se pueden disfrutar con Zenonia 1 mod apk:</p>
|
8 |
-
<ul>
|
9 |
-
<li><b>Oro ilimitado y puntos de habilidad:</b> Con esta función, no tienes que preocuparte por quedarte sin dinero o puntos de habilidad en el juego. Puedes comprar lo que quieras de la tienda, mejorar tus habilidades tanto como quieras, y personalizar tu personaje a tu gusto. </li>
|
10 |
-
<li><b>Sin anuncios y verificación de licencias:</b> Con esta función, no tienes que lidiar con anuncios molestos que aparecen de vez en cuando, o pasar por la molestia de verificar tu licencia cada vez que lanzas el juego. Puedes jugar el juego sin problemas y sin interrupciones. </li>
|
11 |
-
|
12 |
-
<li><b>Modo sin conexión y nube save:</b> Con esta función, puede jugar el juego sin conexión a Internet. También puede guardar su progreso en la nube y acceder a él desde cualquier dispositivo. </li>
|
13 |
-
</ul>
|
14 |
-
<h2>Cómo descargar e instalar Zenonia 1 Mod APK</h2>
|
15 |
-
<p>Si usted está interesado en probar Zenonia 1 mod apk, puede seguir estos sencillos pasos para descargar e instalar en su dispositivo Android:</p>
|
16 |
-
<ol>
|
17 |
-
<li><b>Paso 1:</b> Descargue el archivo APK de una fuente confiable. Puede usar uno de estos enlaces para descargar el archivo de forma segura. </li>
|
18 |
-
<li><b>Paso 2:</b> Habilitar fuentes desconocidas en el dispositivo. Para hacer esto, vaya a Configuración > Seguridad > Fuentes desconocidas y active. </li>
|
19 |
-
<li><b>Paso 3:</b> Instalar el archivo APK y lanzar el juego. Para hacer esto, busque el archivo descargado en su dispositivo y toque en él. Siga las instrucciones en la pantalla para instalar el juego. Una vez hecho, abra el juego desde el cajón de la aplicación o la pantalla de inicio. </li>
|
20 |
-
<li><b Paso 4:</b> Disfruta del juego con características mod. Para hacer esto, inicia un juego nuevo o carga uno ya existente. Verás que tienes puntos de oro y habilidad ilimitados, y puedes acceder al menú de mods tocando el botón M en la esquina superior derecha de la pantalla. También puede ajustar los gráficos y los ajustes de sonido desde el menú de opciones. </li>
|
21 |
-
</ol>
|
22 |
-
<h2> Consejos y trucos para jugar Zenonia 1 Mod APK</h2>
|
23 |
-
<p>Zenonia 1 mod apk es un juego divertido y adictivo que te mantendrá entretenido durante horas. Sin embargo, si quieres dominar el juego y convertirte en un héroe legendario, puedes seguir estos consejos y trucos:</p>
|
24 |
-
<ul>
|
25 |
-
|
26 |
-
<li><b>Mejora tus habilidades y equipo regularmente:</b> A medida que avanzas en el juego, ganarás puntos de experiencia y subirás de nivel. Cada vez que subes de nivel, obtendrás puntos de habilidad que puedes usar para mejorar tus habilidades. Las habilidades se dividen en tres categorías: Activo, Pasivo y Especial. Las habilidades activas son las que puedes usar en combate, las habilidades pasivas son las que te dan bonos permanentes, y las habilidades especiales son las únicas para cada clase. También puede encontrar o comprar equipos como armas, armaduras, accesorios y artículos que mejorarán sus estadísticas y habilidades. Equipar el mejor equipo que usted puede permitirse y que coincida con su clase. </li>
|
27 |
-
<li><b>Explora el mapa y completa misiones:</b> Zenonia 1 tiene un mapa grande y diverso que está lleno de secretos, tesoros, enemigos y PNJ. Puede explorar el mapa moviéndose con el joystick virtual en el lado izquierdo de la pantalla. También puede interactuar con objetos y personajes tocando en ellos. Encontrarás muchas misiones que te darán recompensas como oro, objetos, puntos de experiencia y progresión de la historia. Las misiones están marcadas con iconos en el mapa y en la parte superior de la pantalla. Puedes comprobar tu registro de misiones tocando el botón Q en la esquina superior izquierda de la pantalla. </li>
|
28 |
-
<li><b>Usa pociones y objetos estratégicamente:</b> Zenonia 1 no es un juego fácil, especialmente si juegas en niveles de dificultad más altos. Te enfrentarás a muchos enemigos y jefes desafiantes que pondrán a prueba tus habilidades y resistencia. Para sobrevivir, necesitarás usar pociones y elementos que restauren tu salud, maná, resistencia o efectos de estado. Puedes comprar pociones y artículos en tiendas o encontrarlos en cofres o gotas. También puedes crear pociones y objetos combinando ingredientes que puedes recoger de enemigos o plantas. Puede acceder a su inventario tocando el botón I en la esquina superior derecha de la pantalla. </li>
|
29 |
-
</ul>
|
30 |
-
<h2>Conclusión</h2>
|
31 |
-
|
32 |
-
<p>Si usted está buscando un juego divertido y atractivo que le mantendrá enganchado durante horas, usted debe probar definitivamente Zenonia 1 mod apk. Puede descargarlo desde uno de estos enlaces e instalarlo fácilmente en su dispositivo. Esperamos que disfrute jugando Zenonia 1 mod apk tanto como lo hicimos. </p>
|
33 |
-
<p>¿Tiene alguna pregunta o comentario sobre Zenonia 1 mod apk? No dude en dejar un comentario a continuación o en contacto con nosotros a través de nuestro sitio web. Nos encantaría saber de ti. </p>
|
34 |
-
<h3>Preguntas frecuentes</h3>
|
35 |
-
<ul>
|
36 |
-
<li><b>Q: ¿Es seguro descargar Zenonia 1 mod apk? </b></li>
|
37 |
-
<li>A: Sí, Zenonia 1 mod apk es seguro para descargar siempre y cuando se utiliza una fuente de confianza como uno de estos enlaces . Sin embargo, le recomendamos que escanee el archivo con un antivirus antes de instalarlo. </li>
|
38 |
-
<li><b>Q: ¿Es Zenonia 1 mod apk compatible con mi dispositivo? </b></li>
|
39 |
-
<li>A: Zenonia 1 mod apk es compatible con la mayoría de los dispositivos Android que se ejecutan en Android 4.0 o superior. Sin embargo, algunos dispositivos pueden tener problemas de compatibilidad debido a diferentes especificaciones o configuraciones. </li>
|
40 |
-
<li><b>Q: ¿Cómo puedo actualizar Zenonia 1 mod apk? </b></li>
|
41 |
-
<li>A: Zenonia 1 mod apk se actualiza regularmente para corregir errores y añadir nuevas características. Puede comprobar si hay actualizaciones visitando el sitio web de origen o tocando el botón de actualización en el menú mod. También puede habilitar las actualizaciones automáticas desde el menú de configuración. </li>
|
42 |
-
<li><b>Q: ¿Cómo puedo desinstalar Zenonia 1 mod apk? </b></li>
|
43 |
-
<li>A: Zenonia 1 mod apk se puede desinstalar como cualquier otra aplicación en su dispositivo. Puede ir a Configuración > Aplicaciones > Zenonia 1 y tocar en el botón de desinstalación. También puede eliminar el archivo APK de su dispositivo si ya no lo necesita. </li>
|
44 |
-
<li><b>Q: ¿Puedo jugar Zenonia 1 mod apk con mis amigos? </b></li>
|
45 |
-
<li>A: Zenonia 1 mod apk no es compatible con el modo multijugador, por lo que no se puede jugar con tus amigos en línea. Sin embargo, puedes compartir tu progreso y logros con tus amigos usando la función de guardar en la nube o tomando capturas de pantalla y enviándolas a tus amigos. </li>
|
46 |
-
</ul></p>
|
47 |
-
<p></p> 64aa2da5cf<br />
|
48 |
-
<br />
|
49 |
-
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Big-Web/MMSD/env/Lib/site-packages/pip/_vendor/urllib3/_version.py
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
# This file is protected via CODEOWNERS
|
2 |
-
__version__ = "1.26.15"
|
|
|
|
|
|
spaces/BobbyOleti/MyGenAIChatBot/app.py
DELETED
@@ -1,34 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import gradio as gr
|
3 |
-
from langchain.chat_models import ChatOpenAI
|
4 |
-
from langchain import LLMChain, PromptTemplate
|
5 |
-
from langchain.memory import ConversationBufferMemory
|
6 |
-
|
7 |
-
OPENAI_API_KEY=os.getenv('OPENAI_API_KEY')
|
8 |
-
|
9 |
-
template = """Meet Riya, your youthful and witty personal assistant! At 21 years old, she's full of energy and always eager to help. Riya's goal is to assist you with any questions or problems you might have. Her enthusiasm shines through in every response, making interactions with her enjoyable and engaging.
|
10 |
-
{chat_history}
|
11 |
-
User: {user_message}
|
12 |
-
Chatbot:"""
|
13 |
-
|
14 |
-
prompt = PromptTemplate(
|
15 |
-
input_variables=["chat_history", "user_message"], template=template
|
16 |
-
)
|
17 |
-
|
18 |
-
memory = ConversationBufferMemory(memory_key="chat_history")
|
19 |
-
|
20 |
-
llm_chain = LLMChain(
|
21 |
-
llm=ChatOpenAI(temperature='0.5', model_name="gpt-3.5-turbo"),
|
22 |
-
prompt=prompt,
|
23 |
-
verbose=True,
|
24 |
-
memory=memory,
|
25 |
-
)
|
26 |
-
|
27 |
-
def get_text_response(user_message,history):
|
28 |
-
response = llm_chain.predict(user_message = user_message)
|
29 |
-
return response
|
30 |
-
|
31 |
-
demo = gr.ChatInterface(get_text_response)
|
32 |
-
|
33 |
-
if __name__ == "__main__":
|
34 |
-
demo.launch() #To create a public link, set `share=True` in `launch()`. To enable errors and logs, set `debug=True` in `launch()`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CVPR/LIVE/pybind11/tests/test_smart_ptr.py
DELETED
@@ -1,290 +0,0 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
import pytest
|
3 |
-
from pybind11_tests import smart_ptr as m
|
4 |
-
from pybind11_tests import ConstructorStats
|
5 |
-
|
6 |
-
|
7 |
-
def test_smart_ptr(capture):
|
8 |
-
# Object1
|
9 |
-
for i, o in enumerate([m.make_object_1(), m.make_object_2(), m.MyObject1(3)], start=1):
|
10 |
-
assert o.getRefCount() == 1
|
11 |
-
with capture:
|
12 |
-
m.print_object_1(o)
|
13 |
-
m.print_object_2(o)
|
14 |
-
m.print_object_3(o)
|
15 |
-
m.print_object_4(o)
|
16 |
-
assert capture == "MyObject1[{i}]\n".format(i=i) * 4
|
17 |
-
|
18 |
-
for i, o in enumerate([m.make_myobject1_1(), m.make_myobject1_2(), m.MyObject1(6), 7],
|
19 |
-
start=4):
|
20 |
-
print(o)
|
21 |
-
with capture:
|
22 |
-
if not isinstance(o, int):
|
23 |
-
m.print_object_1(o)
|
24 |
-
m.print_object_2(o)
|
25 |
-
m.print_object_3(o)
|
26 |
-
m.print_object_4(o)
|
27 |
-
m.print_myobject1_1(o)
|
28 |
-
m.print_myobject1_2(o)
|
29 |
-
m.print_myobject1_3(o)
|
30 |
-
m.print_myobject1_4(o)
|
31 |
-
assert capture == "MyObject1[{i}]\n".format(i=i) * (4 if isinstance(o, int) else 8)
|
32 |
-
|
33 |
-
cstats = ConstructorStats.get(m.MyObject1)
|
34 |
-
assert cstats.alive() == 0
|
35 |
-
expected_values = ['MyObject1[{}]'.format(i) for i in range(1, 7)] + ['MyObject1[7]'] * 4
|
36 |
-
assert cstats.values() == expected_values
|
37 |
-
assert cstats.default_constructions == 0
|
38 |
-
assert cstats.copy_constructions == 0
|
39 |
-
# assert cstats.move_constructions >= 0 # Doesn't invoke any
|
40 |
-
assert cstats.copy_assignments == 0
|
41 |
-
assert cstats.move_assignments == 0
|
42 |
-
|
43 |
-
# Object2
|
44 |
-
for i, o in zip([8, 6, 7], [m.MyObject2(8), m.make_myobject2_1(), m.make_myobject2_2()]):
|
45 |
-
print(o)
|
46 |
-
with capture:
|
47 |
-
m.print_myobject2_1(o)
|
48 |
-
m.print_myobject2_2(o)
|
49 |
-
m.print_myobject2_3(o)
|
50 |
-
m.print_myobject2_4(o)
|
51 |
-
assert capture == "MyObject2[{i}]\n".format(i=i) * 4
|
52 |
-
|
53 |
-
cstats = ConstructorStats.get(m.MyObject2)
|
54 |
-
assert cstats.alive() == 1
|
55 |
-
o = None
|
56 |
-
assert cstats.alive() == 0
|
57 |
-
assert cstats.values() == ['MyObject2[8]', 'MyObject2[6]', 'MyObject2[7]']
|
58 |
-
assert cstats.default_constructions == 0
|
59 |
-
assert cstats.copy_constructions == 0
|
60 |
-
# assert cstats.move_constructions >= 0 # Doesn't invoke any
|
61 |
-
assert cstats.copy_assignments == 0
|
62 |
-
assert cstats.move_assignments == 0
|
63 |
-
|
64 |
-
# Object3
|
65 |
-
for i, o in zip([9, 8, 9], [m.MyObject3(9), m.make_myobject3_1(), m.make_myobject3_2()]):
|
66 |
-
print(o)
|
67 |
-
with capture:
|
68 |
-
m.print_myobject3_1(o)
|
69 |
-
m.print_myobject3_2(o)
|
70 |
-
m.print_myobject3_3(o)
|
71 |
-
m.print_myobject3_4(o)
|
72 |
-
assert capture == "MyObject3[{i}]\n".format(i=i) * 4
|
73 |
-
|
74 |
-
cstats = ConstructorStats.get(m.MyObject3)
|
75 |
-
assert cstats.alive() == 1
|
76 |
-
o = None
|
77 |
-
assert cstats.alive() == 0
|
78 |
-
assert cstats.values() == ['MyObject3[9]', 'MyObject3[8]', 'MyObject3[9]']
|
79 |
-
assert cstats.default_constructions == 0
|
80 |
-
assert cstats.copy_constructions == 0
|
81 |
-
# assert cstats.move_constructions >= 0 # Doesn't invoke any
|
82 |
-
assert cstats.copy_assignments == 0
|
83 |
-
assert cstats.move_assignments == 0
|
84 |
-
|
85 |
-
# Object
|
86 |
-
cstats = ConstructorStats.get(m.Object)
|
87 |
-
assert cstats.alive() == 0
|
88 |
-
assert cstats.values() == []
|
89 |
-
assert cstats.default_constructions == 10
|
90 |
-
assert cstats.copy_constructions == 0
|
91 |
-
# assert cstats.move_constructions >= 0 # Doesn't invoke any
|
92 |
-
assert cstats.copy_assignments == 0
|
93 |
-
assert cstats.move_assignments == 0
|
94 |
-
|
95 |
-
# ref<>
|
96 |
-
cstats = m.cstats_ref()
|
97 |
-
assert cstats.alive() == 0
|
98 |
-
assert cstats.values() == ['from pointer'] * 10
|
99 |
-
assert cstats.default_constructions == 30
|
100 |
-
assert cstats.copy_constructions == 12
|
101 |
-
# assert cstats.move_constructions >= 0 # Doesn't invoke any
|
102 |
-
assert cstats.copy_assignments == 30
|
103 |
-
assert cstats.move_assignments == 0
|
104 |
-
|
105 |
-
|
106 |
-
def test_smart_ptr_refcounting():
|
107 |
-
assert m.test_object1_refcounting()
|
108 |
-
|
109 |
-
|
110 |
-
def test_unique_nodelete():
|
111 |
-
o = m.MyObject4(23)
|
112 |
-
assert o.value == 23
|
113 |
-
cstats = ConstructorStats.get(m.MyObject4)
|
114 |
-
assert cstats.alive() == 1
|
115 |
-
del o
|
116 |
-
assert cstats.alive() == 1 # Leak, but that's intentional
|
117 |
-
|
118 |
-
|
119 |
-
def test_unique_nodelete4a():
|
120 |
-
o = m.MyObject4a(23)
|
121 |
-
assert o.value == 23
|
122 |
-
cstats = ConstructorStats.get(m.MyObject4a)
|
123 |
-
assert cstats.alive() == 1
|
124 |
-
del o
|
125 |
-
assert cstats.alive() == 1 # Leak, but that's intentional
|
126 |
-
|
127 |
-
|
128 |
-
def test_unique_deleter():
|
129 |
-
o = m.MyObject4b(23)
|
130 |
-
assert o.value == 23
|
131 |
-
cstats4a = ConstructorStats.get(m.MyObject4a)
|
132 |
-
assert cstats4a.alive() == 2 # Two because of previous test
|
133 |
-
cstats4b = ConstructorStats.get(m.MyObject4b)
|
134 |
-
assert cstats4b.alive() == 1
|
135 |
-
del o
|
136 |
-
assert cstats4a.alive() == 1 # Should now only be one leftover from previous test
|
137 |
-
assert cstats4b.alive() == 0 # Should be deleted
|
138 |
-
|
139 |
-
|
140 |
-
def test_large_holder():
|
141 |
-
o = m.MyObject5(5)
|
142 |
-
assert o.value == 5
|
143 |
-
cstats = ConstructorStats.get(m.MyObject5)
|
144 |
-
assert cstats.alive() == 1
|
145 |
-
del o
|
146 |
-
assert cstats.alive() == 0
|
147 |
-
|
148 |
-
|
149 |
-
def test_shared_ptr_and_references():
|
150 |
-
s = m.SharedPtrRef()
|
151 |
-
stats = ConstructorStats.get(m.A)
|
152 |
-
assert stats.alive() == 2
|
153 |
-
|
154 |
-
ref = s.ref # init_holder_helper(holder_ptr=false, owned=false)
|
155 |
-
assert stats.alive() == 2
|
156 |
-
assert s.set_ref(ref)
|
157 |
-
with pytest.raises(RuntimeError) as excinfo:
|
158 |
-
assert s.set_holder(ref)
|
159 |
-
assert "Unable to cast from non-held to held instance" in str(excinfo.value)
|
160 |
-
|
161 |
-
copy = s.copy # init_holder_helper(holder_ptr=false, owned=true)
|
162 |
-
assert stats.alive() == 3
|
163 |
-
assert s.set_ref(copy)
|
164 |
-
assert s.set_holder(copy)
|
165 |
-
|
166 |
-
holder_ref = s.holder_ref # init_holder_helper(holder_ptr=true, owned=false)
|
167 |
-
assert stats.alive() == 3
|
168 |
-
assert s.set_ref(holder_ref)
|
169 |
-
assert s.set_holder(holder_ref)
|
170 |
-
|
171 |
-
holder_copy = s.holder_copy # init_holder_helper(holder_ptr=true, owned=true)
|
172 |
-
assert stats.alive() == 3
|
173 |
-
assert s.set_ref(holder_copy)
|
174 |
-
assert s.set_holder(holder_copy)
|
175 |
-
|
176 |
-
del ref, copy, holder_ref, holder_copy, s
|
177 |
-
assert stats.alive() == 0
|
178 |
-
|
179 |
-
|
180 |
-
def test_shared_ptr_from_this_and_references():
|
181 |
-
s = m.SharedFromThisRef()
|
182 |
-
stats = ConstructorStats.get(m.B)
|
183 |
-
assert stats.alive() == 2
|
184 |
-
|
185 |
-
ref = s.ref # init_holder_helper(holder_ptr=false, owned=false, bad_wp=false)
|
186 |
-
assert stats.alive() == 2
|
187 |
-
assert s.set_ref(ref)
|
188 |
-
assert s.set_holder(ref) # std::enable_shared_from_this can create a holder from a reference
|
189 |
-
|
190 |
-
bad_wp = s.bad_wp # init_holder_helper(holder_ptr=false, owned=false, bad_wp=true)
|
191 |
-
assert stats.alive() == 2
|
192 |
-
assert s.set_ref(bad_wp)
|
193 |
-
with pytest.raises(RuntimeError) as excinfo:
|
194 |
-
assert s.set_holder(bad_wp)
|
195 |
-
assert "Unable to cast from non-held to held instance" in str(excinfo.value)
|
196 |
-
|
197 |
-
copy = s.copy # init_holder_helper(holder_ptr=false, owned=true, bad_wp=false)
|
198 |
-
assert stats.alive() == 3
|
199 |
-
assert s.set_ref(copy)
|
200 |
-
assert s.set_holder(copy)
|
201 |
-
|
202 |
-
holder_ref = s.holder_ref # init_holder_helper(holder_ptr=true, owned=false, bad_wp=false)
|
203 |
-
assert stats.alive() == 3
|
204 |
-
assert s.set_ref(holder_ref)
|
205 |
-
assert s.set_holder(holder_ref)
|
206 |
-
|
207 |
-
holder_copy = s.holder_copy # init_holder_helper(holder_ptr=true, owned=true, bad_wp=false)
|
208 |
-
assert stats.alive() == 3
|
209 |
-
assert s.set_ref(holder_copy)
|
210 |
-
assert s.set_holder(holder_copy)
|
211 |
-
|
212 |
-
del ref, bad_wp, copy, holder_ref, holder_copy, s
|
213 |
-
assert stats.alive() == 0
|
214 |
-
|
215 |
-
z = m.SharedFromThisVirt.get()
|
216 |
-
y = m.SharedFromThisVirt.get()
|
217 |
-
assert y is z
|
218 |
-
|
219 |
-
|
220 |
-
def test_move_only_holder():
|
221 |
-
a = m.TypeWithMoveOnlyHolder.make()
|
222 |
-
b = m.TypeWithMoveOnlyHolder.make_as_object()
|
223 |
-
stats = ConstructorStats.get(m.TypeWithMoveOnlyHolder)
|
224 |
-
assert stats.alive() == 2
|
225 |
-
del b
|
226 |
-
assert stats.alive() == 1
|
227 |
-
del a
|
228 |
-
assert stats.alive() == 0
|
229 |
-
|
230 |
-
|
231 |
-
def test_holder_with_addressof_operator():
|
232 |
-
# this test must not throw exception from c++
|
233 |
-
a = m.TypeForHolderWithAddressOf.make()
|
234 |
-
a.print_object_1()
|
235 |
-
a.print_object_2()
|
236 |
-
a.print_object_3()
|
237 |
-
a.print_object_4()
|
238 |
-
|
239 |
-
stats = ConstructorStats.get(m.TypeForHolderWithAddressOf)
|
240 |
-
assert stats.alive() == 1
|
241 |
-
|
242 |
-
np = m.TypeForHolderWithAddressOf.make()
|
243 |
-
assert stats.alive() == 2
|
244 |
-
del a
|
245 |
-
assert stats.alive() == 1
|
246 |
-
del np
|
247 |
-
assert stats.alive() == 0
|
248 |
-
|
249 |
-
b = m.TypeForHolderWithAddressOf.make()
|
250 |
-
c = b
|
251 |
-
assert b.get() is c.get()
|
252 |
-
assert stats.alive() == 1
|
253 |
-
|
254 |
-
del b
|
255 |
-
assert stats.alive() == 1
|
256 |
-
|
257 |
-
del c
|
258 |
-
assert stats.alive() == 0
|
259 |
-
|
260 |
-
|
261 |
-
def test_move_only_holder_with_addressof_operator():
|
262 |
-
a = m.TypeForMoveOnlyHolderWithAddressOf.make()
|
263 |
-
a.print_object()
|
264 |
-
|
265 |
-
stats = ConstructorStats.get(m.TypeForMoveOnlyHolderWithAddressOf)
|
266 |
-
assert stats.alive() == 1
|
267 |
-
|
268 |
-
a.value = 42
|
269 |
-
assert a.value == 42
|
270 |
-
|
271 |
-
del a
|
272 |
-
assert stats.alive() == 0
|
273 |
-
|
274 |
-
|
275 |
-
def test_smart_ptr_from_default():
|
276 |
-
instance = m.HeldByDefaultHolder()
|
277 |
-
with pytest.raises(RuntimeError) as excinfo:
|
278 |
-
m.HeldByDefaultHolder.load_shared_ptr(instance)
|
279 |
-
assert "Unable to load a custom holder type from a " \
|
280 |
-
"default-holder instance" in str(excinfo.value)
|
281 |
-
|
282 |
-
|
283 |
-
def test_shared_ptr_gc():
|
284 |
-
"""#187: issue involving std::shared_ptr<> return value policy & garbage collection"""
|
285 |
-
el = m.ElementList()
|
286 |
-
for i in range(10):
|
287 |
-
el.add(m.ElementA(i))
|
288 |
-
pytest.gc_collect()
|
289 |
-
for i, v in enumerate(el.get()):
|
290 |
-
assert i == v.value()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CVPR/LIVE/thrust/thrust/detail/functional/operators/logical_operators.h
DELETED
@@ -1,144 +0,0 @@
|
|
1 |
-
/*
|
2 |
-
* Copyright 2008-2013 NVIDIA Corporation
|
3 |
-
*
|
4 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
-
* you may not use this file except in compliance with the License.
|
6 |
-
* You may obtain a copy of the License at
|
7 |
-
*
|
8 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
9 |
-
*
|
10 |
-
* Unless required by applicable law or agreed to in writing, software
|
11 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
-
* See the License for the specific language governing permissions and
|
14 |
-
* limitations under the License.
|
15 |
-
*/
|
16 |
-
|
17 |
-
#pragma once
|
18 |
-
|
19 |
-
#include <thrust/detail/config.h>
|
20 |
-
#include <thrust/detail/functional/actor.h>
|
21 |
-
#include <thrust/detail/functional/composite.h>
|
22 |
-
#include <thrust/detail/functional/operators/operator_adaptors.h>
|
23 |
-
#include <thrust/functional.h>
|
24 |
-
|
25 |
-
namespace thrust
|
26 |
-
{
|
27 |
-
namespace detail
|
28 |
-
{
|
29 |
-
namespace functional
|
30 |
-
{
|
31 |
-
|
32 |
-
template<typename T1, typename T2>
|
33 |
-
__host__ __device__
|
34 |
-
actor<
|
35 |
-
composite<
|
36 |
-
transparent_binary_operator<thrust::logical_and<>>,
|
37 |
-
actor<T1>,
|
38 |
-
typename as_actor<T2>::type
|
39 |
-
>
|
40 |
-
>
|
41 |
-
operator&&(const actor<T1> &_1, const T2 &_2)
|
42 |
-
{
|
43 |
-
return compose(transparent_binary_operator<thrust::logical_and<>>(),
|
44 |
-
make_actor(_1),
|
45 |
-
make_actor(_2));
|
46 |
-
} // end operator&&()
|
47 |
-
|
48 |
-
template<typename T1, typename T2>
|
49 |
-
__host__ __device__
|
50 |
-
actor<
|
51 |
-
composite<
|
52 |
-
transparent_binary_operator<thrust::logical_and<>>,
|
53 |
-
typename as_actor<T1>::type,
|
54 |
-
actor<T2>
|
55 |
-
>
|
56 |
-
>
|
57 |
-
operator&&(const T1 &_1, const actor<T2> &_2)
|
58 |
-
{
|
59 |
-
return compose(transparent_binary_operator<thrust::logical_and<>>(),
|
60 |
-
make_actor(_1),
|
61 |
-
make_actor(_2));
|
62 |
-
} // end operator&&()
|
63 |
-
|
64 |
-
template<typename T1, typename T2>
|
65 |
-
__host__ __device__
|
66 |
-
actor<
|
67 |
-
composite<
|
68 |
-
transparent_binary_operator<thrust::logical_and<>>,
|
69 |
-
actor<T1>,
|
70 |
-
actor<T2>
|
71 |
-
>
|
72 |
-
>
|
73 |
-
operator&&(const actor<T1> &_1, const actor<T2> &_2)
|
74 |
-
{
|
75 |
-
return compose(transparent_binary_operator<thrust::logical_and<>>(),
|
76 |
-
make_actor(_1),
|
77 |
-
make_actor(_2));
|
78 |
-
} // end operator&&()
|
79 |
-
|
80 |
-
template<typename T1, typename T2>
|
81 |
-
__host__ __device__
|
82 |
-
actor<
|
83 |
-
composite<
|
84 |
-
transparent_binary_operator<thrust::logical_or<>>,
|
85 |
-
actor<T1>,
|
86 |
-
typename as_actor<T2>::type
|
87 |
-
>
|
88 |
-
>
|
89 |
-
operator||(const actor<T1> &_1, const T2 &_2)
|
90 |
-
{
|
91 |
-
return compose(transparent_binary_operator<thrust::logical_or<>>(),
|
92 |
-
make_actor(_1),
|
93 |
-
make_actor(_2));
|
94 |
-
} // end operator&&()
|
95 |
-
|
96 |
-
template<typename T1, typename T2>
|
97 |
-
__host__ __device__
|
98 |
-
actor<
|
99 |
-
composite<
|
100 |
-
transparent_binary_operator<thrust::logical_or<>>,
|
101 |
-
typename as_actor<T1>::type,
|
102 |
-
actor<T2>
|
103 |
-
>
|
104 |
-
>
|
105 |
-
operator||(const T1 &_1, const actor<T2> &_2)
|
106 |
-
{
|
107 |
-
return compose(transparent_binary_operator<thrust::logical_or<>>(),
|
108 |
-
make_actor(_1),
|
109 |
-
make_actor(_2));
|
110 |
-
} // end operator&&()
|
111 |
-
|
112 |
-
template<typename T1, typename T2>
|
113 |
-
__host__ __device__
|
114 |
-
actor<
|
115 |
-
composite<
|
116 |
-
transparent_binary_operator<thrust::logical_or<>>,
|
117 |
-
actor<T1>,
|
118 |
-
actor<T2>
|
119 |
-
>
|
120 |
-
>
|
121 |
-
operator||(const actor<T1> &_1, const actor<T2> &_2)
|
122 |
-
{
|
123 |
-
return compose(transparent_binary_operator<thrust::logical_or<>>(),
|
124 |
-
make_actor(_1),
|
125 |
-
make_actor(_2));
|
126 |
-
} // end operator&&()
|
127 |
-
|
128 |
-
template<typename Eval>
|
129 |
-
__host__ __device__
|
130 |
-
actor<
|
131 |
-
composite<
|
132 |
-
transparent_unary_operator<thrust::logical_not<>>,
|
133 |
-
actor<Eval>
|
134 |
-
>
|
135 |
-
>
|
136 |
-
operator!(const actor<Eval> &_1)
|
137 |
-
{
|
138 |
-
return compose(transparent_unary_operator<thrust::logical_not<>>(), _1);
|
139 |
-
} // end operator!()
|
140 |
-
|
141 |
-
} // end functional
|
142 |
-
} // end detail
|
143 |
-
} // end thrust
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CVPR/LIVE/thrust/thrust/system/cpp/detail/transform.h
DELETED
@@ -1,22 +0,0 @@
|
|
1 |
-
/*
|
2 |
-
* Copyright 2008-2013 NVIDIA Corporation
|
3 |
-
*
|
4 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
-
* you may not use this file except in compliance with the License.
|
6 |
-
* You may obtain a copy of the License at
|
7 |
-
*
|
8 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
9 |
-
*
|
10 |
-
* Unless required by applicable law or agreed to in writing, software
|
11 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
-
* See the License for the specific language governing permissions and
|
14 |
-
* limitations under the License.
|
15 |
-
*/
|
16 |
-
|
17 |
-
#pragma once
|
18 |
-
|
19 |
-
#include <thrust/detail/config.h>
|
20 |
-
|
21 |
-
// cpp has no special transform
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CVPR/LIVE/thrust/thrust/system/detail/generic/scan.h
DELETED
@@ -1,99 +0,0 @@
|
|
1 |
-
/*
|
2 |
-
* Copyright 2008-2013 NVIDIA Corporation
|
3 |
-
*
|
4 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
-
* you may not use this file except in compliance with the License.
|
6 |
-
* You may obtain a copy of the License at
|
7 |
-
*
|
8 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
9 |
-
*
|
10 |
-
* Unless required by applicable law or agreed to in writing, software
|
11 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
-
* See the License for the specific language governing permissions and
|
14 |
-
* limitations under the License.
|
15 |
-
*/
|
16 |
-
|
17 |
-
|
18 |
-
#pragma once
|
19 |
-
|
20 |
-
#include <thrust/detail/config.h>
|
21 |
-
#include <thrust/system/detail/generic/tag.h>
|
22 |
-
|
23 |
-
namespace thrust
|
24 |
-
{
|
25 |
-
namespace system
|
26 |
-
{
|
27 |
-
namespace detail
|
28 |
-
{
|
29 |
-
namespace generic
|
30 |
-
{
|
31 |
-
|
32 |
-
|
33 |
-
template<typename ExecutionPolicy,
|
34 |
-
typename InputIterator,
|
35 |
-
typename OutputIterator>
|
36 |
-
__host__ __device__
|
37 |
-
OutputIterator inclusive_scan(thrust::execution_policy<ExecutionPolicy> &exec,
|
38 |
-
InputIterator first,
|
39 |
-
InputIterator last,
|
40 |
-
OutputIterator result);
|
41 |
-
|
42 |
-
|
43 |
-
// XXX it is an error to call this function; it has no implementation
|
44 |
-
template<typename ExecutionPolicy,
|
45 |
-
typename InputIterator,
|
46 |
-
typename OutputIterator,
|
47 |
-
typename BinaryFunction>
|
48 |
-
__host__ __device__
|
49 |
-
OutputIterator inclusive_scan(thrust::execution_policy<ExecutionPolicy> &exec,
|
50 |
-
InputIterator first,
|
51 |
-
InputIterator last,
|
52 |
-
OutputIterator result,
|
53 |
-
BinaryFunction binary_op);
|
54 |
-
|
55 |
-
|
56 |
-
template<typename ExecutionPolicy,
|
57 |
-
typename InputIterator,
|
58 |
-
typename OutputIterator>
|
59 |
-
__host__ __device__
|
60 |
-
OutputIterator exclusive_scan(thrust::execution_policy<ExecutionPolicy> &exec,
|
61 |
-
InputIterator first,
|
62 |
-
InputIterator last,
|
63 |
-
OutputIterator result);
|
64 |
-
|
65 |
-
|
66 |
-
template<typename ExecutionPolicy,
|
67 |
-
typename InputIterator,
|
68 |
-
typename OutputIterator,
|
69 |
-
typename T>
|
70 |
-
__host__ __device__
|
71 |
-
OutputIterator exclusive_scan(thrust::execution_policy<ExecutionPolicy> &exec,
|
72 |
-
InputIterator first,
|
73 |
-
InputIterator last,
|
74 |
-
OutputIterator result,
|
75 |
-
T init);
|
76 |
-
|
77 |
-
|
78 |
-
// XXX it is an error to call this function; it has no implementation
|
79 |
-
template<typename ExecutionPolicy,
|
80 |
-
typename InputIterator,
|
81 |
-
typename OutputIterator,
|
82 |
-
typename T,
|
83 |
-
typename BinaryFunction>
|
84 |
-
__host__ __device__
|
85 |
-
OutputIterator exclusive_scan(thrust::execution_policy<ExecutionPolicy> &exec,
|
86 |
-
InputIterator first,
|
87 |
-
InputIterator last,
|
88 |
-
OutputIterator result,
|
89 |
-
T init,
|
90 |
-
BinaryFunction binary_op);
|
91 |
-
|
92 |
-
|
93 |
-
} // end namespace generic
|
94 |
-
} // end namespace detail
|
95 |
-
} // end namespace system
|
96 |
-
} // end namespace thrust
|
97 |
-
|
98 |
-
#include <thrust/system/detail/generic/scan.inl>
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CVPR/LIVE/thrust/thrust/system/detail/sequential/copy_if.h
DELETED
@@ -1,73 +0,0 @@
|
|
1 |
-
/*
|
2 |
-
* Copyright 2008-2013 NVIDIA Corporation
|
3 |
-
*
|
4 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
-
* you may not use this file except in compliance with the License.
|
6 |
-
* You may obtain a copy of the License at
|
7 |
-
*
|
8 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
9 |
-
*
|
10 |
-
* Unless required by applicable law or agreed to in writing, software
|
11 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
-
* See the License for the specific language governing permissions and
|
14 |
-
* limitations under the License.
|
15 |
-
*/
|
16 |
-
|
17 |
-
/*! \file copy_if.h
|
18 |
-
* \brief Sequential implementation of copy_if.
|
19 |
-
*/
|
20 |
-
|
21 |
-
#pragma once
|
22 |
-
|
23 |
-
#include <thrust/detail/config.h>
|
24 |
-
#include <thrust/detail/function.h>
|
25 |
-
#include <thrust/system/detail/sequential/execution_policy.h>
|
26 |
-
|
27 |
-
namespace thrust
|
28 |
-
{
|
29 |
-
namespace system
|
30 |
-
{
|
31 |
-
namespace detail
|
32 |
-
{
|
33 |
-
namespace sequential
|
34 |
-
{
|
35 |
-
|
36 |
-
|
37 |
-
__thrust_exec_check_disable__
|
38 |
-
template<typename DerivedPolicy,
|
39 |
-
typename InputIterator1,
|
40 |
-
typename InputIterator2,
|
41 |
-
typename OutputIterator,
|
42 |
-
typename Predicate>
|
43 |
-
__host__ __device__
|
44 |
-
OutputIterator copy_if(sequential::execution_policy<DerivedPolicy> &,
|
45 |
-
InputIterator1 first,
|
46 |
-
InputIterator1 last,
|
47 |
-
InputIterator2 stencil,
|
48 |
-
OutputIterator result,
|
49 |
-
Predicate pred)
|
50 |
-
{
|
51 |
-
thrust::detail::wrapped_function<Predicate,bool> wrapped_pred(pred);
|
52 |
-
|
53 |
-
while(first != last)
|
54 |
-
{
|
55 |
-
if(wrapped_pred(*stencil))
|
56 |
-
{
|
57 |
-
*result = *first;
|
58 |
-
++result;
|
59 |
-
} // end if
|
60 |
-
|
61 |
-
++first;
|
62 |
-
++stencil;
|
63 |
-
} // end while
|
64 |
-
|
65 |
-
return result;
|
66 |
-
} // end copy_if()
|
67 |
-
|
68 |
-
|
69 |
-
} // end namespace sequential
|
70 |
-
} // end namespace detail
|
71 |
-
} // end namespace system
|
72 |
-
} // end namespace thrust
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CVPR/LIVE/thrust/thrust/system/detail/sequential/set_operations.h
DELETED
@@ -1,224 +0,0 @@
|
|
1 |
-
/*
|
2 |
-
* Copyright 2008-2013 NVIDIA Corporation
|
3 |
-
*
|
4 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
-
* you may not use this file except in compliance with the License.
|
6 |
-
* You may obtain a copy of the License at
|
7 |
-
*
|
8 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
9 |
-
*
|
10 |
-
* Unless required by applicable law or agreed to in writing, software
|
11 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
-
* See the License for the specific language governing permissions and
|
14 |
-
* limitations under the License.
|
15 |
-
*/
|
16 |
-
|
17 |
-
|
18 |
-
/*! \file set_operations.h
|
19 |
-
* \brief Sequential implementation of set operation functions.
|
20 |
-
*/
|
21 |
-
|
22 |
-
#pragma once
|
23 |
-
|
24 |
-
#include <thrust/detail/config.h>
|
25 |
-
#include <thrust/system/detail/sequential/execution_policy.h>
|
26 |
-
#include <thrust/detail/copy.h>
|
27 |
-
#include <thrust/detail/function.h>
|
28 |
-
|
29 |
-
namespace thrust
|
30 |
-
{
|
31 |
-
namespace system
|
32 |
-
{
|
33 |
-
namespace detail
|
34 |
-
{
|
35 |
-
namespace sequential
|
36 |
-
{
|
37 |
-
|
38 |
-
|
39 |
-
__thrust_exec_check_disable__
|
40 |
-
template<typename DerivedPolicy,
|
41 |
-
typename InputIterator1,
|
42 |
-
typename InputIterator2,
|
43 |
-
typename OutputIterator,
|
44 |
-
typename StrictWeakOrdering>
|
45 |
-
__host__ __device__
|
46 |
-
OutputIterator set_difference(sequential::execution_policy<DerivedPolicy> &exec,
|
47 |
-
InputIterator1 first1,
|
48 |
-
InputIterator1 last1,
|
49 |
-
InputIterator2 first2,
|
50 |
-
InputIterator2 last2,
|
51 |
-
OutputIterator result,
|
52 |
-
StrictWeakOrdering comp)
|
53 |
-
{
|
54 |
-
// wrap comp
|
55 |
-
thrust::detail::wrapped_function<
|
56 |
-
StrictWeakOrdering,
|
57 |
-
bool
|
58 |
-
> wrapped_comp(comp);
|
59 |
-
|
60 |
-
while(first1 != last1 && first2 != last2)
|
61 |
-
{
|
62 |
-
if(wrapped_comp(*first1,*first2))
|
63 |
-
{
|
64 |
-
*result = *first1;
|
65 |
-
++first1;
|
66 |
-
++result;
|
67 |
-
} // end if
|
68 |
-
else if(wrapped_comp(*first2,*first1))
|
69 |
-
{
|
70 |
-
++first2;
|
71 |
-
} // end else if
|
72 |
-
else
|
73 |
-
{
|
74 |
-
++first1;
|
75 |
-
++first2;
|
76 |
-
} // end else
|
77 |
-
} // end while
|
78 |
-
|
79 |
-
return thrust::copy(exec, first1, last1, result);
|
80 |
-
} // end set_difference()
|
81 |
-
|
82 |
-
|
83 |
-
__thrust_exec_check_disable__
|
84 |
-
template<typename DerivedPolicy,
|
85 |
-
typename InputIterator1,
|
86 |
-
typename InputIterator2,
|
87 |
-
typename OutputIterator,
|
88 |
-
typename StrictWeakOrdering>
|
89 |
-
__host__ __device__
|
90 |
-
OutputIterator set_intersection(sequential::execution_policy<DerivedPolicy> &,
|
91 |
-
InputIterator1 first1,
|
92 |
-
InputIterator1 last1,
|
93 |
-
InputIterator2 first2,
|
94 |
-
InputIterator2 last2,
|
95 |
-
OutputIterator result,
|
96 |
-
StrictWeakOrdering comp)
|
97 |
-
{
|
98 |
-
// wrap comp
|
99 |
-
thrust::detail::wrapped_function<
|
100 |
-
StrictWeakOrdering,
|
101 |
-
bool
|
102 |
-
> wrapped_comp(comp);
|
103 |
-
|
104 |
-
while(first1 != last1 && first2 != last2)
|
105 |
-
{
|
106 |
-
if(wrapped_comp(*first1,*first2))
|
107 |
-
{
|
108 |
-
++first1;
|
109 |
-
} // end if
|
110 |
-
else if(wrapped_comp(*first2,*first1))
|
111 |
-
{
|
112 |
-
++first2;
|
113 |
-
} // end else if
|
114 |
-
else
|
115 |
-
{
|
116 |
-
*result = *first1;
|
117 |
-
++first1;
|
118 |
-
++first2;
|
119 |
-
++result;
|
120 |
-
} // end else
|
121 |
-
} // end while
|
122 |
-
|
123 |
-
return result;
|
124 |
-
} // end set_intersection()
|
125 |
-
|
126 |
-
|
127 |
-
__thrust_exec_check_disable__
|
128 |
-
template<typename DerivedPolicy,
|
129 |
-
typename InputIterator1,
|
130 |
-
typename InputIterator2,
|
131 |
-
typename OutputIterator,
|
132 |
-
typename StrictWeakOrdering>
|
133 |
-
__host__ __device__
|
134 |
-
OutputIterator set_symmetric_difference(sequential::execution_policy<DerivedPolicy> &exec,
|
135 |
-
InputIterator1 first1,
|
136 |
-
InputIterator1 last1,
|
137 |
-
InputIterator2 first2,
|
138 |
-
InputIterator2 last2,
|
139 |
-
OutputIterator result,
|
140 |
-
StrictWeakOrdering comp)
|
141 |
-
{
|
142 |
-
// wrap comp
|
143 |
-
thrust::detail::wrapped_function<
|
144 |
-
StrictWeakOrdering,
|
145 |
-
bool
|
146 |
-
> wrapped_comp(comp);
|
147 |
-
|
148 |
-
while(first1 != last1 && first2 != last2)
|
149 |
-
{
|
150 |
-
if(wrapped_comp(*first1,*first2))
|
151 |
-
{
|
152 |
-
*result = *first1;
|
153 |
-
++first1;
|
154 |
-
++result;
|
155 |
-
} // end if
|
156 |
-
else if(wrapped_comp(*first2,*first1))
|
157 |
-
{
|
158 |
-
*result = *first2;
|
159 |
-
++first2;
|
160 |
-
++result;
|
161 |
-
} // end else if
|
162 |
-
else
|
163 |
-
{
|
164 |
-
++first1;
|
165 |
-
++first2;
|
166 |
-
} // end else
|
167 |
-
} // end while
|
168 |
-
|
169 |
-
return thrust::copy(exec, first2, last2, thrust::copy(exec, first1, last1, result));
|
170 |
-
} // end set_symmetric_difference()
|
171 |
-
|
172 |
-
|
173 |
-
__thrust_exec_check_disable__
|
174 |
-
template<typename DerivedPolicy,
|
175 |
-
typename InputIterator1,
|
176 |
-
typename InputIterator2,
|
177 |
-
typename OutputIterator,
|
178 |
-
typename StrictWeakOrdering>
|
179 |
-
__host__ __device__
|
180 |
-
OutputIterator set_union(sequential::execution_policy<DerivedPolicy> &exec,
|
181 |
-
InputIterator1 first1,
|
182 |
-
InputIterator1 last1,
|
183 |
-
InputIterator2 first2,
|
184 |
-
InputIterator2 last2,
|
185 |
-
OutputIterator result,
|
186 |
-
StrictWeakOrdering comp)
|
187 |
-
{
|
188 |
-
// wrap comp
|
189 |
-
thrust::detail::wrapped_function<
|
190 |
-
StrictWeakOrdering,
|
191 |
-
bool
|
192 |
-
> wrapped_comp(comp);
|
193 |
-
|
194 |
-
while(first1 != last1 && first2 != last2)
|
195 |
-
{
|
196 |
-
if(wrapped_comp(*first1,*first2))
|
197 |
-
{
|
198 |
-
*result = *first1;
|
199 |
-
++first1;
|
200 |
-
} // end if
|
201 |
-
else if(wrapped_comp(*first2,*first1))
|
202 |
-
{
|
203 |
-
*result = *first2;
|
204 |
-
++first2;
|
205 |
-
} // end else if
|
206 |
-
else
|
207 |
-
{
|
208 |
-
*result = *first1;
|
209 |
-
++first1;
|
210 |
-
++first2;
|
211 |
-
} // end else
|
212 |
-
|
213 |
-
++result;
|
214 |
-
} // end while
|
215 |
-
|
216 |
-
return thrust::copy(exec, first2, last2, thrust::copy(exec, first1, last1, result));
|
217 |
-
} // end set_union()
|
218 |
-
|
219 |
-
|
220 |
-
} // end namespace sequential
|
221 |
-
} // end namespace detail
|
222 |
-
} // end namespace system
|
223 |
-
} // end namespace thrust
|
224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CVPR/LIVE/thrust/thrust/system/omp/detail/sort.h
DELETED
@@ -1,55 +0,0 @@
|
|
1 |
-
/*
|
2 |
-
* Copyright 2008-2013 NVIDIA Corporation
|
3 |
-
*
|
4 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
-
* you may not use this file except in compliance with the License.
|
6 |
-
* You may obtain a copy of the License at
|
7 |
-
*
|
8 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
9 |
-
*
|
10 |
-
* Unless required by applicable law or agreed to in writing, software
|
11 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
-
* See the License for the specific language governing permissions and
|
14 |
-
* limitations under the License.
|
15 |
-
*/
|
16 |
-
|
17 |
-
#pragma once
|
18 |
-
|
19 |
-
#include <thrust/detail/config.h>
|
20 |
-
#include <thrust/system/omp/detail/execution_policy.h>
|
21 |
-
|
22 |
-
namespace thrust
|
23 |
-
{
|
24 |
-
namespace system
|
25 |
-
{
|
26 |
-
namespace omp
|
27 |
-
{
|
28 |
-
namespace detail
|
29 |
-
{
|
30 |
-
|
31 |
-
template<typename DerivedPolicy,
|
32 |
-
typename RandomAccessIterator,
|
33 |
-
typename StrictWeakOrdering>
|
34 |
-
void stable_sort(execution_policy<DerivedPolicy> &exec,
|
35 |
-
RandomAccessIterator first,
|
36 |
-
RandomAccessIterator last,
|
37 |
-
StrictWeakOrdering comp);
|
38 |
-
|
39 |
-
template<typename DerivedPolicy,
|
40 |
-
typename RandomAccessIterator1,
|
41 |
-
typename RandomAccessIterator2,
|
42 |
-
typename StrictWeakOrdering>
|
43 |
-
void stable_sort_by_key(execution_policy<DerivedPolicy> &exec,
|
44 |
-
RandomAccessIterator1 keys_first,
|
45 |
-
RandomAccessIterator1 keys_last,
|
46 |
-
RandomAccessIterator2 values_first,
|
47 |
-
StrictWeakOrdering comp);
|
48 |
-
|
49 |
-
} // end namespace detail
|
50 |
-
} // end namespace omp
|
51 |
-
} // end namespace system
|
52 |
-
} // end namespace thrust
|
53 |
-
|
54 |
-
#include <thrust/system/omp/detail/sort.inl>
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/CVPR/regionclip-demo/detectron2/data/datasets/register_coco.py
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
# Copyright (c) Facebook, Inc. and its affiliates.
|
2 |
-
from .coco import register_coco_instances # noqa
|
3 |
-
from .coco_panoptic import register_coco_panoptic_separated # noqa
|
|
|
|
|
|
|
|
spaces/ChandraMohanNayal/AutoGPT/autogpt/memory/milvus.py
DELETED
@@ -1,115 +0,0 @@
|
|
1 |
-
""" Milvus memory storage provider."""
|
2 |
-
from pymilvus import Collection, CollectionSchema, DataType, FieldSchema, connections
|
3 |
-
|
4 |
-
from autogpt.memory.base import MemoryProviderSingleton, get_ada_embedding
|
5 |
-
|
6 |
-
|
7 |
-
class MilvusMemory(MemoryProviderSingleton):
|
8 |
-
"""Milvus memory storage provider."""
|
9 |
-
|
10 |
-
def __init__(self, cfg) -> None:
|
11 |
-
"""Construct a milvus memory storage connection.
|
12 |
-
|
13 |
-
Args:
|
14 |
-
cfg (Config): Auto-GPT global config.
|
15 |
-
"""
|
16 |
-
# connect to milvus server.
|
17 |
-
connections.connect(address=cfg.milvus_addr)
|
18 |
-
fields = [
|
19 |
-
FieldSchema(name="pk", dtype=DataType.INT64, is_primary=True, auto_id=True),
|
20 |
-
FieldSchema(name="embeddings", dtype=DataType.FLOAT_VECTOR, dim=1536),
|
21 |
-
FieldSchema(name="raw_text", dtype=DataType.VARCHAR, max_length=65535),
|
22 |
-
]
|
23 |
-
|
24 |
-
# create collection if not exist and load it.
|
25 |
-
self.milvus_collection = cfg.milvus_collection
|
26 |
-
self.schema = CollectionSchema(fields, "auto-gpt memory storage")
|
27 |
-
self.collection = Collection(self.milvus_collection, self.schema)
|
28 |
-
# create index if not exist.
|
29 |
-
if not self.collection.has_index():
|
30 |
-
self.collection.release()
|
31 |
-
self.collection.create_index(
|
32 |
-
"embeddings",
|
33 |
-
{
|
34 |
-
"metric_type": "IP",
|
35 |
-
"index_type": "HNSW",
|
36 |
-
"params": {"M": 8, "efConstruction": 64},
|
37 |
-
},
|
38 |
-
index_name="embeddings",
|
39 |
-
)
|
40 |
-
self.collection.load()
|
41 |
-
|
42 |
-
def add(self, data) -> str:
|
43 |
-
"""Add an embedding of data into memory.
|
44 |
-
|
45 |
-
Args:
|
46 |
-
data (str): The raw text to construct embedding index.
|
47 |
-
|
48 |
-
Returns:
|
49 |
-
str: log.
|
50 |
-
"""
|
51 |
-
embedding = get_ada_embedding(data)
|
52 |
-
result = self.collection.insert([[embedding], [data]])
|
53 |
-
_text = (
|
54 |
-
"Inserting data into memory at primary key: "
|
55 |
-
f"{result.primary_keys[0]}:\n data: {data}"
|
56 |
-
)
|
57 |
-
return _text
|
58 |
-
|
59 |
-
def get(self, data):
|
60 |
-
"""Return the most relevant data in memory.
|
61 |
-
Args:
|
62 |
-
data: The data to compare to.
|
63 |
-
"""
|
64 |
-
return self.get_relevant(data, 1)
|
65 |
-
|
66 |
-
def clear(self) -> str:
|
67 |
-
"""Drop the index in memory.
|
68 |
-
|
69 |
-
Returns:
|
70 |
-
str: log.
|
71 |
-
"""
|
72 |
-
self.collection.drop()
|
73 |
-
self.collection = Collection(self.milvus_collection, self.schema)
|
74 |
-
self.collection.create_index(
|
75 |
-
"embeddings",
|
76 |
-
{
|
77 |
-
"metric_type": "IP",
|
78 |
-
"index_type": "HNSW",
|
79 |
-
"params": {"M": 8, "efConstruction": 64},
|
80 |
-
},
|
81 |
-
index_name="embeddings",
|
82 |
-
)
|
83 |
-
self.collection.load()
|
84 |
-
return "Obliviated"
|
85 |
-
|
86 |
-
def get_relevant(self, data: str, num_relevant: int = 5):
|
87 |
-
"""Return the top-k relevant data in memory.
|
88 |
-
Args:
|
89 |
-
data: The data to compare to.
|
90 |
-
num_relevant (int, optional): The max number of relevant data.
|
91 |
-
Defaults to 5.
|
92 |
-
|
93 |
-
Returns:
|
94 |
-
list: The top-k relevant data.
|
95 |
-
"""
|
96 |
-
# search the embedding and return the most relevant text.
|
97 |
-
embedding = get_ada_embedding(data)
|
98 |
-
search_params = {
|
99 |
-
"metrics_type": "IP",
|
100 |
-
"params": {"nprobe": 8},
|
101 |
-
}
|
102 |
-
result = self.collection.search(
|
103 |
-
[embedding],
|
104 |
-
"embeddings",
|
105 |
-
search_params,
|
106 |
-
num_relevant,
|
107 |
-
output_fields=["raw_text"],
|
108 |
-
)
|
109 |
-
return [item.entity.value_of_field("raw_text") for item in result[0]]
|
110 |
-
|
111 |
-
def get_stats(self) -> str:
|
112 |
-
"""
|
113 |
-
Returns: The stats of the milvus cache.
|
114 |
-
"""
|
115 |
-
return f"Entities num: {self.collection.num_entities}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/ChrisPreston/diff-svc_minato_aqua/utils/plot.py
DELETED
@@ -1,56 +0,0 @@
|
|
1 |
-
import matplotlib.pyplot as plt
|
2 |
-
import numpy as np
|
3 |
-
import torch
|
4 |
-
|
5 |
-
LINE_COLORS = ['w', 'r', 'y', 'cyan', 'm', 'b', 'lime']
|
6 |
-
|
7 |
-
|
8 |
-
def spec_to_figure(spec, vmin=None, vmax=None):
|
9 |
-
if isinstance(spec, torch.Tensor):
|
10 |
-
spec = spec.cpu().numpy()
|
11 |
-
fig = plt.figure(figsize=(12, 6))
|
12 |
-
plt.pcolor(spec.T, vmin=vmin, vmax=vmax)
|
13 |
-
return fig
|
14 |
-
|
15 |
-
|
16 |
-
def spec_f0_to_figure(spec, f0s, figsize=None):
|
17 |
-
max_y = spec.shape[1]
|
18 |
-
if isinstance(spec, torch.Tensor):
|
19 |
-
spec = spec.detach().cpu().numpy()
|
20 |
-
f0s = {k: f0.detach().cpu().numpy() for k, f0 in f0s.items()}
|
21 |
-
f0s = {k: f0 / 10 for k, f0 in f0s.items()}
|
22 |
-
fig = plt.figure(figsize=(12, 6) if figsize is None else figsize)
|
23 |
-
plt.pcolor(spec.T)
|
24 |
-
for i, (k, f0) in enumerate(f0s.items()):
|
25 |
-
plt.plot(f0.clip(0, max_y), label=k, c=LINE_COLORS[i], linewidth=1, alpha=0.8)
|
26 |
-
plt.legend()
|
27 |
-
return fig
|
28 |
-
|
29 |
-
|
30 |
-
def dur_to_figure(dur_gt, dur_pred, txt):
|
31 |
-
dur_gt = dur_gt.long().cpu().numpy()
|
32 |
-
dur_pred = dur_pred.long().cpu().numpy()
|
33 |
-
dur_gt = np.cumsum(dur_gt)
|
34 |
-
dur_pred = np.cumsum(dur_pred)
|
35 |
-
fig = plt.figure(figsize=(12, 6))
|
36 |
-
for i in range(len(dur_gt)):
|
37 |
-
shift = (i % 8) + 1
|
38 |
-
plt.text(dur_gt[i], shift, txt[i])
|
39 |
-
plt.text(dur_pred[i], 10 + shift, txt[i])
|
40 |
-
plt.vlines(dur_gt[i], 0, 10, colors='b') # blue is gt
|
41 |
-
plt.vlines(dur_pred[i], 10, 20, colors='r') # red is pred
|
42 |
-
return fig
|
43 |
-
|
44 |
-
|
45 |
-
def f0_to_figure(f0_gt, f0_cwt=None, f0_pred=None):
|
46 |
-
fig = plt.figure()
|
47 |
-
f0_gt = f0_gt.cpu().numpy()
|
48 |
-
plt.plot(f0_gt, color='r', label='gt')
|
49 |
-
if f0_cwt is not None:
|
50 |
-
f0_cwt = f0_cwt.cpu().numpy()
|
51 |
-
plt.plot(f0_cwt, color='b', label='cwt')
|
52 |
-
if f0_pred is not None:
|
53 |
-
f0_pred = f0_pred.cpu().numpy()
|
54 |
-
plt.plot(f0_pred, color='green', label='pred')
|
55 |
-
plt.legend()
|
56 |
-
return fig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Cyril666/ContourNet-ABI/maskrcnn_benchmark/utils/metric_logger.py
DELETED
@@ -1,66 +0,0 @@
|
|
1 |
-
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
2 |
-
from collections import defaultdict
|
3 |
-
from collections import deque
|
4 |
-
|
5 |
-
import torch
|
6 |
-
|
7 |
-
|
8 |
-
class SmoothedValue(object):
|
9 |
-
"""Track a series of values and provide access to smoothed values over a
|
10 |
-
window or the global series average.
|
11 |
-
"""
|
12 |
-
|
13 |
-
def __init__(self, window_size=20):
|
14 |
-
self.deque = deque(maxlen=window_size)
|
15 |
-
self.series = []
|
16 |
-
self.total = 0.0
|
17 |
-
self.count = 0
|
18 |
-
|
19 |
-
def update(self, value):
|
20 |
-
self.deque.append(value)
|
21 |
-
self.series.append(value)
|
22 |
-
self.count += 1
|
23 |
-
self.total += value
|
24 |
-
|
25 |
-
@property
|
26 |
-
def median(self):
|
27 |
-
d = torch.tensor(list(self.deque))
|
28 |
-
return d.median().item()
|
29 |
-
|
30 |
-
@property
|
31 |
-
def avg(self):
|
32 |
-
d = torch.tensor(list(self.deque))
|
33 |
-
return d.mean().item()
|
34 |
-
|
35 |
-
@property
|
36 |
-
def global_avg(self):
|
37 |
-
return self.total / self.count
|
38 |
-
|
39 |
-
|
40 |
-
class MetricLogger(object):
|
41 |
-
def __init__(self, delimiter="\t"):
|
42 |
-
self.meters = defaultdict(SmoothedValue)
|
43 |
-
self.delimiter = delimiter
|
44 |
-
|
45 |
-
def update(self, **kwargs):
|
46 |
-
for k, v in kwargs.items():
|
47 |
-
if isinstance(v, torch.Tensor):
|
48 |
-
v = v.item()
|
49 |
-
assert isinstance(v, (float, int))
|
50 |
-
self.meters[k].update(v)
|
51 |
-
|
52 |
-
def __getattr__(self, attr):
|
53 |
-
if attr in self.meters:
|
54 |
-
return self.meters[attr]
|
55 |
-
if attr in self.__dict__:
|
56 |
-
return self.__dict__[attr]
|
57 |
-
raise AttributeError("'{}' object has no attribute '{}'".format(
|
58 |
-
type(self).__name__, attr))
|
59 |
-
|
60 |
-
def __str__(self):
|
61 |
-
loss_str = []
|
62 |
-
for name, meter in self.meters.items():
|
63 |
-
loss_str.append(
|
64 |
-
"{}: {:.4f} ({:.4f})".format(name, meter.median, meter.global_avg)
|
65 |
-
)
|
66 |
-
return self.delimiter.join(loss_str)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/DAMO-NLP-SG/Video-LLaMA/video_llama/models/base_model.py
DELETED
@@ -1,248 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Adapted from salesforce@LAVIS. Below is the original copyright:
|
3 |
-
Copyright (c) 2022, salesforce.com, inc.
|
4 |
-
All rights reserved.
|
5 |
-
SPDX-License-Identifier: BSD-3-Clause
|
6 |
-
For full license text, see the LICENSE_Lavis file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
7 |
-
"""
|
8 |
-
|
9 |
-
import logging
|
10 |
-
import os
|
11 |
-
|
12 |
-
import numpy as np
|
13 |
-
import torch
|
14 |
-
import torch.nn as nn
|
15 |
-
from video_llama.common.dist_utils import download_cached_file, is_dist_avail_and_initialized
|
16 |
-
from video_llama.common.utils import get_abs_path, is_url
|
17 |
-
from omegaconf import OmegaConf
|
18 |
-
|
19 |
-
|
20 |
-
class BaseModel(nn.Module):
|
21 |
-
"""Base class for models."""
|
22 |
-
|
23 |
-
def __init__(self):
|
24 |
-
super().__init__()
|
25 |
-
|
26 |
-
@property
|
27 |
-
def device(self):
|
28 |
-
return list(self.parameters())[0].device
|
29 |
-
|
30 |
-
def load_checkpoint(self, url_or_filename):
|
31 |
-
"""
|
32 |
-
Load from a finetuned checkpoint.
|
33 |
-
|
34 |
-
This should expect no mismatch in the model keys and the checkpoint keys.
|
35 |
-
"""
|
36 |
-
|
37 |
-
if is_url(url_or_filename):
|
38 |
-
cached_file = download_cached_file(
|
39 |
-
url_or_filename, check_hash=False, progress=True
|
40 |
-
)
|
41 |
-
checkpoint = torch.load(cached_file, map_location="cpu")
|
42 |
-
elif os.path.isfile(url_or_filename):
|
43 |
-
checkpoint = torch.load(url_or_filename, map_location="cpu")
|
44 |
-
else:
|
45 |
-
raise RuntimeError("checkpoint url or path is invalid")
|
46 |
-
|
47 |
-
if "model" in checkpoint.keys():
|
48 |
-
state_dict = checkpoint["model"]
|
49 |
-
else:
|
50 |
-
state_dict = checkpoint
|
51 |
-
|
52 |
-
msg = self.load_state_dict(state_dict, strict=False)
|
53 |
-
|
54 |
-
logging.info("Missing keys {}".format(msg.missing_keys))
|
55 |
-
logging.info("load checkpoint from %s" % url_or_filename)
|
56 |
-
|
57 |
-
return msg
|
58 |
-
|
59 |
-
@classmethod
|
60 |
-
def from_pretrained(cls, model_type):
|
61 |
-
"""
|
62 |
-
Build a pretrained model from default configuration file, specified by model_type.
|
63 |
-
|
64 |
-
Args:
|
65 |
-
- model_type (str): model type, specifying architecture and checkpoints.
|
66 |
-
|
67 |
-
Returns:
|
68 |
-
- model (nn.Module): pretrained or finetuned model, depending on the configuration.
|
69 |
-
"""
|
70 |
-
model_cfg = OmegaConf.load(cls.default_config_path(model_type)).model
|
71 |
-
model = cls.from_config(model_cfg)
|
72 |
-
|
73 |
-
return model
|
74 |
-
|
75 |
-
@classmethod
|
76 |
-
def default_config_path(cls, model_type):
|
77 |
-
assert (
|
78 |
-
model_type in cls.PRETRAINED_MODEL_CONFIG_DICT
|
79 |
-
), "Unknown model type {}".format(model_type)
|
80 |
-
return get_abs_path(cls.PRETRAINED_MODEL_CONFIG_DICT[model_type])
|
81 |
-
|
82 |
-
def load_checkpoint_from_config(self, cfg, **kwargs):
|
83 |
-
"""
|
84 |
-
Load checkpoint as specified in the config file.
|
85 |
-
|
86 |
-
If load_finetuned is True, load the finetuned model; otherwise, load the pretrained model.
|
87 |
-
When loading the pretrained model, each task-specific architecture may define their
|
88 |
-
own load_from_pretrained() method.
|
89 |
-
"""
|
90 |
-
load_finetuned = cfg.get("load_finetuned", True)
|
91 |
-
if load_finetuned:
|
92 |
-
finetune_path = cfg.get("finetuned", None)
|
93 |
-
assert (
|
94 |
-
finetune_path is not None
|
95 |
-
), "Found load_finetuned is True, but finetune_path is None."
|
96 |
-
self.load_checkpoint(url_or_filename=finetune_path)
|
97 |
-
else:
|
98 |
-
# load pre-trained weights
|
99 |
-
pretrain_path = cfg.get("pretrained", None)
|
100 |
-
assert "Found load_finetuned is False, but pretrain_path is None."
|
101 |
-
self.load_from_pretrained(url_or_filename=pretrain_path, **kwargs)
|
102 |
-
|
103 |
-
def before_evaluation(self, **kwargs):
|
104 |
-
pass
|
105 |
-
|
106 |
-
def show_n_params(self, return_str=True):
|
107 |
-
tot = 0
|
108 |
-
for p in self.parameters():
|
109 |
-
w = 1
|
110 |
-
for x in p.shape:
|
111 |
-
w *= x
|
112 |
-
tot += w
|
113 |
-
if return_str:
|
114 |
-
if tot >= 1e6:
|
115 |
-
return "{:.1f}M".format(tot / 1e6)
|
116 |
-
else:
|
117 |
-
return "{:.1f}K".format(tot / 1e3)
|
118 |
-
else:
|
119 |
-
return tot
|
120 |
-
|
121 |
-
|
122 |
-
class BaseEncoder(nn.Module):
|
123 |
-
"""
|
124 |
-
Base class for primitive encoders, such as ViT, TimeSformer, etc.
|
125 |
-
"""
|
126 |
-
|
127 |
-
def __init__(self):
|
128 |
-
super().__init__()
|
129 |
-
|
130 |
-
def forward_features(self, samples, **kwargs):
|
131 |
-
raise NotImplementedError
|
132 |
-
|
133 |
-
@property
|
134 |
-
def device(self):
|
135 |
-
return list(self.parameters())[0].device
|
136 |
-
|
137 |
-
|
138 |
-
class SharedQueueMixin:
|
139 |
-
@torch.no_grad()
|
140 |
-
def _dequeue_and_enqueue(self, image_feat, text_feat, idxs=None):
|
141 |
-
# gather keys before updating queue
|
142 |
-
image_feats = concat_all_gather(image_feat)
|
143 |
-
text_feats = concat_all_gather(text_feat)
|
144 |
-
|
145 |
-
batch_size = image_feats.shape[0]
|
146 |
-
|
147 |
-
ptr = int(self.queue_ptr)
|
148 |
-
assert self.queue_size % batch_size == 0 # for simplicity
|
149 |
-
|
150 |
-
# replace the keys at ptr (dequeue and enqueue)
|
151 |
-
self.image_queue[:, ptr : ptr + batch_size] = image_feats.T
|
152 |
-
self.text_queue[:, ptr : ptr + batch_size] = text_feats.T
|
153 |
-
|
154 |
-
if idxs is not None:
|
155 |
-
idxs = concat_all_gather(idxs)
|
156 |
-
self.idx_queue[:, ptr : ptr + batch_size] = idxs.T
|
157 |
-
|
158 |
-
ptr = (ptr + batch_size) % self.queue_size # move pointer
|
159 |
-
self.queue_ptr[0] = ptr
|
160 |
-
|
161 |
-
|
162 |
-
class MomentumDistilationMixin:
|
163 |
-
@torch.no_grad()
|
164 |
-
def copy_params(self):
|
165 |
-
for model_pair in self.model_pairs:
|
166 |
-
for param, param_m in zip(
|
167 |
-
model_pair[0].parameters(), model_pair[1].parameters()
|
168 |
-
):
|
169 |
-
param_m.data.copy_(param.data) # initialize
|
170 |
-
param_m.requires_grad = False # not update by gradient
|
171 |
-
|
172 |
-
@torch.no_grad()
|
173 |
-
def _momentum_update(self):
|
174 |
-
for model_pair in self.model_pairs:
|
175 |
-
for param, param_m in zip(
|
176 |
-
model_pair[0].parameters(), model_pair[1].parameters()
|
177 |
-
):
|
178 |
-
param_m.data = param_m.data * self.momentum + param.data * (
|
179 |
-
1.0 - self.momentum
|
180 |
-
)
|
181 |
-
|
182 |
-
|
183 |
-
class GatherLayer(torch.autograd.Function):
|
184 |
-
"""
|
185 |
-
Gather tensors from all workers with support for backward propagation:
|
186 |
-
This implementation does not cut the gradients as torch.distributed.all_gather does.
|
187 |
-
"""
|
188 |
-
|
189 |
-
@staticmethod
|
190 |
-
def forward(ctx, x):
|
191 |
-
output = [
|
192 |
-
torch.zeros_like(x) for _ in range(torch.distributed.get_world_size())
|
193 |
-
]
|
194 |
-
torch.distributed.all_gather(output, x)
|
195 |
-
return tuple(output)
|
196 |
-
|
197 |
-
@staticmethod
|
198 |
-
def backward(ctx, *grads):
|
199 |
-
all_gradients = torch.stack(grads)
|
200 |
-
torch.distributed.all_reduce(all_gradients)
|
201 |
-
return all_gradients[torch.distributed.get_rank()]
|
202 |
-
|
203 |
-
|
204 |
-
def all_gather_with_grad(tensors):
|
205 |
-
"""
|
206 |
-
Performs all_gather operation on the provided tensors.
|
207 |
-
Graph remains connected for backward grad computation.
|
208 |
-
"""
|
209 |
-
# Queue the gathered tensors
|
210 |
-
world_size = torch.distributed.get_world_size()
|
211 |
-
# There is no need for reduction in the single-proc case
|
212 |
-
if world_size == 1:
|
213 |
-
return tensors
|
214 |
-
|
215 |
-
# tensor_all = GatherLayer.apply(tensors)
|
216 |
-
tensor_all = GatherLayer.apply(tensors)
|
217 |
-
|
218 |
-
return torch.cat(tensor_all, dim=0)
|
219 |
-
|
220 |
-
|
221 |
-
@torch.no_grad()
|
222 |
-
def concat_all_gather(tensor):
|
223 |
-
"""
|
224 |
-
Performs all_gather operation on the provided tensors.
|
225 |
-
*** Warning ***: torch.distributed.all_gather has no gradient.
|
226 |
-
"""
|
227 |
-
# if use distributed training
|
228 |
-
if not is_dist_avail_and_initialized():
|
229 |
-
return tensor
|
230 |
-
|
231 |
-
tensors_gather = [
|
232 |
-
torch.ones_like(tensor) for _ in range(torch.distributed.get_world_size())
|
233 |
-
]
|
234 |
-
torch.distributed.all_gather(tensors_gather, tensor, async_op=False)
|
235 |
-
|
236 |
-
output = torch.cat(tensors_gather, dim=0)
|
237 |
-
return output
|
238 |
-
|
239 |
-
|
240 |
-
def tile(x, dim, n_tile):
|
241 |
-
init_dim = x.size(dim)
|
242 |
-
repeat_idx = [1] * x.dim()
|
243 |
-
repeat_idx[dim] = n_tile
|
244 |
-
x = x.repeat(*(repeat_idx))
|
245 |
-
order_index = torch.LongTensor(
|
246 |
-
np.concatenate([init_dim * np.arange(n_tile) + i for i in range(init_dim)])
|
247 |
-
)
|
248 |
-
return torch.index_select(x, dim, order_index.to(x.device))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/DQChoi/gpt-demo/venv/lib/python3.11/site-packages/gradio/templates/frontend/assets/index-4ffdbeab.css
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
.model3D.svelte-14ct53h{display:flex;position:relative;width:var(--size-full);height:var(--size-full)}canvas.svelte-14ct53h{width:var(--size-full);height:var(--size-full);object-fit:contain}.download.svelte-14ct53h{position:absolute;top:6px;right:6px}.input-model.svelte-wn75i6{display:flex;position:relative;justify-content:center;align-items:center;width:var(--size-full);height:var(--size-64)}canvas.svelte-wn75i6{width:var(--size-full);height:var(--size-full);object-fit:contain}
|
|
|
|
spaces/DQChoi/gpt-demo/venv/lib/python3.11/site-packages/h11/tests/test_headers.py
DELETED
@@ -1,157 +0,0 @@
|
|
1 |
-
import pytest
|
2 |
-
|
3 |
-
from .._events import Request
|
4 |
-
from .._headers import (
|
5 |
-
get_comma_header,
|
6 |
-
has_expect_100_continue,
|
7 |
-
Headers,
|
8 |
-
normalize_and_validate,
|
9 |
-
set_comma_header,
|
10 |
-
)
|
11 |
-
from .._util import LocalProtocolError
|
12 |
-
|
13 |
-
|
14 |
-
def test_normalize_and_validate() -> None:
|
15 |
-
assert normalize_and_validate([("foo", "bar")]) == [(b"foo", b"bar")]
|
16 |
-
assert normalize_and_validate([(b"foo", b"bar")]) == [(b"foo", b"bar")]
|
17 |
-
|
18 |
-
# no leading/trailing whitespace in names
|
19 |
-
with pytest.raises(LocalProtocolError):
|
20 |
-
normalize_and_validate([(b"foo ", "bar")])
|
21 |
-
with pytest.raises(LocalProtocolError):
|
22 |
-
normalize_and_validate([(b" foo", "bar")])
|
23 |
-
|
24 |
-
# no weird characters in names
|
25 |
-
with pytest.raises(LocalProtocolError) as excinfo:
|
26 |
-
normalize_and_validate([(b"foo bar", b"baz")])
|
27 |
-
assert "foo bar" in str(excinfo.value)
|
28 |
-
with pytest.raises(LocalProtocolError):
|
29 |
-
normalize_and_validate([(b"foo\x00bar", b"baz")])
|
30 |
-
# Not even 8-bit characters:
|
31 |
-
with pytest.raises(LocalProtocolError):
|
32 |
-
normalize_and_validate([(b"foo\xffbar", b"baz")])
|
33 |
-
# And not even the control characters we allow in values:
|
34 |
-
with pytest.raises(LocalProtocolError):
|
35 |
-
normalize_and_validate([(b"foo\x01bar", b"baz")])
|
36 |
-
|
37 |
-
# no return or NUL characters in values
|
38 |
-
with pytest.raises(LocalProtocolError) as excinfo:
|
39 |
-
normalize_and_validate([("foo", "bar\rbaz")])
|
40 |
-
assert "bar\\rbaz" in str(excinfo.value)
|
41 |
-
with pytest.raises(LocalProtocolError):
|
42 |
-
normalize_and_validate([("foo", "bar\nbaz")])
|
43 |
-
with pytest.raises(LocalProtocolError):
|
44 |
-
normalize_and_validate([("foo", "bar\x00baz")])
|
45 |
-
# no leading/trailing whitespace
|
46 |
-
with pytest.raises(LocalProtocolError):
|
47 |
-
normalize_and_validate([("foo", "barbaz ")])
|
48 |
-
with pytest.raises(LocalProtocolError):
|
49 |
-
normalize_and_validate([("foo", " barbaz")])
|
50 |
-
with pytest.raises(LocalProtocolError):
|
51 |
-
normalize_and_validate([("foo", "barbaz\t")])
|
52 |
-
with pytest.raises(LocalProtocolError):
|
53 |
-
normalize_and_validate([("foo", "\tbarbaz")])
|
54 |
-
|
55 |
-
# content-length
|
56 |
-
assert normalize_and_validate([("Content-Length", "1")]) == [
|
57 |
-
(b"content-length", b"1")
|
58 |
-
]
|
59 |
-
with pytest.raises(LocalProtocolError):
|
60 |
-
normalize_and_validate([("Content-Length", "asdf")])
|
61 |
-
with pytest.raises(LocalProtocolError):
|
62 |
-
normalize_and_validate([("Content-Length", "1x")])
|
63 |
-
with pytest.raises(LocalProtocolError):
|
64 |
-
normalize_and_validate([("Content-Length", "1"), ("Content-Length", "2")])
|
65 |
-
assert normalize_and_validate(
|
66 |
-
[("Content-Length", "0"), ("Content-Length", "0")]
|
67 |
-
) == [(b"content-length", b"0")]
|
68 |
-
assert normalize_and_validate([("Content-Length", "0 , 0")]) == [
|
69 |
-
(b"content-length", b"0")
|
70 |
-
]
|
71 |
-
with pytest.raises(LocalProtocolError):
|
72 |
-
normalize_and_validate(
|
73 |
-
[("Content-Length", "1"), ("Content-Length", "1"), ("Content-Length", "2")]
|
74 |
-
)
|
75 |
-
with pytest.raises(LocalProtocolError):
|
76 |
-
normalize_and_validate([("Content-Length", "1 , 1,2")])
|
77 |
-
|
78 |
-
# transfer-encoding
|
79 |
-
assert normalize_and_validate([("Transfer-Encoding", "chunked")]) == [
|
80 |
-
(b"transfer-encoding", b"chunked")
|
81 |
-
]
|
82 |
-
assert normalize_and_validate([("Transfer-Encoding", "cHuNkEd")]) == [
|
83 |
-
(b"transfer-encoding", b"chunked")
|
84 |
-
]
|
85 |
-
with pytest.raises(LocalProtocolError) as excinfo:
|
86 |
-
normalize_and_validate([("Transfer-Encoding", "gzip")])
|
87 |
-
assert excinfo.value.error_status_hint == 501 # Not Implemented
|
88 |
-
with pytest.raises(LocalProtocolError) as excinfo:
|
89 |
-
normalize_and_validate(
|
90 |
-
[("Transfer-Encoding", "chunked"), ("Transfer-Encoding", "gzip")]
|
91 |
-
)
|
92 |
-
assert excinfo.value.error_status_hint == 501 # Not Implemented
|
93 |
-
|
94 |
-
|
95 |
-
def test_get_set_comma_header() -> None:
|
96 |
-
headers = normalize_and_validate(
|
97 |
-
[
|
98 |
-
("Connection", "close"),
|
99 |
-
("whatever", "something"),
|
100 |
-
("connectiON", "fOo,, , BAR"),
|
101 |
-
]
|
102 |
-
)
|
103 |
-
|
104 |
-
assert get_comma_header(headers, b"connection") == [b"close", b"foo", b"bar"]
|
105 |
-
|
106 |
-
headers = set_comma_header(headers, b"newthing", ["a", "b"]) # type: ignore
|
107 |
-
|
108 |
-
with pytest.raises(LocalProtocolError):
|
109 |
-
set_comma_header(headers, b"newthing", [" a", "b"]) # type: ignore
|
110 |
-
|
111 |
-
assert headers == [
|
112 |
-
(b"connection", b"close"),
|
113 |
-
(b"whatever", b"something"),
|
114 |
-
(b"connection", b"fOo,, , BAR"),
|
115 |
-
(b"newthing", b"a"),
|
116 |
-
(b"newthing", b"b"),
|
117 |
-
]
|
118 |
-
|
119 |
-
headers = set_comma_header(headers, b"whatever", ["different thing"]) # type: ignore
|
120 |
-
|
121 |
-
assert headers == [
|
122 |
-
(b"connection", b"close"),
|
123 |
-
(b"connection", b"fOo,, , BAR"),
|
124 |
-
(b"newthing", b"a"),
|
125 |
-
(b"newthing", b"b"),
|
126 |
-
(b"whatever", b"different thing"),
|
127 |
-
]
|
128 |
-
|
129 |
-
|
130 |
-
def test_has_100_continue() -> None:
|
131 |
-
assert has_expect_100_continue(
|
132 |
-
Request(
|
133 |
-
method="GET",
|
134 |
-
target="/",
|
135 |
-
headers=[("Host", "example.com"), ("Expect", "100-continue")],
|
136 |
-
)
|
137 |
-
)
|
138 |
-
assert not has_expect_100_continue(
|
139 |
-
Request(method="GET", target="/", headers=[("Host", "example.com")])
|
140 |
-
)
|
141 |
-
# Case insensitive
|
142 |
-
assert has_expect_100_continue(
|
143 |
-
Request(
|
144 |
-
method="GET",
|
145 |
-
target="/",
|
146 |
-
headers=[("Host", "example.com"), ("Expect", "100-Continue")],
|
147 |
-
)
|
148 |
-
)
|
149 |
-
# Doesn't work in HTTP/1.0
|
150 |
-
assert not has_expect_100_continue(
|
151 |
-
Request(
|
152 |
-
method="GET",
|
153 |
-
target="/",
|
154 |
-
headers=[("Host", "example.com"), ("Expect", "100-continue")],
|
155 |
-
http_version="1.0",
|
156 |
-
)
|
157 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Dacoolkid/Oba_-s/app.py
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
import openai
|
2 |
-
import gradio
|
3 |
-
|
4 |
-
openai.api_key = "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"
|
5 |
-
|
6 |
-
messages = [{"role": "system", "content": "You are a chatai"}]
|
7 |
-
|
8 |
-
def CustomChatGPT(user_input):
|
9 |
-
messages.append({"role": "user", "content": user_input})
|
10 |
-
response = openai.ChatCompletion.create(
|
11 |
-
model = "gpt-3.5-turbo",
|
12 |
-
messages = messages
|
13 |
-
)
|
14 |
-
ChatGPT_reply = response["choices"][0]["message"]["content"]
|
15 |
-
messages.append({"role": "assistant", "content": ChatGPT_reply})
|
16 |
-
return ChatGPT_reply
|
17 |
-
|
18 |
-
demo = gr.Interface(fn=CustomChatGPT, inputs = "text", "state", chat= "text", title = "ai")
|
19 |
-
|
20 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/DelinteNicolas/SDG/README.md
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
---
|
2 |
-
title: SDG
|
3 |
-
emoji: 📈
|
4 |
-
colorFrom: yellow
|
5 |
-
colorTo: pink
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 3.2
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: gpl-3.0
|
11 |
-
---
|
12 |
-
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/Diego-0121/ImaText/app.py
DELETED
@@ -1,26 +0,0 @@
|
|
1 |
-
import cv2
|
2 |
-
import pytesseract
|
3 |
-
import gradio as gr
|
4 |
-
|
5 |
-
# ------------------------- Function to extract text from an image -------------------------
|
6 |
-
def extract_text_from_image(image):
|
7 |
-
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Convert the image from BGR to grayscale
|
8 |
-
text = pytesseract.image_to_string(gray) # Extract text from the grayscale image
|
9 |
-
return text
|
10 |
-
|
11 |
-
|
12 |
-
#------------------------------- Graphic interface --------------------------------
|
13 |
-
# Define Gradio interface
|
14 |
-
iface = gr.Interface(
|
15 |
-
fn=extract_text_from_image,
|
16 |
-
inputs=gr.Image (label="Upload Image"),
|
17 |
-
outputs="text",
|
18 |
-
title="OCR APP ",
|
19 |
-
description="Upload an image and we'll extract the text for you.",
|
20 |
-
|
21 |
-
)
|
22 |
-
|
23 |
-
# Launch Gradio Interface
|
24 |
-
iface.launch(share= True)
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/DrHakase/full-body-anime-gan/README.md
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
---
|
2 |
-
title: Full Body Anime GAN
|
3 |
-
emoji: 😇
|
4 |
-
colorFrom: red
|
5 |
-
colorTo: gray
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 3.9.1
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: apache-2.0
|
11 |
-
duplicated_from: skytnt/full-body-anime-gan
|
12 |
-
---
|
13 |
-
|
14 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaces/DrHakase/word2img/app.py
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
|
3 |
-
gr.Interface.load("models/stabilityai/stable-diffusion-2").launch()
|
|
|
|
|
|
|
|