Tfjs: TFJS converter unsupported Ops "BatchMatMul"

Created on 24 Jul 2018  路  11Comments  路  Source: tensorflow/tfjs

Hello,
I was trying to export a model from tf to tfjs, but I run into this error with tfjs 0.5.2:

Multensorflowjs_converter --input_format=tf_saved_model
 --output_node_names='frozen_graph/my_model/full_output'
 --saved_model_tags=serve 
./tests/model_freezing/model_pipe_frozen/a2018-07-24_13-49-43/
./tests/export_tfjs


> Unsupported Ops in the model
BatchMatMul

It seems the op that create this issue is this one:
tf.matmul(point_batch, mat_batch)
The model work just fine in python.

The node is created by a tf.Matmul, and this op is said to be handled by tfjs converter.

converter

Most helpful comment

Hey all, wanted to give an update that in the next release of TFjs, matmul will behave the way it does in other Tensorflow languages: input matrices just need to have ranks of >= 2 with identical outer dimensions (item number 1 in the comment above). Thanks for bringing this to our attention!

All 11 comments

I made a workaround using:

def mult(mat):
            return tf.matmul(face_batch[0],mat)
multiplied = tf.map_fn(mult,mat_batch)

But it would still be nice to have this op handled.

Note that my face_batch is a tiled constant so I can simply use it this way, you'd have to workaround getting the second mat if your mat_batch is already differentied at this point.

@Jylomaki good solution! I'm having the same issue of the BatchMatMul with other operations likeMatrixBandPart, RandomShuffleQueueV2, QueueDequeueManyV2. Any idea for these ones?

Well I don't use those ops, so I quite know about those.

It won't fix your problem but have you made an issue about this? It seems, the op they handle implement are the ones asked by people.

@Jylomaki yes I have added them in another thread with a list of the missing operations, thanks!

I'm not sure if this is covered by this issue, but it would be nice if TFjs matmul behaved in the same way as the Tensorflow matmul, which generalizes the operation to tensors of arbitrary dimensions:

Multiplies matrix a by matrix b, producing a * b.
The inputs must, following any transpositions, be tensors of rank >= 2 where the inner 2 dimensions specify valid matrix multiplication arguments, and any further outer dimensions match.

Great point @chrisdonahue . Will keep this issue to track two things
1) generalizing tf.matMul in tfjs-core
2) Wiring the BatchMatMul op in the tfjs-converter to call the generalized tf.matMul() in core.

Hey all, wanted to give an update that in the next release of TFjs, matmul will behave the way it does in other Tensorflow languages: input matrices just need to have ranks of >= 2 with identical outer dimensions (item number 1 in the comment above). Thanks for bringing this to our attention!

Awesome!! Thx so much

Been looking for a way to cleanly batch-matmul, thanks so much for this!

just to add that BatchMatMul is fundamental to support layers for GRU, seq2seq, transformers, etc!

this op has been added.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RELNO picture RELNO  路  3Comments

KienPM picture KienPM  路  3Comments

JasonShin picture JasonShin  路  4Comments

dhrumil83 picture dhrumil83  路  3Comments

Arturbarth picture Arturbarth  路  3Comments