2017-08-03 4 views
0

を失敗しましたエラーを取得します。は、私はkerasの私のカスタム層(1.1)を作成しました

ValueError: cannot reshape array of size 64 into shape (1,4) 
Apply node that caused the error: Reshape{2}(HostFromGpu.0, MakeVector{dtype='int64'}.0) 
Toposort index: 895 
Inputs types: [TensorType(float32, vector), TensorType(int64, vector)] 
Inputs shapes: [(64,), (2,)] 
Inputs strides: [(4,), (8,)] 
Inputs values: ['not shown', array([1, 4])] 
Inputs type_num: [11, 7] 
Outputs clients: [[InplaceDimShuffle{0,1,x,x}(Reshape{2}.0)]] 

Backtrace when the node is created(use Theano flag traceback.limit=N to make it longer): 
    File "<ipython-input-155-09ee1207017c>", line 22, in get_my_model_2 
    Dense(10, activation='softmax') 
    File "/home/universal/anaconda3/envs/practicecourse2/lib/python2.7/site-packages/keras/models.py", line 255, in __init__ 
    self.add(layer) 

私のカスタムレイヤーで訓練可能なウェイトが間違っていますか?

答えて

0

あなたがTheanoを使用しているので、幅と高さの軸は(2,3)であり、(1,2)ではありません。あなたのcall()関数の出力は(None, 64, 1, 1)するのではなく、形状(None, 4, 1, 1)を持っているためで指定され、エラーが発生した

res= K.sum(x*self.W,axis=(2,3)) 

res= K.sum(x*self.W,axis=(1,2)) 

:ある

は、次の行を変更する必要がありますget_output_shape_for()

+0

ありがとうございました!それは軸番号が1で始まるからです。その場合は0ではないのですか? – Kseniya

+0

はい、 'call()'の中で、配列 'x'の軸0はバッチサイズになります。 –

+0

ありがとう、ありがとう! – Kseniya

関連する問題