org.bytedeco.javacpp.indexer.Indexer Java Examples

The following examples show how to use org.bytedeco.javacpp.indexer.Indexer. 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: CNNGenderDetector.java    From javacv-cnn-example with MIT License 6 votes vote down vote up
/**
 * Predicts gender of a given cropped face
 *
 * @param face  the cropped face as a {@link Mat}
 * @param frame the original frame where the face was cropped from
 * @return Gender
 */
public Gender predictGender(Mat face, Frame frame) {
    try {
        Mat croppedMat = new Mat();
        resize(face, croppedMat, new Size(256, 256));
        normalize(croppedMat, croppedMat, 0, Math.pow(2, frame.imageDepth), NORM_MINMAX, -1, null);

        Mat inputBlob = blobFromImage(croppedMat);
        genderNet.setInput(inputBlob, "data", 1.0, null);      //set the network input

        Mat prob = genderNet.forward("prob");

        Indexer indexer = prob.createIndexer();
        logger.debug("CNN results {},{}", indexer.getDouble(0, 0), indexer.getDouble(0, 1));
        if (indexer.getDouble(0, 0) > indexer.getDouble(0, 1)) {
            logger.debug("Male detected");
            return Gender.MALE;
        } else {
            logger.debug("Female detected");
            return Gender.FEMALE;
        }
    } catch (Exception e) {
        logger.error("Error when processing gender", e);
    }
    return Gender.NOT_RECOGNIZED;
}
 
Example #2
Source File: DefaultDataBufferFactory.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * Create a data buffer based on the
 * given pointer, data buffer opType,
 * and length of the buffer
 *
 * @param pointer the pointer to use
 * @param type    the opType of buffer
 * @param length  the length of the buffer
 * @param indexer the indexer for the pointer
 * @return the data buffer
 * backed by this pointer with the given
 * opType and length.
 */
@Override
public DataBuffer create(Pointer pointer, DataBuffer.Type type, long length, Indexer indexer) {
    switch (type) {
        case INT:
            return new IntBuffer(pointer, indexer, length);
        case DOUBLE:
            return new DoubleBuffer(pointer, indexer, length);
        case FLOAT:
            return new FloatBuffer(pointer, indexer, length);
        case LONG:
            return new LongBuffer(pointer, indexer, length);
    }
    throw new IllegalArgumentException("Invalid opType " + type);
}
 
Example #3
Source File: FloatDataBufferTest.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPointerCreation() {
    FloatPointer floatPointer = new FloatPointer(1, 2, 3, 4);
    Indexer indexer = FloatIndexer.create(floatPointer);
    DataBuffer buffer = Nd4j.createBuffer(floatPointer, DataType.FLOAT, 4, indexer);
    DataBuffer other = Nd4j.createBuffer(new float[] {1, 2, 3, 4});
    assertArrayEquals(other.asFloat(), buffer.asFloat(), 0.001f);
}
 
Example #4
Source File: DoubleDataBufferTest.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPointerCreation() {
    DoublePointer floatPointer = new DoublePointer(1, 2, 3, 4);
    Indexer indexer = DoubleIndexer.create(floatPointer);
    DataBuffer buffer = Nd4j.createBuffer(floatPointer, DataType.DOUBLE, 4, indexer);
    DataBuffer other = Nd4j.createBuffer(new double[] {1, 2, 3, 4});
    assertArrayEquals(other.asDouble(), buffer.asDouble(), 0.001);
}
 
Example #5
Source File: DefaultDataBufferFactory.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * Create a data buffer based on the
 * given pointer, data buffer opType,
 * and length of the buffer
 *
 * @param pointer the pointer to use
 * @param type    the opType of buffer
 * @param length  the length of the buffer
 * @param indexer the indexer for the pointer
 * @return the data buffer
 * backed by this pointer with the given
 * opType and length.
 */
@Override
public DataBuffer create(Pointer pointer, DataType type, long length, @NonNull Indexer indexer) {
    switch (type) {
        case BOOL:
            return new BoolBuffer(pointer, indexer, length);
        case BYTE:
            return new Int8Buffer(pointer, indexer, length);
        case UBYTE:
            return new UInt8Buffer(pointer, indexer, length);
        case UINT16:
            return new UInt16Buffer(pointer, indexer, length);
        case UINT32:
            return new UInt32Buffer(pointer, indexer, length);
        case UINT64:
            return new UInt64Buffer(pointer, indexer, length);
        case SHORT:
            return new Int16Buffer(pointer, indexer, length);
        case INT:
            return new IntBuffer(pointer, indexer, length);
        case LONG:
            return new LongBuffer(pointer, indexer, length);
        case HALF:
            return new HalfBuffer(pointer, indexer, length);
        case BFLOAT16:
            return new BFloat16Buffer(pointer, indexer, length);
        case FLOAT:
            return new FloatBuffer(pointer, indexer, length);
        case DOUBLE:
            return new DoubleBuffer(pointer, indexer, length);
    }
    throw new IllegalArgumentException("Invalid opType " + type);
}
 
Example #6
Source File: DoubleDataBufferTest.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPointerCreation() {
    DoublePointer floatPointer = new DoublePointer(1, 2, 3, 4);
    Indexer indexer = DoubleIndexer.create(floatPointer);
    DataBuffer buffer = Nd4j.createBuffer(floatPointer, DataBuffer.Type.DOUBLE, 4, indexer);
    DataBuffer other = Nd4j.createBuffer(new double[] {1, 2, 3, 4});
    assertArrayEquals(other.asDouble(), buffer.asDouble(), 0.001);
}
 
Example #7
Source File: FloatDataBufferTest.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPointerCreation() {
    FloatPointer floatPointer = new FloatPointer(1, 2, 3, 4);
    Indexer indexer = FloatIndexer.create(floatPointer);
    DataBuffer buffer = Nd4j.createBuffer(floatPointer, DataBuffer.Type.FLOAT, 4, indexer);
    DataBuffer other = Nd4j.createBuffer(new float[] {1, 2, 3, 4});
    assertArrayEquals(other.asFloat(), buffer.asFloat(), 0.001f);
}
 
Example #8
Source File: CudaByteDataBuffer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CudaByteDataBuffer(Pointer pointer, Pointer specialPointer, Indexer indexer, long length){
    super(pointer, specialPointer, indexer, length);
}
 
Example #9
Source File: CudaDoubleDataBuffer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CudaDoubleDataBuffer(Pointer pointer, Pointer specialPointer, Indexer indexer, long length){
    super(pointer, specialPointer, indexer, length);
}
 
Example #10
Source File: CudaHalfDataBuffer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CudaHalfDataBuffer(Pointer pointer, Pointer specialPointer, Indexer indexer, long length){
    super(pointer, specialPointer, indexer, length);
}
 
Example #11
Source File: CudaUInt64DataBuffer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CudaUInt64DataBuffer(Pointer pointer, Pointer specialPointer, Indexer indexer, long length){
    super(pointer, specialPointer, indexer, length);
}
 
Example #12
Source File: CudaBfloat16DataBuffer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CudaBfloat16DataBuffer(Pointer pointer, Pointer specialPointer, Indexer indexer, long length){
    super(pointer, specialPointer, indexer, length);
}
 
Example #13
Source File: CudaUByteDataBuffer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CudaUByteDataBuffer(Pointer pointer, Pointer specialPointer, Indexer indexer, long length){
    super(pointer, specialPointer, indexer, length);
}
 
Example #14
Source File: CompressedDataBuffer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
protected void setIndexer(Indexer indexer) {
    // no-op
}
 
Example #15
Source File: Frame.java    From VideoAndroid with Apache License 2.0 4 votes vote down vote up
/** Returns {@code createIndexer(true, 0)}. */
public <I extends Indexer> I createIndexer() {
    return (I)createIndexer(true, 0);
}
 
Example #16
Source File: Frame.java    From VideoAndroid with Apache License 2.0 4 votes vote down vote up
/** Returns an {@link Indexer} for the <i>i</i>th image plane. */
public <I extends Indexer> I createIndexer(boolean direct, int i) {
    int[] sizes = {imageHeight, imageWidth, imageChannels};
    int[] strides = {imageStride, imageChannels, 1};
    Buffer buffer = image[i];
    Object array = buffer.hasArray() ? buffer.array() : null;
    switch (imageDepth) {
        case DEPTH_UBYTE:
            return array != null ? (I)UByteIndexer.create((byte[])array, sizes, strides)
                        : direct ? (I)UByteIndexer.create((ByteBuffer)buffer, sizes, strides)
                                 : (I)UByteIndexer.create(new BytePointer((ByteBuffer)buffer), sizes, strides, false);
        case DEPTH_BYTE:
            return array != null ? (I)ByteIndexer.create((byte[])array, sizes, strides)
                        : direct ? (I)ByteIndexer.create((ByteBuffer)buffer, sizes, strides)
                                 : (I)ByteIndexer.create(new BytePointer((ByteBuffer)buffer), sizes, strides, false);
        case DEPTH_USHORT:
            return array != null ? (I)UShortIndexer.create((short[])array, sizes, strides)
                        : direct ? (I)UShortIndexer.create((ShortBuffer)buffer, sizes, strides)
                                 : (I)UShortIndexer.create(new ShortPointer((ShortBuffer)buffer), sizes, strides, false);
        case DEPTH_SHORT:
            return array != null ? (I)ShortIndexer.create((short[])array, sizes, strides)
                        : direct ? (I)ShortIndexer.create((ShortBuffer)buffer, sizes, strides)
                                 : (I)ShortIndexer.create(new ShortPointer((ShortBuffer)buffer), sizes, strides, false);
        case DEPTH_INT:
            return array != null ? (I)IntIndexer.create((int[])array, sizes, strides)
                        : direct ? (I)IntIndexer.create((IntBuffer)buffer, sizes, strides)
                                 : (I)IntIndexer.create(new IntPointer((IntBuffer)buffer), sizes, strides, false);
        case DEPTH_LONG:
            return array != null ? (I)LongIndexer.create((long[])array, sizes, strides)
                        : direct ? (I)LongIndexer.create((LongBuffer)buffer, sizes, strides)
                                 : (I)LongIndexer.create(new LongPointer((LongBuffer)buffer), sizes, strides, false);
        case DEPTH_FLOAT:
            return array != null ? (I)FloatIndexer.create((float[])array, sizes, strides)
                        : direct ? (I)FloatIndexer.create((FloatBuffer)buffer, sizes, strides)
                                 : (I)FloatIndexer.create(new FloatPointer((FloatBuffer)buffer), sizes, strides, false);
        case DEPTH_DOUBLE:
            return array != null ? (I)DoubleIndexer.create((double[])array, sizes, strides)
                        : direct ? (I)DoubleIndexer.create((DoubleBuffer)buffer, sizes, strides)
                                 : (I)DoubleIndexer.create(new DoublePointer((DoubleBuffer)buffer), sizes, strides, false);
        default: assert false;
    }
    return null;
}
 
Example #17
Source File: CompressedDataBuffer.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
protected void setIndexer(Indexer indexer) {
    // no-op
}
 
Example #18
Source File: CudaUInt16DataBuffer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CudaUInt16DataBuffer(Pointer pointer, Pointer specialPointer, Indexer indexer, long length){
    super(pointer, specialPointer, indexer, length);
}
 
Example #19
Source File: CudaUInt32DataBuffer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CudaUInt32DataBuffer(Pointer pointer, Pointer specialPointer, Indexer indexer, long length){
    super(pointer, specialPointer, indexer, length);
}
 
Example #20
Source File: CudaIntDataBuffer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CudaIntDataBuffer(Pointer pointer, Pointer specialPointer, Indexer indexer, long length){
    super(pointer, specialPointer, indexer, length);
}
 
Example #21
Source File: CudaFloatDataBuffer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CudaFloatDataBuffer(Pointer pointer, Pointer specialPointer, Indexer indexer, long length){
    super(pointer, specialPointer, indexer, length);
}
 
Example #22
Source File: CudaShortDataBuffer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CudaShortDataBuffer(Pointer pointer, Pointer specialPointer, Indexer indexer, long length){
    super(pointer, specialPointer, indexer, length);
}
 
Example #23
Source File: CudaLongDataBuffer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CudaLongDataBuffer(Pointer pointer, Pointer specialPointer, Indexer indexer, long length){
    super(pointer, specialPointer, indexer, length);
}
 
Example #24
Source File: CudaBoolDataBuffer.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public CudaBoolDataBuffer(Pointer pointer, Pointer specialPointer, Indexer indexer, long length){
    super(pointer, specialPointer, indexer, length);
}
 
Example #25
Source File: DefaultDataBufferFactory.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public DataBuffer create(Pointer pointer, Pointer specialPointer, DataType type, long length, @NonNull Indexer indexer) {
    return create(pointer, type, length, indexer);
}
 
Example #26
Source File: Frame.java    From VideoAndroid with Apache License 2.0 4 votes vote down vote up
@Override public <I extends Indexer> I createIndexer(boolean direct) {
    return (I)createIndexer(direct, 0);
}
 
Example #27
Source File: LongBuffer.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * Meant for creating another view of a buffer
 *
 * @param pointer the underlying buffer to create a view from
 * @param indexer the indexer for the pointer
 * @param length  the length of the view
 */
public LongBuffer(Pointer pointer, Indexer indexer, long length) {
    super(pointer, indexer, length);
}
 
Example #28
Source File: Int8Buffer.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * Meant for creating another view of a buffer
 *
 * @param pointer the underlying buffer to create a view from
 * @param indexer the indexer for the pointer
 * @param length  the length of the view
 */
public Int8Buffer(Pointer pointer, Indexer indexer, long length) {
    super(pointer, indexer, length);
}
 
Example #29
Source File: UInt64Buffer.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * Meant for creating another view of a buffer
 *
 * @param pointer the underlying buffer to create a view from
 * @param indexer the indexer for the pointer
 * @param length  the length of the view
 */
public UInt64Buffer(Pointer pointer, Indexer indexer, long length) {
    super(pointer, indexer, length);
}
 
Example #30
Source File: IntBuffer.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * Meant for creating another view of a buffer
 *
 * @param pointer the underlying buffer to create a view from
 * @param indexer the indexer for the pointer
 * @param length  the length of the view
 */
public IntBuffer(Pointer pointer, Indexer indexer, long length) {
    super(pointer, indexer, length);
}