Skip to content

Commit

Permalink
[api] input property key should be case-insensitive
Browse files Browse the repository at this point in the history
Change-Id: I9bcb5aab336f553f979b58523051af75ea134d90
  • Loading branch information
frankfliu committed Oct 3, 2021
1 parent 64e4b1b commit 6f37fb8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/src/main/java/ai/djl/inference/Predictor.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class Predictor<I, O> implements AutoCloseable {
private boolean prepared;
private Model model;
protected NDManager manager;
Metrics metrics;
protected Metrics metrics;
protected Block block;
protected ParameterStore parameterStore;

Expand Down
15 changes: 11 additions & 4 deletions api/src/main/java/ai/djl/modality/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
import ai.djl.ndarray.NDManager;
import ai.djl.util.PairList;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.TreeMap;

/** A class stores the generic input data for inference. */
public class Input {
Expand All @@ -30,7 +29,7 @@ public class Input {

/** Constructs a new {@code Input} instance. */
public Input() {
properties = new ConcurrentHashMap<>();
properties = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
content = new PairList<>();
}

Expand Down Expand Up @@ -70,7 +69,7 @@ public void addProperty(String key, String value) {
* @return the value to which the specified key is mapped
*/
public String getProperty(String key, String defaultValue) {
return properties.getOrDefault(key.toLowerCase(Locale.ROOT), defaultValue);
return properties.getOrDefault(key, defaultValue);
}

/**
Expand Down Expand Up @@ -167,6 +166,10 @@ public void add(int index, String key, BytesSupplier data) {
* @return the default data item
*/
public BytesSupplier getData() {
if (content.isEmpty()) {
return null;
}

BytesSupplier data = get("data");
if (data == null) {
return get(0);
Expand All @@ -181,6 +184,10 @@ public BytesSupplier getData() {
* @return the default data as {@code NDList}
*/
public NDList getDataAsNDList(NDManager manager) {
if (content.isEmpty()) {
return null;
}

int index = content.indexOf("data");
if (index < 0) {
index = 0;
Expand Down

0 comments on commit 6f37fb8

Please sign in to comment.