Setting input shape for an NLP task in R(Rstudio) using keras 1D convolution layer, when it expects 3 dimensional input (a tensor) Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election Resultsfeature extraction for a pretrained model in kerasKeras — Transfer learning — changing Input tensor shapeKeras shape error in applications Inception Resnet v2How to set input for proper fit with lstm?Keras exception: ValueError: Error when checking input: expected conv2d_1_input to have shape (150, 150, 3) but got array with shape (256, 256, 3)Keras input shape errorKeras input shape returning an error3 dimensional array as input with Embedding Layer and LSTM in KerasIN CIFAR 10 DATASETHow to set kernel size (height and width) for 1D convolution layer in CNN Keras R API for doc2vec input?

GDP with Intermediate Production

Putting class ranking in CV, but against dept guidelines

Why not send Voyager 3 and 4 following up the paths taken by Voyager 1 and 2 to re-transmit signals of later as they fly away from Earth?

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

New Order #6: Easter Egg

How much damage would a cupful of neutron star matter do to the Earth?

Google .dev domain strangely redirects to https

What does this say in Elvish?

Getting out of while loop on console

A term for a woman complaining about things/begging in a cute/childish way

Can two person see the same photon?

Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?

Special flights

Co-worker has annoying ringtone

As a dual citizen, my US passport will expire one day after traveling to the US. Will this work?

Why is std::move not [[nodiscard]] in C++20?

Tannaka duality for semisimple groups

Can an iPhone 7 be made to function as a NFC Tag?

How were pictures turned from film to a big picture in a picture frame before digital scanning?

Should a wizard buy fine inks every time he want to copy spells into his spellbook?

What does Turing mean by this statement?

Why are vacuum tubes still used in amateur radios?

What is the "studentd" process?

One-one communication



Setting input shape for an NLP task in R(Rstudio) using keras 1D convolution layer, when it expects 3 dimensional input (a tensor)



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election Resultsfeature extraction for a pretrained model in kerasKeras — Transfer learning — changing Input tensor shapeKeras shape error in applications Inception Resnet v2How to set input for proper fit with lstm?Keras exception: ValueError: Error when checking input: expected conv2d_1_input to have shape (150, 150, 3) but got array with shape (256, 256, 3)Keras input shape errorKeras input shape returning an error3 dimensional array as input with Embedding Layer and LSTM in KerasIN CIFAR 10 DATASETHow to set kernel size (height and width) for 1D convolution layer in CNN Keras R API for doc2vec input?










0












$begingroup$


I am using R programming language and using Keras API to build a functional 1D CNN.



I have a matrix of my dataset of the following shape rows*features (6000*1024).



The input layer is set using the following code:



input_layer = layer_input(shape = 1024, batch_shape = c(nrow(train_matrix),1024), dtype = 'float64') 


and then I am building a 1d conv layer as follows:



conv1 = input_layer %>% layer_conv_1d(filters = 32, kernel_size = 50, strides = 10, input_shape = 1024, batch_input_shape = list(NULL, 1024) ,dtype = 'float64', activation = 'relu' )


But I get the following error:




Error in py_call_impl(callable, dots$args, dots$keywords) :
ValueError: Input 0 is incompatible with layer conv1d: expected ndim=3, found ndim=2




I believe it is due to the fact that 1D cnn layer expects the input in the following form




Input shape: 3D tensor with shape: (batch_size, steps, input_dim)




