class_docstr: Testing layers from tflearn/layers
class_docstr_tok: ["Testing","layers","from","tflearn\/layers"]
code: def test_core_layers(self):
      X = [[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]]
      Y_nand = [[1.0], [1.0], [1.0], [0.0]]
      Y_or = [[0.0], [1.0], [1.0], [1.0]]
  
      # Graph definition
      with tf.Graph().as_default():
          # Building a network with 2 optimizers
          g = tflearn.input_data(shape=[None, 2])
  
          # Nand operator definition
          g_nand = tflearn.fully_connected(g, 32, activation="linear")
          g_nand = tflearn.fully_connected(
              g_nand, 32, activation="linear"
          )
          g_nand = tflearn.fully_connected(
              g_nand, 1, activation="sigmoid"
          )
          g_nand = tflearn.regression(
              g_nand,
              optimizer="sgd",
              learning_rate=2.0,
              loss="binary_crossentropy",
          )
          # Or operator definition
          g_or = tflearn.fully_connected(g, 32, activation="linear")
          g_or = tflearn.fully_connected(g_or, 32, activation="linear")
          g_or = tflearn.fully_connected(g_or, 1, activation="sigmoid")
          g_or = tflearn.regression(
              g_or,
              optimizer="sgd",
              learning_rate=2.0,
              loss="binary_crossentropy",
          )
          # XOR merging Nand and Or operators
          g_xor = tflearn.merge([g_nand, g_or], mode="elemwise_mul")
  
          # Training
          m = tflearn.DNN(g_xor)
          m.fit(X, [Y_nand, Y_or], n_epoch=400, snapshot_epoch=False)
  
          # Testing
          self.assertLess(m.predict([[0.0, 0.0]])[0][0], 0.01)
          self.assertGreater(m.predict([[0.0, 1.0]])[0][0], 0.9)
          self.assertGreater(m.predict([[1.0, 0.0]])[0][0], 0.9)
          self.assertLess(m.predict([[1.0, 1.0]])[0][0], 0.01)
  
      # Bulk Tests
      with tf.Graph().as_default():
          net = tflearn.input_data(shape=[None, 2])
          net = tflearn.flatten(net)
          net = tflearn.reshape(net, new_shape=[-1])
          net = tflearn.activation(net, "relu")
          net = tflearn.dropout(net, 0.5)
          net = tflearn.single_unit(net)
  
file_path: tflearn/tests/test_layers.py
imports: import tensorflow.compat.v1
  import tflearn
  import unittest
  import os
label_desc: Use image node_id 1 for calling the TestLayers obj's underlying member method code with example usage: obj.test_core_layers() without return types