YoloProcessor extends NeuralNetUtils implements NeuralNetInterface2 { @Override public void setupImageProcessing(Map<String, ?> neuralNetConfig, String sourceName, String modelDirectory, String authToken, String server) throws Exception { setup(neuralNetConfig, sourceName, modelDirectory, authToken, server); try { objectDetector = new ObjectDetector(threshold, pbFile, labelsFile, metaFile, anchorArray, imageUtil, outputDir, labelImage, saveRate, vantiq, sourceName); } catch (Exception e) { throw new Exception(this.getClass().getCanonicalName() + ".yoloBackendSetupError: " + "Failed to create new ObjectDetector", e); } }  @Override void setupImageProcessing(Map<String, ?> neuralNetConfig, String sourceName, String modelDirectory, String authToken, String server); @Override NeuralNetResults processImage(byte[] image); @Override NeuralNetResults processImage(byte[] image,  Map<String, ?> request); @Override NeuralNetResults processImage(Map<String, ?> processingParams, byte[] image); @Override NeuralNetResults processImage(Map<String, ?> processingParams, byte[] image, Map<String, ?> request); @Override void close();  }
@Test public void testInvalidConfig() { Map config = new LinkedHashMap<>(); YoloProcessor ypImageSaver = new YoloProcessor(); try { ypImageSaver.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); fail("Should fail without anything in config."); } catch (Exception e) { assertTrue("Failure should be caused by empty config. Error actually was: " + e.getMessage(), e.getMessage().startsWith(YoloProcessor.class.getCanonicalName() + ".missingConfig:")); } config.put("pbFile", PB_FILE); try { ypImageSaver.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); fail("Should fail without either a label file or a meta file."); } catch (Exception e) { assertTrue("Failure should be caused by lack of either label or meta file. Error actually was: " + e.getMessage(), e.getMessage().startsWith(YoloProcessor.class.getCanonicalName() + ".missingConfig:")); } config.remove("pbFile"); config.put("labelFile", LABEL_FILE); try { ypImageSaver.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); fail("Should fail when label file is included but pbFile is not."); } catch (Exception e) { assertTrue("Failure should be caused by lack of pbFile even when label file is included. Error actually was: " + e.getMessage(), e.getMessage().startsWith(YoloProcessor.class.getCanonicalName() + ".missingConfig:")); } config.remove("labelFile"); config.put("metaFile", META_FILE); try { ypImageSaver.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); fail("Should fail when meta file is included but pbFile is not."); } catch (Exception e) { assertTrue("Failure should be caused by lack of pbFile even when meta file is included. Error actually was: " + e.getMessage(), e.getMessage().startsWith(YoloProcessor.class.getCanonicalName() + ".missingConfig:")); } }
@Test public void testValidConfig() { Map config = new LinkedHashMap<>(); YoloProcessor ypImageSaver = new YoloProcessor(); List<Number> anchorList = Arrays.asList(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); config.put("pbFile", PB_FILE); config.put("metaFile", META_FILE); try { ypImageSaver.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); } catch (Exception e) { fail("Should not fail with meta file but no label file: " + e.getClass().getName() + "::" + e.getMessage()); } config.put("anchors", anchorList); try { ypImageSaver.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); } catch (Exception e) { fail("Should not fail with meta file and anchors: " + e.getClass().getName() + "::" + e.getMessage()); } config.remove("metaFile"); config.remove("anchors"); config.put("labelFile", LABEL_FILE); try { ypImageSaver.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); } catch (Exception e) { fail("Should not fail with label file but no meta file: " + e.getClass().getName() + "::" + e.getMessage()); } config.put("anchors", anchorList); try { ypImageSaver.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); } catch (Exception e) { fail("Should not fail with label file and anchors: " + e.getClass().getName() + "::" + e.getMessage()); } config.put("metaFile", META_FILE); try { ypImageSaver.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); } catch (Exception e) { fail("Should not fail with label and meta file, and anchors: " + e.getClass().getName() + "::" + e.getMessage()); } }
@Test public void testMetaConfig() { Map config = new LinkedHashMap<>(); YoloProcessor ypImageSaver = new YoloProcessor(); YoloProcessor ypImageSaver2 = new YoloProcessor(); config.put("pbFile", PB_FILE_608); config.put("metaFile", META_FILE_608); try { ypImageSaver.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); } catch (Exception e) { fail("Should not fail setup: " + e.getClass().getName() + "::" + e.getMessage()); } assert ypImageSaver.objectDetector.metaConfigOptions.useMetaIfAvailable == true; assert ypImageSaver.objectDetector.metaConfigOptions.frameSize == 608; config.remove("metaFile"); config.put("labelFile", LABEL_FILE); try { ypImageSaver2.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); } catch (Exception e) { fail("Should not fail setup: " + e.getClass().getName() + "::" + e.getMessage()); } assert ypImageSaver2.objectDetector.metaConfigOptions.useMetaIfAvailable == true; assert ypImageSaver2.objectDetector.metaConfigOptions.frameSize == 416; }
@Test public void testValidAnchors() throws ImageProcessingException { Map config = new LinkedHashMap<>(); YoloProcessor ypImageSaver = new YoloProcessor(); List<Number> anchorList = Arrays.asList(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); config.put("pbFile", PB_FILE); config.put("labelFile", LABEL_FILE); config.put("anchors", anchorList); try { ypImageSaver.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); } catch (Exception e) { fail("Should not fail with valid anchors: " + e.getClass().getName() + "::" + e.getMessage()); } anchorList = Arrays.asList(1, 1.0, 0.01, 1, 1.0, 0.01, 1, 1.0, 0.01, 1); config.remove("anchors"); config.put("anchors", anchorList); try { ypImageSaver.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); } catch (Exception e) { fail("Should not fail with invalid anchors: " + e.getClass().getName() + "::" + e.getMessage()); } }
@Test public void testInvalidAnchors() throws ImageProcessingException { Map config = new LinkedHashMap<>(); YoloProcessor ypImageSaver = new YoloProcessor(); List anchorList = Arrays.asList(0.5); config.put("pbFile", PB_FILE); config.put("labelFile", LABEL_FILE); config.put("anchors", anchorList); try { ypImageSaver.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); } catch (Exception e) { fail("Should not fail with invalid anchors: " + e.getClass().getName() + "::" + e.getMessage()); } anchorList = Arrays.asList(1, 3, 6, 4, 4, 5, 7, 4, 9, 0, 9); config.remove("anchors"); config.put("anchors", anchorList); try { ypImageSaver.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); } catch (Exception e) { fail("Should not fail with invalid anchors: " + e.getClass().getName() + "::" + e.getMessage()); } anchorList = Arrays.asList(1, 3, 6, "a", 4, 5, 7, 4, 9, 0); config.remove("anchors"); config.put("anchors", anchorList); try { ypImageSaver.setupImageProcessing(config, SOURCE_NAME, MODEL_DIRECTORY, testAuthToken, testVantiqServer); } catch (Exception e) { fail("Should not fail with invalid anchors: " + e.getClass().getName() + "::" + e.getMessage()); } }