tf.keras and tfp.tfp.layers. are not compatible
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 38/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- jupyter-notebook
调研方向
首先复现所提供的 notebook 示例:将 tfp.layers.VariationalGaussianProcess 添加到 tf.keras.Sequential 模型中,包括显示的 ValueError。检查该层与 Keras 之间涉及的兼容性;完成的标准是该示例能够构建模型而不出现兼容性错误。
由索引模型根据 Issue 内容生成。
描述
hello fellow developers, it appears that the tf.keras and tfp.tfp.layers. are not compatible
i have this code="
**num_inducing_points = 40
model = tf.keras.Sequential([
tf.keras.layers.InputLayer(input_shape=[1], dtype=x.dtype),
tf.keras.layers.Dense(1, kernel_initializer='ones', use_bias=False),
tfp.layers.VariationalGaussianProcess(
num_inducing_points=num_inducing_points,
kernel_provider=RBFKernelFn(dtype=x.dtype),
event_shape=[1],
inducing_index_points_initializer=tf.constant_initializer(
np.linspace(*x_range, num=num_inducing_points,
dtype=x.dtype)[..., np.newaxis]),
unconstrained_observation_noise_variance_initializer=(
tf.constant_initializer(
np.log(np.expm1(1.)).astype(x.dtype))),
),
])
//Do inference.
batch_size = 32
loss = lambda y, rv_y: rv_y.variational_loss(
y, kl_weight=np.array(batch_size, x.dtype) / x.shape[0])
model.compile(optimizer=tf.optimizers.Adam(learning_rate=0.01), loss=loss)
model.fit(x, y, batch_size=batch_size, epochs=1000, verbose=False)
//Make predictions.
yhats = [model(x_tst) for _ in range(100)]**
"
and i get the following
error output=
"**:7: UserWarning: layer.add_variable is deprecated and will be removed in a future version. Please use the layer.add_weight() method instead.
self._amplitude = self.add_variable(
:12: UserWarning: layer.add_variable is deprecated and will be removed in a future version. Please use the layer.add_weight() method instead.
self._length_scale = self.add_variable(
ValueError Traceback (most recent call last)
in <cell line: 2>()
1 num_inducing_points = 40
----> 2 model = tf.keras.Sequential([
3 tf.keras.layers.InputLayer(input_shape=[1], dtype=x.dtype),
4 tf.keras.layers.Dense(1, kernel_initializer='ones', use_bias=False),
5 tfp.layers.VariationalGaussianProcess(
1 frames
/usr/local/lib/python3.10/dist-packages/keras/src/models/sequential.py in add(self, layer, rebuild)
93 layer = origin_layer
94 if not isinstance(layer, Layer):
---> 95 raise ValueError(
96 "Only instances of keras.Layer can be "
97 f"added to a Sequential model. Received: {layer} "
ValueError: Only instances of keras.Layer can be added to a Sequential model. Received: <tensorflow_probability.python.layers.distribution_layer.VariationalGaussianProcess object at 0x7acd5e77fc70> (of type <class 'tensorflow_probability.python.layers.distribution_layer.VariationalGaussianProcess'>)**"
- 主要语言
- Jupyter Notebook
- 星标
- 4.4k
- 派生
- 1.1k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
tensorflow/probability 的其他 Issue
-
KL divergence between two `TransformedDistribution`s with a shared non-injective bijector (`AbsoluteValue`) returns the base KL可能已有人在做 @Andreas-Hum 于 7 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
tensorflow/probability#2036 ·
-
难度 3/5 1-2 天 新手友好度 68/100
tensorflow/probability#2034 ·
-
难度 5/5 一周以上 新手友好度 35/100
tensorflow/probability#2021 ·
-
难度 4/5 3-5 天 新手友好度 30/100
tensorflow/probability#2015 ·
-
难度 3/5 1-2 天 新手友好度 48/100
tensorflow/probability#2013 ·
查看 tensorflow/probability 的全部 Issue
相似的 Issue
-
[Bug]: DoubleMLRDDData accepts a score_col that is no data column (as in its docstring example); the running variable then becomes a covariate and RDFlex fails可能已有人在做 @vrjdev 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
DoubleML/doubleml-for-py#455 ·
维护者通常 1 天内回复
-
Install page: spectarf's CUDA engine fails with PyTorch for CUDA 13.0 (nvvmError: ERROR_INVALID_IR)可能已有人在做 @lukepolson 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 79/100
PyTomography/PyTomography#435 ·
维护者通常 1 天内回复
-
beginner friendly
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 82/100
aws-samples/sample-per-model-bedrock#821 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
instadeepai/InstaNovo-FM#50 ·