2017-09-29 13 views
0

1つの入力ノード(バイアスノードに加えて)と隠れ層に2つのノードを持つネットワークの重みを手動で設定しようとしています。これどうやってするの?Kerasモデル(R)で使用する重みを指定するにはどうすればよいですか?

スターターコード:

library(keras) 

model <- keras_model_sequential() 

wts = list(matrix(c(1, 1), ncol=1), matrix(c(1, 1), ncol=1)) 
model <- layer_dense(
    object = model, input_shape = 1L, use_bias = TRUE, units = 2L, activation = 'sigmoid', 
    weights = wts 
) 

これが与える "とValueErrorを:層重量形状を(1,2)に設けられ重量形状に対応していない(2、1)"

答えて

0

それは、これを行うにトリックですバイアス幅を指定するには配列を使用します。

model <- keras_model_sequential() 
wts = list(matrix(c(1, 1), nrow=1), array(c(1, 1))) 
model <- layer_dense(
    object = model, input_shape = 1L, use_bias = TRUE, units = 2L, activation = 'sigmoid', weights = wts 
) 

get_weights(model) 
[[1]] 
    [,1] [,2] 
[1,] 1 1 

[[2]] 
[1] 1 1 
関連する問題