• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ParentPathLabelGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.datavec.api.io.labels.ParentPathLabelGenerator的典型用法代码示例。如果您正苦于以下问题:Java ParentPathLabelGenerator类的具体用法?Java ParentPathLabelGenerator怎么用?Java ParentPathLabelGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ParentPathLabelGenerator类属于org.datavec.api.io.labels包,在下文中一共展示了ParentPathLabelGenerator类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: configure

import org.datavec.api.io.labels.ParentPathLabelGenerator; //导入依赖的package包/类
@Override
protected void configure() {
    bind(PathLabelGenerator.class).toInstance(new ParentPathLabelGenerator());
    bind(Random.class).toProvider(RandomProvider.class);
    bind(DataSetIteratorFactory.class).to(DataSetIteratorFactoryImpl.class);
    bind(InputSplitService.class).to(InputSplitServiceImpl.class);
    bind(ImageTransformFactory.class).to(ImageTransformFactoryImpl.class);
    bind(MultiLayerConfigurationFactory.class).to(MultiLayerConfigurationFactoryImpl.class);
    bind(MachineLearningService.class).to(MachineLearningServiceImpl.class);
    bind(MultiLayerNetworkFactory.class).to(MultiLayerNetworkFactoryImpl.class);
    bind(MultiLayerNetworkSaver.class).to(MultiLayerNetworkSaverImpl.class);
}
 
开发者ID:scaliby,项目名称:ceidg-captcha,代码行数:13,代码来源:CEIDGCaptchaMachineLearningModule.java


示例2: testMetaData

