Skip to content

separableConv2d and depthwiseConv2d incorrectly initialize depthwise convolutional weights #8568

@vmukhachev

Description

@vmukhachev

This affects initializers like 'glorotUniform' and 'glorotNormal'.

I think computeFans (see https://github.com/tensorflow/tfjs/blob/master/tfjs-layers/src/initializers.ts ) is incorrect:

  • fan_in should be: kernelHeight × kernelWidth

Reproducible Example:

const input = tf.randomNormal([1, 64, 64, 64]);
const dw = tf.layers.depthwiseConv2d({
  kernelSize: 3,
  useBias: false,
  depthwiseInitializer: 'leCunUniform'
});
const output = dw.apply(input);
console.log(`Output mean=${tf.moments(output).mean.arraySync().toFixed(3)}, variance=${tf.moments(output).variance.arraySync().toFixed(3)}`);
// Output mean=-0.000, variance=0.016

Corrected Behavior Example:

const input = tf.randomNormal([1, 64, 64, 64]);
const dw = tf.layers.depthwiseConv2d({
  kernelSize: 3,
  useBias: false,
  depthwiseInitializer: tf.initializers.randomUniform({minval: -Math.sqrt(3 / (3**2)), maxval: Math.sqrt(3 / (3**2))})
});
const output = dw.apply(input);
console.log(`Output mean=${tf.moments(output).mean.arraySync().toFixed(3)}, variance=${tf.moments(output).variance.arraySync().toFixed(3)}`);
// Output mean=-0.004, variance=0.964

Metadata

Metadata

Assignees

Labels

type:bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions