title: How to replace loss function during training tensorflow.keras
body: <p>I want to replace the loss function related to my neural network during training, this is the network:</p>
  
  <pre><code>model = tensorflow.keras.models.Sequential()
          model.add(tensorflow.keras.layers.Conv2D(32, kernel_size=(3, 3), activation="relu", input_shape=input_shape))
          model.add(tensorflow.keras.layers.Conv2D(64, (3, 3), activation="relu"))
          model.add(tensorflow.keras.layers.MaxPooling2D(pool_size=(2, 2)))
          model.add(tensorflow.keras.layers.Dropout(0.25))
          model.add(tensorflow.keras.layers.Flatten())
          model.add(tensorflow.keras.layers.Dense(128, activation="relu"))
          model.add(tensorflow.keras.layers.Dropout(0.5))
          model.add(tensorflow.keras.layers.Dense(output_classes, activation="softmax"))
          model.compile(loss=tensorflow.keras.losses.categorical_crossentropy, optimizer=tensorflow.keras.optimizers.Adam(0.001), metrics=['accuracy'])
          history = model.fit(x_train, y_train, batch_size=128, epochs=5, validation_data=(x_test, y_test))
  </code></pre>
  
  <p>so now I want to change <code>tensorflow.keras.losses.categorical_crossentropy</code> with another, so I made this:</p>
  
  <pre><code>model.compile(loss=tensorflow.keras.losses.mse, optimizer=tensorflow.keras.optimizers.Adam(0.001), metrics=['accuracy'])
      history = model.fit(x_improve, y_improve, epochs=1, validation_data=(x_test, y_test)) #FIXME bug during training
  </code></pre>
  
  <p>but I have this error:</p>
  
  <pre><code>ValueError: No gradients provided for any variable: ['conv2d/kernel:0', 'conv2d/bias:0', 'conv2d_1/kernel:0', 'conv2d_1/bias:0', 'dense/kernel:0', 'dense/bias:0', 'dense_1/kernel:0', 'dense_1/bias:0'].
  </code></pre>
  
  <p>Why? How can I fix it? There is another way to change loss function?</p>
  
  <p>Thanks</p>