org.datavec.api.records.writer.RecordWriter Java Examples

The following examples show how to use org.datavec.api.records.writer.RecordWriter. 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: RecordReaderConverter.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * Write all values from the specified record reader to the specified record writer.
 * Optionally, close the record writer on completion
 *
 * @param reader Record reader (source of data)
 * @param writer Record writer (location to write data)
 * @param closeOnCompletion if true: close the record writer once complete, via {@link RecordWriter#close()}
 * @throws IOException If underlying reader/writer throws an exception
 */
public static void convert(RecordReader reader, RecordWriter writer, boolean closeOnCompletion) throws IOException {

    if(!reader.hasNext()){
        throw new UnsupportedOperationException("Cannot convert RecordReader: reader has no next element");
    }

    while(reader.hasNext()){
        writer.write(reader.next());
    }

    if(closeOnCompletion){
        writer.close();
    }
}
 
Example #2
Source File: SVMLightOutputFormat.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public RecordWriter createWriter(Configuration conf) throws DataVecException {
    String outputPath = conf.get(OutputFormat.OUTPUT_PATH, ".");
    try {
        //return new LineRecordWriter(new File(outputPath));
        return new SVMLightRecordWriter();
    } catch (Exception e) {
        throw new DataVecException(e);
    }
}
 
Example #3
Source File: SVMLightOutputFormat.java    From DataVec with Apache License 2.0 5 votes vote down vote up
@Override
public RecordWriter createWriter(Configuration conf) throws DataVecException {
    String outputPath = conf.get(OutputFormat.OUTPUT_PATH, ".");
    try {
        //return new LineRecordWriter(new File(outputPath));
        return new SVMLightRecordWriter();
    } catch (Exception e) {
        throw new DataVecException(e);
    }
}
 
Example #4
Source File: RecordReaderConverter.java    From DataVec with Apache License 2.0 5 votes vote down vote up
/**
 * Write all values from the specified record reader to the specified record writer.
 * Optionally, close the record writer on completion
 *
 * @param reader Record reader (source of data)
 * @param writer Record writer (location to write data)
 * @param closeOnCompletion if true: close the record writer once complete, via {@link RecordWriter#close()}
 * @throws IOException If underlying reader/writer throws an exception
 */
public static void convert(RecordReader reader, RecordWriter writer, boolean closeOnCompletion) throws IOException {

    if(!reader.hasNext()){
        throw new UnsupportedOperationException("Cannot convert RecordReader: reader has no next element");
    }

    while(reader.hasNext()){
        writer.write(reader.next());
    }

    if(closeOnCompletion){
        writer.close();
    }
}
 
Example #5
Source File: LogRecordListener.java    From DataVec with Apache License 2.0 4 votes vote down vote up
@Override
public void recordWrite(RecordWriter writer, Object record) {
    invoke();
    log.info("Writing " + record);
}
 
Example #6
Source File: LogRecordListener.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public void recordWrite(RecordWriter writer, Object record) {
    invoke();
    log.info("Writing " + record);
}
 
Example #7
Source File: CSVOutputFormat.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public RecordWriter createWriter(Configuration conf) throws DataVecException {
    String outputPath = conf.get(OutputFormat.OUTPUT_PATH, ".");
    return new CSVRecordWriter();
}
 
Example #8
Source File: LineOutputFormat.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public RecordWriter createWriter(Configuration conf) throws DataVecException {
    String outputPath = conf.get(OutputFormat.OUTPUT_PATH, ".");
    return new LineRecordWriter();
}
 
Example #9
Source File: LibSvmOutputFormat.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public RecordWriter createWriter(Configuration conf) throws DataVecException {
    RecordWriter writer = new LibSvmRecordWriter();
    writer.setConf(conf);
    return writer;
}
 
Example #10
Source File: WaveOutputFormat.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public RecordWriter createWriter(Configuration conf) throws DataVecException {
    return null;
}
 
Example #11
Source File: TestImageRecordReader.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public void recordWrite(RecordWriter writer, Object record) {
    this.listener.recordWrite(writer, record);
    this.count++;
}
 
Example #12
Source File: LocalExecuteExample.java    From Java-Deep-Learning-Cookbook with MIT License 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    try {
        int numClasses = 2;
        int batchSize = 8;

        File file = new File("Path/to/titanic.csv-file");
        RecordReader recordReader = new CSVRecordReader(1,',');
        recordReader.initialize(new FileSplit(file));
        // WritableConverter writableConverter = new SelfWritableConverter();

        Schema schema = new Schema.Builder()
                .addColumnInteger("Survived")
                .addColumnCategorical("Pclass", Arrays.asList("1","2","3"))
                .addColumnString("Name")
                .addColumnCategorical("Sex", Arrays.asList("male","female"))
                .addColumnsInteger("Age","Siblings/Spouses Aboard","Parents/Children Aboard")
                .addColumnDouble("Fare")
                .build();
        TransformProcess transformProcess = new TransformProcess.Builder(schema)
                .removeColumns("Name","Fare")
                .categoricalToInteger("Sex")
                .categoricalToOneHot("Pclass")
                .removeColumns("Pclass[1]")
                .build();

        List<List<Writable>> outputData = new ArrayList<>();

        RecordWriter recordWriter = new CSVRecordWriter();
        Partitioner partitioner = new NumberOfRecordsPartitioner();
        recordWriter.initialize(new FileSplit(new File("/Path/To/LocalExecuteExample.csv/file")),partitioner);

        while(recordReader.hasNext()){
            outputData.add(recordReader.next());
        }
        List<List<Writable>> transformedOutput=LocalTransformExecutor.execute(outputData,transformProcess);
        recordWriter.writeBatch(transformedOutput);
        recordWriter.close();
    } catch (IllegalArgumentException e) {
        System.out.println("Please provide proper file paths for titanic.csv & fle in place of: Path/to/titanic.csv-file && /Path/To/LocalExecuteExample.csv");
        System.out.println("You need to create an empty CSV file and mention the file path in place of /Path/To/LocalExecuteExample.csv");
    }
}
 
