ColdFusion 2016 Java API call TensorFlow cannot initialize class

I am trying to call the TensorFlow Java API from ColdFusion 2016 developer edition on Windows 10 Home.

I took my cues from TensorFlow Readme.md In addition to the jar, it uses the platform-specific JNI DLL, so I installed my test: <cfscript> CreateObject("java","java.lang.System").load("C:\\absolutepath\\tensorflow_jni.dll"); variables.tensorflow = CreateObject("Java","org.tensorflow.TensorFlow"); WriteDump(variables.tensorflow); WriteOutput("I'm running TensorFlow version: " & variables.tensorflow.version()); </cfscript>

I thought it would be a piece of cake when I see the WriteDump object: enter image description here

but calling version () just leaves the browser spinning.

Application log shows the following error: Could not initialize class org.tensorflow.TensorFlow The specific sequence of files included or processed is: C:\ColdFusionBuilder2016\ColdFusion\cfusion\wwwroot\CF_TensorFlow\index.cfm, line: 5

The JNI seems to be loading ... When it doesn't, the error message is very clear "Cannot find native TensorFlow library for OS: windows ..."

I'm not sure what to do at this point. Is there something I need to do for the Java source to play well with CF?

+3


source to share


1 answer


As you've probably figured out, the library looks for standard DLL locations first. So adding a path or file to one of these locations (after restarting CF) will definitely work:

  • Add the DLL path to java.library.path

  • Copy the DLL file to the directory jre\bin

Looking back at the source and comments , it seems the DLL can also be added to the TensorFlow jar. The exact path depends on o / s:



private static String makeResourceName() {
    return "org/tensorflow/native/"
        + String.format("%s-%s/", os(), architecture())
        + System.mapLibraryName(LIBNAME);
}

      

So instead of using it, System.load()

open the jar and copy the DLL to the appropriate folder. For 64 bit windows the expected path org/tensorflow/native/windows-x86_64/tensorflow_jni.dll

.

libtensorflow-1.1.0-rc2-with-dll.jar 

  |-- META-INF
  |-- org    
      |-- tensorflow    
          |-- TensorFlow.class
          |-- ... 
          |-- native 
              |-- windows-x86_64
                  |-- tensorflow_jni.dll

      

+2


source







All Articles