0
votes

I want to use a convolutional neural network, but I have a 2D array for the input, not an image. I am trying to evaluate a board game state where shapes are important.

The board is 5x5 and the values can be between -1 and 1, stored as a list of lists ex:

[[-1,1.0,-1,1,-1],[0,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[-1,0.6,-1,-1,1]]

the first layer of the model is

tf.keras.layers.Conv2D(32, (3,3), input_shape=(5,5,1))

I convert the board to a numpy array

np.array([[-1,1.0,-1,1,-1],[0,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[-1,0.6,-1,-1,1]])

I gather the boards into a list. Then I convert the list into an array of arrays to fit

model.fit(np.array(x_train_l), y_train, epochs=10)

I get the following error:

ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 5, 5]

1

1 Answers

0
votes

Just reshape your numpy array to have shape (5,5,1). Currently it is with shape (5,5).

 np.array([[-1,1.0,-1,1,-1],[0,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[-1,0.6,-1,-1,1]]).reshape(5,5,1)