question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'length' of null (dilations is null in depthwiseConv2dNativeBackpropInput_)

See original GitHub issue

System information

  • From the simple-object-detection example
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): tried both on Mac OS and Windows and Windows WSL
  • TensorFlow.js installed from (npm or script link): npm library
  • TensorFlow.js version (use command below): tested on ^2.6.0 and ^3.3.0

Describe the current behavior Playing with the simple-object-detection example. Ran npm run train and the following happens

Step 1: (Phase 1 of 2: initial transfer learning) - this runs without any problems

  const tBegin = tf.util.now();
  console.log(`Generating ${args.numExamples} training data...`);
  const { images, targets } = await trainingData();
  const { model, fineTuningLayers } = await buildObjectDetectionModel();
  model.compile({ loss: customLossFunction, optimizer: tf.train.rmsprop(5e-3) });
  model.summary();

  // Initial phase of transfer learning.
  // console.log('Images Shape:', images.shape);
  // console.log('Targets Shape', targets.shape);
  console.log('Phase 1 of 2: initial transfer learning');
  await model.fit(images, targets, {
    epochs: args.initialTransferEpochs,
    batchSize: args.batchSize,
    validationSplit: args.validationSplit,
    callbacks: args.logDir == null ? null : tfn.node.tensorBoard(args.logDir, {
      updateFreq: args.logUpdateFreq
    })
  });

Step 2: (Phase 2 of 2: fine-tuning phase) - this is where it breaks

  // Fine-tuning phase of transfer learning.
  // Unfreeze layers for fine-tuning.
  for (const layer of fineTuningLayers) {
    console.log(fineTuningLayers);
    layer.trainable = true;
  }
  model.compile({ loss: customLossFunction, optimizer: tf.train.rmsprop(2e-3) });
  model.summary();

  // Do fine-tuning.
  // The batch size is reduced to avoid CPU/GPU OOM. This has
  // to do with the unfreezing of the fine-tuning layers above,
  // which leads to higher memory consumption during backpropagation.
  console.log('Phase 2 of 2: fine-tuning phase. Top Layer Name:', topLayerName, 'Group Names:', topLayerGroupNames);
  await model.fit(images, targets, {
    epochs: args.fineTuningEpochs,
    batchSize: Math.round(args.batchSize / 2),
    validationSplit: args.validationSplit,
    callbacks: args.logDir == null ? null : tfn.node.tensorBoard(args.logDir, {
      updateFreq: args.logUpdateFreq
    })
  });

I get this error after model.fit(images, targets, {... is executed:

image

I debugged down a bit further - turns out that somewhere at the kernel input (I think??), it’s giving a dilation value of null (should be number or number[]).

image

image

Please advise, I’m going off the tfjs-examples repo simple-object-dectection https://github.com/tensorflow/tfjs-examples/blob/master/simple-object-detection/package.json

…then just running npm install and npm run train

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
opiepjcommented, Mar 27, 2021

Still broken, but found a workaround (though probably the model is not even transfer learning)

  1. train.js change the tensorflow import from @tensorflow/tfjs to @tensorflow/tfjs-node
  2. replaced const topLayerGroupNames = ['conv_pw_9', 'conv_pw_10', 'conv_pw_11']; to const topLayerGroupNames = [ 'conv_pw_11'];

Both changes are required, one without the other leads to the same problem. I have no idea why this fixes it.

0reactions
google-ml-butler[bot]commented, Aug 17, 2021

Are you satisfied with the resolution of your issue? Yes No

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Solved] TypeError: Cannot read property 'length' of null
The TypeError: Cannot read property 'length' of null occurs if you are trying to get the length of an object that is null....
Read more >
Uncaught TypeError: Cannot read property 'length' of null- ...
If when fetching localStorage.getItem('options') and there is no stored "options" key-value, then null is returned. You then JSON parse this, ...
Read more >
Resolve Netsuite Scripting Error “Cannot read property “length ...
This error occurs when you try to get length of search record object which returns a null value. Length method can be used...
Read more >
Typeerror: Cannot Read Property 'length' of Undefined
The length property returns a number for essentially any object in JavaScript. Typeerrors can be thrown when attempting to change a value that ......
Read more >
Fix 'cannot read properties of null (reading length)' in JS
Learn what is the cause, and how you can fix 'Uncaught TypeError: Cannot read properties of null (reading 'length')' errors in JavaScript.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found