Java Code Examples for org.nd4j.autodiff.samediff.SameDiff#fromFlatFile()

The following examples show how to use org.nd4j.autodiff.samediff.SameDiff#fromFlatFile() . 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: SameDiffModelLoader.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
@Override
public SameDiff loadModel() throws Exception {
    if (ModelGuesser.isTensorflowFile(pathToModel)) {
        log.debug("Loading tensorflow model from " + pathToModel.getAbsolutePath());
        return TFGraphMapper.importGraph(pathToModel);
    } else if (ModelGuesser.isSameDiffZipFile(pathToModel)) {
        return SameDiff.load(pathToModel, true);
    }

    log.debug("Loading samediff model from " + pathToModel.getAbsolutePath());
    return SameDiff.fromFlatFile(pathToModel);
}
 
Example 2
Source File: SameDiffVerticleClassificationMetricsTest.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
@Override
public JsonObject getConfigObject() throws Exception {
    SameDiff sameDiff = SameDiff.create();
    SDVariable x = sameDiff.placeHolder("x", DataType.FLOAT, 2);
    SDVariable y = sameDiff.placeHolder("y", DataType.FLOAT, 2);
    SDVariable add = x.add("output", y);
    File tmpSameDiffFile = temporary.newFile();
    sameDiff.asFlatFile(tmpSameDiffFile);
    SameDiff values = SameDiff.fromFlatFile(tmpSameDiffFile);

    ServingConfig servingConfig = ServingConfig.builder()
            .outputDataFormat(Output.DataFormat.ND4J)
            .metricsConfigurations(Collections.singletonList(ClassificationMetricsConfig.builder()
                    .classificationLabels(Arrays.asList("0", "1")).build()))
            .metricTypes(Collections.singletonList(MetricType.CLASSIFICATION))
            .httpPort(port)
            .build();

    SameDiffStep modelPipelineConfig = SameDiffStep.builder()
            .path(tmpSameDiffFile.getAbsolutePath())
            .inputNames(Arrays.asList("x", "y"))
            .outputNames(Collections.singletonList("output"))
            .build();

    InferenceConfiguration inferenceConfiguration = InferenceConfiguration.builder()
            .servingConfig(servingConfig)
            .step(modelPipelineConfig)
            .build();

    return new JsonObject(inferenceConfiguration.toJson());
}
 
Example 3
Source File: SameDiffVerticleNd4jTest.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
@Override
public JsonObject getConfigObject() throws Exception {
    SameDiff sameDiff = SameDiff.create();
    SDVariable x = sameDiff.placeHolder("x", DataType.FLOAT, 2);
    SDVariable y = sameDiff.placeHolder("y", DataType.FLOAT, 2);
    SDVariable add = x.add("output", y);
    File tmpSameDiffFile = temporary.newFile();
    sameDiff.asFlatFile(tmpSameDiffFile);
    SameDiff values = SameDiff.fromFlatFile(tmpSameDiffFile);

    ServingConfig servingConfig = ServingConfig.builder()
            .outputDataFormat(Output.DataFormat.ND4J)
            .httpPort(port)
            .build();

    SameDiffStep modelPipelineConfig = SameDiffStep.builder()
            .path(tmpSameDiffFile.getAbsolutePath())
            .inputNames(Arrays.asList("x", "y"))
            .outputNames(Collections.singletonList("output"))
            .build();

    InferenceConfiguration inferenceConfiguration = InferenceConfiguration.builder()
            .servingConfig(servingConfig)
            .step(modelPipelineConfig)
            .build();

    return new JsonObject(inferenceConfiguration.toJson());
}