tf.contrib.layers.flatten(x) flattens the input and the flattened tensor with shape [batch_size, k]. Does not affect the batch size. It is equivalent to the following:
flattened = tf.reshape(x, [tf.shape(x)[0], -1])
If you want to learn Artificial Intelligence using TensorFlow, then check out this Artificial Intelligence Course by Intellipaat.