tensorflow - 在 tensorflow 中查看神经网络中的各个组件
问题描述
实际上有没有办法查看神经网络中的各个组件?假设下面的代码在 tensorflow 中。如何查看每一层的内容、神经元和权重?
# Create a `Sequential` model and add a Dense layer as the first layer.
model = tf.keras.models.Sequential()
model.add(tf.keras.Input(shape=(16,)))
model.add(tf.keras.layers.Dense(32, activation='relu'))
# Now the model will take as input arrays of shape (None, 16)
# and output arrays of shape (None, 32).
# Note that after the first layer, you don't need to specify
# the size of the input anymore:
model.add(tf.keras.layers.Dense(32))
model.output_shape
解决方案
你可以给你的图层命名。您的代码如下所示:
model = tf.keras.models.Sequential()
model.add(tf.keras.Input(shape=(16,)))
model.add(tf.keras.layers.Dense(32, activation='relu'), name="layer_1")
# Now the model will take as input arrays of shape (None, 16)
# and output arrays of shape (None, 32).
# Note that after the first layer, you don't need to specify
# the size of the input anymore:
model.add(tf.keras.layers.Dense(32), name="layer_1")
model.output_shape
如果你这样做,你可以通过做访问层权重
model.get_layer("layer_1").weights
因此,您可以通过这种方式打印图层的权重。
推荐阅读
- python - Django 石墨烯,按对象过滤
- powerbi - DAX 创建带有附加字段的日历表
- flutter - SlidingUpPanel 中的 ListView 滚动
- python - 使用参数作为变量的一部分
- javascript - 适配一个 jQuery 函数来发送文件
- google-play - Google Play 商店应用程序:无需发布即可获得审核
- ios - 在 swift (SwiftyMarkdown) 的 markdown 文件中渲染 document.directory 中的图像
- javascript - 如何更新依赖于状态中 if 语句的函数的状态?
- python - XGBoost 错误 - 当提供分类类型时,DMatrix 参数 `enable_categorical` 必须设置为 `True`
- vue.js - Quasar Framework:如何使用 QUploader 使用不同的图标集