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.

tfjs-converter produces error at prediction time

See original GitHub issue

TensorFlow.js Version: 0.3.1 TensorFlow Version: 1.7.0 Chrome 66.0.3359.181

I downloaded the smallest/fastest MobileNetV2 from here and used the tfjs-converter to convert the model.

I cloned the tfjs-converter repo and changed a few variables in the mobilenet example:

const GOOGLE_CLOUD_STORAGE_DIR =
    'web_model/';
const MODEL_FILE_URL = 'tensorflowjs_model.pb';
const WEIGHT_MANIFEST_FILE_URL = 'weights_manifest.json';
const INPUT_NODE_NAME = 'input';
const OUTPUT_NODE_NAME = 'MobilenetV2/Predictions/Reshape_1';

I made these changes while running yarn mobilenet, but it produces an error:

> yarn mobilenet
yarn run v1.6.0
$ NODE_ENV=development parcel --no-hmr --open mobilenet/index.html 
Server running at http://localhost:1234 
🚨  /Users/kyle/Documents/Learning/tfjs-converter/demo/mobilenet/index.js: Cannot read property '__esModule' of null
    at Function.normalisePlugin (/Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:142:21)
    at /Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
    at Array.map (<anonymous>)
    at Function.normalisePlugins (/Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
🚨  /Users/kyle/Documents/Learning/tfjs-converter/demo/mobilenet/mobilenet.js: Cannot read property '__esModule' of null
    at Function.normalisePlugin (/Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:142:21)
    at /Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
    at Array.map (<anonymous>)
🚨  /Users/kyle/Documents/Learning/tfjs-converter/demo/mobilenet/index.js: Cannot read property '__esModule' of null
    at Function.normalisePlugin (/Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:142:21)
    at /Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
    at Array.map (<anonymous>)
🚨  /Users/kyle/Documents/Learning/tfjs-converter/demo/mobilenet/mobilenet.js: Cannot read property '__esModule' of null
    at Function.normalisePlugin (/Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:142:21)
    at /Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
    at Array.map (<anonymous>)
    at Function.normalisePlugins (/Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
    at OptionManager.mergeOptions (/Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
    at OptionManager.init (/Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
    at File.initOptions (/Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/babel-core/lib/transformation/file/index.js:212:65)
    at new File (/Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/babel-core/lib/transformation/file/index.js:135:24)
    at JSAsset.getParserOptions (/Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/parcel-bundler/src/assets/JSAsset.js:69:20)
    at <anonymous>
Unhandled promise rejection: TypeError: this.reject is not a function
    at PromiseQueue._runJob (/Users/kyle/Documents/Learning/tfjs-converter/demo/node_modules/parcel-bundler/src/utils/PromiseQueue.js:50:12)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Could this be related to the fact that I installed the modules using npm install instead of yarn? I initially tried with yarn but it was giving me this error:

> yarn
yarn install v1.6.0
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
warning There appears to be trouble with our server. Retrying...
error An unexpected error occurred: "http://registry.npmjs.org/@types/node/-/node-8.9.5.tgz: Request failed \"503 Service Unavailable\"".
info If you think this is a bug, please open a bug report with the information provided in "/Users/kyle/Documents/Learning/tfjs-converter/demo/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Anyway, I exited yarn mobilenet, deleted dist and ran yarn mobilenet command again, and it successfully generated the new files in dist. However, it didn’t copy the web_model folder so I copied it manually. But it wouldn’t serve the folder, so I started an instance of http-server in the root directory and it successfully loaded the model.

Unfortunately, at prediction time it seems to fail:

Loading of model: 335.180908203125ms
es6.promise.js:110 Unhandled promise rejection Error: Can't squeeze axis 1 since its dim '6' is not 1
    at Object.squeezeShape (util.js:225)
    at Object.ArrayOps.squeeze (array_ops.js:378)
    at Object.exports.executeOp (transformation_executor.js:14)
    at executeOp (operation_executor.js:41)
    at graph_executor.js:116
    at Array.reduce (<anonymous>)
    at graph_executor.js:115
    at Tracking.tidy (tracking.js:34)
    at GraphExecutor.execute (graph_executor.js:113)
    at FrozenModel.execute (frozen_model.js:136)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tafsiricommented, May 31, 2018

@pyu10055 for serving local files i would suggest starting a local http server like http-serve (python based). parcel won’t really do that for you unless the asset is included in the bundle (in which case it may try to pre-load everything).

1reaction
pyu10055commented, May 30, 2018

@kylemcdonald I tried tf-hub mobilenetv2 https://www.tensorflow.org/hub/modules/google/imagenet/mobilenet_v2_100_224/classification/1

using the converter

tensorflowjs_converter     --input_format=tf_hub     'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/1'     /tmp/mobilenet2/web_model

Initially I have the same issue as the squeeze failed, I notice it require strictly the input image size to be 224x224, after I resize the image the model works.

Also, you need to make sure the input and output matches to the model, in my case they are:

const INPUT_NODE_NAME = 'images';
const OUTPUT_NODE_NAME = 'module_apply_default/MobilenetV2/Logits/output';
Read more comments on GitHub >

github_iconTop Results From Across the Web

TFJS-TFLITE error when model outputs quantized values ...
TFJS-TFLITE error when model outputs quantized values when calling predict(...) Issue #5701 · tensorflow/tfjs · GitHub.
Read more >
TFJS model not working problem - TensorFlow Forum
When I want to run the tfjs model I obtained after converting it to tfsj in the react web interface, the web browser...
Read more >
Understanding failure of loadFrozenModel - Google Groups
So currently i'm trying to get the pipeline TF-Model -> export -> convert -> load & predict with tfjs going. Currently i'm in...
Read more >
Different model.predict() result after converting to Tensorflow ...
or am I making a mistake somewhere--I think I have the JS image ... Tensorflow.js as: tfjs.converters.save_keras_model(model, filepath2).
Read more >
@tensorflow/tfjs-converter - npm
A 2-step process to import your model: A python pip package to convert a TensorFlow SavedModel or TensorFlow Hub module to a web...
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