Skip to content

Commit

Permalink
Consolidation of json and yaml configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
ShamsUlAzeem committed Apr 28, 2020
1 parent ebc4645 commit 1c59bdd
Show file tree
Hide file tree
Showing 20 changed files with 2,268 additions and 1,174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,21 @@
import ai.konduit.serving.config.MemMapConfig;
import ai.konduit.serving.config.ServingConfig;
import ai.konduit.serving.config.TextConfig;
import ai.konduit.serving.model.PythonConfig;
import ai.konduit.serving.model.TensorDataType;
import ai.konduit.serving.pipeline.PipelineStep;
import ai.konduit.serving.pipeline.step.ModelStep;
import ai.konduit.serving.pipeline.step.PythonStep;
import ai.konduit.serving.util.ObjectMappers;
import lombok.*;
import org.nd4j.shade.jackson.annotation.JsonAlias;
import org.nd4j.shade.jackson.annotation.JsonSetter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Data
@AllArgsConstructor
Expand All @@ -40,11 +49,45 @@ public class InferenceConfiguration implements Serializable, TextConfig {

@Singular
private List<PipelineStep> steps;

@JsonAlias({"serving"})
private ServingConfig servingConfig;

private MemMapConfig memMapConfig;

@JsonSetter("steps")
public void stepSetup(List<PipelineStep> steps) throws Exception {
for(PipelineStep step : steps) {
if(step instanceof PythonStep) {
PythonStep pythonStep = (PythonStep) step;
Map<String, PythonConfig> pythonConfigs = pythonStep.getPythonConfigs();

for(String key : pythonConfigs.keySet()) {
if(pythonStep.getInputNames() == null || !pythonStep.getInputNames().contains(key))
pythonStep.step(key, pythonConfigs.get(key));
}
}

if(step instanceof ModelStep) {
ModelStep modelStep = (ModelStep) step;
Map<String, TensorDataType> inputDataTypes = modelStep.getInputDataTypes();
Map<String, TensorDataType> outputDataTypes = modelStep.getOutputDataTypes();

if(inputDataTypes != null && !inputDataTypes.isEmpty()) {
modelStep.setInputNames(new ArrayList<>(inputDataTypes.keySet()));
}

if(outputDataTypes != null && !outputDataTypes.isEmpty()) {
modelStep.setOutputNames(new ArrayList<>(outputDataTypes.keySet()));
}
}
}

this.steps = steps;
}

/**
* Create a configuration from a yaml string
* Create a configuration from a yaml string
*
* @param yaml the yaml to create from
* @return the initialized object from the yaml content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import lombok.NoArgsConstructor;
import org.nd4j.shade.jackson.annotation.JsonIgnore;
import org.nd4j.shade.jackson.annotation.JsonIgnoreProperties;
import org.nd4j.shade.jackson.databind.annotation.JsonDeserialize;
import org.nd4j.shade.jackson.databind.annotation.JsonPOJOBuilder;

import java.io.Serializable;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
@AllArgsConstructor
public class PythonConfig implements Serializable {


private String pythonCode, pythonCodePath, pythonPath;

@Singular
Expand All @@ -58,6 +57,4 @@ public class PythonConfig implements Serializable {
private boolean setupAndRun;

private static String defaultPythonPath;


}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import lombok.extern.slf4j.Slf4j;
import org.datavec.api.transform.schema.Schema;
import org.datavec.python.PythonType;
import org.nd4j.shade.jackson.annotation.JsonProperty;
import org.nd4j.shade.jackson.annotation.JsonSetter;

import java.util.*;
import java.util.stream.Collectors;
Expand All @@ -50,10 +52,9 @@
@AllArgsConstructor
@NoArgsConstructor
@Slf4j
@Data
public class PythonStep extends BasePipelineStep<PythonStep> {

@Getter
@Setter
@Singular
private Map<String, PythonConfig> pythonConfigs;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import ai.konduit.serving.pipeline.config.NormalizationConfig;
import ai.konduit.serving.pipeline.config.ObjectDetectionConfig;
import ai.konduit.serving.pipeline.step.*;
import ai.konduit.serving.pipeline.step.model.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand Down Expand Up @@ -68,18 +69,11 @@ public static void main( String[] args ) throws Exception {
clazzes.add(RegressionMetricsConfig.class);
clazzes.add(SavedModelConfig.class);
clazzes.add(ParallelInferenceConfig.class);
clazzes.add(ModelConfig.class);
clazzes.add(TensorDataType.class);
clazzes.add(ObjectDetectionConfig.class);
clazzes.add(SchemaType.class);
clazzes.add(Input.class);
clazzes.add(Output.class);
clazzes.add(KerasConfig.class);
clazzes.add(DL4JConfig.class);
clazzes.add(PmmlConfig.class);
clazzes.add(SameDiffConfig.class);
clazzes.add(TensorFlowConfig.class);
clazzes.add(OnnxConfig.class);
clazzes.add(PythonConfig.class);
clazzes.add(ServingConfig.class);
clazzes.add(PipelineStep.class);
Expand All @@ -89,6 +83,12 @@ public static void main( String[] args ) throws Exception {
clazzes.add(PythonStep.class);
clazzes.add(TransformProcessStep.class);
clazzes.add(ModelStep.class);
clazzes.add(KerasStep.class);
clazzes.add(Dl4jStep.class);
clazzes.add(PmmlStep.class);
clazzes.add(SameDiffStep.class);
clazzes.add(TensorFlowStep.class);
clazzes.add(OnnxStep.class);
clazzes.add(ArrayConcatenationStep.class);
clazzes.add(JsonExpanderTransformStep.class);
clazzes.add(ImageLoadingStep.class);
Expand Down
Loading

0 comments on commit 1c59bdd

Please sign in to comment.