實際上有沒有辦法查看神經網路中的各個組件?假設下面的代碼在 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
uj5u.com熱心網友回復:
您可以為圖層命名。您的代碼如下所示:
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
因此,通過這種方式,您可以列印圖層的權重。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/323910.html
標籤:张量流
上一篇:Keras錯誤:尺寸必須相等,但對于輸入形狀為[8,10]、[8,2]的“loss/output_1_loss/SquaredDifference”,尺寸為10和2
