title: Loss become Nan suddenly after some iterations
body: <pre><code>## Read the datasheet
  
  X, Y = read_dataset()
  
  model_path = "/Users/shalinsavalia/Desktop/ECG_CNN/CNN"
  
   ## Shuffle the dataset to mix up the rows
  
  X, Y = shuffle(X, Y, random_state=1)
  
   ## Convert the dataset into train and test part
  
  train_x, test_x, train_y, test_y = train_test_split(X, Y, test_size=0.20, random_state=415)
  
  print "Shape of ECG signals in training dataset {}".format(train_x.shape)
  
  print "Shape of ECG diseases in training dataset {}".format(train_y.shape)
  
  print "Shape of ECG signals in testing dataset {}".format(test_x.shape)
  
  print "Shape of ECG diseases in testing dataset {}".format(test_y.shape)
  
   ## Define the important parameters and variables to work with tensors
  
  n_dim = X.shape[1]
  
  n_class = 9
  
   # Input - shape 'None' states that, the value can be anything, i.e we can feed in any number of ECG signals
  
   ## Input ECG signals length 
  
  x=tf.placeholder(tf.float32,shape=[None,n_dim])
  
   ## Input class ( having total 9 Dieseases )
  
  y_=tf.placeholder(tf.float32,shape=[None, n_class])
  
   ## Reshape the Input signal for Feeding to CNN
  
  x_input=tf.reshape(x,[-1,1,60,1], name='input')
  
   ## First convolutional layer with 32 output filters, filter size 5x5, stride of 2,same padding, and RELU activation.
  
  conv_layer1=tflearn.layers.conv.conv_2d(x_input, nb_filter=32, filter_size=5, strides=[1,1,1,1],
                                          padding='same', activation='relu', regularizer="L2", name='conv_layer_1')
  
  out_layer1=tflearn.layers.conv.max_pool_2d(conv_layer1, 2)
  
  
   ## Second Convolutional layer
  
  conv_layer2=tflearn.layers.conv.conv_2d(out_layer1, nb_filter=128, filter_size=5, strides=[1,1,1,1],
                                          padding='same', activation='relu',  regularizer="L2", name='conv_layer_2')
  
  out_layer2=tflearn.layers.conv.max_pool_2d(conv_layer2, 2)
  
   ## Third Convolutional layer 
  
  conv_layer3=tflearn.layers.conv.conv_2d(out_layer2, nb_filter=64, filter_size=5, strides=[1,1,1,1],
                                          padding='same', activation='relu',  regularizer="L2", name='conv_layer_3')
  
  out_layer3=tflearn.layers.conv.max_pool_2d(conv_layer3, 2)
  
   ## Fourth Convolutional layer 
  
  conv_layer4=tflearn.layers.conv.conv_2d(out_layer3, nb_filter=32, filter_size=5, strides=[1,1,1,1],
                                          padding='same', activation='relu',  regularizer="L2", name='conv_layer_4')
  
  out_layer4=tflearn.layers.conv.max_pool_2d(conv_layer4, 2)
  
   ## Fully connected layer
  
  fcl= tflearn.layers.core.fully_connected(out_layer4, 1024, activation='relu')
  
  fcl_dropout = tflearn.layers.core.dropout(fcl, 0.8)
  
  y_predicted = tflearn.layers.core.fully_connected(fcl_dropout, 9, activation='softmax', name='output')
  
   ## Loss function
  
  cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y_predicted), reduction_indices=[1]))
  
   ## Optimiser 
  
  train_step = tf.train.GradientDescentOptimizer(0.2).minimize(cross_entropy)
  
   ## Calculating accuracy of our model 
  
  correct_prediction = tf.equal(tf.argmax(y_predicted,1), tf.argmax(y_,1))
  
  accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
  </code></pre>
  
  <blockquote>
    <p>RESULT LOOK LIKE THIS </p>
  </blockquote>
  
  <pre><code>Shape of ECG diseases in testing dataset (5309, 9)
  
  Shape of input : [None, 1, 60, 1]
  
  Shape of first convolutional layer : [None, 1, 30, 32]
  
  Shape of second convolutional layer : [None, 1, 15, 128]
  
  Shape of third convolutional layer : [None, 1, 15, 64]
  
  Shape of fourth convolutional layer : [None, 1, 15, 32]
  
  Shape of fully connected layer : [None, 1024]
  
  Shape of output layer : [None, 9]
  
  ('Epoch :', 198, '- Loss: ', 1.046878, '- Train Accuracy: ',
  0.6050674)
  
  ('Epoch :', 199, '- Loss: ', 1.0282028, '- Train Accuracy: ',
  0.60676277)
  
  ('Epoch :', 200, '- Loss: ', 1.0455937, '- Train Accuracy: ',
  0.59508336)
  
  ('Epoch :', 201, '- Loss: ', 1.0259817, '- Train Accuracy: ',
  0.6227277)
  
  ('Epoch :', 202, '- Loss: ', 1.0068184, '- Train Accuracy: ',
  0.61241406)
  
  ('Epoch :', 203, '- Loss: ', 0.9958509, '- Train Accuracy: ',
  0.6385985)
  
  ('Epoch :', 204, '- Loss: ', nan, '- Train Accuracy: ', 0.6148159)
  
  ('Epoch :', 205, '- Loss: ', nan, '- Train Accuracy: ', 0.118065365)
  
  ('Epoch :', 206, '- Loss: ', nan, '- Train Accuracy: ', 0.118065365)
  
  ('Epoch :', 207, '- Loss: ', nan, '- Train Accuracy: ', 0.118065365)
  
  ('Epoch :', 208, '- Loss: ', nan, '- Train Accuracy: ', 0.118065365)
  </code></pre>
  
  <p>If you see my training, the loss was decreasing initially till 203 epoch and all of sudden it went down to nan, I tried to change a number of convolution layer, max pooling layer but still, it doesn't work. it all cases it becomes nan after some epoch. I have observed one thing in all cases when loss reached around .98 or 0.99 it becomes nan after that only. I don't know whats wrong with my code? please help me I will really appreciate.</p>