Conv2d constructor

Conv2d({
  1. required int inChannels,
  2. required int outChannels,
  3. required int kernelSize,
  4. int stride = 1,
  5. int padding = 0,
})

Implementation

Conv2d({
  required this.inChannels,
  required this.outChannels,
  required this.kernelSize,
  this.stride = 1,
  this.padding = 0,
}) {
  int patchSize = inChannels * kernelSize * kernelSize;

  // Using fromList for initial weights (Xavier-like initialization)
  final initialWeights = List.generate(outChannels * patchSize, (i) => 0.1);
  weight = Tensor.fromList([outChannels, patchSize], initialWeights);

  // Using fromList for bias [1, outChannels]
  final initialBias = List.generate(outChannels, (i) => 0.0);
  bias = Tensor.fromList([1, outChannels], initialBias);
}