Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a custom layer at the end of a trained Model #7350

Open
jenniew opened this issue Jan 27, 2023 · 4 comments
Open

Add a custom layer at the end of a trained Model #7350

jenniew opened this issue Jan 27, 2023 · 4 comments

Comments

@jenniew
Copy link
Contributor

jenniew commented Jan 27, 2023

From user group issue, how to add layer to end of existing dllib keras graph model. Using nodes(someNames) or node(someName) can only apply to layers having name. The getInputs() and getOutputs() are private now. Should we make them public to easily manipulate input and output layers?
Related issue: https://groups.google.com/u/1/g/bigdl-user-group/c/G8HvbLpZCZ8

@jason-dai
Copy link
Contributor

Can we add the model and additional layers to Sequential?

Or something like

in = Input(...)
out = model(in)
...

@emartinezs44
Copy link

emartinezs44 commented Feb 2, 2023

I could add more examples using the functional api in the doc. I usually use stackoverflow, because there are a lot of spark community and it will help for bigdl to reach to more people.

@emartinezs44
Copy link

emartinezs44 commented Feb 2, 2023

An example would be:

  val input = Variable[Float](Shape(1, 10))
  val dense1 = Dense[Float](2).from(input)
  
  // existing model
  val model = Model(input, dense1)

  val newLayer = Dense[Float](2)
  // Add a new layer to existing model
  val sequential =
    Sequential[Float]()
    .add(model)
    .add(newLayer)
Original model:
------------------------------------------------------------------------------------------------------------------------
Layer (type)                            Output Shape              Param #       Connected to                          
========================================================================================================================
Inputeadea940 (Input)                   (None, 1, 10)             0                                                   
________________________________________________________________________________________________________________________
Densee7b602d8 (Dense)                   (None, 1, 2)              22            Inputeadea940                         
________________________________________________________________________________________________________________________
Total params: 22
Trainable params: 22
Non-trainable params: 0


Model with a new layer:
------------------------------------------------------------------------------------------------------------------------
23-02-02 18:40:50 [main] INFO  InternalDistriOptimizer$:182 - Model Summary:
------------------------------------------------------------------------------------------------------------------------
Layer (type)                            Output Shape              Param #       Connected to                          
========================================================================================================================
Inputb1d1e4a4 (Input)                   (None, 1, 10)             0                                                   
________________________________________________________________________________________________________________________
Modele623acc9 (Model)                   (None, 1, 2)              22            Inputb1d1e4a4                         
________________________________________________________________________________________________________________________
Dense38b91e4d (Dense)                   (None, 1, 2)              6             Modele623acc9                         
________________________________________________________________________________________________________________________
Total params: 28
Trainable params: 28
Non-trainable params: 0
------------------------------------------------------------------------------------------------------------------------

@jason-dai
Copy link
Contributor

I could add more examples using the functional api in the doc. I usually use stackoverflow, because there are a lot of spark community and it will help for bigdl to reach to more people.

stackoverflow sounds like a great idea :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants