ValueError:モデルターゲットをチェックするときのエラー:モデルに渡すNumpy配列のリストが、モデルが期待するサイズではありません

クリーク

マルチ出力があります

out = [Dense(19, name='one', activation='softmax')(out),
           Dense(19, name='two', activation='softmax')(out),
           Dense(19, name='three', activation='softmax')(out),
           Dense(19, name='four', activation='softmax')(out)]


model.fit(reshape_train_X,  y_onehot, batch_size=400, epochs=100, verbose=2,
          validation_split=0.2, callbacks=callbacks_list)

これは私のy_onehotフォーマットです:

[array([[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]],
      dtype=uint8), array([[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]],dtype=uint8),.....]

そして、私はこのエラーメッセージを受け取りました

ValueError: Error when checking model target: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 4 array(s), but instead got the following list of 5000 arrays: [array([[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 ...

y_onehotの配列に4つのリストがある場合に、このエラーが発生する理由がわかりません。

len(y_onehot):5000

print( "y_onehot"、y_onehot [0])

[[1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
 [0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0]]

print( "y_onehot"、len(y_onehot [0]))

y_onehot 4

これを試してみますしかし、それでも機能しませんでした。

ご協力いただきありがとうございます。

マルコ・セリアーニ

これはダミーの例です。あなたのyに注意を払ってください。分離された各出力に合わせて渡す必要があります

inp = Input((50))
x = Dense(32)(inp)
x1 = Dense(19, name='one', activation='softmax')(x)
x2 = Dense(19, name='two', activation='softmax')(x)
x3 = Dense(19, name='three', activation='softmax')(x)
x4 = Dense(19, name='four', activation='softmax')(x)

model = Model(inp, [x1,x2,x3,x4])
model.compile('adam', 'categorical_crossentropy')

X = np.random.uniform(0,1, (5000,50))
y1 = np.random.randint(0,2, (5000,19))
y2 = np.random.randint(0,2, (5000,19))
y3 = np.random.randint(0,2, (5000,19))
y4 = np.random.randint(0,2, (5000,19))

model.fit(X, [y1,y2,y3,y4], epochs=10)

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

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

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