How to expand dims of my Keras layer and avoid using Lambda layerKeras: Use the same layer in different models (share weights)Unable to understand how lambda layer work in keras?Keras Lambda Layer giving ValueError: None values not supported when trying to fit modelWrap tensorflow function in keras layerHow to load MobileNet weights with an input tensor in KerasHow to Build a 2D Weights Matrix in Keras?Multiple Embedding layers for Keras Sequential modelValueError: Output tensors to a Model must be the output of a TensorFlow Layer with tf.keras Lambda layerThe initial state or constants of an RNN layer cannot be specified with a mix of Keras tensors and non-Keras tensors3 dimensional array as input with Embedding Layer and LSTM in Keras

How to re-create Edward Weson's Pepper No. 30?

Why is the design of haulage companies so “special”?

Representing power series as a function - what to do with the constant after integration?

Theorems that impeded progress

Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

Today is the Center

Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)

Why Is Death Allowed In the Matrix?

What is the offset in a seaplane's hull?

XeLaTeX and pdfLaTeX ignore hyphenation

"You are your self first supporter", a more proper way to say it

A function which translates a sentence to title-case

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?

Motorized valve interfering with button?

Python: Add Submenu

What do you call something that goes against the spirit of the law, but is legal when interpreting the law to the letter?

"which" command doesn't work / path of Safari?

Download, install and reboot computer at night if needed

How to add power-LED to my small amplifier?

How to report a triplet of septets in NMR tabulation?

Copenhagen passport control - US citizen

Why don't electron-positron collisions release infinite energy?



How to expand dims of my Keras layer and avoid using Lambda layer


