Why you don’t implement your custom metric composing TF ops if you want to run in graph mode?
See also Custom metrics section in:

  
      

      keras.io
  

  
    

Keras documentation: Metrics 21