Thank you so much for your reply. This method works when we know about the input already. If I want to use this self-attention block inside of any other bigger network at multiple locations, I need to query different class methods every time to estimate the input shape. For each query, I need to build the network up to that point.
I am expecting way like the forward class method which can automatically take the input x from the training batch for the first time only and update self.weight and self.height