Example #13
Source File: CSVOutputFormat.java    From DataVec with Apache License 2.0 4 votes vote down vote up
@Override
public RecordWriter createWriter(Configuration conf) throws DataVecException {
    String outputPath = conf.get(OutputFormat.OUTPUT_PATH, ".");
    return new CSVRecordWriter();
}
 
Example #14
Source File: LineOutputFormat.java    From DataVec with Apache License 2.0 4 votes vote down vote up
@Override
public RecordWriter createWriter(Configuration conf) throws DataVecException {
    String outputPath = conf.get(OutputFormat.OUTPUT_PATH, ".");
    return new LineRecordWriter();
}
 
Example #15
Source File: LibSvmOutputFormat.java    From DataVec with Apache License 2.0 4 votes vote down vote up
@Override
public RecordWriter createWriter(Configuration conf) throws DataVecException {
    RecordWriter writer = new LibSvmRecordWriter();
    writer.setConf(conf);
    return writer;
}
 
Example #16
Source File: WaveOutputFormat.java    From DataVec with Apache License 2.0 4 votes vote down vote up
@Override
public RecordWriter createWriter(Configuration conf) throws DataVecException {
    return null;
}
 
Example #17
Source File: TestImageRecordReader.java    From DataVec with Apache License 2.0 4 votes vote down vote up
@Override
public void recordWrite(RecordWriter writer, Object record) {
    this.listener.recordWrite(writer, record);
    this.count++;
}
 
