Java Code Examples for org.tensorflow.Graph#operation()

The following examples show how to use org.tensorflow.Graph#operation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphHelper.java    From cineast with MIT License 6 votes vote down vote up
/**
 * filters operations which are not part of a provided graph
 */
public static List<String> filterOperations(List<String> operations, Graph graph){

  if(operations == null || operations.isEmpty() || graph == null){
    return Collections.emptyList();
  }

  ArrayList<String> _return = new ArrayList<>(operations.size());

  for(String operation : operations){
    if(graph.operation(operation) != null){
      _return.add(operation);
    }
  }

  return _return;

}
 
Example 2
Source File: TensorFlowObjectDetectionAPIModel.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static Classifier create(AssetManager assetManager, String modelFilename, String labelFilename, int inputSize) throws IOException {
    TensorFlowObjectDetectionAPIModel d = new TensorFlowObjectDetectionAPIModel();
    BufferedReader br = new BufferedReader(new InputStreamReader(assetManager.open(labelFilename.split("file:///android_asset/")[1])));
    while (true) {
        String line = br.readLine();
        if (line == null) {
            break;
        }
        d.labels.add(line);
    }
    br.close();
    d.inferenceInterface = new TensorFlowInferenceInterface(assetManager, modelFilename);
    Graph g = d.inferenceInterface.graph();
    d.inputName = "image_tensor";
    if (g.operation(d.inputName) == null) {
        throw new RuntimeException("Failed to find input Node '" + d.inputName + "'");
    }
    d.inputSize = inputSize;
    if (g.operation("detection_scores") == null) {
        throw new RuntimeException("Failed to find output Node 'detection_scores'");
    } else if (g.operation("detection_boxes") == null) {
        throw new RuntimeException("Failed to find output Node 'detection_boxes'");
    } else if (g.operation("detection_classes") == null) {
        throw new RuntimeException("Failed to find output Node 'detection_classes'");
    } else {
        d.outputNames = new String[]{"detection_boxes", "detection_scores", "detection_classes", "num_detections"};
        d.intValues = new int[(d.inputSize * d.inputSize)];
        d.byteValues = new byte[((d.inputSize * d.inputSize) * 3)];
        d.outputScores = new float[100];
        d.outputLocations = new float[400];
        d.outputClasses = new float[100];
        d.outputNumDetections = new float[1];
        return d;
    }
}
 
Example 3
Source File: DeeplabMobile.java    From ml with Apache License 2.0 5 votes vote down vote up
public static void printOp(Graph graph, String opName) {
    if (graph == null
            || TextUtils.isEmpty(opName)) {
        return;
    }

    Operation op = graph.operation(opName);

    Logger.debug("op[%s]: %s",
            opName, op);
}
 
Example 4
Source File: RNTensorFlowGraphModule.java    From react-native-tensorflow with Apache License 2.0 5 votes vote down vote up
public Operation getOperation(String id, String name) {
    Graph graph = graphs.get(id);
    if(graph != null && name != null) {
        return graph.operation(name);
    } else {
        return null;
    }
}
 
Example 5
Source File: SavedModel.java    From jpmml-tensorflow with GNU Affero General Public License v3.0 4 votes vote down vote up
public Operation getOperation(String name){
	Graph graph = getGraph();

	return graph.operation(name);
}