title: logits and labels must be broadcastable
body: <p>I've started tensorflow and trying to implement simple neural network with identify the digit practice problem from analyticsvidhya.com with followed this post: 
  <a href="https://www.analyticsvidhya.com/blog/2016/10/an-introduction-to-implementing-neural-networks-using-tensorflow/" rel="nofollow noreferrer">https://www.analyticsvidhya.com/blog/2016/10/an-introduction-to-implementing-neural-networks-using-tensorflow/</a></p>
  
  <p>here is my full code:
  <a href="https://github.com/NilSagor/AV_ml_practice/blob/master/digit_reco/digit_practise_01.ipynb" rel="nofollow noreferrer">https://github.com/NilSagor/AV_ml_practice/blob/master/digit_reco/digit_practise_01.ipynb</a></p>
  
  <pre><code>cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(
      logits =output_layer, labels =y))
  </code></pre>
  
  <p><strong>error: logits and labels must be broadcastable</strong></p>
  
  <p>image reshape</p>
  
  <pre><code>temp = []
  for img_name in train.filename:
      image_path = os.path.join(data_dir, 'train', 'Images', 'train', img_name)
      img = Image.open(filepath)
      img= np.array(img).astype('float32')
      temp.append(img)
  
  train_x = np.stack(temp)
  
  temp = []
  for img_name in test.filename:
      image_path = os.path.join(data_dir, 'train', 'Images', 'test', img_name)   
      img = Image.open(filepath)    
      img= np.array(img).astype('float32')
      temp.append(img)
  
  test_x = np.stack(temp)
  
  
  with tf.Session() as sess:
      sess.run(init)
  
      for epoch in range(epochs):
          avg_cost = 0
          total_batch = int(train_data.shape[0]//batch_size)
          for i in range(total_batch):
              batch_x, batch_y = batch_creator(batch_size, train_x.shape[0], 'train')
  
              _,c = sess.run([optimizer, cost], feed_dict = {x: batch_x, y: batch_y})
              avg_cost += c/total_batch
          print("Epoch: ", (epoch+1), "cost: ", "{:.5f}".format(avg_cost))
      print("Training complete")
  </code></pre>
  
  <p>and batch_creator funciton</p>
  
  <pre><code>def batch_creator(batch_size, dataset_length, dataset_name):
      """ Create batch with random samples and return appropiate format"""
      batch_mask = rng.choice(dataset_length, batch_size)
      batch_x = eval(dataset_name + "_x")[[batch_mask]].reshape(-1, input_num_units)
      batch_x = preproc(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
  
  weights = {
      'hidden': tf.Variable(tf.random_normal([input_num_units, hidden_num_units], seed = seed)),
      'output': tf.Variable(tf.random_normal([hidden_num_units, output_num_units], seed = seed))
  }
  
  biases = {
      'hidden': tf.Variable(tf.random_normal([hidden_num_units], seed = seed)),
      'output': tf.Variable(tf.random_normal([output_num_units], seed = seed))
  </code></pre>
  
  <p>}</p>
  
  <pre><code>hidden_layer = tf.add(tf.matmul(x, weights['hidden']), biases['hidden'])
  hidden_layer = tf.nn.relu(hidden_layer)
  output_layer = tf.matmul(hidden_layer, weights['output']) + biases['output']
  
  
  
  cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(logits =output_layer, labels =y))
  optimizer = tf.train.AdamOptimizer(learning_rate = learning_rate).minimize(cost)
  </code></pre>
  
  <p>how to get rid of the error and how to create batch for efficiently?</p>
  
  <p>Thanks in advance</p>