本文整理汇总了Java中org.datavec.image.recordreader.ImageRecordReader.initialize方法的典型用法代码示例。如果您正苦于以下问题:Java ImageRecordReader.initialize方法的具体用法?Java ImageRecordReader.initialize怎么用?Java ImageRecordReader.initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.datavec.image.recordreader.ImageRecordReader
的用法示例。
在下文中一共展示了ImageRecordReader.initialize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: check
import org.datavec.image.recordreader.ImageRecordReader; //导入方法依赖的package包/类
private void check(BufferedImage image) throws Exception
{
ImageIO.write(image, "png", new File("tmp.png")); //saves the image to the tmp.png file
ImageRecordReader reader = new ImageRecordReader(150, 150, 3);
reader.initialize(new FileSplit(new File("tmp.png"))); //reads the tmp.png file
DataSetIterator dataIter = new RecordReaderDataSetIterator(reader, 1);
while (dataIter.hasNext())
{
//Normalize the data from the file
DataNormalization normalization = new NormalizerMinMaxScaler();
DataSet set = dataIter.next();
normalization.fit(set);
normalization.transform(set);
INDArray array = MainGUI.model.output(set.getFeatures(), false); //send the data to the model and get the results
//Process the results and print them in an understandable format (percentage scores)
String txt = "";
DecimalFormat df = new DecimalFormat("#.00");
for (int i = 0; i < array.length(); i++)
{
txt += MainGUI.labels.get(i) + ": " + (array.getDouble(i)*100 < 1 ? "0" : "") + df.format((array.getDouble(i)*100)) + "%\n";
}
probabilityArea.setText(txt);
}
reader.close();
}
示例2: createInternal
import org.datavec.image.recordreader.ImageRecordReader; //导入方法依赖的package包/类
private DataSetIterator createInternal(InputSplit inputSplit) throws IOException {
ImageTransform imageTransform = imageTransformFactory.create();
int width = imageTransformConfigurationResource.getScaledWidth();
int height = imageTransformConfigurationResource.getScaledHeight();
int channels = imageTransformConfigurationResource.getChannels();
int batchSize = networkConfigurationResource.getBatchSize();
int outputs = networkConfigurationResource.getOutputs();
ImageRecordReader recordReader = new ImageRecordReader(height, width, channels, pathLabelGenerator);
recordReader.initialize(inputSplit, imageTransform);
RecordReaderDataSetIterator recordReaderDataSetIterator = new RecordReaderDataSetIterator(recordReader, batchSize, 1, outputs);
DataNormalization scaler = new ImagePreProcessingScaler(0, 1);
scaler.fit(recordReaderDataSetIterator);
recordReaderDataSetIterator.setPreProcessor(scaler);
return recordReaderDataSetIterator;
}
示例3: getImageRecordReader
import org.datavec.image.recordreader.ImageRecordReader; //导入方法依赖的package包/类
@Override
protected ImageRecordReader getImageRecordReader(Instances data) throws Exception {
ArffMetaDataLabelGenerator labelGenerator =
new ArffMetaDataLabelGenerator(data, getImagesLocation().toString());
ResizeImageTransform rit = new ResizeImageTransform(width, height);
ImageRecordReader reader =
new ImageRecordReader(height, width, getNumChannels(), labelGenerator, rit);
CollectionInputSplit cis = new CollectionInputSplit(labelGenerator.getPathURIs());
reader.initialize(cis);
return reader;
}
示例4: getImageRecordReader
import org.datavec.image.recordreader.ImageRecordReader; //导入方法依赖的package包/类
/**
* Returns the image recorder.
*
* @param data the dataset to use
* @return the image recorder
* @throws Exception
*/
protected ImageRecordReader getImageRecordReader(Instances data) throws Exception {
ArffMetaDataLabelGenerator labelGenerator =
new ArffMetaDataLabelGenerator(data, getImagesLocation().toString());
ImageRecordReader reader =
new ImageRecordReader(getHeight(), getWidth(), getNumChannels(), labelGenerator);
CollectionInputSplit cis = new CollectionInputSplit(labelGenerator.getPathURIs());
reader.initialize(cis);
return reader;
}
示例5: testImagesRRDMSI
import org.datavec.image.recordreader.ImageRecordReader; //导入方法依赖的package包/类
@Test
public void testImagesRRDMSI() throws Exception {
File parentDir = Files.createTempDir();
parentDir.deleteOnExit();
String str1 = FilenameUtils.concat(parentDir.getAbsolutePath(), "Zico/");
String str2 = FilenameUtils.concat(parentDir.getAbsolutePath(), "Ziwang_Xu/");
File f1 = new File(str1);
File f2 = new File(str2);
f1.mkdirs();
f2.mkdirs();
writeStreamToFile(new File(FilenameUtils.concat(f1.getPath(), "Zico_0001.jpg")),
new ClassPathResource("lfwtest/Zico/Zico_0001.jpg").getInputStream());
writeStreamToFile(new File(FilenameUtils.concat(f2.getPath(), "Ziwang_Xu_0001.jpg")),
new ClassPathResource("lfwtest/Ziwang_Xu/Ziwang_Xu_0001.jpg").getInputStream());
int outputNum = 2;
Random r = new Random(12345);
ParentPathLabelGenerator labelMaker = new ParentPathLabelGenerator();
ImageRecordReader rr1 = new ImageRecordReader(10, 10, 1, labelMaker);
ImageRecordReader rr1s = new ImageRecordReader(5, 5, 1, labelMaker);
rr1.initialize(new FileSplit(parentDir));
rr1s.initialize(new FileSplit(parentDir));
MultiDataSetIterator trainDataIterator = new RecordReaderMultiDataSetIterator.Builder(1).addReader("rr1", rr1)
.addReader("rr1s", rr1s).addInput("rr1", 0, 0).addInput("rr1s", 0, 0)
.addOutputOneHot("rr1s", 1, outputNum).build();
//Now, do the same thing with ImageRecordReader, and check we get the same results:
ImageRecordReader rr1_b = new ImageRecordReader(10, 10, 1, labelMaker);
ImageRecordReader rr1s_b = new ImageRecordReader(5, 5, 1, labelMaker);
rr1_b.initialize(new FileSplit(parentDir));
rr1s_b.initialize(new FileSplit(parentDir));
DataSetIterator dsi1 = new RecordReaderDataSetIterator(rr1_b, 1, 1, 2);
DataSetIterator dsi2 = new RecordReaderDataSetIterator(rr1s_b, 1, 1, 2);
for (int i = 0; i < 2; i++) {
MultiDataSet mds = trainDataIterator.next();
DataSet d1 = dsi1.next();
DataSet d2 = dsi2.next();
assertEquals(d1.getFeatureMatrix(), mds.getFeatures(0));
assertEquals(d2.getFeatureMatrix(), mds.getFeatures(1));
assertEquals(d1.getLabels(), mds.getLabels(0));
}
}
示例6: testImagesRRDMSI_Batched
import org.datavec.image.recordreader.ImageRecordReader; //导入方法依赖的package包/类
@Test
public void testImagesRRDMSI_Batched() throws Exception {
File parentDir = Files.createTempDir();
parentDir.deleteOnExit();
String str1 = FilenameUtils.concat(parentDir.getAbsolutePath(), "Zico/");
String str2 = FilenameUtils.concat(parentDir.getAbsolutePath(), "Ziwang_Xu/");
File f1 = new File(str1);
File f2 = new File(str2);
f1.mkdirs();
f2.mkdirs();
writeStreamToFile(new File(FilenameUtils.concat(f1.getPath(), "Zico_0001.jpg")),
new ClassPathResource("lfwtest/Zico/Zico_0001.jpg").getInputStream());
writeStreamToFile(new File(FilenameUtils.concat(f2.getPath(), "Ziwang_Xu_0001.jpg")),
new ClassPathResource("lfwtest/Ziwang_Xu/Ziwang_Xu_0001.jpg").getInputStream());
int outputNum = 2;
ParentPathLabelGenerator labelMaker = new ParentPathLabelGenerator();
ImageRecordReader rr1 = new ImageRecordReader(10, 10, 1, labelMaker);
ImageRecordReader rr1s = new ImageRecordReader(5, 5, 1, labelMaker);
URI[] uris = new FileSplit(parentDir).locations();
rr1.initialize(new CollectionInputSplit(uris));
rr1s.initialize(new CollectionInputSplit(uris));
MultiDataSetIterator trainDataIterator = new RecordReaderMultiDataSetIterator.Builder(2).addReader("rr1", rr1)
.addReader("rr1s", rr1s).addInput("rr1", 0, 0).addInput("rr1s", 0, 0)
.addOutputOneHot("rr1s", 1, outputNum).build();
//Now, do the same thing with ImageRecordReader, and check we get the same results:
ImageRecordReader rr1_b = new ImageRecordReader(10, 10, 1, labelMaker);
ImageRecordReader rr1s_b = new ImageRecordReader(5, 5, 1, labelMaker);
rr1_b.initialize(new FileSplit(parentDir));
rr1s_b.initialize(new FileSplit(parentDir));
DataSetIterator dsi1 = new RecordReaderDataSetIterator(rr1_b, 2, 1, 2);
DataSetIterator dsi2 = new RecordReaderDataSetIterator(rr1s_b, 2, 1, 2);
MultiDataSet mds = trainDataIterator.next();
DataSet d1 = dsi1.next();
DataSet d2 = dsi2.next();
assertEquals(d1.getFeatureMatrix(), mds.getFeatures(0));
assertEquals(d2.getFeatureMatrix(), mds.getFeatures(1));
assertEquals(d1.getLabels(), mds.getLabels(0));
//Check label assignment:
File currentFile = rr1_b.getCurrentFile();
INDArray expLabels;
if(currentFile.getAbsolutePath().contains("Zico")){
expLabels = Nd4j.create(new double[][] {{0, 1}, {1, 0}});
} else {
expLabels = Nd4j.create(new double[][] {{1, 0}, {0, 1}});
}
assertEquals(expLabels, d1.getLabels());
assertEquals(expLabels, d2.getLabels());
}