It is explained here in the doc:

Since the function takes numpy arrays, you cannot take gradients through a numpy_function. If you require something that is differentiable, please consider using tf.py_function.

If you just need a dilation you could try to add a dilation layer:

  

      stackoverflow.com
  

  
      
    
  


  Tensorflow dilation behave differently than morphological dilation 2



  python, tensorflow, image-processing, mathematical-morphology



  asked by
  
  
    Jav
  
  on 09:19AM - 14 Feb 19 UTC


  

  
    
    
  

  


We have also a subset of numpy API (with some limits) available at:

  
      

      TensorFlow
  

  
    

NumPy API on TensorFlow  |  TensorFlow Core 1