Error when checking target: expected dense to have shape (1,) but got array with shape (15662,) maxpooling as a first layer2019 Community Moderator ElectionError when checking model input: expected lstm_1_input to have 3 dimensions, but got array with shape (339732, 29)Maxpooling Layer causes error in KerasKeras: Expected 3 dimensions, but got array with shape - dense modelValueError: Error when checking target: expected dense_2 to have 3 dimensions, but got array with shape (10000, 1)Keras: expected activation_3 to have shape (None, 3) but got array with shape (5708, 1)ValueError: Error when checking target: expected activation_6 to have shape(None,2) but got array with shape (5760,1)ValueError: Error when checking target: expected dense_2 to have shape (None, 2) but got array with shape (321, 3)TimeDistribution Wrapper Fails the CompilationIs it possible to train a CNN starting at an intermediate layer (in general and in Keras)?classifier. fit error- Error when checking input: expected dense_25_input

Sword in the Stone story where the sword was held in place by electromagnets

Old race car problem/puzzle

How could a scammer know the apps on my phone / iTunes account?

Pinhole Camera with Instant Film

Welcoming 2019 Pi day: How to draw the letter π?

How do I hide Chekhov's Gun?

How to generate globally unique ids for different tables of the same database?

Replacing Windows 7 security updates with anti-virus?

Humanity loses the vast majority of its technology, information, and population in the year 2122. How long does it take to rebuild itself?

What has been your most complicated TikZ drawing?

Possible Leak In Concrete

I need to drive a 7/16" nut but am unsure how to use the socket I bought for my screwdriver

My story is written in English, but is set in my home country. What language should I use for the dialogue?

Why are there 40 737 Max planes in flight when they have been grounded as not airworthy?

Making a sword in the stone, in a medieval world without magic

How could a female member of a species produce eggs unto death?

Can hydraulic brake levers get hot when brakes overheat?

Can the damage from a Talisman of Pure Good (or Ultimate Evil) be non-lethal?

How is the Swiss post e-voting system supposed to work, and how was it wrong?

How to make healing in an exploration game interesting

Schematic conventions for different supply rails

Is it normal that my co-workers at a fitness company criticize my food choices?

Why must traveling waves have the same amplitude to form a standing wave?

Is having access to past exams cheating and, if yes, could it be proven just by a good grade?



Error when checking target: expected dense to have shape (1,) but got array with shape (15662,) maxpooling as a first layer



2019 Community Moderator ElectionError when checking model input: expected lstm_1_input to have 3 dimensions, but got array with shape (339732, 29)Maxpooling Layer causes error in KerasKeras: Expected 3 dimensions, but got array with shape - dense modelValueError: Error when checking target: expected dense_2 to have 3 dimensions, but got array with shape (10000, 1)Keras: expected activation_3 to have shape (None, 3) but got array with shape (5708, 1)ValueError: Error when checking target: expected activation_6 to have shape(None,2) but got array with shape (5760,1)ValueError: Error when checking target: expected dense_2 to have shape (None, 2) but got array with shape (321, 3)TimeDistribution Wrapper Fails the CompilationIs it possible to train a CNN starting at an intermediate layer (in general and in Keras)?classifier. fit error- Error when checking input: expected dense_25_input










0















I'm trying to use maxpooling as a first layer using keras and I have a problem with the input and output dimensions.



print(x_train.shape)
print(y_train.shape)
(15662, 6)
(15662,)

x_train = np.reshape(x_train, (-1,15662, 6))
y_train = label_array.reshape(1, -1)

model = Sequential()
model.add(MaxPooling1D(pool_size = 2 , strides=1, input_shape = (15662,6)))
model.add(Dense(5, activation='relu'))
model.add(Flatten())
model.add(Dense(1, activation='softmax'))

model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=
['accuracy'])
model.fit(x_train, y_train, batch_size= 32, epochs=1)


After running the model, I get the following error:




ValueError: Error when checking target: expected dense_622 (last layer)
to have shape (1,) but got array with shape (15662,)




I'm doing classification and my target is binary (0,1)
Thank you










share|improve this question
























  • Note that softmax with one neuron makes no sense, it will give you a constant output of 1.0. If you want binary classification you need the sigmoid activation.

    – Matias Valdenegro
    Mar 6 at 20:15















0















I'm trying to use maxpooling as a first layer using keras and I have a problem with the input and output dimensions.



print(x_train.shape)
print(y_train.shape)
(15662, 6)
(15662,)

x_train = np.reshape(x_train, (-1,15662, 6))
y_train = label_array.reshape(1, -1)

model = Sequential()
model.add(MaxPooling1D(pool_size = 2 , strides=1, input_shape = (15662,6)))
model.add(Dense(5, activation='relu'))
model.add(Flatten())
model.add(Dense(1, activation='softmax'))

model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=
['accuracy'])
model.fit(x_train, y_train, batch_size= 32, epochs=1)


After running the model, I get the following error:




ValueError: Error when checking target: expected dense_622 (last layer)
to have shape (1,) but got array with shape (15662,)




I'm doing classification and my target is binary (0,1)
Thank you










share|improve this question
























  • Note that softmax with one neuron makes no sense, it will give you a constant output of 1.0. If you want binary classification you need the sigmoid activation.

    – Matias Valdenegro
    Mar 6 at 20:15













0












0








0








I'm trying to use maxpooling as a first layer using keras and I have a problem with the input and output dimensions.



print(x_train.shape)
print(y_train.shape)
(15662, 6)
(15662,)

x_train = np.reshape(x_train, (-1,15662, 6))
y_train = label_array.reshape(1, -1)

model = Sequential()
model.add(MaxPooling1D(pool_size = 2 , strides=1, input_shape = (15662,6)))
model.add(Dense(5, activation='relu'))
model.add(Flatten())
model.add(Dense(1, activation='softmax'))

model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=
['accuracy'])
model.fit(x_train, y_train, batch_size= 32, epochs=1)


After running the model, I get the following error:




ValueError: Error when checking target: expected dense_622 (last layer)
to have shape (1,) but got array with shape (15662,)




I'm doing classification and my target is binary (0,1)
Thank you










share|improve this question
















I'm trying to use maxpooling as a first layer using keras and I have a problem with the input and output dimensions.



print(x_train.shape)
print(y_train.shape)
(15662, 6)
(15662,)

x_train = np.reshape(x_train, (-1,15662, 6))
y_train = label_array.reshape(1, -1)

model = Sequential()
model.add(MaxPooling1D(pool_size = 2 , strides=1, input_shape = (15662,6)))
model.add(Dense(5, activation='relu'))
model.add(Flatten())
model.add(Dense(1, activation='softmax'))

model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=
['accuracy'])
model.fit(x_train, y_train, batch_size= 32, epochs=1)


After running the model, I get the following error:




ValueError: Error when checking target: expected dense_622 (last layer)
to have shape (1,) but got array with shape (15662,)




I'm doing classification and my target is binary (0,1)
Thank you







keras layer max-pooling






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 6 at 18:38









desertnaut

19.4k74076




19.4k74076










asked Mar 6 at 18:35









user10950908user10950908

11




11












  • Note that softmax with one neuron makes no sense, it will give you a constant output of 1.0. If you want binary classification you need the sigmoid activation.

    – Matias Valdenegro
    Mar 6 at 20:15

















  • Note that softmax with one neuron makes no sense, it will give you a constant output of 1.0. If you want binary classification you need the sigmoid activation.

    – Matias Valdenegro
    Mar 6 at 20:15
















Note that softmax with one neuron makes no sense, it will give you a constant output of 1.0. If you want binary classification you need the sigmoid activation.

– Matias Valdenegro
Mar 6 at 20:15





Note that softmax with one neuron makes no sense, it will give you a constant output of 1.0. If you want binary classification you need the sigmoid activation.

– Matias Valdenegro
Mar 6 at 20:15












1 Answer
1






active

oldest

votes


















0














Your target should have shape (batch_size, 1) but you are passing an array of shape (1, 15662). It seems like 15662 should be the batch size, in which case x_train should have shape (15662, 6) and y_train should have shape (15662, 1). In this case however, it doesn't make any sense to have a MaxPooling1D layer as the first layer of your model since max pooling requires a 3D input (i.e. shape (batch_size, time_steps, features)). You probably want to leave out the max pooling layer (and the Flatten layer). The following code should work:



# x_train: (15662, 6)
# y_train: (15662,)

