@Test public void recognise() throws Exception { TikaConfig config = null; try (InputStream is = getClass().getResourceAsStream("dl4j-inception3-config.xml")) { config = new TikaConfig(is); } catch (Exception e) { if (e.getMessage() != null && (e.getMessage().contains("Connection refused") || e.getMessage().contains("connect timed out"))) { assumeTrue("skipping test because of connection issue", false); } throw e; } assumeTrue("something went wrong loading tika config", config != null); Tika tika = new Tika(config); Metadata md = new Metadata(); try (InputStream is = getClass().getResourceAsStream("cat.jpg")) { tika.parse(is, md); } String[] objects = md.getValues("OBJECT"); boolean found = false; for (String object : objects) { if (object.contains("_cat")) { found = true; break; } } assertTrue(found); }
@Override public List<RecognisedObject> recognise( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { INDArray image = preProcessImage(imageLoader.asMatrix(stream)); INDArray scores = graph.outputSingle(image); List<RecognisedObject> result = new ArrayList<>(); for (int i = 0; i < scores.length(); i++) { if (scores.getDouble(i) > minConfidence) { String label = labelMap.get(i); String id = i + ""; result.add(new RecognisedObject(label, labelLang, id, scores.getDouble(i))); LOG.debug("Found Object {}", label); } } return result; }
DL4JInceptionV3Net implements ObjectRecogniser { @Override public List<RecognisedObject> recognise( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { INDArray image = preProcessImage(imageLoader.asMatrix(stream)); INDArray scores = graph.outputSingle(image); List<RecognisedObject> result = new ArrayList<>(); for (int i = 0; i < scores.length(); i++) { if (scores.getDouble(i) > minConfidence) { String label = labelMap.get(i); String id = i + ""; result.add(new RecognisedObject(label, labelLang, id, scores.getDouble(i))); LOG.debug("Found Object {}", label); } } return result; } }
DL4JInceptionV3Net implements ObjectRecogniser { @Override public List<RecognisedObject> recognise( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { INDArray image = preProcessImage(imageLoader.asMatrix(stream)); INDArray scores = graph.outputSingle(image); List<RecognisedObject> result = new ArrayList<>(); for (int i = 0; i < scores.length(); i++) { if (scores.getDouble(i) > minConfidence) { String label = labelMap.get(i); String id = i + ""; result.add(new RecognisedObject(label, labelLang, id, scores.getDouble(i))); LOG.debug("Found Object {}", label); } } return result; }  }
DL4JInceptionV3Net implements ObjectRecogniser { @Override public List<RecognisedObject> recognise( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { INDArray image = preProcessImage(imageLoader.asMatrix(stream)); INDArray scores = graph.outputSingle(image); List<RecognisedObject> result = new ArrayList<>(); for (int i = 0; i < scores.length(); i++) { if (scores.getDouble(i) > minConfidence) { String label = labelMap.get(i); String id = i + ""; result.add(new RecognisedObject(label, labelLang, id, scores.getDouble(i))); LOG.debug("Found Object {}", label); } } return result; }  @Override Set<MediaType> getSupportedMimes(); @Override void initialize(Map<String, Param> params); @Override void checkInitialization(InitializableProblemHandler problemHandler); @Override boolean isAvailable(); INDArray preProcessImage(INDArray input); Map<Integer, String> loadClassIndex(InputStream stream); @Override List<RecognisedObject> recognise(
            InputStream stream, ContentHandler handler, Metadata metadata,
            ParseContext context); }
DL4JInceptionV3Net implements ObjectRecogniser { @Override public List<RecognisedObject> recognise( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { INDArray image = preProcessImage(imageLoader.asMatrix(stream)); INDArray scores = graph.outputSingle(image); List<RecognisedObject> result = new ArrayList<>(); for (int i = 0; i < scores.length(); i++) { if (scores.getDouble(i) > minConfidence) { String label = labelMap.get(i); String id = i + ""; result.add(new RecognisedObject(label, labelLang, id, scores.getDouble(i))); LOG.debug("Found Object {}", label); } } return result; }  @Override Set<MediaType> getSupportedMimes(); @Override void initialize(Map<String, Param> params); @Override void checkInitialization(InitializableProblemHandler problemHandler); @Override boolean isAvailable(); INDArray preProcessImage(INDArray input); Map<Integer, String> loadClassIndex(InputStream stream); @Override List<RecognisedObject> recognise(
            InputStream stream, ContentHandler handler, Metadata metadata,
            ParseContext context);  }