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

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved