Visual-Behavior / detr-tensorflow

Tensorflow implementation of DETR : Object Detection with Transformers
MIT License
168 stars 53 forks source link

visualisation of transformer attention #38

Open BeusenBart opened 2 years ago

BeusenBart commented 2 years ago

Hi, When trying to access the transformers internal outputs, in an attempt to visualize attention, I am unable to access these layers on the normal tensorflow way using e.g. "model.get_layer('transformer').get_layer('decoder').get_layer('layer_5').multihead_attn.output". It seems the graph is not fully connected as it should be. I have found a couple of fixes that allowed me to access these layers succesfully:

Maxlanglet commented 2 years ago

Hey, could you provide an example code ? Following you advice, it indeed build correctly the graph, the only thing is that when running this line : model.get_layer('transformer').get_layer('decoder').get_layer('layer_5').multihead_attn.output the following error comes up 'AttributeError: Layer multi_head_attn has no inbound nodes.'

Looking into it, it seems that this is related to the input shape being not specified. Since it should be defined in the DETR model, I am a bit lost.

Thanks in advance