From 22993f853fca8e6189e6d489e5eb775dc6e3b6cb Mon Sep 17 00:00:00 2001 From: jxtps Date: Wed, 24 Jul 2019 21:51:57 -0700 Subject: [PATCH] Disallow creating bad classification iterator (#8042) When doing classification we need to know the `numPossibleLabels`. If it's set to -1, then we get obscure and confusing null-pointers when accessing labels when calling `ComputationGraph.fit` on the iterator. This PR blocks the user from shooting themselves in the foot. --- .../datasets/datavec/RecordReaderDataSetIterator.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/deeplearning4j/deeplearning4j-data/deeplearning4j-datavec-iterators/src/main/java/org/deeplearning4j/datasets/datavec/RecordReaderDataSetIterator.java b/deeplearning4j/deeplearning4j-data/deeplearning4j-datavec-iterators/src/main/java/org/deeplearning4j/datasets/datavec/RecordReaderDataSetIterator.java index 361dd1dd1..53cdc82e7 100644 --- a/deeplearning4j/deeplearning4j-data/deeplearning4j-datavec-iterators/src/main/java/org/deeplearning4j/datasets/datavec/RecordReaderDataSetIterator.java +++ b/deeplearning4j/deeplearning4j-data/deeplearning4j-datavec-iterators/src/main/java/org/deeplearning4j/datasets/datavec/RecordReaderDataSetIterator.java @@ -160,6 +160,11 @@ public class RecordReaderDataSetIterator implements DataSetIterator { */ public RecordReaderDataSetIterator(RecordReader recordReader, int batchSize, int labelIndexFrom, int labelIndexTo, boolean regression) { + if (!regression) { + throw new IllegalArgumentException("This constructor is only for creating regression iterators. " + + "If you're doing classification you need to use another constructor that " + + "(implicitly) specifies numPossibleLabels"); + } this(recordReader, new SelfWritableConverter(), batchSize, labelIndexFrom, labelIndexTo, -1, -1, regression); }