-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refine returned model data types & add initial examples
- Loading branch information
Showing
18 changed files
with
545 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
///usr/bin/env jbang "$0" "$@" ; exit $? | ||
//DEPS com.github.tadayosi.torchserve:torchserve-client:0.1-SNAPSHOT | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import com.github.tadayosi.torchserve.client.impl.DefaultInference; | ||
import com.github.tadayosi.torchserve.client.inference.invoker.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 inference = new DefaultInference(); | ||
var result0 = inference.predictions(MNIST_MODEL, zero); | ||
System.out.println("Answer> " + result0); | ||
var result1 = inference.predictions(MNIST_MODEL, one); | ||
System.out.println("Answer> " + result1); | ||
} catch (ApiException e) { | ||
System.err.println(e.getResponseBody()); | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
///usr/bin/env jbang "$0" "$@" ; exit $? | ||
//DEPS com.github.tadayosi.torchserve:torchserve-client:0.1-SNAPSHOT | ||
|
||
import com.github.tadayosi.torchserve.client.impl.DefaultManagement; | ||
import com.github.tadayosi.torchserve.client.management.invoker.ApiException; | ||
import com.github.tadayosi.torchserve.client.model.RegisterModelOptions; | ||
import com.github.tadayosi.torchserve.client.model.SetAutoScaleOptions; | ||
|
||
public class register_mnist { | ||
|
||
private static String MNIST_URL = "https://torchserve.pytorch.org/mar_files/mnist_v2.mar"; | ||
private static String MNIST_MODEL = "mnist_v2"; | ||
|
||
public static void main(String... args) throws Exception { | ||
try { | ||
var management = new DefaultManagement(); | ||
var response = management.registerModel(MNIST_URL, RegisterModelOptions.empty()); | ||
System.out.println("registerModel> " + response.getStatus()); | ||
response = management.setAutoScale(MNIST_MODEL, SetAutoScaleOptions.builder() | ||
.minWorker(1) | ||
.maxWorker(1) | ||
.build()); | ||
System.out.println("setAutoScale> " + response.getStatus()); | ||
} catch (ApiException e) { | ||
System.err.println(e.getResponseBody()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/com/github/tadayosi/torchserve/client/model/API.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.github.tadayosi.torchserve.client.model; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class API { | ||
|
||
private String openapi = null; | ||
private Map<String, String> info = new HashMap<>(); | ||
private Map<String, Object> paths = new HashMap<>(); | ||
|
||
public API() { | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static API from(com.github.tadayosi.torchserve.client.inference.model.InlineResponse200 src) { | ||
API api = new API(); | ||
api.setOpenapi(src.getOpenapi()); | ||
api.setInfo((Map<String, String>) src.getInfo()); | ||
api.setPaths((Map<String, Object>) src.getPaths()); | ||
return api; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static API from(com.github.tadayosi.torchserve.client.management.model.InlineResponse200 src) { | ||
API api = new API(); | ||
api.setOpenapi(src.getOpenapi()); | ||
api.setInfo((Map<String, String>) src.getInfo()); | ||
api.setPaths((Map<String, Object>) src.getPaths()); | ||
return api; | ||
} | ||
|
||
public String getOpenapi() { | ||
return openapi; | ||
} | ||
|
||
public void setOpenapi(String openapi) { | ||
this.openapi = openapi; | ||
} | ||
|
||
public Map<String, String> getInfo() { | ||
return info; | ||
} | ||
|
||
public void setInfo(Map<String, String> info) { | ||
this.info = info; | ||
} | ||
|
||
public Map<String, Object> getPaths() { | ||
return paths; | ||
} | ||
|
||
public void setPaths(Map<String, Object> paths) { | ||
this.paths = paths; | ||
} | ||
} |
Oops, something went wrong.