Example #18
Source File: LocalExecuteExample.java    From Java-Deep-Learning-Cookbook with MIT License 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    try {
        int numClasses = 2;
        int batchSize = 8;

        File file = new File("Path/to/titanic.csv-file");
        RecordReader recordReader = new CSVRecordReader(1,',');
        recordReader.initialize(new FileSplit(file));
        // WritableConverter writableConverter = new SelfWritableConverter();

        Schema schema = new Schema.Builder()
                .addColumnInteger("Survived")
                .addColumnCategorical("Pclass", Arrays.asList("1","2","3"))
                .addColumnString("Name")
                .addColumnCategorical("Sex", Arrays.asList("male","female"))
                .addColumnsInteger("Age","Siblings/Spouses Aboard","Parents/Children Aboard")
                .addColumnDouble("Fare")
                .build();
        TransformProcess transformProcess = new TransformProcess.Builder(schema)
                .removeColumns("Name","Fare")
                .categoricalToInteger("Sex")
                .categoricalToOneHot("Pclass")
                .removeColumns("Pclass[1]")
                .build();

        List<List<Writable>> outputData = new ArrayList<>();

        RecordWriter recordWriter = new CSVRecordWriter();
        Partitioner partitioner = new NumberOfRecordsPartitioner();
        recordWriter.initialize(new FileSplit(new File("/Path/To/LocalExecuteExample.csv/file")),partitioner);

        while(recordReader.hasNext()){
            outputData.add(recordReader.next());
        }
        List<List<Writable>> transformedOutput=LocalTransformExecutor.execute(outputData,transformProcess);
        recordWriter.writeBatch(transformedOutput);
        recordWriter.close();
    } catch (IllegalArgumentException e) {
        System.out.println("Please provide proper file paths for titanic.csv & fle in place of: Path/to/titanic.csv-file && /Path/To/LocalExecuteExample.csv");
        System.out.println("You need to create an empty CSV file and mention the file path in place of /Path/To/LocalExecuteExample.csv");
    }
}
 
Example #19
Source File: RecordListener.java    From DataVec with Apache License 2.0 2 votes vote down vote up
/**
 * Event listener for each record to be written.
 * @param writer the record writer
 * @param record in raw format (Collection, File, String, Writable, etc)
 */
void recordWrite(RecordWriter writer, Object record);
 
Example #20
Source File: RecordReaderConverter.java    From DataVec with Apache License 2.0 2 votes vote down vote up
/**
 * Write all values from the specified record reader to the specified record writer.
 * Closes the record writer on completion
 *
 * @param reader Record reader (source of data)
 * @param writer Record writer (location to write data)
 * @throws IOException If underlying reader/writer throws an exception
 */
public static void convert(RecordReader reader, RecordWriter writer) throws IOException {
    convert(reader, writer, true);
}
 
Example #21
Source File: OutputFormat.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * Create a record writer
 * @return the created writer
 */
RecordWriter createWriter(Configuration conf) throws DataVecException;
 
Example #22
Source File: OutputFormat.java    From DataVec with Apache License 2.0 2 votes vote down vote up
/**
 * Create a record writer
 * @return the created writer
 */
RecordWriter createWriter(Configuration conf) throws DataVecException;
 
Example #23
Source File: RecordReaderConverter.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * Write all values from the specified record reader to the specified record writer.
 * Closes the record writer on completion
 *
 * @param reader Record reader (source of data)
 * @param writer Record writer (location to write data)
 * @throws IOException If underlying reader/writer throws an exception
 */
public static void convert(RecordReader reader, RecordWriter writer) throws IOException {
    convert(reader, writer, true);
}
 
Example #24
Source File: RecordListener.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * Event listener for each record to be written.
 * @param writer the record writer
 * @param record in raw format (Collection, File, String, Writable, etc)
 */
void recordWrite(RecordWriter writer, Object record);
 
Example #25
Source File: RecordWriterFactory.java    From deeplearning4j with Apache License 2.0 votes vote down vote up
/**
 *
 * @param uri destination for saving model
 * @return record writer instance
 * @throws Exception
 */

RecordWriter create(URI uri) throws Exception;
 
Example #26
Source File: RecordWriterFactory.java    From DataVec with Apache License 2.0 votes vote down vote up
/**
 *
 * @param uri destination for saving model
 * @return record writer instance
 * @throws Exception
 */

RecordWriter create(URI uri) throws Exception;