tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.39k stars 1.92k forks source link

depthToSpace dataformat comparison not conside about lower case letters may raise exception when use pretrained model by python #1069

Closed Frankdog closed 4 years ago

Frankdog commented 5 years ago

To get help from the community, check out our Google group.

TensorFlow.js version

in html

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.14.1/dist/tf.min.js"></script>    

converter

tensorflowjs_converter --version
Using TensorFlow backend.

tensorflowjs 0.6.7

Dependency versions:
  keras 2.2.2
  tensorflow 1.12.0

Browser version

chrome Version 71.0.3578.98 (Official Build) (64-bit)

Describe the problem or feature request

https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.14.1/node_modules/@tensorflow/tfjs-core/src/ops/array_ops.ts

function depthToSpace_

 const inputHeight = (dataFormat === 'NHWC') ? $x.shape[1] : $x.shape[2];
  const inputWidth = (dataFormat === 'NHWC') ? $x.shape[2] : $x.shape[3];
  const inputDepth = (dataFormat === 'NHWC') ? $x.shape[3] : $x.shape[1];

the compare does not consider about lower case letters.

in my case:

  1. pretrained model by tensorflow 1.6 (python)
  2. convert to tensorflow js model by tensorflowjs_converter
  3. the input shape is (10,48,48,9) and the dataFormat is nhwc (which is in lower case)
  4. but then compare use (dataFormat === 'NHWC') will cause inputDepth = x.shape[1] = 48
  5. and may raise exception
    uncaught (in promise) Error: Dimension size must be evenly divisible by 9 but is 48 for depthToSpace with input shape 10,48,48,9
    at assert (util.ts:81)
    at depthToSpace_ (array_ops.ts:1083)
    at depthToSpace (operation.ts:46)
    at executeOp$15 (transformation_executor.ts:85)
    at executeOp$16 (operation_executor.ts:81)
    at graph_executor.ts:168
    at engine.ts:156
    at e.scopedRun (engine.ts:167)
    at e.tidy (engine.ts:153)
    at e.tidy (environment.ts:186)

Code to reproduce the bug / link to feature request

see detail above

rthadur commented 4 years ago

Related PR has been merged , so closing this issue.