I'm looking for a way to get model metadata from all currently active models on Tensorflow Serving in Java Maven.
I have some working code for retrieving metadata from a specific model and version so if it would be possible to get a list of all model names and versions through grpc (or api) that would be great. Working code using tensorflow-client (com.yesup.oss) :
static ManagedChannel channel = ManagedChannelBuilder.forAddress(TF_SERVICE_HOST, TF_SERVICE_PORT)
.usePlaintext(true).build();
static PredictionServiceGrpc.PredictionServiceBlockingStub stub = PredictionServiceGrpc.newBlockingStub(channel);
public static void getMetadata(String model, Integer version) {
System.out.println("Create request");
GetModelMetadataRequest request = GetModelMetadataRequest.newBuilder()
.setModelSpec(ModelSpec.newBuilder()
.setName(model)
.setSignatureName("serving_default")
.setVersion(Int64Value.newBuilder().setValue(version))
)
.addMetadataField("signature_def")
.build();
System.out.println("Collecting metadata...");
GetModelMetadataResponse response = stub.getModelMetadata(request);
System.out.println("Done");
try {
SignatureDefMap sdef = SignatureDefMap.parseFrom(
response.getMetadataMap().get("signature_def").getValue());
System.out.println( sdef);
} catch (InvalidProtocolBufferException e1) {
e1.printStackTrace();
}
}
Own thoughts
I have thought about a couple of solutions, however none of them are preferable.
Create a server on the same device running Tensorflow Serving that can share the content of Tensorflow Serving config file. The config file contains model names and version, but we will not know if they are currently active.
Use jython or python to access other libraries (tensorflow-serving-api) which seems to contain "list-all-model-names" and "retriveConfig".
Any advice are appreciated, thanks in advance!
Related
I'm working on a Spring Boot application with integration of Stripe for payment management.
When a user is dealing with a payment, an invoice is generated through Stripe.
Application downloads this invoice from Stripe to copy it in a Cloud provider using S3 API.
All of this is working correctly.
My concern is application users can choose different language.
When downloading Stripe invoice through Stripe dashboard, invoice is automatically generated in language defined in web browser.
I would like to be able to "set" the language when downloading invoice through API depending on user settings.
Here is how my current code looks like:
public void copyInvoice(Etude etude, String invoiceName, URL invoiceURL, String bucketName) {
var invoiceTmp = new File(System.getProperty("java.io.tmpdir") + invoiceName);
try {
var defaultLocale = Locale.getDefault();
log.debug("copyInvoice - defaultLocale : {}", defaultLocale);
FileUtils.copyURLToFile(invoiceDTO.getUrl(), invoiceTmp);
var s3 = this.getCredentials();
s3.putObject(new PutObjectRequest(bucketName, "invoices/" + invoiceName, invoiceTmp));
invoiceTmp.delete();
} catch (IOException e) {
log.error("copyInvoice, IOException exception when copying invoice from Stripe", e);
}
}
When trying on my side, generated invoice downloaded by this code is always in English, even if the linked Customer in Stripe is set as French, invoice account country is FR (invoice) and my default JVM locale is fr_FR.
Thanks in advance for all suggestions and advices !
Unfortunately it's not possible to define a language when getting the PDF from the Invoice. The language is determined by the browser locale and cannot be set via the API.
I'm new to Spring Boot, so I'm not sure about how to store/manipulate files (use persistance within spring). Use case: Store list of films (title, director...) on a JSON file stored on API server with persistance instead of using a DB.
I have a favorites.json at src/main/resources. This file is updated when request arrives as I said. Code here: GitHub Repo
A kind person has left in the comments what is probably the problem. Changes files in classpath won't work. I still struggling how store data in JSON without a database.
Problem I'm facing:
Files are updated correctly at POST request via OutputStream, but it seems like favorites.json is treated as a static resource, so any update will be ignored until API starts again (I have tried restarting the api when the file is updated, see this but it doesn't change anything. It's still needed to stop and start manually, bash script may help, but I prefer another solution if better-possible.
Maybe I'm looking for a file-based repository, place this file in a specific project path where spring detect updates.
I think I'm skipping some important concepts of spring behaviour.
Here POST Resource
#CrossOrigin(origins = "http://localhost:3000")
#PostMapping(path = TaskLinks.FAVORITES, consumes = "application/json", produces = "application/json")
#ResponseBody
public String updateFavs(#RequestBody List<Show> newFavorites) {
showService.updateFavorites(newFavorites);
return "All right";
}
Methods that modify the file:
public boolean updateFavorites(List<Show> newFavorites) {
if (newFavorites == null)
return false;
setNewFavorites(newFavorites);
return true;
}
private void setNewFavorites(List<Show> newFavorites) {
Gson gson = new Gson();
try {
FileWriter fileW = new FileWriter(FAVORITES_PATH);
String strNewFavs = gson.toJson(newFavorites);
fileW.write(strNewFavs);
fileW.close(); // auto flush
} catch (JsonIOException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
If someone needs to use spring boot persistence system, I will let here what I've found.
The unique solution that I've found to use file persistance on spring-boot (API) is to hard-reload the whole API, which I think is not a clean thing.
So I ended up storing the JSON file on mysql.
Maybe spring have specific tools that I've omitted, but I don't have time to check right now.
The closest approach I got was accessing system temporary file, which is correctly updated because it's allocated outside the application.
I didn't get access to files outside the application other than temporary ones.
Now I'm working with NodeJS express and implemented a png delivery API. I don't really know how I would've done it with spring at all, but there's probably a file focused database or something that may work fine with spring. If I have to face this situation, I will upload the solution that I find most favorable. At the moment express works fine.
I have this code that works for python
X = numpy.loadtxt("compiledFeatures.csv", delimiter=",")
model = load_model("kerasnaive.h5")
predictions = model.predict(X)
print(predictions);
and I am trying to write a code with the same functionality in java,
I have written this code but it do not works, anyone knows what I am doing wrong or is there another simpler way to do it?
the code is going to the catch block, and during debugging the code it seems that all the information gained from the model file is null
path = String.format("%s\\kerasnaive.h5", System.getProperty("user.dir"),
pAgents[i]);
try {
network = KerasModelImport.importKerasModelAndWeights(path, false);
}
catch (Exception e){
System.out.println("cannot build keras layers");
}
INDArray input = Nd4j.create(1);
input.add(featuresInput); //an NDarray that i got in the method
INDArray output = network[i].outputSingle(input);
it seems that the model does not built (the network is still null)
the code for python loads the model and it works,
in java i get the error: "Could not determine number of outputs for layer: no output_dim or nb_filter field found. For more information, see http://deeplearning4j.org/model-import-keras."
although the same file is used in both casses
Thanks,
Ori
You are currently importing the trained keras model using importKerasModelAndWeights. I'm not sure how you trained your model, but in Keras there are two types of models available: the Sequential model, and the Model class that uses the functional API. You can read more here.
If you used the Sequential model when you created the network, you need to use the importKerasSequentialModel function. Keras Sequential models.
I want to fetch history of file elements like pdf files, doc files, etc. which are under clearcase control using Rational CM API which are provided by clearcase. I have written following code to fetch the history but it is incomplete so please help me out here.
public void fetchFileElementHistory()
{
try
{
CcFile fetchElement = provider.ccFile(provider.filePathLocation(testFile)); // file under Clearcase control
PropertyRequest wantedProps = new PropertyRequest(CcFile.DISPLAY_NAME, CcFile.CREATION_DATE,CcFile.VIEW_RELATIVE_PATH,CcFile.CLIENT_PATH,CcFile.VERSION_HISTORY,CcFile.PREDECESSOR_LIST,CcFile.ELEMENT);
fetchElement = (CcFile) fetchElement.doReadProperties(wantedProps);
VersionHistory versionHistory = fetchElement.getVersionHistory();
versionHistory = (VersionHistory) versionHistory.doReadProperties(new PropertyRequest(VersionHistory.CHILD_LIST,VersionHistory.ROOT_VERSION,
VersionHistory.CHILD_MAP,VersionHistory.PARENT_LIST,VersionHistory.PROVIDER_LIST,VersionHistory.WORKSPACE_FOLDER_LIST));
/*
* what to do here ?
*/
}
catch(Exception e){
e.printStackTrace();
}
}
Thanks in advance
The official documentation for CM API 7.1.x.
Make sure you have selected the "CM Library Samples and Documentation" feature under the Client Components section of the install. in order to check the code examples included with the javadoc.
From the object model overview, check if collections apply your case.
I have just downloaded the Samsung SDK 1.2 for Java Development.
Now, it's pure based J2ME architecture, so I have a requirement to store some files inside the memory for my application usage.
That file can have a .csv extension, so for that I have tried JSR 75's FileConnection class with following piece of code :
try {
FileConnection fconn = (FileConnection) Connector.open("file:///CFCard/newfile.txt");
if (!fconn.exists()) {
fconn.create(); // create the file if it doesn't exist
}
fconn.close();
} catch (IOException ioe) {
System.out.println("exception = "+ioe);
}
But in this case, it's giving me following exception :
exception = java.io.IOException: Root is not accessible
So, I don't exactly, I am on the right track or not..
Thanks in advance.
The roots available to you vary between devices. Read the JSR 75 documentation -- the method FileSystemRegistry.listRoots() will be of interest to you.
I'm not sure about that "CFCard". For example, on my phone, I think it would be "file:///E:/newfile.txt"
I'll try to do some research about this