PixelCNN example from the documentation does not work

未关闭
#2,013 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
jupyter-notebook, python, tensorflow

调研方向

从 TensorFlow Probability API 文档 URL 中的 PixelCNN 示例开始,并使用 TensorFlow 2.19 在 Google Colab 中复现该示例。检查 dist.log_prob(image_input) 处的失败,并追踪报告的 KerasTensor 异常。完成的标准是文档中的示例能够成功运行且不出现此异常。

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

描述

How to repro?

TF version: 2.19.0

  1. Take an example from https://www.tensorflow.org/probability/api_docs/python/tfp/distributions/PixelCNN#examples
  2. Create Google Colab
  3. Past the example into the Google Colab
  4. Run it

The following exception occurs:

    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    [/tmp/ipython-input-624558695.py](https://localhost:8080/#) in <cell line: 0>()
         33 
         34 # Define the log likelihood for the loss fn
    ---> 35 log_prob = dist.log_prob(image_input)
         36 
         37 # Define the model
    
    6 frames
    <decorator-gen-128> in shape_v2(input, out_type, name)
    
    [/usr/local/lib/python3.12/dist-packages/keras/src/backend/common/keras_tensor.py](https://localhost:8080/#) in __tf_tensor__(self, dtype, name)
        154 
        155     def __tf_tensor__(self, dtype=None, name=None):
    --> 156         raise ValueError(
        157             "A KerasTensor cannot be used as input to a TensorFlow function. "
        158             "A KerasTensor is a symbolic placeholder for a shape and dtype, "
    
    ValueError: A KerasTensor cannot be used as input to a TensorFlow function. A KerasTensor is a symbolic placeholder for a shape and dtype, used when constructing Keras Functional models or Keras Functions. You can only use it as input to a Keras layer or a Keras operation (from the namespaces `keras.layers` and `keras.ops`). You are likely doing something like:
    
    ```
    x = Input(...)
    ...
    tf_fn(x)  # Invalid.
    ```
    
    What you should do instead is wrap `tf_fn` in a layer:
    
    ```
    class MyLayer(Layer):
        def call(self, x):
            return tf_fn(x)
    
    x = MyLayer()(x)
    ```
主要语言
Jupyter Notebook
星标
4.4k
派生
1.1k
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

tensorflow/probability 的其他 Issue

查看 tensorflow/probability 的全部 Issue

相似的 Issue

更多 Documentation Issue

把新 issue 发到你的邮箱

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