Search in sources :

Example 1 with OpDef

use of org.tensorflow.framework.OpDef in project nd4j by deeplearning4j.

the class TensorflowDescriptorParser method opDescs.

/**
 * Get the op descriptors for tensorflow
 * @return the op descriptors for tensorflow
 * @throws Exception
 */
public static Map<String, OpDef> opDescs() throws Exception {
    InputStream contents = new ClassPathResource("ops.proto").getInputStream();
    try (BufferedInputStream bis2 = new BufferedInputStream(contents);
        BufferedReader reader = new BufferedReader(new InputStreamReader(bis2))) {
        org.tensorflow.framework.OpList.Builder builder = org.tensorflow.framework.OpList.newBuilder();
        StringBuilder str = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            // .append("\n");
            str.append(line);
        }
        TextFormat.getParser().merge(str.toString(), builder);
        List<OpDef> list = builder.getOpList();
        Map<String, OpDef> map = new HashMap<>();
        for (OpDef opDef : list) {
            map.put(opDef.getName(), opDef);
        }
        return map;
    } catch (Exception e2) {
        e2.printStackTrace();
    }
    throw new ND4JIllegalStateException("Unable to load tensorflow descriptors!");
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) OpDef(org.tensorflow.framework.OpDef) ClassPathResource(org.nd4j.linalg.io.ClassPathResource) ND4JIllegalStateException(org.nd4j.linalg.exception.ND4JIllegalStateException) BufferedInputStream(java.io.BufferedInputStream) BufferedReader(java.io.BufferedReader) ND4JIllegalStateException(org.nd4j.linalg.exception.ND4JIllegalStateException)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 BufferedReader (java.io.BufferedReader)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1 ND4JIllegalStateException (org.nd4j.linalg.exception.ND4JIllegalStateException)1 ClassPathResource (org.nd4j.linalg.io.ClassPathResource)1 OpDef (org.tensorflow.framework.OpDef)1