code: def permute_and_flatten(layer, N, A, C, H, W):
      # type: (Tensor, int, int, int, int, int) -> Tensor
      """
      调整tensor顺序，并进行reshape
      Args:
          layer: 预测特征层上预测的目标概率或bboxes regression参数
          N: batch_size
          A: anchors_num_per_position
          C: classes_num or 4(bbox coordinate)
          H: height
          W: width
  
      Returns:
          layer: 调整tensor顺序，并reshape后的结果[N, -1, C]
      """
      # view和reshape功能是一样的，先展平所有元素在按照给定shape排列
      # view函数只能用于内存中连续存储的tensor，permute等操作会使tensor在内存中变得不再连续，此时就不能再调用view函数
      # reshape则不需要依赖目标tensor是否在内存中是连续的
      # [batch_size, anchors_num_per_position * (C or 4), height, width]
      layer = layer.view(N, -1, C, H, W)
      # 调换tensor维度
      layer = layer.permute(0, 3, 4, 1, 2)  # [N, H, W, -1, C]
      layer = layer.reshape(N, -1, C)
      return layer
  
imports: from typing import List, Optional, Dict, Tuple
  import torch
  from torch import nn, Tensor
  from torch.nn import functional
  import torchvision
  from .None import det_utils
  from .None import boxes
  from .image_list import ImageList
label_desc: Use image node_id 2 for calling a global function with example usage: permute_and_flatten(layer, N, A, C, H, W) and returns: layer