title: Assignment with Tensor Object for custom loss function
body: <p>I am trying to define a custom rmse loss function for Keras. I wrote the function below to penalize the loss when the value of the data is less than 0.15 and otherwise.</p>
  <pre><code>import keras.backend as K
  
  def custom_rmse(y_true, y_pred):
    loss = K.square(y_pred - y_true)
    for i in range(len(y_true)):
      for j in range(y_true.shape[1]):
        tmp = float(y_true[i][j])
        if (tmp &lt; 0.15):
          loss[i][j] *= 0.2
        else:
          loss[i][j] *=0.8
    loss = K.sqrt(K.sum(loss, axis=1)) 
    return loss
  </code></pre>
  <p>But when I ran the model and attempted to fix it, I kept getting this error</p>
  <pre><code> /usr/local/lib/python3.7/dist-packages/keras/engine/training.py:853 train_function  *
          return step_function(self, iterator)
      &lt;ipython-input-95-efab27dd2563&gt;:8 custom_rmse  *
          if (tmp &lt; 0.15):
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/autograph/operators/control_flow.py:1172 if_stmt
          _tf_if_stmt(cond, body, orelse, get_state, set_state, symbol_names, nouts)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/autograph/operators/control_flow.py:1219 _tf_if_stmt
          cond, aug_body, aug_orelse, strict=True)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py:206 wrapper
          return target(*args, **kwargs)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/util/deprecation.py:549 new_func
          return func(*args, **kwargs)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/control_flow_ops.py:1254 cond
          return cond_v2.cond_v2(pred, true_fn, false_fn, name)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/cond_v2.py:88 cond_v2
          op_return_value=pred)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/func_graph.py:1007 func_graph_from_py_func
          func_outputs = python_func(*func_args, **func_kwargs)
      /usr/local/lib/python3.7/dist-packages/tensorflow/python/autograph/operators/control_flow.py:1197 aug_body
          set_state(init_vars)
      /tmp/tmp_3e6lmrw.py:35 set_state
          (loss[i][j],) = vars_
  
      TypeError: 'Tensor' object does not support item assignment
  </code></pre>
  <p>I will appreciate suggestions on how to fix this. Thanks.</p>