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);
}
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);
}
}
Aggregations