Closed lorenzo-park closed 2 years ago
Perhaps the problem could be found in these lines
for layer in vit_model.layers:
x = layer(x)
# Some modification will be made here playing with x
The models in tfimm
are not functional models. They are subclassed models with a custom implementation of call()
, see e.g., vit.
I am wondering if the modifications you are introducing don't play nicely with the expectations of call()
. Note, e.g., that ViT adds positional encodings as weights, not keras layers.
Thank you for your reply. Now I understand what subclassed models and functional models are. The approach above seems not allowed for subclassed model. I was trying to access the intermediate outputs of the ViT model, especially the attention value of MHA layer. Could you give any suggestion on this?
Well, I end up modifying the original code and add a feed-forward function returning the MHA layer output.
Hi, I was building a model using ViT by iterating through the layers, but got error
Incompatible shapes: [4] vs. [4,196]
when I callmodel.fit
. Any ideas where the mismatch is happening? or it would be grateful if you guide me how to debug it (I am new to tensorflow). Here is the function for building a ViT model for finetuning.