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] Fixed NDList decode numpy file bug #2804

Merged
merged 1 commit into from
Oct 12, 2023
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
8 changes: 4 additions & 4 deletions api/src/main/java/ai/djl/ndarray/NDList.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ public static NDList decode(NDManager manager, byte[] byteArray) {
try {
if (byteArray[0] == 'P' && byteArray[1] == 'K') {
return decodeNumpy(manager, new ByteArrayInputStream(byteArray));
} else if (byteArray[0] == (byte) 0x39
} else if (byteArray[0] == (byte) 0x93
&& byteArray[1] == 'N'
&& byteArray[2] == 'U'
&& byteArray[3] == 'M') {
return new NDList(
NDSerializer.decode(manager, new ByteArrayInputStream(byteArray)));
NDSerializer.decodeNumpy(manager, new ByteArrayInputStream(byteArray)));
} else if (byteArray[8] == '{') {
return decodeSafetensors(manager, new ByteArrayInputStream(byteArray));
}
Expand Down Expand Up @@ -144,11 +144,11 @@ public static NDList decode(NDManager manager, InputStream is) {
if (magic[0] == 'P' && magic[1] == 'K') {
// assume this is npz file
return decodeNumpy(manager, pis);
} else if (magic[0] == (byte) 0x39
} else if (magic[0] == (byte) 0x93
&& magic[1] == 'N'
&& magic[2] == 'U'
&& magic[3] == 'M') {
return new NDList(NDSerializer.decode(manager, pis));
return new NDList(NDSerializer.decodeNumpy(manager, pis));
} else if (magic[8] == '{') {
return decodeSafetensors(manager, pis);
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/test/java/ai/djl/ndarray/NDSerializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private static byte[] encode(NDArray array) throws IOException {

private static NDArray decode(NDManager manager, byte[] data) throws IOException {
try (ByteArrayInputStream bis = new ByteArrayInputStream(data)) {
return NDSerializer.decodeNumpy(manager, bis);
return NDList.decode(manager, bis).get(0);
}
}

Expand Down
Loading