python - 将函数映射到 TensorFlow 中的部分张量
问题描述
在 TensorFlow 架构中,如何将函数仅应用于张量中的某些元素?例如,在层的最终输出中,一些变量表示我想通过 sigmoid 运行的像素密度,而张量开头的一些变量表示无界的连续值,我不想应用激活完全发挥作用。
这是我正在尝试的:
output_activation=tf.nn.sigmoid
x = tf.layers.dense(z, hidden_size, activation=hidden_activation)
x = tf.layers.dense(x, hidden_size, activation=hidden_activation)
_logits = tf.layers.dense(x, output_size, activation=None)
# Apply sigmoid only to image variables
logits = tf.concat(_logits[:functional_inputs], tf.map_fn(output_activation, _logits[functional_inputs:]), 0)
这给出了以下值错误:
ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("build_decoder/map/TensorArrayStack/TensorArrayGatherV3:0", shape=(?, 288755), dtype=float32)'
这是最好的方法吗?
解决方案
推荐阅读
- c# - 在 C# 中使用反射与对象类
- angular - how to stop angular router events from printing on console
- sql - 如何将周末和假期的值添加到前一个工作日
- c# - 从 ViewModel 推送时如何更改 TabbedPage 的 TabIndex
- javascript - 如何将一个或多个算术运算的事件绑定到复选框?
- mysql - 可以在服务器资源管理器中添加表数据库,但不能在数据源中添加
- oracle - 使用 SQL Developer 将 CSV 文件导入 Oracle
- apache - 如何在 Excel 文件中显示更改单元格值的错误?
- c++ - C2440 static_cast 无法从基类转换为派生类
- javascript - 如何使用 javascript 识别设备型号