75527

Multiplying two tensors

Question:

I have the two tensors in Tensorflow, which have the following two shapes:

print(tf.valid_dataset.get_shape()) print(weights1.get_shape())

Has the result:

(10000, 784) (784, 1024)

However, if I try to multiply them, like this:

tf.matmul(tf_valid_dataset, weights1)

I get:

Tensor("Variable:0", shape=(784, 1024), dtype=float32_ref) must be from the same graph as Tensor("Const:0", shape=(10000, 784), dtype=float32).

Since I am multiplying them on the side where they both have the size 784, this seems correct to me.

Any idea what could be wrong?

EDIT:

The code I have before the print statements is this:

num_hidden_nodes=1024 batch_size = 128 learning_rate = 0.5 graph = tf.Graph() with graph.as_default(): tf_train_dataset = tf.placeholder(tf.float32, shape=(batch_size, image_size*image_size)) tf_train_labels = tf.placeholder(tf.float32, shape=(batch_size, num_labels)) tf.valid_dataset = tf.constant(valid_dataset) tf.test_dataset = tf.constant(test_dataset) weights1 = tf.Variable(tf.truncated_normal([image_size * image_size, num_hidden_nodes])) biases1 = tf.Variable(tf.zeros([num_hidden_nodes])) weights2 = tf.Variable(tf.truncated_normal([num_hidden_nodes, num_labels])) biases2 = tf.Variable(tf.zeros([num_labels])) weights = [weights1, biases1, weights2, biases2] lay1_train = tf.nn.relu(tf.matmul(tf_train_dataset, weights1) + biases1) logits = tf.matmul(lay1_train, weights2) + biases2 loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=tf_train_labels)) optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss)

Answer1:

Your code seems correct. Please check again. Verify it by running the below code:

num_hidden_nodes=1024 batch_size = 1000 learning_rate = 0.5 image_size = 28 num_labels = 10 tf_train_dataset = tf.placeholder(tf.float32, shape=(batch_size, image_size*image_size)) tf_train_labels = tf.placeholder(tf.float32, shape=(batch_size, num_labels)) # tf.valid_dataset = tf.constant(valid_dataset) # tf.test_dataset = tf.constant(test_dataset) weights1 = tf.Variable(tf.truncated_normal([image_size * image_size, num_hidden_nodes])) biases1 = tf.Variable(tf.zeros([num_hidden_nodes])) weights2 = tf.Variable(tf.truncated_normal([num_hidden_nodes, num_labels])) biases2 = tf.Variable(tf.zeros([num_labels])) weights = [weights1, biases1, weights2, biases2] lay1_train = tf.nn.relu(tf.matmul(tf_train_dataset, weights1) + biases1) logits = tf.matmul(lay1_train, weights2) + biases2 loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=tf_train_labels)) optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(loss) sess.run(tf.initialize_all_variables()) input_data = np.random.randn(batch_size, 784) input_labels = [np.random.randint(0,10) for _ in xrange(batch_size)] import sklearn.preprocessing label_binarizer = sklearn.preprocessing.LabelBinarizer() transformed_labels = label_binarizer.fit_transform(input_labels) sess.run(optimizer,feed_dict={tf_train_dataset:input_data, tf_train_labels:transformed_labels})

Recommend

  • Loss in Tensorflow suddenly turn into nan
  • Unable to set class weights for U-net in keras: `class_weight` not supported for 3+ dimensional targ
  • TensorFlow/TFLearn: ValueError: Cannot feed value of shape (256, 400, 400) for Tensor u'Targets
  • tensorflow embeddings don't exist after first RNN example
  • I am receiving HibernateException “No Hibernate Session bound to thread, and configuration does not
  • How can Delete be both a DDL and a DML statement
  • Why use database factory in asp.net mvc?
  • Angular2 component view does not update on value change via method
  • pyodbc doesn't report sql server error
  • Debug.DrawLine not showing in the GameView
  • Parsing a CSV string while ignoring commas inside the individual columns
  • Jackson Parser: ignore deserializing for type mismatch
  • Swift: Switch statement fallthrough behavior
  • Magento Fatal error: Maximum execution error solution, on WAMP
  • Meteor: Do Something On Email Verification Confirmation
  • OpenGL ES texture problem, 4 duplicate columns and horizontal lines (Android)
  • C++ Partial template specialization - design simplification
  • Repeat a vertical line on every page in Report Builder / SSRS
  • Android screen density dpi vs ppi
  • NetLogo BehaviorSpace - Measure runs using reporters
  • Read text file and split every line in MSBuild
  • Fetching methods from BroadcastReceiver to update UI
  • C# - Serializing and deserializing static member
  • Java applet as stand-alone Windows application?
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Where to put my custom functions in Wordpress?
  • Change an a tag attribute in JavaScript based on screen width
  • Symfony2: How to get request parameter
  • How can I estimate amount of memory left with calling System.gc()?
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • GridView Sorting works once only
  • 0x202A in filename: Why?
  • RestKit - RKRequestDelegate does not exist
  • WPF Applying a trigger on binding failure
  • Error creating VM instance in Google Compute Engine
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • File not found error Google Drive API
  • How can I remove ASP.NET Designer.cs files?
  • java string with new operator and a literal