Skip to content
Advertisement

Tensorflow dataset from numpy array

I have two numpy Arrays (X, Y) which I want to convert to a tensorflow dataset. According to the documentation it should be possible to run

JavaScript

When doing this however I get the error: ValueError: Shapes (15, 1) and (768, 15) are incompatible

This would make sense if the shapes of the numpy Arrays would be incompatible to the expected inputs/outputs. But if I run it with the numpy arrays by using model.fit(X,Y) it runs without any problems, so the shapes seem to be okay.

In a next step I checked the output sizes:

JavaScript

The input layer for the neural network expect (None, None) and the output (None, 15). So this also seems to match.

My dataset is rather large, so it’s difficult to share that, but here is a minimal reproducible example which shows the problem. It’s the same error, and the fit with just the numpy arrays works.

JavaScript

Can someone point me into the right direction on how to solve this?

Tensorflow version is 2.3.1.

Advertisement

Answer

It will work if you batch your dataset:

JavaScript
Advertisement