TensorFlowとtflearnを使い、ネットワークを構築しています。
ValueError: setting an array element with a sequence.
とエラーがでました。
Tracebackには、
Traceback (most recent call last): File "cnn.py", line 182, in <module> model.fit(trainDataSet, trainLabel, n_epoch=100, batch_size=4, validation_set=0.1, show_metric=True) File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tflearn/models/dnn.py", line 216, in fit callbacks=callbacks) File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tflearn/helpers/trainer.py", line 339, in fit show_metric) File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tflearn/helpers/trainer.py", line 818, in _train feed_batch) File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 929, in run run_metadata_ptr) File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1121, in _run np_val = np.asarray(subfeed_val, dtype=subfeed_dtype) File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/numpy/core/numeric.py", line 501, in asarray return array(a, dtype, copy=False, order=order) ValueError: setting an array element with a sequence.
とエラーがでました。
import tensorflow as tf import tflearn from tflearn.layers.core import input_data,dropout,fully_connected from tflearn.layers.conv import conv_2d, max_pool_2d from tflearn.layers.normalization import local_response_normalization from tflearn.layers.estimator import regression tf.reset_default_graph() net = input_data(shape=[32, 4, 104, 1]) net = conv_3d(net, 4, 16, activation='relu') net = max_pool_3d(net, 1) net = tflearn.activations.relu(net) net = dropout(net, 0.5) net = tflearn.fully_connected(net, 10, activation='softmax') net = tflearn.regression(net, optimizer='adam', learning_rate=0.5, loss='categorical_crossentropy') model = tflearn.DNN(net) model.fit(trainDataSet, trainLabel, n_epoch=100, batch_size=32, validation_set=0.1, show_metric=True) pred = np.array(model.predict(testDataSet).argmax(axis=1)) label = testLabel.argmax(axis=1) accuracy = np.mean(pred == label, axis=0) print(accuracy)
とコードを書きました。
model.fit(trainDataSet, trainLabel, n_epoch=100, batch_size=32, validation_set=0.1, show_metric=True)
の行でエラーが出ています。
trainDataSetには、
[array([[0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0. , 1. , 0. , 1. , 0. , 1. , 1. , 0. , 0. , 0. , 0. , 1. , 0. , 0. , 0. , 0. , 0. , 0. , 1. , 1. , 0. , 0. , 0. , 1. , 0. , 1. , 0. , 0. , 1. , 0. , 0. , 1. , 0. , 1. , 1. , 1. , 0. , 0. , 0. , 0. , 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25], ・ ・ ・ array([[0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 1. , 0. , 0. , 1. , 0. , 0. , 0. , 0. , 0. , 0. , 1. , 0. , 0. , 0. , 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25], [0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0. , 0. , 0. , 0. , 1. , 1. , 1. , 1. , 0. , 0. , 0. , 0. , 0. , 0. , 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25], [0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 1. , 0. , 0. , 0. , 0. , 0. , 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25], [0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0. , 1. , 1. , 0. , 0. , 0. , 0. , 0. , 0. , 1. , 0. , 1. , 1. , 1. , 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25]], dtype=float32)]
が入っていて、長さ12の配列です。
trainLabelには
[[1. 0.] [0. 1.] [0. 1.] [1. 0.] [1. 0.] [1. 0.] [0. 1.] [1. 0.] [0. 1.] [1. 0.] [0. 1.] [1. 0.]]
のように値が入っています。
何が原因でエラーが引き起こされるのかわかりません。どのようにコードを修正したらいいでしょうか?
コード全文、または参考にした(元ネタの)書籍、URLを追記すると回答得られやすくなるかもしれません。
入っている値を追記しました、もし何かご存知ならお願いします。
提示されたデータは省略されておりshapeも不明です。全データおよび完全なコードを追記すると回答得られるかもしれません。
12以上あるように見えるのですが、何故なのでしょうか?理由が分かりましたら追記ください。
リストの要素自体は12です。リストの中の子要素の大きさは12以上あります。
なぜ子要素が12以上あるのでしょうか理由が分かりましたら追記ください。
うーん、そういうデータだからとしか説明できません・・・。
ご自身で書かれたコードなので、データとソースが何故合っていない(合わせることができない)理由を明確にされないと回答は得られないと思うのですが・・・。
あなたの回答
tips
プレビュー