I understand that I have to reshape my data as (NULL, nrow(train_matrix), 1; as this has been suggested in various answer for the same issue arising for keras when used in Python.



If I am right,



  1. what values should I provide to input layer

  2. how should i reshape my training data?

  3. does that mean I have to reshape the test data as well?

also if my understanding is wrong what should be done otherwise ?










share|improve this question











$endgroup$
















    0












    $begingroup$


    I am using R programming language and using Keras API to build a functional 1D CNN.



    I have a matrix of my dataset of the following shape rows*features (6000*1024).



    The input layer is set using the following code:



    input_layer = layer_input(shape = 1024, batch_shape = c(nrow(train_matrix),1024), dtype = 'float64') 


    and then I am building a 1d conv layer as follows:



    conv1 = input_layer %>% layer_conv_1d(filters = 32, kernel_size = 50, strides = 10, input_shape = 1024, batch_input_shape = list(NULL, 1024) ,dtype = 'float64', activation = 'relu' )


    But I get the following error:




    Error in py_call_impl(callable, dots$args, dots$keywords) :
    ValueError: Input 0 is incompatible with layer conv1d: expected ndim=3, found ndim=2




    I believe it is due to the fact that 1D cnn layer expects the input in the following form




    Input shape: 3D tensor with shape: (batch_size, steps, input_dim)




    I understand that I have to reshape my data as (NULL, nrow(train_matrix), 1; as this has been suggested in various answer for the same issue arising for keras when used in Python.



    If I am right,



    1. what values should I provide to input layer

    2. how should i reshape my training data?

    3. does that mean I have to reshape the test data as well?

    also if my understanding is wrong what should be done otherwise ?










    share|improve this question











    $endgroup$














      0












      0








      0





      $begingroup$


      I am using R programming language and using Keras API to build a functional 1D CNN.



      I have a matrix of my dataset of the following shape rows*features (6000*1024).



      The input layer is set using the following code:



      input_layer = layer_input(shape = 1024, batch_shape = c(nrow(train_matrix),1024), dtype = 'float64') 


      and then I am building a 1d conv layer as follows:



      conv1 = input_layer %>% layer_conv_1d(filters = 32, kernel_size = 50, strides = 10, input_shape = 1024, batch_input_shape = list(NULL, 1024) ,dtype = 'float64', activation = 'relu' )


      But I get the following error:




      Error in py_call_impl(callable, dots$args, dots$keywords) :
      ValueError: Input 0 is incompatible with layer conv1d: expected ndim=3, found ndim=2




      I believe it is due to the fact that 1D cnn layer expects the input in the following form




      Input shape: 3D tensor with shape: (batch_size, steps, input_dim)




      I understand that I have to reshape my data as (NULL, nrow(train_matrix), 1; as this has been suggested in various answer for the same issue arising for keras when used in Python.



      If I am right,



      1. what values should I provide to input layer

      2. how should i reshape my training data?

      3. does that mean I have to reshape the test data as well?

      also if my understanding is wrong what should be done otherwise ?










      share|improve this question











      $endgroup$




      I am using R programming language and using Keras API to build a functional 1D CNN.



      I have a matrix of my dataset of the following shape rows*features (6000*1024).



      The input layer is set using the following code:



      input_layer = layer_input(shape = 1024, batch_shape = c(nrow(train_matrix),1024), dtype = 'float64') 


      and then I am building a 1d conv layer as follows:



      conv1 = input_layer %>% layer_conv_1d(filters = 32, kernel_size = 50, strides = 10, input_shape = 1024, batch_input_shape = list(NULL, 1024) ,dtype = 'float64', activation = 'relu' )


      But I get the following error:




      Error in py_call_impl(callable, dots$args, dots$keywords) :
      ValueError: Input 0 is incompatible with layer conv1d: expected ndim=3, found ndim=2




      I believe it is due to the fact that 1D cnn layer expects the input in the following form




      Input shape: 3D tensor with shape: (batch_size, steps, input_dim)




      I understand that I have to reshape my data as (NULL, nrow(train_matrix), 1; as this has been suggested in various answer for the same issue arising for keras when used in Python.



      If I am right,



      1. what values should I provide to input layer

      2. how should i reshape my training data?

      3. does that mean I have to reshape the test data as well?

      also if my understanding is wrong what should be done otherwise ?







      deep-learning keras r convnet






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 2 at 13:45







      user3516188

















      asked Apr 2 at 13:24









      user3516188user3516188

      62




      62




















          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          The input layer was producing a 2d tensor, whereas 1d convolutional layer expects a 3d tensor as input. A good explanation of as to why keras expects it and how should you reshape your 2d input to 3d can be found in this answer.



          I used Keras R API function k_reshape( 2d_tensor, (list_of_new_dims)) --> k_reshape(input_layer, list(nrow(train_matrix), num_of_feature_vectors, 1).



          nrow(train_matrix) - the total number of rows in my matrix (no of samples)



          num_of_feature_vectors - total number of columns in matrix (total number of features)



          1 - i want a 3d tensor with only 1 element at z axis, therefore z axis is initialised to 1






          share|improve this answer









          $endgroup$













            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "557"
            ;
            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: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2fdatascience.stackexchange.com%2fquestions%2f48442%2fsetting-input-shape-for-an-nlp-task-in-rrstudio-using-keras-1d-convolution-lay%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












            $begingroup$

            The input layer was producing a 2d tensor, whereas 1d convolutional layer expects a 3d tensor as input. A good explanation of as to why keras expects it and how should you reshape your 2d input to 3d can be found in this answer.



            I used Keras R API function k_reshape( 2d_tensor, (list_of_new_dims)) --> k_reshape(input_layer, list(nrow(train_matrix), num_of_feature_vectors, 1).



            nrow(train_matrix) - the total number of rows in my matrix (no of samples)



            num_of_feature_vectors - total number of columns in matrix (total number of features)



            1 - i want a 3d tensor with only 1 element at z axis, therefore z axis is initialised to 1






            share|improve this answer









            $endgroup$

















              0












              $begingroup$

              The input layer was producing a 2d tensor, whereas 1d convolutional layer expects a 3d tensor as input. A good explanation of as to why keras expects it and how should you reshape your 2d input to 3d can be found in this answer.



              I used Keras R API function k_reshape( 2d_tensor, (list_of_new_dims)) --> k_reshape(input_layer, list(nrow(train_matrix), num_of_feature_vectors, 1).



              nrow(train_matrix) - the total number of rows in my matrix (no of samples)



              num_of_feature_vectors - total number of columns in matrix (total number of features)



              1 - i want a 3d tensor with only 1 element at z axis, therefore z axis is initialised to 1






              share|improve this answer









              $endgroup$















                0












                0








                0





                $begingroup$

                The input layer was producing a 2d tensor, whereas 1d convolutional layer expects a 3d tensor as input. A good explanation of as to why keras expects it and how should you reshape your 2d input to 3d can be found in this answer.



                I used Keras R API function k_reshape( 2d_tensor, (list_of_new_dims)) --> k_reshape(input_layer, list(nrow(train_matrix), num_of_feature_vectors, 1).



                nrow(train_matrix) - the total number of rows in my matrix (no of samples)



                num_of_feature_vectors - total number of columns in matrix (total number of features)



                1 - i want a 3d tensor with only 1 element at z axis, therefore z axis is initialised to 1






                share|improve this answer









                $endgroup$



                The input layer was producing a 2d tensor, whereas 1d convolutional layer expects a 3d tensor as input. A good explanation of as to why keras expects it and how should you reshape your 2d input to 3d can be found in this answer.



                I used Keras R API function k_reshape( 2d_tensor, (list_of_new_dims)) --> k_reshape(input_layer, list(nrow(train_matrix), num_of_feature_vectors, 1).



                nrow(train_matrix) - the total number of rows in my matrix (no of samples)



                num_of_feature_vectors - total number of columns in matrix (total number of features)



                1 - i want a 3d tensor with only 1 element at z axis, therefore z axis is initialised to 1







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 3 at 10:26









                user3516188user3516188

                62




                62



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Data Science Stack Exchange!


                    • 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.

                    Use MathJax to format equations. MathJax reference.


                    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%2fdatascience.stackexchange.com%2fquestions%2f48442%2fsetting-input-shape-for-an-nlp-task-in-rrstudio-using-keras-1d-convolution-lay%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

                    Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

                    Luettelo Yhdysvaltain laivaston lentotukialuksista Lähteet | Navigointivalikko

                    Gary (muusikko) Sisällysluettelo Historia | Rockin' High | Lähteet | Aiheesta muualla | NavigointivalikkoInfobox OKTuomas "Gary" Keskinen Ancaran kitaristiksiProjekti Rockin' High