@graydon1234 wrote:
I am following the guide on An Introduction to Implementing Neural Networks using TensorFlow by Faizan Shaikh and am having difficulties with some parts. I know I am jumping into the problem, but it is a long tutorial. I am willing to provide any other background information if needed. I am new to TensorFlow and am really trying to read all the documentation, but it is still very challenging. Please help me work through this issue.
Problem:
I receive the following error: InvalidArgumentError (see above for traceback): logits and labels must be broadcastable: logits_size=[512,10] labels_size=[128,10]From what I have read on the discussion of this tutorial, is that this is caused by batch_x and batch_y not being the same length. I confirm that they are not the same length. However, I do not know how to get them the same length.
He created a batch_creator function which should handle this. Here is the batch_creator function:def batch_creator(batch_size, dataset_length, dataset_name): """Create batch with random samples and return appropriate format""" batch_mask = rng.choice(dataset_length, batch_size) batch_x = eval(dataset_name + '_x')[[batch_mask]].reshape(-1, 784) batch_x = preprocess(batch_x) if dataset_name == 'train': batch_y = eval(dataset_name).ix[batch_mask, 'label'].values batch_y = dense_to_one_hot(batch_y) return batch_x, batch_y
I do not understand the line:
batch_x = eval(dataset_name + '_x')[[batch_mask]].reshape(-1, 784)
At this point the batch_x size is incorrect [512, 784] and the batch_y size is [128,10].
I am trying my best to understand what the batch_x line is doing, but cannot seem to figure it out and do not know how to properly modify the size. I also get deprecation warnings for this line of code.
Inside the nested for loop is where batch_creator is called.
with tf.Session() as sess: sess.run(init) # For each epoch, do: # For each batch (total data rows / batch size), do: # Create pre-processed batch # Run optimizer by feeding batch # Find cost and reiterate to minimize for epoch in range(epochs): avg_cost = 0 total_batch = int(train.shape[0] / batch_size) for batch in range(total_batch): batch_x, batch_y = batch_creator(batch_size, train_x.shape[0], 'train') _, cost = sess.run([optimizer, cost], feed_dict = {x: batch_x, y: batch_y})
If anyone could assist me with this problem, or at least the one line of code I don’t understand that would be super helpful. If my problem doesn’t make sense, someone else has posted something similar in the comments which you can look at.
Thank you
Posts: 1
Participants: 1