-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmnist.java
executable file
·30 lines (24 loc) · 1.03 KB
/
mnist.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 17+
//DEPS io.github.tadayosi.torchserve:torchserve-client:0.4.0
//DEPS org.slf4j:slf4j-simple:1.7.36
import java.nio.file.Files;
import java.nio.file.Path;
import io.github.tadayosi.torchserve.client.TorchServeClient;
import io.github.tadayosi.torchserve.client.model.ApiException;
public class mnist {
private static String MNIST_MODEL = "mnist_v2";
public static void main(String... args) throws Exception {
var zero = Files.readAllBytes(Path.of("src/test/resources/data/0.png"));
var one = Files.readAllBytes(Path.of("src/test/resources/data/1.png"));
try {
var client = TorchServeClient.newInstance();
var result0 = client.inference().predictions(MNIST_MODEL, zero);
System.out.println("Answer> " + result0);
var result1 = client.inference().predictions(MNIST_MODEL, one);
System.out.println("Answer> " + result1);
} catch (ApiException e) {
e.printStackTrace();
}
}
}