org.datavec.image.transform.ImageTransform Java Examples

The following examples show how to use org.datavec.image.transform.ImageTransform. 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: SvhnDataFetcher.java    From deeplearning4j with Apache License 2.0 7 votes vote down vote up
@Override
public RecordReader getRecordReader(long rngSeed, int[] imgDim, DataSetType set, ImageTransform imageTransform) {
    try {
        Random rng = new Random(rngSeed);
        File datasetPath = getDataSetPath(set);

        FileSplit data = new FileSplit(datasetPath, BaseImageLoader.ALLOWED_FORMATS, rng);
        ObjectDetectionRecordReader recordReader = new ObjectDetectionRecordReader(imgDim[1], imgDim[0], imgDim[2],
                        imgDim[4], imgDim[3], null);

        recordReader.initialize(data);
        return recordReader;
    } catch (IOException e) {
        throw new RuntimeException("Could not download SVHN", e);
    }
}
 
Example #2
Source File: BaseImageInputAdapter.java    From konduit-serving with Apache License 2.0 6 votes vote down vote up
/**
 * Get the image loader
 * configuring it using the
 * {@link ConverterArgs}
 *
 * @param input         the input to convert
 * @param converterArgs the converter args to use
 * @return the configured {@link NativeImageLoader}
 */
public NativeImageLoader getImageLoader(T input, ConverterArgs converterArgs) {
    if (converterArgs == null || converterArgs.getLongs().isEmpty())
        return new NativeImageLoader();
    else if (converterArgs.getLongs().size() == 3) {
        if (converterArgs.getImageTransformProcess() != null) {
            return new NativeImageLoader(converterArgs.getLongs().get(0), converterArgs.getLongs().get(1), converterArgs.getLongs().get(2), new MultiImageTransform(converterArgs.getImageTransformProcess().getTransformList().toArray(new ImageTransform[1])));

        } else if (converterArgs.getImageTransformProcess() != null)
            return new NativeImageLoader(converterArgs.getLongs().get(0), converterArgs.getLongs().get(1), converterArgs.getLongs().get(2), new MultiImageTransform(converterArgs.getImageTransformProcess().getTransformList().toArray(new ImageTransform[1])));
        else {
            return new NativeImageLoader(converterArgs.getLongs().get(0), converterArgs.getLongs().get(1), converterArgs.getLongs().get(2));

        }
    } else if (converterArgs.getLongs().size() == 3) {
        if (converterArgs.getImageTransformProcess() != null) {
            return new NativeImageLoader(converterArgs.getLongs().get(0).intValue(), converterArgs.getLongs().get(1).intValue()
                    , converterArgs.getLongs().get(2).intValue(), new MultiImageTransform(converterArgs.getImageTransformProcess().getTransformList().toArray(new ImageTransform[1])));
        } else
            return new NativeImageLoader(converterArgs.getLongs().get(0).intValue(), converterArgs.getLongs().get(1).intValue()
                    , converterArgs.getLongs().get(2).intValue());
    }


    return new NativeImageLoader();
}
 
Example #3
Source File: CifarLoader.java    From DataVec with Apache License 2.0 6 votes vote down vote up
/**
 * Preprocess and store cifar based on successful Torch approach by Sergey Zagoruyko
 * Reference: https://github.com/szagoruyko/cifar.torch
 */
public opencv_core.Mat convertCifar(Mat orgImage) {
    numExamples++;
    Mat resImage = new Mat();
    OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat();
    //        ImageTransform yuvTransform = new ColorConversionTransform(new Random(seed), COLOR_BGR2Luv);
    //        ImageTransform histEqualization = new EqualizeHistTransform(new Random(seed), COLOR_BGR2Luv);
    ImageTransform yuvTransform = new ColorConversionTransform(new Random(seed), COLOR_BGR2YCrCb);
    ImageTransform histEqualization = new EqualizeHistTransform(new Random(seed), COLOR_BGR2YCrCb);

    if (converter != null) {
        ImageWritable writable = new ImageWritable(converter.convert(orgImage));
        // TODO determine if need to normalize y before transform - opencv docs rec but currently doing after
        writable = yuvTransform.transform(writable); // Converts to chrome color to help emphasize image objects
        writable = histEqualization.transform(writable); // Normalizes values to further clarify object of interest
        resImage = converter.convert(writable.getFrame());
    }

    return resImage;
}
 