import org.datavec.api.io.labels.ParentPathLabelGenerator; //导入依赖的package包/类
@Test
public void testMetaData() throws IOException {

    ClassPathResource cpr = new ClassPathResource("/testimages/class0/0.jpg");
    File parentDir = cpr.getFile().getParentFile().getParentFile();
    //        System.out.println(f.getAbsolutePath());
    //        System.out.println(f.getParentFile().getParentFile().getAbsolutePath());
    ParentPathLabelGenerator labelMaker = new ParentPathLabelGenerator();
    ImageRecordReader rr = new ImageRecordReader(32, 32, 3, labelMaker);
    rr.initialize(new FileSplit(parentDir));

    List<List<Writable>> out = new ArrayList<>();
    while (rr.hasNext()) {
        List<Writable> l = rr.next();
        out.add(l);
        assertEquals(2, l.size());
    }

    assertEquals(6, out.size());

    rr.reset();
    List<List<Writable>> out2 = new ArrayList<>();
    List<Record> out3 = new ArrayList<>();
    List<RecordMetaData> meta = new ArrayList<>();

    while (rr.hasNext()) {
        Record r = rr.nextRecord();
        out2.add(r.getRecord());
        out3.add(r);
        meta.add(r.getMetaData());
        //            System.out.println(r.getMetaData() + "\t" + r.getRecord().get(1));
    }

    assertEquals(out, out2);

    List<Record> fromMeta = rr.loadFromMetaData(meta);
    assertEquals(out3, fromMeta);
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:39,代码来源:TestImageRecordReader.java


示例3: testImageRecordReaderLabelsOrder

import org.datavec.api.io.labels.ParentPathLabelGenerator; //导入依赖的package包/类
@Test
public void testImageRecordReaderLabelsOrder() throws Exception {
    //Labels order should be consistent, regardless of file iteration order

    //Idea: labels order should be consistent regardless of input file order
    File f0 = new ClassPathResource("/testimages/class0/0.jpg").getFile();
    File f1 = new ClassPathResource("/testimages/class1/A.jpg").getFile();

    List<URI> order0 = Arrays.asList(f0.toURI(), f1.toURI());
    List<URI> order1 = Arrays.asList(f1.toURI(), f0.toURI());

    ParentPathLabelGenerator labelMaker0 = new ParentPathLabelGenerator();
    ImageRecordReader rr0 = new ImageRecordReader(32, 32, 3, labelMaker0);
    rr0.initialize(new CollectionInputSplit(order0));

    ParentPathLabelGenerator labelMaker1 = new ParentPathLabelGenerator();
    ImageRecordReader rr1 = new ImageRecordReader(32, 32, 3, labelMaker1);
    rr1.initialize(new CollectionInputSplit(order1));

    List<String> labels0 = rr0.getLabels();
    List<String> labels1 = rr1.getLabels();

    //        System.out.println(labels0);
    //        System.out.println(labels1);

    assertEquals(labels0, labels1);
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:28,代码来源:TestImageRecordReader.java


示例4: testImageRecordReaderRandomization

import org.datavec.api.io.labels.ParentPathLabelGenerator; //导入依赖的package包/类
@Test
public void testImageRecordReaderRandomization() throws Exception {
    //Order of FileSplit+ImageRecordReader should be different after reset

    //Idea: labels order should be consistent regardless of input file order
    File f0 = new ClassPathResource("/testimages/").getFile();

    FileSplit fs = new FileSplit(f0, new Random(12345));

    ParentPathLabelGenerator labelMaker = new ParentPathLabelGenerator();
    ImageRecordReader rr = new ImageRecordReader(32, 32, 3, labelMaker);
    rr.initialize(fs);

    List<List<Writable>> out1 = new ArrayList<>();
    List<File> order1 = new ArrayList<>();
    while (rr.hasNext()) {
        out1.add(rr.next());
        order1.add(rr.getCurrentFile());
    }
    assertEquals(6, out1.size());
    assertEquals(6, order1.size());

    rr.reset();
    List<List<Writable>> out2 = new ArrayList<>();
    List<File> order2 = new ArrayList<>();
    while (rr.hasNext()) {
        out2.add(rr.next());
        order2.add(rr.getCurrentFile());
    }
    assertEquals(6, out2.size());
    assertEquals(6, order2.size());

    assertNotEquals(out1, out2);
    assertNotEquals(order1, order2);

    //Check that different seed gives different order for the initial iteration
    FileSplit fs2 = new FileSplit(f0, new Random(999999999));

    ParentPathLabelGenerator labelMaker2 = new ParentPathLabelGenerator();
    ImageRecordReader rr2 = new ImageRecordReader(32, 32, 3, labelMaker2);
    rr2.initialize(fs2);

    List<File> order3 = new ArrayList<>();
    while (rr2.hasNext()) {
        rr2.next();
        order3.add(rr2.getCurrentFile());
    }
    assertEquals(6, order3.size());

    assertNotEquals(order1, order3);
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:52,代码来源:TestImageRecordReader.java


示例5: testSample

import org.datavec.api.io.labels.ParentPathLabelGenerator; //导入依赖的package包/类
@Test
public void testSample() throws URISyntaxException {
    BaseInputSplit split = new BaseInputSplit() {
        {
            String[] paths = {"label0/group1_img.tif", "label1/group1_img.jpg", "label2/group1_img.png",
                            "label3/group1_img.jpeg", "label4/group1_img.bmp", "label5/group1_img.JPEG",
                            "label0/group2_img.JPG", "label1/group2_img.TIF", "label2/group2_img.PNG",
                            "label3/group2_img.jpg", "label4/group2_img.jpg", "label5/group2_img.wtf"};

            uriStrings = new ArrayList<>(paths.length);
            for (String s : paths) {
                uriStrings.add("file:///" + s);
            }
        }

        @Override
        public void reset() {
            //No op
        }

        @Override
        public boolean resetSupported() {
            return true;
        }

        @Override
        public void write(DataOutput out) throws IOException {}

        @Override
        public void readFields(DataInput in) throws IOException {}
    };

    Random random = new Random(42);
    String[] extensions = {"tif", "jpg", "png", "jpeg", "bmp", "JPEG", "JPG", "TIF", "PNG"};
    ParentPathLabelGenerator parentPathLabelGenerator = new ParentPathLabelGenerator();
    PatternPathLabelGenerator patternPathLabelGenerator = new PatternPathLabelGenerator("_", 0);
    RandomPathFilter randomPathFilter = new RandomPathFilter(random, extensions);
    RandomPathFilter randomPathFilter2 = new RandomPathFilter(random, extensions, 7);
    BalancedPathFilter balancedPathFilter =
                    new BalancedPathFilter(random, extensions, parentPathLabelGenerator, 0, 4, 0, 1);
    BalancedPathFilter balancedPathFilter2 =
                    new BalancedPathFilter(random, extensions, patternPathLabelGenerator, 0, 4, 0, 1);

    InputSplit[] samples = split.sample(randomPathFilter);
    assertEquals(1, samples.length);
    assertEquals(11, samples[0].length());

    InputSplit[] samples2 = split.sample(randomPathFilter2);
    assertEquals(1, samples2.length);
    assertEquals(7, samples2[0].length());

    InputSplit[] samples3 = split.sample(balancedPathFilter, 80, 20);
    assertEquals(2, samples3.length);
    assertEquals(3, samples3[0].length());
    assertEquals(1, samples3[1].length());

    InputSplit[] samples4 = split.sample(balancedPathFilter2, 50, 50);
    assertEquals(2, samples4.length);
    assertEquals(1, samples4[0].length());
    assertEquals(1, samples4[1].length());
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:62,代码来源:InputSplitTests.java


示例6: LFWDataSetIterator

import org.datavec.api.io.labels.ParentPathLabelGenerator; //导入依赖的package包/类
/** Loads subset of images with given imgDim returned by the generator. */
public LFWDataSetIterator(int[] imgDim) {
    this(LFWLoader.SUB_NUM_IMAGES, LFWLoader.SUB_NUM_IMAGES, imgDim, LFWLoader.SUB_NUM_LABELS, false,
                    new ParentPathLabelGenerator(), true, 1, null, new Random(System.currentTimeMillis()));
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:6,代码来源:LFWDataSetIterator.java


示例7: testImagesRRDMSI

import org.datavec.api.io.labels.ParentPathLabelGenerator; //导入依赖的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));
    }
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:54,代码来源:RecordReaderMultiDataSetIteratorTest.java


示例8: testImagesRRDMSI_Batched

import org.datavec.api.io.labels.ParentPathLabelGenerator; //导入依赖的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());
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:64,代码来源:RecordReaderMultiDataSetIteratorTest.java



注:本文中的org.datavec.api.io.labels.ParentPathLabelGenerator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ConsoleColorProvider类代码示例发布时间:2022-05-22
下一篇:
Java SmartThriftClient类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap