Skip to content

Instantly share code, notes, and snippets.

@AlexDBlack
Created November 23, 2018 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexDBlack/a98a50ce1e2db323e0dcc4d8a3a9ea30 to your computer and use it in GitHub Desktop.
Save AlexDBlack/a98a50ce1e2db323e0dcc4d8a3a9ea30 to your computer and use it in GitHub Desktop.
package org.deeplearning4j.examples;
import org.datavec.image.loader.NativeImageLoader;
import org.deeplearning4j.nn.graph.ComputationGraph;
import org.deeplearning4j.nn.layers.objdetect.DetectedObject;
import org.deeplearning4j.nn.layers.objdetect.YoloUtils;
import org.deeplearning4j.parallelism.ParallelInference;
import org.deeplearning4j.parallelism.inference.InferenceMode;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.dataset.api.preprocessor.ImagePreProcessingScaler;
import org.nd4j.linalg.factory.Nd4j;
import java.io.File;
import java.util.List;
public class Debug6730 {
public static final double[][] DEFAULT_PRIOR_BOXES = {{0.57273, 0.677385}, {1.87446, 2.06253}, {3.33843, 5.47434}, {7.88282, 3.52778}, {9.77052, 9.16828}};
public static void main(String[] args) throws Exception {
// int height = 224;
// int width = 224;
int height = 416;
int width = 416;
// ComputationGraph cg = ComputationGraph.load(new File("C:/Users/Alex/Downloads/tiny_224.zip"), false);
ComputationGraph cg = ComputationGraph.load(new File("C:/Users/Alex/Downloads/tiny_416.zip"), false);
ParallelInference pi = new ParallelInference.Builder(cg).inferenceMode(InferenceMode.BATCHED).batchLimit(8).workers(4).build();
NativeImageLoader loader = new NativeImageLoader(height, width, 3);
ImagePreProcessingScaler imagePreProcessingScaler = new ImagePreProcessingScaler(0, 1);
File[] fileList = new File("E:\\Data\\VOC\\VOCtrainval_11-May-2012\\VOCdevkit\\VOC2012\\JPEGImages").listFiles();
for(File img : fileList) {
System.out.println(img);
INDArray indArray = loader.asMatrix(img);
imagePreProcessingScaler.transform(indArray);
INDArray out = cg.outputSingle(indArray);
INDArray outPi = pi.output(indArray);
boolean equals = out.equals(outPi);
List<DetectedObject> predictedObjects = YoloUtils.getPredictedObjects(Nd4j.create(DEFAULT_PRIOR_BOXES), out, 0.5, 0);
List<DetectedObject> predictedObjectsPI = YoloUtils.getPredictedObjects(Nd4j.create(DEFAULT_PRIOR_BOXES), outPi, 0.5, 0);
if(!equals || predictedObjects.size() > 0){
if(!equals){
System.out.println("NOT EQUAL");
}
System.out.println(predictedObjects);
System.out.println(predictedObjectsPI);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment