Java Code Examples for org.nd4j.linalg.factory.Nd4j#saveBinary()

The following examples show how to use org.nd4j.linalg.factory.Nd4j#saveBinary() . 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: ArraySavingListener.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Override
public void opExecution(SameDiff sd, At at, MultiDataSet batch, SameDiffOp op, OpContext opContext, INDArray[] outputs) {
    List<String> outNames = op.getOutputsOfOp();
    for(int i=0; i<outputs.length; i++ ){
        String filename = (count++) + "_" + outNames.get(i).replaceAll("/", "__") + ".bin";
        File outFile = new File(dir, filename);

        INDArray arr = outputs[i];
        try {
            Nd4j.saveBinary(arr, outFile);
            System.out.println(outFile.getAbsolutePath());
        } catch (IOException e){
            throw new RuntimeException(e);
        }
    }
}
 
Example 2
Source File: NormalizerMinMaxScaler.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 * Save the current min and max
 *
 * @param files the statistics to save
 * @throws IOException
 * @deprecated use {@link NormalizerSerializer instead}
 */
public void save(File... files) throws IOException {
    Nd4j.saveBinary(getMin(), files[0]);
    Nd4j.saveBinary(getMax(), files[1]);
    if (isFitLabel()) {
        Nd4j.saveBinary(getLabelMin(), files[2]);
        Nd4j.saveBinary(getLabelMax(), files[3]);
    }
}
 
Example 3
Source File: NormalizerMinMaxScaler.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * Save the current min and max
 *
 * @param files the statistics to save
 * @throws IOException
 * @deprecated use {@link NormalizerSerializer instead}
 */
public void save(File... files) throws IOException {
    Nd4j.saveBinary(getMin(), files[0]);
    Nd4j.saveBinary(getMax(), files[1]);
    if (isFitLabel()) {
        Nd4j.saveBinary(getLabelMin(), files[2]);
        Nd4j.saveBinary(getLabelMax(), files[3]);
    }
}
 
Example 4
Source File: IntDataBufferTests.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Test
public void testBasicSerde1() throws Exception {


    DataBuffer dataBuffer = Nd4j.createBuffer(new int[] {1, 2, 3, 4, 5});
    DataBuffer shapeBuffer = Nd4j.getShapeInfoProvider().createShapeInformation(new int[] {1, 5}).getFirst();
    INDArray intArray = Nd4j.createArrayFromShapeBuffer(dataBuffer, shapeBuffer);

    File tempFile = File.createTempFile("test", "test");
    tempFile.deleteOnExit();

    Nd4j.saveBinary(intArray, tempFile);

    InputStream stream = new FileInputStream(tempFile);
    BufferedInputStream bis = new BufferedInputStream(stream);
    DataInputStream dis = new DataInputStream(bis);

    INDArray loaded = Nd4j.read(dis);

    assertEquals(DataBuffer.Type.INT, loaded.data().dataType());
    assertEquals(DataBuffer.Type.LONG, loaded.shapeInfoDataBuffer().dataType());

    assertEquals(intArray.data().length(), loaded.data().length());

    assertArrayEquals(intArray.data().asInt(), loaded.data().asInt());
}
 
Example 5
Source File: IntDataBufferTests.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Test
public void testBasicSerde1() throws Exception {


    DataBuffer dataBuffer = Nd4j.createBuffer(new int[] {1, 2, 3, 4, 5});
    DataBuffer shapeBuffer = Nd4j.getShapeInfoProvider().createShapeInformation(new long[] {1, 5}, DataType.INT).getFirst();
    INDArray intArray = Nd4j.createArrayFromShapeBuffer(dataBuffer, shapeBuffer);

    File tempFile = File.createTempFile("test", "test");
    tempFile.deleteOnExit();

    Nd4j.saveBinary(intArray, tempFile);

    InputStream stream = new FileInputStream(tempFile);
    BufferedInputStream bis = new BufferedInputStream(stream);
    DataInputStream dis = new DataInputStream(bis);

    INDArray loaded = Nd4j.read(dis);

    assertEquals(DataType.INT, loaded.data().dataType());
    assertEquals(DataType.LONG, loaded.shapeInfoDataBuffer().dataType());

    assertEquals(intArray.data().length(), loaded.data().length());

    assertArrayEquals(intArray.data().asInt(), loaded.data().asInt());
}
 
Example 6
Source File: DistributionStats.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * Save distribution statistics to the file system
 *
 * @param meanFile file to contain the means
 * @param stdFile  file to contain the standard deviations
 */
public void save(@NonNull File meanFile, @NonNull File stdFile) throws IOException {
    Nd4j.saveBinary(getMean(), meanFile);
    Nd4j.saveBinary(getStd(), stdFile);
}
 
Example 7
Source File: StandardScaler.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * Save the current mean and std
 * @param mean the mean
 * @param std the std
 * @throws IOException
 */
public void save(File mean, File std) throws IOException {
    Nd4j.saveBinary(this.mean, mean);
    Nd4j.saveBinary(this.std, std);
}
 
Example 8
Source File: DistributionStats.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * Save distribution statistics to the file system
 *
 * @param meanFile file to contain the means
 * @param stdFile  file to contain the standard deviations
 */
public void save(@NonNull File meanFile, @NonNull File stdFile) throws IOException {
    Nd4j.saveBinary(getMean(), meanFile);
    Nd4j.saveBinary(getStd(), stdFile);
}
 
Example 9
Source File: StandardScaler.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 * Save the current mean and std
 * @param mean the mean
 * @param std the std
 * @throws IOException
 */
public void save(File mean, File std) throws IOException {
    Nd4j.saveBinary(this.mean, mean);
    Nd4j.saveBinary(this.std, std);
}