From what I understand, this error is caused by not using numpy arrays in tensorflow. I convert all of my lists to numpy arrays, but it doesn't work.
Is the dimensionality wrong? How can I determine what's causing the error?
The shapes and dtypes of the relevant arrays are:
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
Here's the 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")
Produces the following in the console:
daniel@beepboop:~/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.
daniel@beepboop:~/ML$