model = Sequential()
model.add(Dense(5, activation='relu', input_shape=(6,))) # Note: don't specify the batch size in input_shape
model.add(Dense(1, activation='sigmoid'))

model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=
['accuracy'])
model.fit(x_train, y_train, batch_size= 32, epochs=1)


But it of course depends on what kind of data you have.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55030026%2ferror-when-checking-target-expected-dense-to-have-shape-1-but-got-array-with%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Your target should have shape (batch_size, 1) but you are passing an array of shape (1, 15662). It seems like 15662 should be the batch size, in which case x_train should have shape (15662, 6) and y_train should have shape (15662, 1). In this case however, it doesn't make any sense to have a MaxPooling1D layer as the first layer of your model since max pooling requires a 3D input (i.e. shape (batch_size, time_steps, features)). You probably want to leave out the max pooling layer (and the Flatten layer). The following code should work:



    # x_train: (15662, 6)
    # y_train: (15662,)

    model = Sequential()
    model.add(Dense(5, activation='relu', input_shape=(6,))) # Note: don't specify the batch size in input_shape
    model.add(Dense(1, activation='sigmoid'))

    model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=
    ['accuracy'])
    model.fit(x_train, y_train, batch_size= 32, epochs=1)


    But it of course depends on what kind of data you have.






    share|improve this answer





























      0














      Your target should have shape (batch_size, 1) but you are passing an array of shape (1, 15662). It seems like 15662 should be the batch size, in which case x_train should have shape (15662, 6) and y_train should have shape (15662, 1). In this case however, it doesn't make any sense to have a MaxPooling1D layer as the first layer of your model since max pooling requires a 3D input (i.e. shape (batch_size, time_steps, features)). You probably want to leave out the max pooling layer (and the Flatten layer). The following code should work:



      # x_train: (15662, 6)
      # y_train: (15662,)

      model = Sequential()
      model.add(Dense(5, activation='relu', input_shape=(6,))) # Note: don't specify the batch size in input_shape
      model.add(Dense(1, activation='sigmoid'))

      model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=
      ['accuracy'])
      model.fit(x_train, y_train, batch_size= 32, epochs=1)


      But it of course depends on what kind of data you have.






      share|improve this answer



























        0












        0








        0







        Your target should have shape (batch_size, 1) but you are passing an array of shape (1, 15662). It seems like 15662 should be the batch size, in which case x_train should have shape (15662, 6) and y_train should have shape (15662, 1). In this case however, it doesn't make any sense to have a MaxPooling1D layer as the first layer of your model since max pooling requires a 3D input (i.e. shape (batch_size, time_steps, features)). You probably want to leave out the max pooling layer (and the Flatten layer). The following code should work:



        # x_train: (15662, 6)
        # y_train: (15662,)

        model = Sequential()
        model.add(Dense(5, activation='relu', input_shape=(6,))) # Note: don't specify the batch size in input_shape
        model.add(Dense(1, activation='sigmoid'))

        model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=
        ['accuracy'])
        model.fit(x_train, y_train, batch_size= 32, epochs=1)


        But it of course depends on what kind of data you have.






        share|improve this answer















        Your target should have shape (batch_size, 1) but you are passing an array of shape (1, 15662). It seems like 15662 should be the batch size, in which case x_train should have shape (15662, 6) and y_train should have shape (15662, 1). In this case however, it doesn't make any sense to have a MaxPooling1D layer as the first layer of your model since max pooling requires a 3D input (i.e. shape (batch_size, time_steps, features)). You probably want to leave out the max pooling layer (and the Flatten layer). The following code should work:



        # x_train: (15662, 6)
        # y_train: (15662,)

        model = Sequential()
        model.add(Dense(5, activation='relu', input_shape=(6,))) # Note: don't specify the batch size in input_shape
        model.add(Dense(1, activation='sigmoid'))

        model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=
        ['accuracy'])
        model.fit(x_train, y_train, batch_size= 32, epochs=1)


        But it of course depends on what kind of data you have.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 6 at 20:17

























        answered Mar 6 at 18:50









        Anna KrogagerAnna Krogager

        1,523314




        1,523314





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55030026%2ferror-when-checking-target-expected-dense-to-have-shape-1-but-got-array-with%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            1928 у кіно

            Захаров Федір Захарович

            Ель Греко