1

I've written my own matrix multiplication implementation in TensorFlow that works with tf placeholders when their dimensions are properly defined. But many times in neural networks you want to leave one of the dimensions undefined so that the batch size or size of the input can change such as:

X = tf.placeholder(tf.float32, shape=(None, n_inputs), name="X")
y = tf.placeholder(tf.int64, shape=(None), name="y")

In my implementation, I first check the dimensions of the matrices so that they match and so that I can initialize a matrix with the correct dimensions with:

(m, n) = A.get_shape().as_list()

But then when I use it in a tf neural network I get the error:

raise ValueError("None values not supported.")

Because my matrix multiplication only works for defined matrices. Is there a way to handle this error so that it will work when the dimensions are eventually defined? Tensorflow's tf.matmul() must have a way but I can't figure it out. https://www.tensorflow.org/api_docs/python/tf/linalg/matmul

jharkins
  • 191
  • 1
  • 8
  • what is the problem? the following works for me print(tf.placeholder(tf.float32, shape=(None, 10), name="X").get_shape().as_list()) – eugen Sep 30 '19 at 06:54
  • The shape should come out as (?, 10), because the first dimension is not defined. This happens when I try and begin training for the neural network and it throws an error because my matrix multiplication only works for matrices with both dimensions defined. – jharkins Sep 30 '19 at 13:10
  • i would recommend you put some minimum reproducible code so we understand. otherwise I am not sure where your code breakes – eugen Sep 30 '19 at 13:52

1 Answers1

0

You may need to share some minimum reproducible code to understand the issue. Also, please see the answer from Salvador Dali at the below link to gain further understanding of how TF.matmul works:

Tensorflow - matmul of input matrix with batch data

AG_Gurgaon
  • 19
  • 4