如何修复使用Pyjnius时的jnius.JavaException

如何修复使用Pyjnius时的jnius.JavaException,java,python,tensorflow,pyjnius,Java,Python,Tensorflow,Pyjnius,我正在尝试获取以下示例,以便在Java中导入TensorFlow以运行: 经过一些修改后,我成功地使Java导入工作起来。 但是,我无法在Python的DeepLearning4J中使用该模型。我通过以下修改使其运行,但在加载模型时出现此异常: log4j:WARN No appenders could be found for logger (org.nd4j.linalg.factory.Nd4jBackend). log4j:WARN Please initialize the log4j

我正在尝试获取以下示例,以便在Java中导入TensorFlow以运行:

经过一些修改后,我成功地使Java导入工作起来。 但是,我无法在Python的DeepLearning4J中使用该模型。我通过以下修改使其运行,但在加载模型时出现此异常:

log4j:WARN No appenders could be found for logger (org.nd4j.linalg.factory.Nd4jBackend).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.rits.cloning.Cloner (file:/home/micha/.deeplearning4j/pydl4j/pydl4j-1.0.0-SNAPSHOT-cpu-core-datavec-spark2-2.11/pydl4j-1.0.0-SNAPSHOT-bin.jar) to field java.util.TreeSet.m
WARNING: Please consider reporting this to the maintainers of com.rits.cloning.Cloner
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Traceback (most recent call last):
  File "/home/micha/Documents/01_work/git/tf_java_import_testing/tf-import/mnist/mnist_jumpy.py", line 17, in <module>
    tf_model = jp.TFModel(path + '/mnist.pb')
  File "/home/micha/Documents/01_work/git/tf_java_import_testing/tf-import/venv-deepmom/lib/python3.7/site-packages/jumpy/tf_model.py", line 22, in __init__
    self.sd = TFGraphMapper.getInstance().importGraph(filepath)
  File "jnius/jnius_export_class.pxi", line 906, in jnius.JavaMultipleMethod.__call__
  File "jnius/jnius_export_class.pxi", line 638, in jnius.JavaMethod.__call__
  File "jnius/jnius_export_class.pxi", line 715, in jnius.JavaMethod.call_method
  File "jnius/jnius_utils.pxi", line 93, in jnius.check_exception
jnius.JavaException: JVM exception occurred: class java.lang.String cannot be cast to class org.tensorflow.framework.GraphDef (java.lang.String is in module java.base of loader 'bootstrap'; org.tensorflow.framework.GraphDef is in unnamed module of loader 'app')

这是一个合法的问题,不知道为什么没有人接受
import os
try:
     # from jnius import autoclass
     import jumpy as jp
except KeyError:
     os.environ['JDK_HOME'] = "/usr/lib/jvm/java-11-openjdk-amd64"
     os.environ['JAVA_HOME'] = "/usr/lib/jvm/java-11-openjdk-amd64"
     import jumpy as jp

from scipy import ndimage
# import numpy as np
import os

path = os.path.dirname(os.path.abspath(__file__))

# load tensorflow model
tf_model = jp.TFModel(path + '/mnist.pb')

# load jpg to numpy array
image = ndimage.imread(path + '/img (1).jpg').reshape((1, 28, 28))

# inference - uses nd4j
prediction = tf_model(image)  # prediction is a jumpy array

# get label from predction using argmax
label = jp.argmax(prediction.reshape((10,)))

print(label)