Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

VaeImageProcessor.denormalize() raises AttributeError for NumPy inputs

未关闭 适合新手
#15,011 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@tonycoder-hub 已经在做这个了。

开始于 2026年10月12日。

  • #15012 来自 @tonycoder-hub —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
numpy, python, pytorch

调研方向

阅读 src/diffusers/image_processor.py 中的 VaeImageProcessor.denormalize(),并检查文档中说明的输入类型。使用 issue 中的 NumPy 示例复现该故障,然后检查附近的图像处理器测试,确认是否覆盖 NumPy 和 PyTorch 输入。完成标准是:NumPy 输入返回裁剪到 [0, 1] 范围内的值,并保留其类型,同时现有的 PyTorch 行为仍能正常工作。

由索引模型根据 Issue 内容生成。

描述

bug
Describe the bug

VaeImageProcessor.denormalize() is documented to accept both NumPy arrays (np.ndarray) and PyTorch tensors (torch.Tensor). However, passing a NumPy array raises an AttributeError because the implementation uses the PyTorch-specific .clamp() method.

Root cause

In src/diffusers/image_processor.py, line 234:

return (images * 0.5 + 0.5).clamp(0, 1)

NumPy arrays do not implement .clamp(), despite being included in the function's type annotations and documentation.

Expected behavior

The function should denormalize NumPy inputs to [0, 1], preserving the input type and existing PyTorch behavior.

Proposed direction

Use input-type-appropriate clipping, such as np.clip() for NumPy and .clamp() for PyTorch, or clarify the supported types if NumPy support is not intended.

I'd be happy to contribute a fix after discussing the preferred approach with maintainers.

Reproduction
import numpy as np
import torch
from diffusers.image_processor import VaeImageProcessor

values = [-2.0, -1.0, 0.0, 1.0, 2.0]

numpy_input = np.array(values, dtype=np.float32)
torch_input = torch.tensor(values, dtype=torch.float32)

# PyTorch succeeds
print("PyTorch:", VaeImageProcessor.denormalize(torch_input))

# NumPy raises AttributeError
print("NumPy:", VaeImageProcessor.denormalize(numpy_input))

The issue is reproducible on CPU without pretrained models or external downloads.

Logs
File "E:\diffusers\src\diffusers\image_processor.py", line 234, in denormalize
    return (images * 0.5 + 0.5).clamp(0, 1)
AttributeError: 'numpy.ndarray' object has no attribute 'clamp'. Did you mean: 'clip'?


Additional validation:


PyTorch actual: [0.0, 0.0, 0.5, 1.0, 1.0]
NumPy expected: [0.0, 0.0, 0.5, 1.0, 1.0]
Outputs match: True
System Info
  • 🤗 Diffusers version: 0.41.0.dev0
  • Platform: Windows-10-10.0.22631-SP0
  • Running on Google Colab?: No
  • Python version: 3.11.16
  • PyTorch version (GPU?): 2.14.1+cpu (False)
  • NumPy version: 2.4.6
  • Huggingface_hub version: 1.33.0
  • Transformers version: 5.18.0
  • Accelerate version: 1.15.0
  • PEFT version: 0.21.2
  • Safetensors version: 0.8.0

Source revision: 899c9f3fd0e64f3206781c00c71c28249eff9ca5

Reproduction environment: Windows, CPU only. No pretrained models or external downloads required.

Who can help?

@DN6 @sayakpaul

I'd appreciate your feedback on the expected NumPy support and the preferred approach to resolving this issue. I'm happy to contribute a fix once the implementation approach is agreed upon.

主要语言
Python
星标
34.7k
派生
7.4k
平均合并
2 天 16 小时
30 天内合并 PR
55

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

huggingface/diffusers 的其他 Issue

查看 huggingface/diffusers 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。