Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api] input property key should be case-insensitive #1264

Merged
merged 1 commit into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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