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] Makes Sam2 input consistent with other CV model #3498

Merged
merged 1 commit into from
Oct 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import ai.djl.translate.TranslatorContext;
import ai.djl.util.JsonUtils;

import com.google.gson.annotations.SerializedName;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -340,7 +342,7 @@ float[][] getLabels() {
public static Sam2Input fromJson(String input) throws IOException {
Prompt prompt = JsonUtils.GSON.fromJson(input, Prompt.class);
if (prompt.image == null) {
throw new IllegalArgumentException("Missing image value");
throw new IllegalArgumentException("Missing image_url value");
}
if (prompt.prompt == null || prompt.prompt.length == 0) {
throw new IllegalArgumentException("Missing prompt value");
Expand Down Expand Up @@ -477,7 +479,10 @@ public void setLabel(int label) {
}

private static final class Prompt {

@SerializedName("image_url")
String image;

Location[] prompt;
boolean visualize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void test() throws IOException {
Path file = Paths.get("../examples/src/test/resources/kitten.jpg");
Image img = ImageFactory.getInstance().fromFile(file);
String json =
"{\"image\": \""
"{\"image_url\": \""
+ file.toUri().toURL()
+ "\",\n"
+ "\"visualize\": true,\n"
Expand Down
Loading