Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Tensorflow Tfjs Convolutional Test: Difference between revisions

From Leeroopedia
Auto-imported from implementations/Tensorflow_Tfjs_Convolutional_Test.md
 
Sync from local file
 
Line 99: Line 99:
== Related Pages ==
== Related Pages ==


* [[Tensorflow_Tfjs_ConvLSTM2D_Test]]
* [[Implementation:Tensorflow_Tfjs_ConvLSTM2D_Test]]
* [[Tensorflow_Tfjs_Pooling_Test]]
* [[Implementation:Tensorflow_Tfjs_Pooling_Test]]
* [[Tensorflow_Tfjs_Normalization_Test]]
* [[Implementation:Tensorflow_Tfjs_Normalization_Test]]


[[Category:Implementations]]
[[Category:Implementations]]


[[Category:Implementations]]
[[Category:Implementations]]

Latest revision as of 10:52, 27 September 2026


Knowledge Sources
Domains Testing, Layers_API
Last Updated 2026-02-10 06:00 GMT

Overview

This large test suite (1758 lines) validates all convolutional layer implementations in the TensorFlow.js Layers API. It covers 1D, 2D, and 3D convolutions including standard convolutions, transposed (deconvolution) layers, separable convolutions, cropping, and upsampling. Tests are organized by both low-level convolution functions (conv1dWithBias, conv2d, conv2dWithBiasActivation, conv3d, conv3dWithBias) and high-level Keras-style layer APIs. Each layer type is tested at both symbolic (shape inference) and tensor (numerical correctness) levels across data formats, padding modes, strides, and dilations.

Code Reference

Source Location: tfjs-layers/src/layers/convolutional_test.ts (1758 lines)

Repository: GitHub

Test Describe Blocks

  • conv1dWithBias - Low-level 1D convolution with bias across output channels, data formats, padding modes
  • conv1d - Low-level 1D convolution with strides and dilations
  • conv2d - Low-level 2D convolution across formats and padding
  • conv2dWithBiasActivation - 2D convolution with fused bias and activation
  • Conv2D Layers: Symbolic - 2D conv layer shape inference
  • Conv2D Layer: Tensor - 2D conv layer numerical correctness
  • conv3d - Low-level 3D convolution
  • Conv3D Layers: Symbolic - 3D conv layer shape inference
  • Conv3D Layer: Tensor - 3D conv layer numerical correctness
  • Conv2DTranspose: Symbolic - Transposed 2D conv shape inference
  • Conv2DTranspose: Tensor - Transposed 2D conv numerical correctness
  • Conv1D Layers: Symbolic - 1D conv layer shape inference
  • Conv1D Layer: Tensor - 1D conv layer numerical correctness
  • SeparableConv2D Layers: Symbolic - Depthwise separable 2D conv shape inference
  • SeparableConv2D Layer: Tensor - Depthwise separable 2D conv numerical correctness
  • Cropping2D Layer - Spatial cropping of 2D feature maps
  • UpSampling2D Layer: Symbolic - Upsampling shape inference (nearest, bilinear)
  • UpSampling2D Layer - Upsampling numerical correctness
  • Conv3DTranspose: Symbolic - Transposed 3D conv shape inference
  • Conv3DTranspose: Tensor - Transposed 3D conv numerical correctness

I/O Contract

Inputs to tests:

  • 3D tensors for Conv1D: [batch, width, channels]
  • 4D tensors for Conv2D: [batch, height, width, channels] or [batch, channels, height, width]
  • 5D tensors for Conv3D: [batch, depth, height, width, channels]
  • Kernel tensors, bias tensors, and layer configurations
  • Parameters: outChannels, stride, dilations, padding (valid/same), dataFormat (channelsFirst/channelsLast)

Expected outputs/assertions:

  • Output tensor shapes match expected spatial dimensions after convolution
  • Numerical output values match hand-computed expected values (e.g., convolution of [10, 20, 40, 80] with kernel [1, -1] plus bias)
  • Symbolic shape inference produces correct output shapes
  • Transposed convolution reverses spatial dimension reduction
  • Separable convolution correctly decomposes into depthwise and pointwise stages

Usage Example

describeMathCPUAndGPU('conv1dWithBias', () => {
  it('outChannels=1, stride=1, valid, channelsLast', () => {
    let x: Tensor = tensor3d([10, 20, 40, 80], [1, 4, 1]);
    const kernel = tfc.transpose(
        tensor3d([1, -1], [1, 1, 2]), [2, 0, 1]);
    const bias = tensor1d([2.2]);
    const y = conv1dWithBias(x, kernel, bias, 1, 'valid', 'channelsLast');
    expectTensorsClose(y, tensor3d([-7.8, -17.8, -37.8], [1, 3, 1]));
  });
});

Test Coverage Summary

Category Count Details
Conv1D 30+ Low-level functions and layer API (symbolic + tensor)
Conv2D 40+ Standard, transposed, separable, with bias/activation
Conv3D 30+ Standard and transposed (symbolic + tensor)
Cropping2D 5+ Spatial cropping with various configurations
UpSampling2D 10+ Nearest and bilinear interpolation
Test Environment Mixed CPU, GPU, WebGL2

Related Pages