Skip to content

Commit

Permalink
#6101 DataVec ObjectDetectionRecordReader image center validation
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDBlack committed Aug 29, 2018
1 parent 78e45ad commit ebc4e41
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Expand Up @@ -16,7 +16,6 @@

package org.datavec.image.recordreader.objdetect;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.datavec.image.loader.NativeImageLoader;
import org.datavec.image.recordreader.BaseImageRecordReader;
import org.datavec.image.util.ImageUtils;
import org.nd4j.base.Preconditions;
import org.nd4j.linalg.api.concurrency.AffinityManager;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;
Expand Down Expand Up @@ -230,6 +231,13 @@ private void label(Image image, List<ImageObject> objectsThisImg, INDArray outLa
brPost[1] = brPost[1] / height * gridH;

//Put TL, BR into label array:
Preconditions.checkState(imgGridY >= 0 && imgGridY < outLabel.size(2), "Invalid image center in Y axis: "
+ "calculated grid location of %s, must be between 0 (inclusive) and %s (exclusive). Object label center is outside "
+ "of image bounds. Image object: %s", imgGridY, outLabel.size(2), io);
Preconditions.checkState(imgGridX >= 0 && imgGridX < outLabel.size(3), "Invalid image center in X axis: "
+ "calculated grid location of %s, must be between 0 (inclusive) and %s (exclusive). Object label center is outside "
+ "of image bounds. Image object: %s", imgGridY, outLabel.size(2), io);

outLabel.putScalar(exampleNum, 0, imgGridY, imgGridX, tlPost[0]);
outLabel.putScalar(exampleNum, 1, imgGridY, imgGridX, tlPost[1]);
outLabel.putScalar(exampleNum, 2, imgGridY, imgGridX, brPost[0]);
Expand Down

0 comments on commit ebc4e41

Please sign in to comment.