'Forward pass in keras network

I have done some hand calculations for a small and simple neural network and wanted to try verify the result in a keras network (built the same). the network looks like this:

model = keras.models.Sequential([
    Dense(units=3, input_shape=(3,2), activation='relu'),
    Dense(units=2, activation='sigmoid'),
    Dense(units=1)
    
])

The input is 2 datapoints, and the entire "dataset" is of the length 3. It looks like this:

X = [[1,2][2,3],[3,3]]

The plan was to see what the output was after running X through the model with batch size equal 3, so it runs the entire set in one iteration.

I have tried to use, and to set X as a tensor.

model.predict(X)

But then I get this error:

ValueError: Input 0 of layer "sequential_5" is incompatible with the layer: expected shape=(None, 3, 2), found shape=(None, 2)
 

Any tips for getting this to work? Would also like to be able to print out the output from every layer if possible. I have seen that model.ouputs gives something like this, but then I guess i have to train it first. The reason is that I first want to see the result of the forward pass, and then I will check the backward pass.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source