Search in sources :

Example 1 with RecordMetaDataComposable

use of org.datavec.api.records.metadata.RecordMetaDataComposable in project deeplearning4j by deeplearning4j.

the class SequenceRecordReaderDataSetIterator method nextMultipleSequenceReaders.

private DataSet nextMultipleSequenceReaders(int num) {
    List<INDArray> featureList = new ArrayList<>(num);
    List<INDArray> labelList = new ArrayList<>(num);
    List<RecordMetaData> meta = (collectMetaData ? new ArrayList<RecordMetaData>() : null);
    for (int i = 0; i < num && hasNext(); i++) {
        List<List<Writable>> featureSequence;
        List<List<Writable>> labelSequence;
        if (collectMetaData) {
            SequenceRecord f = recordReader.nextSequence();
            SequenceRecord l = labelsReader.nextSequence();
            featureSequence = f.getSequenceRecord();
            labelSequence = l.getSequenceRecord();
            meta.add(new RecordMetaDataComposable(f.getMetaData(), l.getMetaData()));
        } else {
            featureSequence = recordReader.sequenceRecord();
            labelSequence = labelsReader.sequenceRecord();
        }
        assertNonZeroLengthSequence(featureSequence, "features");
        assertNonZeroLengthSequence(labelSequence, "labels");
        INDArray features = getFeatures(featureSequence);
        //2d time series, with shape [timeSeriesLength,vectorSize]
        INDArray labels = getLabels(labelSequence);
        featureList.add(features);
        labelList.add(labels);
    }
    return nextMultipleSequenceReaders(featureList, labelList, meta);
}
Also used : RecordMetaData(org.datavec.api.records.metadata.RecordMetaData) RecordMetaDataComposable(org.datavec.api.records.metadata.RecordMetaDataComposable) SequenceRecord(org.datavec.api.records.SequenceRecord) INDArray(org.nd4j.linalg.api.ndarray.INDArray)

Example 2 with RecordMetaDataComposable

use of org.datavec.api.records.metadata.RecordMetaDataComposable in project deeplearning4j by deeplearning4j.

the class SequenceRecordReaderDataSetIterator method loadFromMetaData.

/**
     * Load a multiple sequence examples to a DataSet, using the provided RecordMetaData instances.
     *
     * @param list List of RecordMetaData instances to load from. Should have been produced by the record reader provided
     *             to the SequenceRecordReaderDataSetIterator constructor
     * @return DataSet with the specified examples
     * @throws IOException If an error occurs during loading of the data
     */
public DataSet loadFromMetaData(List<RecordMetaData> list) throws IOException {
    //Two cases: single vs. multiple reader...
    if (singleSequenceReaderMode) {
        List<SequenceRecord> records = recordReader.loadSequenceFromMetaData(list);
        List<INDArray> listFeatures = new ArrayList<>(list.size());
        List<INDArray> listLabels = new ArrayList<>(list.size());
        int minLength = Integer.MAX_VALUE;
        int maxLength = Integer.MIN_VALUE;
        for (SequenceRecord sr : records) {
            INDArray[] fl = getFeaturesLabelsSingleReader(sr.getSequenceRecord());
            listFeatures.add(fl[0]);
            listLabels.add(fl[1]);
            minLength = Math.min(minLength, fl[0].size(0));
            maxLength = Math.max(maxLength, fl[1].size(0));
        }
        return getSingleSequenceReader(listFeatures, listLabels, minLength, maxLength, list);
    } else {
        //Expect to get a RecordReaderMetaComposable here
        List<RecordMetaData> fMeta = new ArrayList<>();
        List<RecordMetaData> lMeta = new ArrayList<>();
        for (RecordMetaData m : list) {
            RecordMetaDataComposable m2 = (RecordMetaDataComposable) m;
            fMeta.add(m2.getMeta()[0]);
            lMeta.add(m2.getMeta()[1]);
        }
        List<SequenceRecord> f = recordReader.loadSequenceFromMetaData(fMeta);
        List<SequenceRecord> l = labelsReader.loadSequenceFromMetaData(lMeta);
        List<INDArray> featureList = new ArrayList<>(fMeta.size());
        List<INDArray> labelList = new ArrayList<>(fMeta.size());
        for (int i = 0; i < fMeta.size(); i++) {
            featureList.add(getFeatures(f.get(i).getSequenceRecord()));
            labelList.add(getLabels(l.get(i).getSequenceRecord()));
        }
        return nextMultipleSequenceReaders(featureList, labelList, list);
    }
}
Also used : RecordMetaData(org.datavec.api.records.metadata.RecordMetaData) RecordMetaDataComposable(org.datavec.api.records.metadata.RecordMetaDataComposable) SequenceRecord(org.datavec.api.records.SequenceRecord) INDArray(org.nd4j.linalg.api.ndarray.INDArray)

Aggregations

SequenceRecord (org.datavec.api.records.SequenceRecord)2 RecordMetaData (org.datavec.api.records.metadata.RecordMetaData)2 RecordMetaDataComposable (org.datavec.api.records.metadata.RecordMetaDataComposable)2 INDArray (org.nd4j.linalg.api.ndarray.INDArray)2