Keras layer.weightsとlayer.get_weights()は異なる値を与えます

M_Gorky

私のKerasモデルには、重みとバイアス値にアクセスするために必要な高密度レイヤーがあります。get_weights()メソッドを使用してそれらにアクセスできます。重みとバイアスの予想サイズの行列(重みの場合は57X50)が返されます。

model.layers[0].get_weights()[0]

ただし、次のコードスニペットは、値が異なる同じサイズの行列を提供します。

import tensorflow as tf
init_op = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init_op)
    print(sess.run(model.layers[0].weights[0]))

2番目のメソッドでは、すべてのモデルのすべてのゼロと重みがget_weights()メソッドの出力とは異なるため、バイアス値が返されます。

どちらの方法が正しいか、そして2番目の方法が正確に何をするかについて何か考えがありますか?

sdcbr

を使用してinit_op、トレーニング可能なすべての変数を初期化します。これは、バイアスの場合はゼロ、モデルの他の重みの場合はランダム値を意味します。試してください:

import keras.backend as K
with K.get_session() as sess:
    print(sess.run(model.layers[0].weights[0]))

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How do I copy specific layer weights from pretrained models using Tensorflow Keras api?

分類Dev

Modify layer parameters in Keras

分類Dev

Splitting cnn layer in keras

分類Dev

Tensorflow returns same weights in hidden layer

分類Dev

Different methods for initializing embedding layer weights in Pytorch

分類Dev

`layer.get_weights()`は何を返しますか?

分類Dev

Keras Dense layer shape error

分類Dev

Is it possible to set keras layer output?

分類Dev

How to cache layer activations in Keras?

分類Dev

Keras clarification on definition of hidden layer

分類Dev

Initialize single layer of a trained keras network and get predictions

分類Dev

Return layer activations and weights from Tensorflow model in separate threads

分類Dev

Add dense layer before LSTM layer in keras or Tensorflow?

分類Dev

How to replace (or insert) intermediate layer in Keras model?

分類Dev

Will custom Lambda layer be included in the backpropagating in Keras

分類Dev

keras usage of the Activation layer instead of activation parameter

分類Dev

keras bidirectional layer with custom RNN Cell

分類Dev

Keras Concatenate layer dimensions acting up

分類Dev

isinstance() to check Keras Layer Type on Tensor

分類Dev

Can Numba be used to subclass a Keras Layer?

分類Dev

set / get_weights()の後の2つの等しいKerasモデルは、numpy.array_equal()によると同じ重みを持ちません。

分類Dev

Keras:get_weights()の出力の解釈

分類Dev

TensorFlow-tf.keras.layers.Layerとtf.keras.Modelの違い

分類Dev

Get parameters/weights for each layer of the model using the c++ API on OpenVINO

分類Dev

RNNクラスとLayerクラスを使用してKerasに最小限のLSTMCellを実装する

分類Dev

How can I load the weights of some layer of a trained network in a new network in returnn?

分類Dev

分離可能な畳み込み層のlayer.get_weights()はどういう意味ですか?

分類Dev

.get_layerメソッドを使用してKerasでモデルを作成しようとすると、グラフが切断されます

分類Dev

Keras: Difference between AveragePooling1D layer and GlobalAveragePooling1D layer

Related 関連記事

  1. 1

    How do I copy specific layer weights from pretrained models using Tensorflow Keras api?

  2. 2

    Modify layer parameters in Keras

  3. 3

    Splitting cnn layer in keras

  4. 4

    Tensorflow returns same weights in hidden layer

  5. 5

    Different methods for initializing embedding layer weights in Pytorch

  6. 6

    `layer.get_weights()`は何を返しますか?

  7. 7

    Keras Dense layer shape error

  8. 8

    Is it possible to set keras layer output?

  9. 9

    How to cache layer activations in Keras?

  10. 10

    Keras clarification on definition of hidden layer

  11. 11

    Initialize single layer of a trained keras network and get predictions

  12. 12

    Return layer activations and weights from Tensorflow model in separate threads

  13. 13

    Add dense layer before LSTM layer in keras or Tensorflow?

  14. 14

    How to replace (or insert) intermediate layer in Keras model?

  15. 15

    Will custom Lambda layer be included in the backpropagating in Keras

  16. 16

    keras usage of the Activation layer instead of activation parameter

  17. 17

    keras bidirectional layer with custom RNN Cell

  18. 18

    Keras Concatenate layer dimensions acting up

  19. 19

    isinstance() to check Keras Layer Type on Tensor

  20. 20

    Can Numba be used to subclass a Keras Layer?

  21. 21

    set / get_weights()の後の2つの等しいKerasモデルは、numpy.array_equal()によると同じ重みを持ちません。

  22. 22

    Keras:get_weights()の出力の解釈

  23. 23

    TensorFlow-tf.keras.layers.Layerとtf.keras.Modelの違い

  24. 24

    Get parameters/weights for each layer of the model using the c++ API on OpenVINO

  25. 25

    RNNクラスとLayerクラスを使用してKerasに最小限のLSTMCellを実装する

  26. 26

    How can I load the weights of some layer of a trained network in a new network in returnn?

  27. 27

    分離可能な畳み込み層のlayer.get_weights()はどういう意味ですか?

  28. 28

    .get_layerメソッドを使用してKerasでモデルを作成しようとすると、グラフが切断されます

  29. 29

    Keras: Difference between AveragePooling1D layer and GlobalAveragePooling1D layer

ホットタグ

アーカイブ