Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No OpKernel was registered to support Op 'PyFunc' when loading model in Java

Here is the question. I am using tensorflow:1.8.0-rc0 Java to load the model saved by python (tf.saved_model.builder.SavedModelBuilder). The model is saved and I can see the variables files.

However, when I try to load this model in Java. using SavedModelBundle.load(featureExtractionModel,"foo-tag");

I get the following issue

Exception in thread "main" java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'PyFunc' with these attrs.  Registered devices: [CPU], Registered kernels:
  <no registered kernels>

     [[Node: cond_15/PyFunc = PyFunc[Tin=[DT_UINT8], Tout=[DT_UINT8], _output_shapes=[<unknown>], token="pyfunc_3"](cond_15/PyFunc/Switch:1)]]
    at org.tensorflow.SavedModelBundle.load(Native Method)
    at org.tensorflow.SavedModelBundle.load(SavedModelBundle.java:39)

Do I need to strip it somehow before saving the model? Clarifications: The model is pre-trained and I got it from (facenet)[https://github.com/davidsandberg/facenet]


1 Answers

The PyFunc kernel corresponds to a tf.py_func in your model, which requires a Python interpreter to execute.

So, it seems the model you're using requires the Python interpreter, which is not linked into the Java API and hence you see the error.

You'd want to figure out where in your model tf.py_func is being used replace the computation expressed as a Python function in your model with something that uses TensorFlow operations.

Hope that helps.

like image 193
ash Avatar answered Aug 22 '26 16:08

ash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!