granth_jain:

Besides I am unable to get why convolution output is nan for valid inputs.Does it have weighs that are updated?


Yes, convolution layers are trainable and have a weight (filters) and bias parameter.
If the loss is exploding and thus the gradients are large in their magnitude, the parameter updates might yield to overflows.