def forward(self, src,
mask: Optional[Tensor] = None,
src_key_padding_mask: Optional[Tensor] = None,
pos: Optional[Tensor] = None):
output = src
When I was learning the codes of DETR, I was puzzled with the Optional[Tensor]; what is the meaning?
Optional
is used for type hints. Please refer to this from the Python docs.
Typing was introduced in Python 3.5. It does not affect your run time, but it can be used by IDES, linters, etc to help the programmer see type annotations.
Basically, it helps you - the programmer - see what type a object is. This will help you reduce bugs and help you manage a large code base.