SwinEncoder constructor

SwinEncoder({
  1. required List<int> inputSize,
  2. bool alignLongAxis = false,
  3. int windowSize = 10,
  4. List<int> encoderLayer = const [2, 2, 14, 2],
  5. int embedDim = 128,
  6. List<int> numHeads = const [4, 8, 16, 32],
  7. int patchSize = 4,
})

Implementation

SwinEncoder({
  required this.inputSize,
  this.alignLongAxis = false,
  this.windowSize = 10,
  this.encoderLayer = const [2, 2, 14, 2],
  this.embedDim = 128,
  this.numHeads = const [4, 8, 16, 32],
  this.patchSize = 4,
}) {
  patchEmbed = PatchEmbed(
    imgSize: inputSize,
    patchSize: patchSize,
    embedDim: embedDim,
  );

  patchH = inputSize[0] ~/ patchSize;
  patchW = inputSize[1] ~/ patchSize;

  posDropout = Dropout();

  layers = [];
  int currentDim = embedDim;
  for (int i = 0; i < encoderLayer.length; i++) {
    final isLast = i == encoderLayer.length - 1;
    layers.add(SwinLayer(
      dim: currentDim,
      depth: encoderLayer[i],
      numHeads: numHeads[i],
      windowSize: windowSize,
      downsample: !isLast,
    ));
    if (!isLast) {
      currentDim *= 2;
    }
  }
}