Advertisement
Guest User

Untitled

a guest
Jun 5th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. File file = new File("Java.jpg");
  2.             Image image = new Image(file.toURI().toString());
  3.             imga.setImage(image);
  4.             String modelpath = "C:\\Users\\AngruAdminAlex\\Documents\\inception_dec_2015";
  5.             graphDef
  6.                     = readAllBytesOrExit(Paths.get(modelpath,
  7.                             "tensorflow_inception_graph.pb"));
  8.             labels
  9.                     = readAllLinesOrExit(Paths.get(modelpath,
  10.                             "imagenet_comp_graph_label_strings.txt"));
  11.             File file1 = new File("Java.jpg");
  12.             String imagepath = "Java.jpg";
  13.             System.out.println(
  14.             "Image
  15.    Path: " + imagepath); BufferedImage img = ImageIO.read(file1); //read
  16.     image System
  17.             .out.println("Reading complete.");
  18.             byte[] imageBytes
  19.                     = readAllBytesOrExit(Paths.get(imagepath));
  20.             byte data[] = imageBytes;
  21.             FileOutputStream out = new FileOutputStream("buffer.rawfile");
  22.             out.write(data);
  23.             out.close();
  24.             try (Tensor image1
  25.                     = Tensor.create(imageBytes)) {
  26.                 float[] labelProbabilities
  27.                         = executeInceptionGraph(graphDef, image1);
  28.                 int bestLabelIdx
  29.                         = maxIndex(labelProbabilities);
  30.                 System.out.println(String.format( "BEST
  31.    MATCH:
  32.                 % s( % .2f likely)", labels.get(bestLabelIdx),
  33.     labelProbabilities[bestLabelIdx] * 100f
  34.                 )); results.setText(
  35.                         String.format("BEST MATCH: %s (%.2f likely)",
  36.                                 labels.get(bestLabelIdx), labelProbabilities[bestLabelIdx] * 100f));
  37.             }
  38.         }
  39.     }
  40.    
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement