Patchify: The order in which the image block is leveled also belongs to the model protocol
Vision Transformer cuts the image into patch and projectes each pixel as token.
Learning objectives and first steps2 objectives 2 first fixes
Try to do it after reading
- Track Image to token It's... shape Change
- Inspection patch Internal and patch Arrange between
Suggested first
- Thrust and Matrix Operations
- Basic neural network
Image block is not a random sequence from reshape
Vision Transformer cuts the image into patch and projectes each pixel as token. It must also be clear what order the blocks are arranged between them, what order they are to be levelled within them, and where the axis of the tunnel is placed. The correct sum of elements is not sufficient to ensure that the image is structured correctly.
Enter a single channel 4x4, with values from rows 1 to 16, and patch 2 x 2. By row, the first block was shown in equal numbers [1,2,5,5,6], the second [3,4,7,8], the third [9,10,13,14], and the fourth [11,12,15,16]. Just take the whole picture. reshape In four rows, four columns do not get the same inner relationship.
If there are 3 channels, the length of each block is 2 x 2 x 3 = 12. Passage priority and pixel priority can be achieved by using different projector weights, provided that the load is identical to the weight already given. The error order usually still produces a legal [number of blocks,12] and therefore requires a fixed index sample to be verified.
Projection and position encoding are different
Each linear projection maps the pixel dimensions to hidden dimensions, and the position code distinguishes the location of the block. If the block order changes, the old location code continues to be used, and the content is wrongly matched to the location. Special CLS and other special tokens also need to be inserted separately and cannot be commingled when space grids are reset.
When the size is not separated from the size of patch, you must clearly crop, complete or reject it. Changes in the range of the completed back blocks and active pixels shall also be recorded in sync with the original coordinate map and mask. Not all realizations support any size, and cannot rely solely on a generic Transformer interface.
Patchify can also be achieved with a volume the size of which is equal to the length of the step. It corresponds to a visible mass plus linear projection in the right order, but requires that nuclear weight be matched to the order of scale. Different forms of realization need not mean different models, but the key is that the equivalence relationship is validated.
This section refers to ViT, the original paper and Torchvision, currently implemented, with 4 x 4 being the synthetic image number. Training and services should preserve the size, channel order and patch protocol to avoid pre-processing misallocation as a generalization of the model.
Value recovery
image=[list(range(i,i+4)) for i in [1,5,9,13]]patches=[[image[r+i][c+j] for i in range(2) for j in range(2)] for r in [0,2] for c in [0,2]]assert patches == [[1,2,5,6],[3,4,7,8],[9,10,13,14],[11,12,15,16]]4x4 line 1-16, what's the first piece 2x2 exhibition?
[1,2,5,5,6], not [1,2,3,4].
Change the order of blocks as long as the number of token remains unchanged?
No, the location code and the trained projection protocol need to be matched, and shape is not consistent enough to prove semantic.
A secure check is the only numbering of each pixel that is written in the column, and the block is sliced to item by item, and then the reverse puzzle is restored to the original. It is not sufficient to compare the same sum of all elements after the level, since the wrong replacement also retains the sum of the sum of the pools.
Sources and reconciliations
Definitions, methods and interfaces are available.
- An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
- Torchvision — VisionTransformer source
Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.