denoising diffusion implicit models

提供商keras-io
分类speech-enhancement
许可证Apache-2.0
下载量40
星标0

简介

DDIM 是一种针对扩散模型的加速采样算法,旨在解决传统 DDPM 推理速度慢的痛点。它通过引入非马尔可夫过程,允许在生成过程中跳过部分步骤,从而在保持生成质量的同时,大幅提升采样效率。在语音增强场景下,DDIM 能快速剔除背景噪声并还原清晰语音。对于开发者而言,该模型通过 Keras 实现,上手门槛低,非常适合需要将高质量生成能力落地到实时或近实时音频处理场景的项目。

核心亮点

  • 大幅提升采样速度,降低生成语音的延迟
  • 在减少推理步骤的同时保持高保真度
  • 基于 Keras 实现,易于集成到现有工作流
  • 适用于实时语音增强与噪声剔除场景

使用方法

安装依赖
# 安装 Hugging Face transformers
pip install transformers torch
SDK 使用
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained("keras-io/denoising-diffusion-implicit-models")
tokenizer = AutoTokenizer.from_pretrained("keras-io/denoising-diffusion-implicit-models")

Hugging Face 下载

我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 huggingface_hub:

操作指引
pip install -U huggingface_hub

命令行下载

下载完整模型库

下载完整模型库
huggingface-cli download keras-io/denoising-diffusion-implicit-models

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download keras-io/denoising-diffusion-implicit-models config.json --local-dir ./dir

更多命令行下载选项,可参见官方文档

SDK 下载

SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('keras-io/denoising-diffusion-implicit-models')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://huggingface.co/keras-io/denoising-diffusion-implicit-models

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/keras-io/denoising-diffusion-implicit-models

模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。

PyTorch / Transformers 使用

安装 Transformers

安装 Transformers
pip install -U transformers torch

模型加载和推理

模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained('keras-io/denoising-diffusion-implicit-models')
tokenizer = AutoTokenizer.from_pretrained('keras-io/denoising-diffusion-implicit-models')

完整文档

来源: HuggingFace

---
library_name: tf-keras
tags:

  • generative

  • denoising

  • diffusion

  • ddim

  • ddpm

  • unconditional-image-generation

---

This model was created for the Keras code example on denoising diffusion implicit models (DDIM).

Model description

The model uses a U-Net with identical input and output dimensions. It progressively downsamples and upsamples its input image, adding skip connections between layers having the same resolution. The architecture is a simplified version of the architecture of DDPM. It consists of convolutional residual blocks and lacks attention layers. The network takes two inputs, the noisy images and the variances of their noise components, which it encodes using sinusoidal embeddings.

Intended uses & limitations

The model is intended for educational purposes, as a simple example of denoising diffusion generative models. It has modest compute requirements with reasonable natural image generation performance.

Training and evaluation data

The model is trained on the Oxford Flowers 102 dataset for generating images, which is a diverse natural dataset containing around 8,000 images of flowers. Since the official splits are imbalanced (most of the images are contained in the test splite), new random splits were created (80% train, 20% validation) for training the model. Center crops were used for preprocessing.

Training procedure

The model is trained to denoise noisy images, and can generate images by iteratively denoising pure Gaussian noise.

For more details check out the Keras code example, or the companion code repository, with additional features..

Training hyperparameters

| Hyperparameters | Value |
| :-- | :-- |
| num epochs | 80 |
| dataset repetitions per epoch| 5 |
| image resolution | 64 |
| min signal rate | 0.02 |
| max signal rate | 0.95 |
| embedding dimensions | 32 |
| embedding max frequency | 1000.0 |
| block widths | 32, 64, 96, 128 |
| block depth | 2 |
| batch size | 64 |
| exponential moving average | 0.999 |
| optimizer | AdamW |
| learning rate | 1e-3 |
| weight decay | 1e-4 |

## Model plot

<details>
<summary>View model plot</summary>

!network architecture residual unet

</details>