Giter Site home page Giter Site logo

get_config about keras-attention HOT 14 CLOSED

philipperemy avatar philipperemy commented on June 27, 2024
get_config

from keras-attention.

Comments (14)

philipperemy avatar philipperemy commented on June 27, 2024

Which version of tensorflow are you using? Update your tensorflow.

from keras-attention.

edithangelicar avatar edithangelicar commented on June 27, 2024

I have tensorflow 2.3.0.

For example, at the end of your example (example-attention.py ) after "model.fit" I wrote:

model.fit(x_train, y_train, validation_data=(x_val, y_val), epochs=max_epoch,
batch_size=64, callbacks=[VisualiseAttentionMap()])

#What I wrote
model.save('test_model.h5')
modelh5 = load_model('test_model.h5', custom_objects={'Attention': Attention})

Error I get:

File "C:\Users\edith\anaconda3\lib\site-packages\tensorflow\python\keras\layers\merge.py", line 663, in build
raise ValueError('A Dot layer should be called '

ValueError: A Dot layer should be called on a list of 2 inputs.

I am attaching a picture of the script where I try to save and load the model
save_error

Thank you very much for your help and time!

from keras-attention.

philipperemy avatar philipperemy commented on June 27, 2024

Good catch I think we need to use Dot instead of dot.

from keras-attention.

philipperemy avatar philipperemy commented on June 27, 2024

Hum still does not work and not sure why:

image

from keras-attention.

philipperemy avatar philipperemy commented on June 27, 2024

@edithangelicar save can sometimes be very tricky. I advise you to use load_weights and save_weights instead:

You will have to re-define your model and instanciate your model beforehand but I don't see any other solutions in the short term.

model.save_weights('test_model.h5')
model = <bla bla>
model.load_weights('test_model.h5')

from keras-attention.

edithangelicar avatar edithangelicar commented on June 27, 2024

Thank you for checking and for your help!
If at some point you get to know how to solve the problem, please let me know.
Thank you!

from keras-attention.

edithangelicar avatar edithangelicar commented on June 27, 2024

I think I managed, you have to change your model from sequential to functional API. Thank you!

from keras-attention.

nickion avatar nickion commented on June 27, 2024

Have literally just hit this issue myself; thanks for the comments and update.

from keras-attention.

edithangelicar avatar edithangelicar commented on June 27, 2024

Nickion, also remember to create the get_config and from_config in the class: https://keras.io/guides/serialization_and_saving/

from keras-attention.

philipperemy avatar philipperemy commented on June 27, 2024

Great @edithangelicar can you provide a small snippet to show how to get it to work?

from keras-attention.

edithangelicar avatar edithangelicar commented on June 27, 2024

yes. here are some pictures, it is lightly modified for fitting what I am doing so it doesn't correspond exactly to your example.
attention_class
lstm_api

from keras-attention.

philipperemy avatar philipperemy commented on June 27, 2024

@edithangelicar can you paste it here instead of pictures? It will be easier for others to understand it.

from keras-attention.

edithangelicar avatar edithangelicar commented on June 27, 2024

I am attaching txt since here I can't paste python files

functional_lstm.txt
attention.txt

from keras-attention.

philipperemy avatar philipperemy commented on June 27, 2024

Alright thanks!

from keras-attention.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.