Example #4
Source File: CifarLoader.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * Preprocess and store cifar based on successful Torch approach by Sergey Zagoruyko
 * Reference: <a href="https://github.com/szagoruyko/cifar.torch">https://github.com/szagoruyko/cifar.torch</a>
 */
public Mat convertCifar(Mat orgImage) {
    numExamples++;
    Mat resImage = new Mat();
    OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat();
    //        ImageTransform yuvTransform = new ColorConversionTransform(new Random(seed), COLOR_BGR2Luv);
    //        ImageTransform histEqualization = new EqualizeHistTransform(new Random(seed), COLOR_BGR2Luv);
    ImageTransform yuvTransform = new ColorConversionTransform(new Random(seed), COLOR_BGR2YCrCb);
    ImageTransform histEqualization = new EqualizeHistTransform(new Random(seed), COLOR_BGR2YCrCb);

    if (converter != null) {
        ImageWritable writable = new ImageWritable(converter.convert(orgImage));
        // TODO determine if need to normalize y before transform - opencv docs rec but currently doing after
        writable = yuvTransform.transform(writable); // Converts to chrome color to help emphasize image objects
        writable = histEqualization.transform(writable); // Normalizes values to further clarify object of interest
        resImage = converter.convert(writable.getFrame());
    }

    return resImage;
}
 
Example #5
Source File: CaptchaLoader.java    From twse-captcha-solver-dl4j with MIT License 6 votes vote down vote up
public CaptchaLoader(
    int height, int width, int channels, ImageTransform imageTransform, String dataSetType) {
  super(height, width, channels, imageTransform);
  this.height = height;
  this.width = width;
  this.channels = channels;
  try {
    this.fullDir = new File("src/main/resources");
    logger.info("fullDir: " + fullDir);
  } catch (Exception e) {
    logger.error("The datasets directory failed, please checking.", e);
    throw new RuntimeException(e);
  }
  this.fullDir = new File(fullDir, dataSetType);
  load();
}
 
Example #6
Source File: CifarLoader.java    From DataVec with Apache License 2.0 6 votes vote down vote up
public CifarLoader(int height, int width, int channels, ImageTransform imgTransform, boolean train,
                boolean useSpecialPreProcessCifar, File fullDir, long seed, boolean shuffle) {
    super(height, width, channels, imgTransform);
    this.height = height;
    this.width = width;
    this.channels = channels;
    this.train = train;
    this.useSpecialPreProcessCifar = useSpecialPreProcessCifar;
    this.seed = seed;
    this.shuffle = shuffle;

    if (fullDir == null) {
        this.fullDir = getDefaultDirectory();
    } else {
        this.fullDir = fullDir;
    }
    meanVarPath = new File(this.fullDir, "meanVarPath.txt");
    trainFilesSerialized = FilenameUtils.concat(this.fullDir.toString(), "cifar_train_serialized");
    testFilesSerialized = FilenameUtils.concat(this.fullDir.toString(), "cifar_test_serialized.ser");

    load();
}
 
Example #7
Source File: CifarLoader.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
public CifarLoader(int height, int width, int channels, ImageTransform imgTransform, boolean train,
                boolean useSpecialPreProcessCifar, File fullDir, long seed, boolean shuffle) {
    super(height, width, channels, imgTransform);
    this.height = height;
    this.width = width;
    this.channels = channels;
    this.train = train;
    this.useSpecialPreProcessCifar = useSpecialPreProcessCifar;
    this.seed = seed;
    this.shuffle = shuffle;

    if (fullDir == null) {
        this.fullDir = getDefaultDirectory();
    } else {
        this.fullDir = fullDir;
    }
    meanVarPath = new File(this.fullDir, "meanVarPath.txt");
    trainFilesSerialized = FilenameUtils.concat(this.fullDir.toString(), "cifar_train_serialized");
    testFilesSerialized = FilenameUtils.concat(this.fullDir.toString(), "cifar_test_serialized.ser");

    load();
}
 
Example #8
Source File: BaseImageRecordReader.java    From DataVec with Apache License 2.0 5 votes vote down vote up
protected BaseImageRecordReader(int height, int width, int channels, PathLabelGenerator labelGenerator,
                                PathMultiLabelGenerator labelMultiGenerator, ImageTransform imageTransform) {
    this.height = height;
    this.width = width;
    this.channels = channels;
    this.labelGenerator = labelGenerator;
    this.labelMultiGenerator = labelMultiGenerator;
    this.imageTransform = imageTransform;
    this.appendLabel = (labelGenerator != null || labelMultiGenerator != null);
}
 
Example #9
Source File: LFWLoader.java    From DataVec with Apache License 2.0 5 votes vote down vote up
public LFWLoader(int[] imgDim, ImageTransform imgTransform, boolean useSubset) {
    this.height = imgDim[0];
    this.width = imgDim[1];
    this.channels = imgDim[2];
    this.imageTransform = imgTransform;
    this.useSubset = useSubset;
    this.localDir = useSubset ? localSubDir : localDir;
    this.fullDir = new File(BASE_DIR, localDir);
    generateLfwMaps();
}
 
Example #10
Source File: BaseImageRecordReader.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
protected BaseImageRecordReader(long height, long width, long channels, boolean nchw_channels_first, PathLabelGenerator labelGenerator,
                                PathMultiLabelGenerator labelMultiGenerator, ImageTransform imageTransform) {
    this.height = height;
    this.width = width;
    this.channels = channels;
    this.labelGenerator = labelGenerator;
    this.labelMultiGenerator = labelMultiGenerator;
    this.imageTransform = imageTransform;
    this.appendLabel = (labelGenerator != null || labelMultiGenerator != null);
    this.nchw_channels_first = nchw_channels_first;
}
 
Example #11
Source File: NNTrainingUsingZoo.java    From java-ml-projects with Apache License 2.0 5 votes vote down vote up
private static ImageTransform[] getTransforms() {
	ImageTransform randCrop = new CropImageTransform(new Random(), 10);
	ImageTransform warpTransform = new WarpImageTransform(new Random(), 42);
	ImageTransform flip = new FlipImageTransform(new Random());
	ImageTransform scale = new ScaleImageTransform(new Random(), 1);
	return new ImageTransform[] { randCrop, warpTransform, flip, scale };
}
 
Example #12
Source File: LFWLoader.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
public LFWLoader(int[] imgDim, ImageTransform imgTransform, boolean useSubset) {
    this.height = imgDim[0];
    this.width = imgDim[1];
    this.channels = imgDim[2];
    this.imageTransform = imgTransform;
    this.useSubset = useSubset;
    this.localDir = useSubset ? localSubDir : localDir;
    this.fullDir = new File(BASE_DIR, localDir);
    generateLfwMaps();
}
 
Example #13
Source File: LFWLoader.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
public LFWLoader(long[] imgDim, ImageTransform imgTransform, boolean useSubset) {
    this.height = imgDim[0];
    this.width = imgDim[1];
    this.channels = imgDim[2];
    this.imageTransform = imgTransform;
    this.useSubset = useSubset;
    this.localDir = useSubset ? localSubDir : localDir;
    this.fullDir = new File(BASE_DIR, localDir);
    generateLfwMaps();
}
 
Example #14
Source File: UciSequenceDataFetcher.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public CSVSequenceRecordReader getRecordReader(long rngSeed, int[] shape, DataSetType set, ImageTransform transform) {
    return getRecordReader(rngSeed, set);
}
 
Example #15
Source File: Java2DNativeImageLoader.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public Java2DNativeImageLoader(int height, int width, int channels, ImageTransform imageTransform) {
    super(height, width, channels, imageTransform);
}
 
Example #16
Source File: AndroidNativeImageLoader.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public AndroidNativeImageLoader(int height, int width, int channels, ImageTransform imageTransform) {
    super(height, width, channels, imageTransform);
}
 
Example #17
Source File: CifarLoader.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CifarLoader(int height, int width, int channels, ImageTransform imgTransform, boolean train,
                boolean useSpecialPreProcessCifar) {
    this(height, width, channels, imgTransform, train, useSpecialPreProcessCifar, DEFAULT_SHUFFLE);
}
 
Example #18
Source File: CifarLoader.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CifarLoader(int height, int width, int channels, ImageTransform imgTransform, boolean train,
                boolean useSpecialPreProcessCifar, boolean shuffle) {
    this(height, width, channels, imgTransform, train, useSpecialPreProcessCifar, null, System.currentTimeMillis(),
                    shuffle);
}
 
Example #19
Source File: BaseImageRecordReader.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
protected BaseImageRecordReader(long height, long width, long channels, PathLabelGenerator labelGenerator,
                                PathMultiLabelGenerator labelMultiGenerator, ImageTransform imageTransform) {
    this(height, width, channels, true, labelGenerator, labelMultiGenerator, imageTransform);
}
 
Example #20
Source File: BaseImageRecordReader.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public BaseImageRecordReader(long height, long width, long channels, PathLabelGenerator labelGenerator,
                             ImageTransform imageTransform) {
    this(height, width, channels, labelGenerator, null, imageTransform);
}
 
Example #21
Source File: ObjectDetectionRecordReader.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
/**
 * As per {@link #ObjectDetectionRecordReader(int, int, int, int, int, boolean, ImageObjectLabelProvider, ImageTransform)}
 * but hardcoded to NCHW format
 */
public ObjectDetectionRecordReader(int height, int width, int channels, int gridH, int gridW,
                                   ImageObjectLabelProvider labelProvider, ImageTransform imageTransform) {
    this(height, width, channels, gridH, gridW, true, labelProvider, imageTransform);
}
 
Example #22
Source File: ImageRecordReader.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
/** Loads images with given height, width, and channels, appending no labels.
 * Output format is NCHW (channels first) - [numExamples, channels, height, width]*/
public ImageRecordReader(long height, long width, long channels, ImageTransform imageTransform) {
    super(height, width, channels, null, imageTransform);
}
 
Example #23
Source File: ImageRecordReader.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
/** Loads images with given height, width, and channels, appending labels returned by the generator.<br>
 * If {@code nchw_channels_first == true} output format is NCHW (channels first) - [numExamples, channels, height, width]<br>
 * If {@code nchw_channels_first == false} output format is NHWC (channels last) - [numExamples, height, width, channels]<br>
 */
public ImageRecordReader(long height, long width, long channels, boolean nchw_channels_first, PathLabelGenerator labelGenerator,
                         ImageTransform imageTransform) {
    super(height, width, channels, nchw_channels_first, labelGenerator, null, imageTransform);
}
 
Example #24
Source File: LegacyImageMappingHelper.java    From DataVec with Apache License 2.0 4 votes vote down vote up
public LegacyImageTransformDeserializer() {
    super(ImageTransform.class, LegacyMappingHelper.getLegacyMappingImageTransform());
}
 
Example #25
Source File: Java2DNativeImageLoader.java    From DataVec with Apache License 2.0 4 votes vote down vote up
public Java2DNativeImageLoader(int height, int width, int channels, ImageTransform imageTransform) {
    super(height, width, channels, imageTransform);
}
 
Example #26
Source File: CifarLoader.java    From DataVec with Apache License 2.0 4 votes vote down vote up
public CifarLoader(int height, int width, int channels, ImageTransform imgTransform, boolean train,
                boolean useSpecialPreProcessCifar, boolean shuffle) {
    this(height, width, channels, imgTransform, train, useSpecialPreProcessCifar, null, System.currentTimeMillis(),
                    shuffle);
}
 
Example #27
Source File: Java2DNativeImageLoader.java    From konduit-serving with Apache License 2.0 4 votes vote down vote up
public Java2DNativeImageLoader(int height, int width, int channels, ImageTransform imageTransform) {
    super(height, width, channels, imageTransform);
}
 
Example #28
Source File: CifarLoader.java    From DataVec with Apache License 2.0 4 votes vote down vote up
public CifarLoader(int height, int width, int channels, ImageTransform imgTransform, boolean train,
                boolean useSpecialPreProcessCifar) {
    this(height, width, channels, imgTransform, train, useSpecialPreProcessCifar, DEFAULT_SHUFFLE);
}
 
Example #29
Source File: CaptchaSetIterator.java    From twse-captcha-solver-dl4j with MIT License 4 votes vote down vote up
public CaptchaSetIterator(int batchSize, ImageTransform imageTransform, String dataSetType) {
  this.batchSize = batchSize;
  load = new CaptchaLoader(imageTransform, dataSetType);
  numExample = load.totalExamples();
}
 
Example #30
Source File: AndroidNativeImageLoader.java    From DataVec with Apache License 2.0 4 votes vote down vote up
public AndroidNativeImageLoader(int height, int width, int channels, ImageTransform imageTransform) {
    super(height, width, channels, imageTransform);
}