pytorch yolov5 focus layer
The definition of focus in yolov5 is as follows:
It can be more intuitively understood from the image
4 * 4 * 3 becomes 2 * 2 * 12
The meaning of x[..., ::2, ::2] is as follows
... : Indicates all channels (3 channels in the figure)
::2 : Indicates all values from the first line to the end of the last line with a step size of 2 (all values in the first line and the third line in the figure)
::2 : Indicates all values from the first column to the end of the last column with a step size of 2 (all values in the first column and the third column in the figure)
The final intersection is the square marked 1 in the figure (marked with a red background in the figure)
Usage of torch.cat()
If we have two tensors A and B, and want to stitch them together, we need to do the following:
C = torch.cat( (A,B),0 ) #splicing according to dimension 0 (vertically) splicing in rows
C = torch.cat( (A,B),1 ) #splicing according to dimension 1 (horizontally) spell) splicing by column
The definition of focus in yolov5 is as follows:
It can be more intuitively understood from the image
4 * 4 * 3 becomes 2 * 2 * 12
The meaning of x[..., ::2, ::2] is as follows
... : Indicates all channels (3 channels in the figure)
::2 : Indicates all values from the first line to the end of the last line with a step size of 2 (all values in the first line and the third line in the figure)
::2 : Indicates all values from the first column to the end of the last column with a step size of 2 (all values in the first column and the third column in the figure)
The final intersection is the square marked 1 in the figure (marked with a red background in the figure)
Usage of torch.cat()
If we have two tensors A and B, and want to stitch them together, we need to do the following:
C = torch.cat( (A,B),0 ) #splicing according to dimension 0 (vertically) splicing in rows
C = torch.cat( (A,B),1 ) #splicing according to dimension 1 (horizontally) spell) splicing by column