title: Segmentation fault with Keras Sequential Model
body: <p>Program has segmentation fault when using keras Sequential model after at least one episode. </p>
  
  <p>Our program uses a Sequential model to control a pong paddle to avoid descending pong balls. Every frame an image of the game is downloaded, processed into a 80*60 array, and sent to the model to take an action (move right or left by one pixel). At the end of the game (one episode), the X_train array, Y_train array, and rewards array are fit to the model. Our error occurs after at least after the second episode has finished, but sometimes occurs after several episodes. The error is occurring somewhere inside the keras model computation.</p>
  
  <p>Using keras 2.1.6, tensor flow 1.13.1, pygame 1.9.5.</p>
  
  <pre class="lang-py prettyprint-override"><code>def create_network():
      model = Sequential()
  
      model.add(Dense(units=200,input_dim=80*60, activation='relu', kernel_initializer='glorot_uniform'))
  
      model.add(Dense(units=1, activation='sigmoid', kernel_initializer='RandomNormal'))
  
      model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
  
      epochs_before_saving = 10
      log_dir = './log' + datetime.now().strftime("%Y%m%d-%H%M%S") + "/"
  
      tbCallBack = callbacks.TensorBoard(log_dir=settings.log_dir, histogram_freq=0,  
           write_graph=True, write_images=True)
  </code></pre>
  
  <p>The above code initializes the model. </p>
  
  <pre><code>    model.fit(x=np.vstack(sX_train), y=np.vstack(Y_train), verbose=1, sample_weight=reward_array)
  </code></pre>
  
  <p>The above line fits the x_train, y_train, and reward array to the model at the end of an episode.</p>
  
  <pre><code>172-26-86-157:ML tomhardy$ python dodge.py
  pygame 1.9.5
  Hello from the pygame community. https://www.pygame.org/contribute.html
  Using TensorFlow backend.
  WARNING:tensorflow:From /Users/tomhardy/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
  Instructions for updating:
  Colocations handled automatically by placer.
  2019-05-16 18:20:37.788946: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
  WARNING:tensorflow:From /Users/tomhardy/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
  Instructions for updating:
  Use tf.cast instead.
  Epoch 1/1
  15/15 [==============================] - 0s 22ms/step - loss: -0.8084 - acc: 0.6000
  Epoch 1/1
  15/15 [==============================] - 0s 286us/step - loss: -1.4546 - acc: 0.6000
  Segmentation fault: 11
  172-26-86-157:ML tomhardy$ 
  </code></pre>
  
  <p>The segmentation fault occurred after two episodes in this case.</p>