2

I've processed some data for usage with tensorflow into two python lists. Unfortunately, Tensorflow does not support Python lists as an input for fitting a model. A short and simple code snippet of what my current implementation looks like follows below:

data = loadData()
pythonListInputData = data[0]
pythonListInputLabels = data[1]
model = prepModel() #note that this uses keras
model.fit(pythonListInputData, pythonListInputLabels) #Leaving out my configuration settings here for simplicities sake

This results in an error:

ValueError: Please provide as model inputs either a single array or a list of arrays.

I get this error when pythonListInputData is either a list of lists or a list of arrays.

I've read through the Tensorflow tutorials and documentation but am struggling to find any useful info that makes this work.

Edit: Data structure is as follows:

pythonListInputData = data[0]

is a list of lists of integers e.g. [[234, 1, 4], [245, 2, 5], [123, 5, 11], ...]

I have also tried an alternative which is constructed as follows

pythonListInputData = []
for entry in data[0]:
    pythonListInputData.append(array.array('I', entry))

where data[0] is the format mentioned above.

pythonListInputLabels = data[1]

is a list of integers e.g. [1, 4, 2, ...]

5
  • Hard to tell the structure of your data here. Can you share some more information to make sure folks trying to answer it can replicate the issue? Commented Sep 3, 2018 at 0:38
  • Yes! Edited the question, apologies. Commented Sep 3, 2018 at 0:45
  • If you just drop an np.array(pythonListInputData) does it solve this? np here being from 'import numpy as np' Commented Sep 3, 2018 at 0:47
  • @PeterBarrettBryan that did the trick! Turns out tensorflow is referencing numpy arrays and not python's built in arrays. If you post that comment as the answer I'll mark it correct. Commented Sep 3, 2018 at 1:27
  • You got it. Thanks! Commented Sep 3, 2018 at 1:28

1 Answer 1

3

Sam! I'm posting here in case the answer is useful to folks in the future. We came to the answer in comments.

The issue is that the keras/ tensorflow model is expecting a numpy array np.array(listName)

That should fix your issue! Cheers!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.