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.

I got "in matMul: inputs must be rank 2" error when I used retained model.

See original GitHub issue

Hi I love Emoji Scavenger Hunt. I want to play the game with my own trained model. But I got the following error. Can you please help me?

Summary

I created a model and deployed it. However I got Error: Error in matMul: inputs must be rank 2, got ranks 1 and 2. error during starting the game. I want to solve it.

Steps to Reproduce

# Git clone from my forked repo
$ git clone --depth 1 --branch matmul-error https://github.com/y-zono/emoji-scavenger-hunt.git

# Training
$ cd emoji-scavenger-hunt/training/
$ docker build -t model-builder .
$ docker run -v /xxx/xxx/emoji-scavenger-hunt/training/data:/data -it model-builder

# Copy the trained files into dist
$ cp data/saved_model_web/group1-shard1of1 ../dist/model/group1-shard1of1
$ cp data/saved_model_web/tensorflowjs_model.pb ../dist/model/web_model.pb
$ cp data/saved_model_web/weights_manifest.json ../dist/model/weights_manifest.json

# Run the app
$ cd ..; yarn prep; yarn dev

# Open browser and click "LET'S PLAY"
http://localhost:3000

Expected Results

The game is started normally.

Actual Results

The following message was showed on the page.

It looks like your browser or device doesn’t support this experiment. It’s designed to work best on mobile (iOS/Safari or Android/Chrome). 😭

The following error was occurred at matmul.ts

Error: Error in matMul: inputs must be rank 2, got ranks 1 and 2.

https://github.com/tensorflow/tfjs-core/blob/master/src/ops/matmul.ts#L49

Notes

  1. The versions are the following.
@tensorflow/tfjs-converter@0.1.0
@tensorflow/tfjs-core@0.6.0

tensorflow v1.7.0 for training
  1. Chrome browser version is 65.0.3325.181(Official Build)(64bit)

  2. The original trained model worked normally on my local PC.

  3. I added some images into my own forked repo for training and changed some files like game.ts and scavenger_classes.ts.

https://github.com/google/emoji-scavenger-hunt/compare/master...y-zono:matmul-error

  1. I downloaded the cat and dog images from image-net
$ wget http://www.image-net.org/api/text/imagenet.synset.geturls?wnid=n02123045 -O cat.txt
$ wget http://www.image-net.org/api/text/imagenet.synset.geturls?wnid=n02087122 -O dog.txt
$ i=0; for file in `head -100 cat.txt`;do wget $file -O cat-$i.jpg; let i++ ;done
$ i=0; for file in `head -100 dog.txt`;do wget $file -O dog-$i.jpg; let i++ ;done

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
zonocommented, Apr 23, 2018

@tushuhei The issue was solved. Thank you!

0reactions
tushuheicommented, Apr 27, 2018

@jbruwer Looks like the upstream issue is not fixed fully. I still see that the required op reshape is removed after conversion. I will follow up tensorflow/tfjs#85 on this. We can keep the branch flag for tensorflow repo as is because it is to fix the path to retrain.py and separated from this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tesnsor Flow error :Shape must be rank 2 but is rank 1 for ...
This is a matrix multiplication and it can happen only for matrices with atleast rank 2 and the number of columns in matrix...
Read more >
Shape must be rank 2 but is rank 1 for 'MatMul' (op ... - GitHub
When I try to load the model to tensorflow, this line tf_rep = prepare(model) throws the error, InvalidArgumentError: Shape must be rank 2 ......
Read more >
tf.Variable | TensorFlow v2.11.0
The function must take as input the unprojected Tensor representing the value of the variable and return the Tensor for the projected value...
Read more >
cuBLAS - NVIDIA Documentation Center
To use the cuBLAS API, the application must allocate the required matrices and vectors in the GPU memory space, fill them with data,...
Read more >
Changelog | Barracuda | 3.0.0 - Unity - Manual
Fixed OneHot when using rank 2 input tensor. ... Breaking Change: Barracuda now requires Unity 2019.4 LTS or later (was 2018.4 LTS) ...
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