Java Code Examples for org.deeplearning4j.nn.graph.ComputationGraph#getOutputLayer()

The following examples show how to use org.deeplearning4j.nn.graph.ComputationGraph#getOutputLayer() . 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: TransformRotatingImages.java    From Java-Machine-Learning-for-Computer-Vision with MIT License 6 votes vote down vote up
private static void cropImageWithYOLOBoundingBox(ComputationGraph yolo,
                                                 Speed selectedSpeed, File file) throws Exception {
    if (file.isDirectory()) {
        return;
    }
    BufferedImage bufferedImage = ImageIO.read(file);
    INDArray features = LOADER.asMatrix(bufferedImage);
    opencv_core.Mat mat = LOADER.asMat(features);
    PRE_PROCESSOR.transform(features);
    INDArray results = yolo.outputSingle(features);
    Yolo2OutputLayer outputLayer = (Yolo2OutputLayer) yolo.getOutputLayer(0);
    List<DetectedObject> predictedObjects = outputLayer.getPredictedObjects(results, 0.5);
    YoloUtils.nms(predictedObjects, 0.5);
    Optional<DetectedObject> max = predictedObjects.stream()
            .max((o1, o2) -> ((Double) o1.getConfidence()).compareTo(o2.getConfidence()));
    createCroppedImage(mat, selectedSpeed, max.get(), file);
}
 
Example 2
Source File: YOLOModel.java    From java-ml-projects with Apache License 2.0 6 votes vote down vote up
public void init() {
	try {
		if (Objects.isNull(modelPath)) {

			yoloModel = (ComputationGraph) YOLO2.builder().build().initPretrained();
			setModelClasses(COCO_CLASSES);
		} else {
			yoloModel = ModelSerializer.restoreComputationGraph(modelPath);
			if (!(yoloModel.getOutputLayer(0) instanceof Yolo2OutputLayer)) {
				throw new Error("The model is not an YOLO model (output layer is not Yolo2OutputLayer)");
			}
			setModelClasses(classes.split("\\,"));
		}
		imageLoader = new NativeImageLoader(getInputWidth(), getInputHeight(), getInputChannels(),
				new ColorConversionTransform(COLOR_BGR2RGB));
		loadInputParameters();
	} catch (IOException e) {
		throw new Error("Not able to init the model", e);
	}
}
 
Example 3
Source File: Yolo.java    From Java-Machine-Learning-for-Computer-Vision with MIT License 5 votes vote down vote up
private void warmUp(ComputationGraph model) throws IOException {
    Yolo2OutputLayer outputLayer = (Yolo2OutputLayer) model.getOutputLayer(0);
    BufferedImage read = ImageIO.read(new File("CarTracking/src/main/resources/sample.jpg"));
    INDArray indArray = prepareImage(loader.asMatrix(read));
    INDArray results = model.outputSingle(indArray);
    outputLayer.getPredictedObjects(results, YOLO_DETECTION_THRESHOLD);
}
 
Example 4
Source File: ActorCriticCompGraph.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public ActorCriticCompGraph(ComputationGraph cg) {
    this.cg = cg;
    this.recurrent = cg.getOutputLayer(0) instanceof RnnOutputLayer;
}