2

I have this error and I'm not sure how do I reshape where there's a dimension with None.

Exception: Error when checking : expected input_1 to have shape (None, 192) but got array with shape (192, 1)

How do I reshape an array to (None, 192)?

I've the array accuracy with shape (12, 16) and I did accuracy.reshape(-1) that gives (192,). However this is not (None, 192).

4
  • arr.ravel()[None] or arr.reshape(1,-1)? Commented Oct 19, 2016 at 23:06
  • 1
    Suspiciously similar Commented Oct 19, 2016 at 23:11
  • @AndrasDeak Thanks for the link! Commented Oct 19, 2016 at 23:47
  • So you need to tell us which module(s) you are running. Apparently this is not occurring in numpy itself. I'd expect the error to be, expected (1,192) got ...; None (np.newaxis) is used to create a a size 1 dimension, but you won't see it in a shape tuple or error message. But a module in early stages of development might still use it. Commented Oct 20, 2016 at 1:34

1 Answer 1

0

In keras/keras/engine/training.py

def standardize_input_data(data, names, shapes=None,
                           check_batch_dim=True,
                           exception_prefix=''):
     ...

    # check shapes compatibility
    if shapes:
        for i in range(len(names)):
        ...
        for j, (dim, ref_dim) in enumerate(zip(array.shape, shapes[i])):
            if not j and not check_batch_dim:
                # skip the first axis
                continue
            if ref_dim:
                if ref_dim != dim:
                    raise Exception('Error when checking ' + exception_prefix +
                                    ': expected ' + names[i] +
                                    ' to have shape ' + str(shapes[i]) +
                                    ' but got array with shape ' +
                                    str(array.shape))

Comparing that with the error

Error when checking : expected input_1 to have shape (None, 192) but got array with shape (192, 1)

So it is comparing (None, 192) with (192, 1), and skipping the 1st axis; that is comparing 192 and 1. If array has shape (n, 192) it probably would pass.

So basically, what ever is generating the (192,1) shape, as opposed to (1,192) or a broadcastable (192,) is causing the error.

I'm adding keras to the tags on the guess that this is the problem module.

Searching other keras tagged SO questions:

Exception: Error when checking model target: expected dense_3 to have shape (None, 1000) but got array with shape (32, 2)

Error: Error when checking model input: expected dense_input_6 to have shape (None, 784) but got array with shape (784L, 1L)

Dimensions not matching in keras LSTM model

Getting shape dimension errors with a simple regression using Keras

Deep autoencoder in Keras converting one dimension to another i

I don't know enough about keras to understand the answers, but there's more to it than simply reshaping your input array.

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.