Keras: Use the same layer in different models (share weights)Unable to understand how lambda layer work in keras?Keras Lambda Layer giving ValueError: None values not supported when trying to fit modelWrap tensorflow function in keras layerHow to load MobileNet weights with an input tensor in KerasHow to Build a 2D Weights Matrix in Keras?Multiple Embedding layers for Keras Sequential modelValueError: Output tensors to a Model must be the output of a TensorFlow Layer with tf.keras Lambda layerThe initial state or constants of an RNN layer cannot be specified with a mix of Keras tensors and non-Keras tensors3 dimensional array as input with Embedding Layer and LSTM in Keras






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I' m using tensorflow.js and try to convert my keras model to tf.js model. However, it doesn't support Lambda layer which I try to use to convert tensorto layer(I use expand_dims) in my model(If not use it, model won't be created correctly, you know the reason). So I wonder if there is any way that I can avoid using Lambda layer and expand the dim of my embedding_layer.



# input layer
input_x = Input(shape=(sequence_length, ), dtype='int32')

# embedding layer
embedding_layer = Embedding(vocab_size,
embedding_size,
embeddings_initializer=random_uniform(minval=-1.0, maxval=1.0))(input_x)
embedded_sequences = Lambda(lambda x: expand_dims(x, -1))(embedding_layer)


I'll appreciate it if you could give me some help, thanks!










share|improve this question






















  • js.tensorflow.org/api/0.15.3/#expandDims

    – Manoj Mohan
    Mar 22 at 1:24











  • But my model is converted from Keras, so I can't expand dim of the model in js, it's fixed in "model.json".

    – Jackie Swocky
    Mar 22 at 2:28

















0















I' m using tensorflow.js and try to convert my keras model to tf.js model. However, it doesn't support Lambda layer which I try to use to convert tensorto layer(I use expand_dims) in my model(If not use it, model won't be created correctly, you know the reason). So I wonder if there is any way that I can avoid using Lambda layer and expand the dim of my embedding_layer.



# input layer
input_x = Input(shape=(sequence_length, ), dtype='int32')

# embedding layer
embedding_layer = Embedding(vocab_size,
embedding_size,
embeddings_initializer=random_uniform(minval=-1.0, maxval=1.0))(input_x)
embedded_sequences = Lambda(lambda x: expand_dims(x, -1))(embedding_layer)


I'll appreciate it if you could give me some help, thanks!










share|improve this question






















  • js.tensorflow.org/api/0.15.3/#expandDims

    – Manoj Mohan
    Mar 22 at 1:24











  • But my model is converted from Keras, so I can't expand dim of the model in js, it's fixed in "model.json".

    – Jackie Swocky
    Mar 22 at 2:28













0












0








0


1






I' m using tensorflow.js and try to convert my keras model to tf.js model. However, it doesn't support Lambda layer which I try to use to convert tensorto layer(I use expand_dims) in my model(If not use it, model won't be created correctly, you know the reason). So I wonder if there is any way that I can avoid using Lambda layer and expand the dim of my embedding_layer.



# input layer
input_x = Input(shape=(sequence_length, ), dtype='int32')

# embedding layer
embedding_layer = Embedding(vocab_size,
embedding_size,
embeddings_initializer=random_uniform(minval=-1.0, maxval=1.0))(input_x)
embedded_sequences = Lambda(lambda x: expand_dims(x, -1))(embedding_layer)


I'll appreciate it if you could give me some help, thanks!










share|improve this question














I' m using tensorflow.js and try to convert my keras model to tf.js model. However, it doesn't support Lambda layer which I try to use to convert tensorto layer(I use expand_dims) in my model(If not use it, model won't be created correctly, you know the reason). So I wonder if there is any way that I can avoid using Lambda layer and expand the dim of my embedding_layer.



# input layer
input_x = Input(shape=(sequence_length, ), dtype='int32')

# embedding layer
embedding_layer = Embedding(vocab_size,
embedding_size,
embeddings_initializer=random_uniform(minval=-1.0, maxval=1.0))(input_x)
embedded_sequences = Lambda(lambda x: expand_dims(x, -1))(embedding_layer)


I'll appreciate it if you could give me some help, thanks!







tensorflow keras






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 0:43









Jackie SwockyJackie Swocky

133




133












  • js.tensorflow.org/api/0.15.3/#expandDims

    – Manoj Mohan
    Mar 22 at 1:24











  • But my model is converted from Keras, so I can't expand dim of the model in js, it's fixed in "model.json".

    – Jackie Swocky
    Mar 22 at 2:28

















  • js.tensorflow.org/api/0.15.3/#expandDims

    – Manoj Mohan
    Mar 22 at 1:24











  • But my model is converted from Keras, so I can't expand dim of the model in js, it's fixed in "model.json".

    – Jackie Swocky
    Mar 22 at 2:28
















js.tensorflow.org/api/0.15.3/#expandDims

– Manoj Mohan
Mar 22 at 1:24





js.tensorflow.org/api/0.15.3/#expandDims

– Manoj Mohan
Mar 22 at 1:24













But my model is converted from Keras, so I can't expand dim of the model in js, it's fixed in "model.json".

– Jackie Swocky
Mar 22 at 2:28





But my model is converted from Keras, so I can't expand dim of the model in js, it's fixed in "model.json".

– Jackie Swocky
Mar 22 at 2:28












1 Answer
1






active

oldest

votes


















0














I solved it by myself.
Just use reshape.



from keras.backend import int_shape
......
embedded_sequences = Reshape((int_shape(embedding_layer)[1], int_shape(embedding_layer)[2], 1))(embedding_layer)
......


You could expand dim without using expand_dims and Lambda layer.






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%2f55291277%2fhow-to-expand-dims-of-my-keras-layer-and-avoid-using-lambda-layer%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














    I solved it by myself.
    Just use reshape.



    from keras.backend import int_shape
    ......
    embedded_sequences = Reshape((int_shape(embedding_layer)[1], int_shape(embedding_layer)[2], 1))(embedding_layer)
    ......


    You could expand dim without using expand_dims and Lambda layer.






    share|improve this answer



























      0














      I solved it by myself.
      Just use reshape.



      from keras.backend import int_shape
      ......
      embedded_sequences = Reshape((int_shape(embedding_layer)[1], int_shape(embedding_layer)[2], 1))(embedding_layer)
      ......


      You could expand dim without using expand_dims and Lambda layer.






      share|improve this answer

























        0












        0








        0







        I solved it by myself.
        Just use reshape.



        from keras.backend import int_shape
        ......
        embedded_sequences = Reshape((int_shape(embedding_layer)[1], int_shape(embedding_layer)[2], 1))(embedding_layer)
        ......


        You could expand dim without using expand_dims and Lambda layer.






        share|improve this answer













        I solved it by myself.
        Just use reshape.



        from keras.backend import int_shape
        ......
        embedded_sequences = Reshape((int_shape(embedding_layer)[1], int_shape(embedding_layer)[2], 1))(embedding_layer)
        ......


        You could expand dim without using expand_dims and Lambda layer.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 4:06









        Jackie SwockyJackie Swocky

        133




        133





























            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%2f55291277%2fhow-to-expand-dims-of-my-keras-layer-and-avoid-using-lambda-layer%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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해