Giter Club home page Giter Club logo

Comments (3)

leondgarse avatar leondgarse commented on May 17, 2024

It's caused by swin_transformer_v2.py#L95 attn = keras.layers.Add()([attn, mask]). It can be fixed using attn = attn + mask instead:

# Use `attn = attn + mask` instead of `attn = keras.layers.Add()([attn, mask])`
from keras_cv_attention_models import swin_transformer_v2
mm = swin_transformer_v2.SwinTransformerV2Small_ns()
mm.save('aa.h5')
bb = keras.models.load_model('aa.h5')

But then it will throw error using TPU with bfloat16 in model saving... Not sure if any method fit both situation.
Currently, you may reload using load_weights:

from keras_cv_attention_models import swin_transformer_v2
mm = swin_transformer_v2.SwinTransformerV2Small_ns(input_shape=..., num_classes=...)
# Any other layers
mm.load_weights("{pretrained.h5}")

Maybe wrapping make_window_attention_mask as a layer can work for both situation. Will take a try.

from keras_cv_attention_models.

leondgarse avatar leondgarse commented on May 17, 2024

It should works now, for both situation. May save and load your model again:

from keras_cv_attention_models import swin_transformer_v2
mm = swin_transformer_v2.SwinTransformerV2Small_ns(input_shape=..., num_classes=...)
# Any other layers
mm.load_weights("{pretrained.h5}")
mm.save("aa.h5")

bb = keras.models.load_model('aa.h5')

from keras_cv_attention_models.

SergioG-M avatar SergioG-M commented on May 17, 2024

It works now, amazing job, thanks!

from keras_cv_attention_models.

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.