Java Code Examples for org.datavec.api.util.ndarray.RecordConverter#toRecord()

The following examples show how to use org.datavec.api.util.ndarray.RecordConverter#toRecord() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideoRecordReader.java    From DataVec with Apache License 2.0 6 votes vote down vote up
@Override
public List<List<Writable>> sequenceRecord() {
    File next = iter.next();
    invokeListeners(next);
    if (!next.isDirectory())
        return Collections.emptyList();
    File[] list = next.listFiles();
    List<List<Writable>> ret = new ArrayList<>();
    for (File f : list) {
        try {
            List<Writable> record = RecordConverter.toRecord(imageLoader.asRowVector(f));
            ret.add(record);
            if (appendLabel)
                record.add(new DoubleWritable(labels.indexOf(next.getName())));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
    return ret;
}
 
Example 2
Source File: SpecialImageRecordReader.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Override
public List<List<Writable>> next(int num) {
    int numExamples = Math.min(num, limit - counter.get());
    //counter.addAndGet(numExamples);

    INDArray features = zFeatures;
    for (int i = 0; i < numExamples; i++) {
        fillNDArray(features.tensorAlongDimension(i, 1, 2, 3), counter.getAndIncrement());
    }

    INDArray labels = Nd4j.create(numExamples, numClasses);
    for (int i = 0; i < numExamples; i++) {
        labels.getRow(i).assign(labelsCounter.getAndIncrement());
    }

    List<Writable> ret = RecordConverter.toRecord(features);
    ret.add(new NDArrayWritable(labels));

    return Collections.singletonList(ret);
}
 
Example 3
Source File: RecordConverterTest.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testToRecordWithListOfObject(){
    final List<Object> list = Arrays.asList((Object)3, 7.0f, "Foo", "Bar", 1.0, 3f, 3L, 7, 0L);
    final Schema schema = new Schema.Builder()
            .addColumnInteger("a")
            .addColumnFloat("b")
            .addColumnString("c")
            .addColumnCategorical("d", "Bar", "Baz")
            .addColumnDouble("e")
            .addColumnFloat("f")
            .addColumnLong("g")
            .addColumnInteger("h")
            .addColumnTime("i", TimeZone.getDefault())
            .build();

    final List<Writable> record = RecordConverter.toRecord(schema, list);

    assertEquals(record.get(0).toInt(), 3);
    assertEquals(record.get(1).toFloat(), 7f, 1e-6);
    assertEquals(record.get(2).toString(), "Foo");
    assertEquals(record.get(3).toString(), "Bar");
    assertEquals(record.get(4).toDouble(), 1.0, 1e-6);
    assertEquals(record.get(5).toFloat(), 3f, 1e-6);
    assertEquals(record.get(6).toLong(), 3L);
    assertEquals(record.get(7).toInt(), 7);
    assertEquals(record.get(8).toLong(), 0);


}
 
Example 4
Source File: RecordReaderMultiDataSetIteratorTest.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public List<Writable> next() {
    INDArray nd = Nd4j.create(new float[nZ*nY*nX], new int[] {1, 1, nZ, nY, nX }, 'c').assign(n);
    final List<Writable>res = RecordConverter.toRecord(nd);
    res.add(new IntWritable(0));
    n++;
    return res;
}
 
Example 5
Source File: SpecialImageRecordReader.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public List<Writable> next() {
    INDArray features = Nd4j.create(channels, height, width);
    fillNDArray(features, counter.getAndIncrement());
    features = features.reshape(1, channels, height, width);
    List<Writable> ret = RecordConverter.toRecord(features);
    ret.add(new IntWritable(RandomUtils.nextInt(0, numClasses)));
    return ret;
}