python - tensorflow: ValueError: Shape must be rank 2 but is rank 4 for 'MatMul_1' -


i met error in following code, when i'm trying multiply dense matrix sparse matrix.

import tensorflow tf import numpy np  = tf.sparse_placeholder(tf.float32) b = tf.sparse_placeholder(tf.float32)  isfoc = tf.placeholder(tf.float32, [none, 1]) isfoc_diag = tf.diag(isfoc)  isunfoc = tf.placeholder(tf.float32, [none, 1]) isunfoc_diag = tf.diag(isunfoc)  b = tf.matmul(isfoc_diag,isunfoc_diag) = tf.matmul(isfoc_diag,tf.sparse_tensor_to_dense(a),a_is_sparse=false,b_is_sparse=true) 

the error says:

traceback (most recent call last):   file "a.py", line 14, in <module>     = tf.matmul(isfoc_diag,tf.sparse_tensor_to_dense(a),a_is_sparse=false,b_is_sparse=true)   file "/home/mypath.pfc/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/math_ops.py", line 1813, in matmul     name=name)   file "/home/mypath.pfc/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_math_ops.py", line 2245, in _sparse_mat_mul     b_is_sparse=b_is_sparse, name=name)   file "/home/mypath.pfc/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op     op_def=op_def)   file "/home/mypath.pfc/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2508, in create_op     set_shapes_for_outputs(ret)   file "/home/mypath.pfc/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1873, in set_shapes_for_outputs     shapes = shape_func(op)   file "/home/mypath.pfc/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1823, in call_with_requiring     return call_cpp_shape_fn(op, require_shape_fn=true)   file "/home/mypath.pfc/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 610, in call_cpp_shape_fn     debug_python_shape_fn, require_shape_fn)   file "/home/mypath.pfc/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.py", line 676, in _call_cpp_shape_fn_impl     raise valueerror(err.message) valueerror: shape must rank 2 rank 4 'matmul_1' (op: 'sparsematmul') input shapes: [?,1,?,1], ?. 

i know there similar questions discussing similar errors, however, cannot key reason type of error.

the error happens line a = tf.matmul(isfoc_diag,tf.sparse_tensor_to_dense(a),a_is_sparse=false,b_is_sparse=true). hope kindly answer question.

thank much!


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -