use of boofcv.factory.scene.ClassifierAndSource in project BoofCV by lessthanoptimal.
the class ExampleImageClassification method main.
public static void main(String[] args) throws IOException {
// Test set 89.9% for 10 categories
ClassifierAndSource cs = FactoryImageClassifier.vgg_cifar10();
// ClassifierAndSource cs = FactoryImageClassifier.nin_imagenet(); // Test set 62.6% for 1000 categories
File path = DeepBoofDataBaseOps.downloadModel(cs.getSource(), new File("download_data"));
ImageClassifier<Planar<GrayF32>> classifier = cs.getClassifier();
classifier.loadModel(path);
List<String> categories = classifier.getCategories();
String imagePath = UtilIO.pathExample("recognition/pixabay");
List<File> images = Arrays.asList(UtilIO.findMatches(new File(imagePath), "\\w*.jpg"));
Collections.sort(images);
ImageClassificationPanel gui = new ImageClassificationPanel();
ShowImages.showWindow(gui, "Image Classification", true);
for (File f : images) {
BufferedImage buffered = UtilImageIO.loadImage(f.getPath());
if (buffered == null)
throw new RuntimeException("Couldn't find input image");
Planar<GrayF32> image = new Planar<>(GrayF32.class, buffered.getWidth(), buffered.getHeight(), 3);
ConvertBufferedImage.convertFromPlanar(buffered, image, true, GrayF32.class);
classifier.classify(image);
// add image and results to the GUI for display
gui.addImage(buffered, f.getName(), classifier.getAllResults(), categories);
}
}
Aggregations