2016-06-10 1 views
0

Von dem, was ich verstehe, wird dieser Fehler durch die Verwendung von numpy Arrays in Tensorflow verursacht. Ich konvertiere alle meine Listen in numme Arrays, aber es funktioniert nicht.TensorFlow: ValueError: das Festlegen eines Array-Elements mit einer Sequenz funktioniert nicht, obwohl ich numpy Arrays verwende

Ist die Dimensionalität falsch? Wie kann ich feststellen, was den Fehler verursacht hat?

Die Formen und dtypes der relevanten Arrays sind:

Shapes and dtypes: 
traininginput: 
(44137,) (Should be (44137, 221)?) 
object 
trainingoutput: 
(44137,) (Should be (44137, 1)?) 
object 
validationinput: 
(2454,) (Should be (2454, 221)?) 
object 
validationoutput: 
(2454,) (Should be (2454, 1)?) 
object 

Hier ist der Code:

from __future__ import absolute_import, division, print_function 
import scipy.io as sio 
import tflearn 
import numpy 
from itertools import chain 

mat_contents = sio.loadmat('spdata05_036.mat') 
print(type(mat_contents['spdata'])) 

spdata = mat_contents['spdata'] 

print(spdata.dtype) 
data = spdata[0][0][0][0][0][0] 
labels = spdata[0][0][0][0][0][1] 
set = spdata[0][0][0][0][0][2] 

print(data[0,:,0,:].ndim) 
sliced = data[0,:,0,:].transpose() 



print(len(sliced)) 
traininginput = [[]] 
trainingoutput = [[]] 
validationinput = [[]] 
validationoutput = [[]] 
print(set[0].size) 
for indx, slice in enumerate(sliced): 
    if (set[0][indx] == 0): 
     traininginput.append(slice) 
     trainingoutput.append(labels[0][indx]) 

    if (set[0][indx] == 1): 
     validationinput.append(slice) 
     validationoutput.append(labels[0][indx]) 


traininginput = numpy.asarray(traininginput) 
trainingoutput = numpy.asarray(trainingoutput) 
validationinput = numpy.asarray(validationinput) 
validationoutput = numpy.asarray(validationoutput) 

tflearn.init_graph() 

net = tflearn.input_data(shape=[None, 221]) 
net = tflearn.fully_connected(net, 64) 
net = tflearn.dropout(net, 0.5) 
net = tflearn.fully_connected(net, 10, activation = 'softmax') 
net = tflearn.regression(net, optimizer='adam', loss='categorical_crossentropy') 

model = tflearn.DNN(net, tensorboard_verbose=1) 
model.fit(traininginput, trainingoutput, n_epoch=100, validation_set=(validationinput, validationoutput), show_metric=True, run_id="blah") 

Erzeugt die folgenden in der Konsole:

daniel[email protected]:~/ML$ python tf 
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcublas.so locally 
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcudnn.so locally 
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcufft.so locally 
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcuda.so.1 locally 
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcurand.so locally 
hdf5 not supported (please install/reinstall h5py) 
<type 'numpy.ndarray'> 
[('signals', 'O')] 
2 
48961 
48961 
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:900] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 
I tensorflow/core/common_runtime/gpu/gpu_init.cc:102] Found device 0 with properties: 
name: GeForce GTX 860M 
major: 5 minor: 0 memoryClockRate (GHz) 1.0195 
pciBusID 0000:01:00.0 
Total memory: 2.00GiB 
Free memory: 1.72GiB 
I tensorflow/core/common_runtime/gpu/gpu_init.cc:126] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 0: Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:755] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 860M, pci bus id: 0000:01:00.0) 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:755] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 860M, pci bus id: 0000:01:00.0) 
--------------------------------- 
Run id: blah 
Log directory: /tmp/tflearn_logs/ 
--------------------------------- 
Training samples: 44137 
Validation samples: 2454 
-- 
-- 
Traceback (most recent call last): 
    File "tf", line 52, in <module> 
    model.fit(traininginput, trainingoutput, n_epoch=100, validation_set=(validationinput, validationoutput), show_metric=True, run_id="blah") 
    File "/home/daniel/.local/lib/python2.7/site-packages/tflearn/models/dnn.py", line 188, in fit 
    run_id=run_id) 
    File "/home/daniel/.local/lib/python2.7/site-packages/tflearn/helpers/trainer.py", line 277, in fit 
    show_metric) 
    File "/home/daniel/.local/lib/python2.7/site-packages/tflearn/helpers/trainer.py", line 684, in _train 
    feed_batch) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 340, in run 
    run_metadata_ptr) 
    File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 548, in _run 
    np_val = np.array(subfeed_val, dtype=subfeed_t.dtype.as_numpy_dtype) 
ValueError: setting an array element with a sequence. 
[email protected]:~/ML$ 

Antwort

0

Was die Form ist und dtype von fit Eingaben. Ich frage mich, speziell über Arrays wie traininginput, trainingoutput

ich Ihre Fehlermeldung mit

In [2]: np.array([[1,2,3],[1,2],[]],dtype=float) 
--------------------------------------------------------------------------- 
ValueError        Traceback (most recent call last) 
<ipython-input-2-8d52a0bc26f2> in <module>() 
----> 1 np.array([[1,2,3],[1,2],[]],dtype=float) 

ValueError: setting an array element with a sequence. 

In [3]: np.array([[1,2,3],[1,2],[]],dtype=object) 
Out[3]: array([[1, 2, 3], [1, 2], []], dtype=object) 

Meine Eingabe ist eine Liste von Listen unterschiedlicher Länge produzieren kann. Es kann ein Objekt-dtype-Array erstellen, aber wenn es angewiesen wird, es zu floaten, wenn dieser sequence-Fehler auslöst.

Beim Debuggen von numpy Code ist die erste Sache zu überprüfen, die shape und dtype der entsprechenden Arrays.

+0

Ich fügte die Formen und Typen hinzu. Die Formen sind alle nur die Anzahl der Exemplare; muss ich sie umsetzen? Ich bin mir nicht sicher, was ich mit diesen Informationen anfangen soll. –

+0

Es scheint, dass die Formen falsch sind, aber ich habe keine Ahnung warum. –

+0

Was ist los mit der Form? Was sollen diese Arrays darstellen? Zahlen, zerlumpte Listen, zufällige Objekte? Arrays anderer Arrays? Mehrdimensionale Arrays? – hpaulj

0

Es scheint, dass Sie ein Array mit inkonsistenter Dimension füttern. Also der Fehler, der ausgelöst wird. TensorFlow versucht, Ihr Array in ein numpiges Array zu konvertieren, schlägt aber fehl, weil inkonsistente Dimensionsfelder nicht in numpy ndarray umgewandelt werden können. Es könnte also ein Problem mit Ihren Daten sein.

See: Tensorflow (python): "ValueError: setting an array element with a sequence" in train_step.run(...)

Auch für das Debuggen Zweck können Sie versuchen, den Validierungssatz zu entfernen, um zu sehen, ob das funktioniert.

0

Ich hatte den gleichen Fehler "ValueError: Setzen eines Array-Elements mit einer Sequenz." für Iris Problem eingestellt. Also um es zu lösen habe ich meinen Datentyp geändert. Ich konvertierte Daten in numpy.darray und für Etiketten Ich machte zuerst ein One-Hot-Array für alle Etiketten und dann eine Liste dieser Arrays.

und es löste meinen Fehler

Verwandte Themen