Java Code Examples for org.deeplearning4j.zoo.model.helper.DarknetHelper#getGridHeight()

The following examples show how to use org.deeplearning4j.zoo.model.helper.DarknetHelper#getGridHeight() . 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: YOLOOutputAdapter.java    From konduit-serving with Apache License 2.0 6 votes vote down vote up
@Builder
public YOLOOutputAdapter(double threshold, int[] inputShape, Labels labels, int numLabels, double[][] boundingBoxPriors) {
    this.labels = labels == null ? getLabels() : labels;
    if (threshold == 0.0)
        this.threshold = 0.5;
    else
        this.threshold = threshold;
    if (inputShape != null)
        this.inputShape = inputShape;
    else
        this.inputShape = new int[]{3, 608, 608};
    this.labels = labels;
    this.numLabels = numLabels;
    if (boundingBoxPriors == null)
        this.boundingBoxPriors = Nd4j.create(YOLO2.DEFAULT_PRIOR_BOXES).castTo(DataType.FLOAT);
    else {
        this.boundingBoxPriors = Nd4j.create(boundingBoxPriors).castTo(DataType.FLOAT);
    }

    gridWidth = DarknetHelper.getGridWidth(inputShape);
    gridHeight = DarknetHelper.getGridHeight(inputShape);

}
 
Example 2
Source File: YOLOOutputAdapter.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public YOLOOutputAdapter(double threshold, Labels labels, int numLabels) {
    this.threshold = threshold;
    inputShape = new int[]{3, 608, 608};
    this.labels = labels;
    this.numLabels = numLabels;
    boundingBoxPriors = Nd4j.create(YOLO2.DEFAULT_PRIOR_BOXES).castTo(DataType.FLOAT);
    gridWidth = DarknetHelper.getGridWidth(inputShape);
    gridHeight = DarknetHelper.getGridHeight(inputShape);

}
 
Example 3
Source File: TestInstantiation.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
public static void runTest(ZooModel model, String modelName, int numClasses) throws Exception {
    ignoreIfCuda();
    int gridWidth = -1;
    int gridHeight = -1;
    if (modelName.equals("TinyYOLO") || modelName.equals("YOLO2")) {
        int[] inputShapes = model.metaData().getInputShape()[0];
        gridWidth = DarknetHelper.getGridWidth(inputShapes);
        gridHeight = DarknetHelper.getGridHeight(inputShapes);
        numClasses += 4;
    }

    // set up data iterator
    int[] inputShape = model.metaData().getInputShape()[0];
    DataSetIterator iter = new BenchmarkDataSetIterator(
            new int[]{8, inputShape[0], inputShape[1], inputShape[2]}, numClasses, 1,
            gridWidth, gridHeight);

    Model initializedModel = model.init();
    AsyncDataSetIterator async = new AsyncDataSetIterator(iter);
    if (initializedModel instanceof MultiLayerNetwork) {
        ((MultiLayerNetwork) initializedModel).fit(async);
    } else {
        ((ComputationGraph) initializedModel).fit(async);
    }
    async.shutdown();

    // clean up for current model
    model = null;
    initializedModel = null;
    async = null;
    iter = null;
    Nd4j.getWorkspaceManager().destroyAllWorkspacesForCurrentThread();
    System.gc();
    Thread.sleep(1000);
    System.gc();
}