title: Tensorflow: AttributeError: 'dict' object has no attribute 'train'
body: <blockquote>
  <p>I am following a deep learning course, I get this error when I try to run my &gt;code:'AttributeError: 'dict' object has no attribute 'train'
  I have a feeling it is a tensorflow version handling issue -&amp; the fact of my limited knowledge &gt;about it at the moment. I would like some help on how I can clean this up and have a smooth &gt;running algorithm
  Here is my import before my actual algorithm</p>
  </blockquote>
  <pre><code>import numpy as np
  import tensorflow.compat.v1 as tf
  tf.disable_v2_behavior() 
  #deprecated - from tensorflow.examples.tutorials.mnist import input_data
  
  import tensorflow_datasets as tfds
  mnist = tfds.load('mnist')
  #depricated - mnist = input_data.read_data_sets(&quot;MNIST_data/&quot;, one_hot = True, with_info=True, as_supervised=True)```
  
  input_size = 784
  output_size = 10
  hidden_layer_size = 50
  
  #Clear memory of variables from previous runs
  #depricated - tf.reset_default_graph()
  tf.compat.v1.reset_default_graph()
  #tf.disable_v2_behavior() 
  
  #Declare the placeholders
  inputs = tf.placeholder(tf.float32, [None, input_size])
  targets = tf.placeholder(tf.float32, [None, output_size])
  
  #Declare the weights and biases
  weights_1 = tf.get_variable(&quot;weights_1&quot;, [input_size,hidden_layer_size])
  biases_1 = tf.get_variable(&quot;biases_1&quot;, [hidden_layer_size])
  #Declare the output nodes for the 1st hidden layer using the desired activation function
  outputs_1 = tf.nn.relu(tf.matmul(inputs,weights_1) + biases_1)
  
  #Declare the weights and biases for the second hidden layer
  weights_2 = tf.get_variable(&quot;weights_2&quot;, [hidden_layer_size, hidden_layer_size])
  biases_2 = tf.get_variable(&quot;biases_2&quot;, [hidden_layer_size])
  #Declare the output nodes for hidden layer_2
  outputs_2 = tf.nn.relu(tf.matmul(outputs_1, weights_2) + biases_2)
  
  #Declare the weights &amp; biases for the output layer
  weights_3 = tf.get_variable(&quot;weights_3&quot;, [hidden_layer_size,output_size])
  biases_3 = tf.get_variable(&quot;biases_3&quot;, [output_size])
  #Declare the final output nodes (nb: you can add a transformation final output with a desired 
  optimizer)
  outputs = tf.matmul(outputs_2, weights_3) + biases_3
  
  #Next we need an activation function - we'll use the softmax activation with logits - the 
  values b4 the activation occurs
  loss = tf.nn.softmax_cross_entropy_with_logits(logits=outputs, labels=targets)
  #we'll use the mean loss function as that give great performance boost to our algorithm
  mean_loss = tf.reduce_mean(loss)
  
  #Next, let's choose out optimization algorithm
  optimize = tf.train.AdamOptimizer(learning_rate=0.001).minimize(mean_loss)
  
  # Let's measure the accuracy of our model - using tf.argmax - which returns the index of the 
  largest value
  out_equals_target = tf.equal(tf.argmax(outputs,1),tf.argmax(targets,1))
  
  accuracy = tf.reduce_mean(tf.cast(out_equals_target, tf.float32))
  
  #Now, let's set early stopping &amp; Batching Mechanisms
  sess = tf.InteractiveSession()
  initializer = tf.global_variables_initializer()
  sess.run(initializer)
  
  batch_size = 100
  # batches = #samples/batch_size
  batches_number = mnist.train._num_examples // batch_size
  
  #Create the optimization
  
  for epoch_counter in range(max_epochs):
      curr_epoch_loss = 0.
      for batch_counter in range(batches_number):
          input_batch, target_batch = mnist.train.next_batch(batch_size)
      
          _, batch_loss = sess.run([optimize, mean_loss],
                                  feed_dict = {inputs: input_batch, targets: target_batch})
          curr_epoch_loss += batch_loss
      #Let's set the avg. loss over all batches - n.b: its outside the batches for loop
      curr_epoch_loss /= batches_number
  
  #The validation loss
  input_batch, target_batch = mnist.validation.next_batch(mnist.validation._num_examples)
  validation_loss, validation_accuracy = sess.run([mean_loss,accuracy],
                                                  feed_dict={inputs: input_batch, target: 
  target_batch})
  
  #Finally print the results you've obtained - n.b: inside for loop
      print('Epoch' + str(epoch_counter + 1) + '_ Training loss: ' + 
  '(0:.3f)'.format(curr_epoch_loss)+
            '_ Validation loss: ' + '(0:.3f)'.format(validation_loss) + 
            '_ Validation accuracy: ' + '(0:.2f)'.format(validation_accuracy * 100.) + '%')
  # Add early stopping mechanism related to the early stop
  
  if validation_loss &gt; prev_validation_loss:
      break
  prev_validation_loss = validation_loss
      print('End of training.')
  </code></pre>