本文整理匯總了Java中org.nd4j.linalg.dataset.api.preprocessor.VGG16ImagePreProcessor類的典型用法代碼示例。如果您正苦於以下問題:Java VGG16ImagePreProcessor類的具體用法?Java VGG16ImagePreProcessor怎麽用?Java VGG16ImagePreProcessor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
VGG16ImagePreProcessor類屬於org.nd4j.linalg.dataset.api.preprocessor包,在下文中一共展示了VGG16ImagePreProcessor類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testImageNetLabels
import org.nd4j.linalg.dataset.api.preprocessor.VGG16ImagePreProcessor; //導入依賴的package包/類
@Test
public void testImageNetLabels() throws IOException {
// set up model
ZooModel model = new VGG19(1, 123); //num labels doesn't matter since we're getting pretrained imagenet
ComputationGraph initializedModel = (ComputationGraph) model.initPretrained();
// set up input and feedforward
NativeImageLoader loader = new NativeImageLoader(224, 224, 3);
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
INDArray image = loader.asMatrix(classloader.getResourceAsStream("goldenretriever.jpg"));
DataNormalization scaler = new VGG16ImagePreProcessor();
scaler.transform(image);
INDArray[] output = initializedModel.output(false, image);
// check output labels of result
String decodedLabels = new ImageNetLabels().decodePredictions(output[0]);
log.info(decodedLabels);
assertTrue(decodedLabels.contains("golden_retriever"));
// clean up for current model
Nd4j.getWorkspaceManager().destroyAllWorkspacesForCurrentThread();
System.gc();
}
示例2: classifyImageVGG16
import org.nd4j.linalg.dataset.api.preprocessor.VGG16ImagePreProcessor; //導入依賴的package包/類
public Map<String, Double> classifyImageVGG16(IplImage iplImage) throws IOException {
NativeImageLoader loader = new NativeImageLoader(224, 224, 3);
BufferedImage buffImg = OpenCV.IplImageToBufferedImage(iplImage);
INDArray image = loader.asMatrix(buffImg);
// TODO: we should consider the model as not only the model, but also the input transforms
// for that model.
DataNormalization scaler = new VGG16ImagePreProcessor();
scaler.transform(image);
INDArray[] output = vgg16.output(false,image);
// TODO: return a more native datastructure!
//String predictions = TrainedModels.VGG16.decodePredictions(output[0]);
// log.info("Image Predictions: {}", predictions);
return decodeVGG16Predictions(output[0]);
}
示例3: classifyImageFileVGG16
import org.nd4j.linalg.dataset.api.preprocessor.VGG16ImagePreProcessor; //導入依賴的package包/類
public Map<String, Double> classifyImageFileVGG16(String filename) throws IOException {
File file = new File(filename);
NativeImageLoader loader = new NativeImageLoader(224, 224, 3);
INDArray image = loader.asMatrix(file);
// TODO: we should consider the model as not only the model, but also the input transforms
// for that model.
DataNormalization scaler = new VGG16ImagePreProcessor();
scaler.transform(image);
INDArray[] output = vgg16.output(false,image);
// TODO: return a more native datastructure!
//String predictions = TrainedModels.VGG16.decodePredictions(output[0]);
//log.info("Image Predictions: {}", predictions);
return decodeVGG16Predictions(output[0]);
}
示例4: normalizeImage
import org.nd4j.linalg.dataset.api.preprocessor.VGG16ImagePreProcessor; //導入依賴的package包/類
private void normalizeImage(final INDArray image) {
DataNormalization scaler = new VGG16ImagePreProcessor();
scaler.transform(image);
}