use of org.apache.ignite.ml.inference.storage.model.ModelStorageFactory in project ignite by apache.
the class IgniteModelStorageUtil method saveModelEntity.
/**
* Saves specified serialized model into storage as a file.
*
* @param ignite Ignite instance.
* @param serializedMdl Serialized model represented as a byte array.
* @param mdlId Model identifier.
*/
private static void saveModelEntity(Ignite ignite, byte[] serializedMdl, UUID mdlId) {
ModelStorage storage = new ModelStorageFactory().getModelStorage(ignite);
storage.mkdirs(IGNITE_MDL_FOLDER);
storage.putFile(IGNITE_MDL_FOLDER + "/" + mdlId, serializedMdl, true);
}
use of org.apache.ignite.ml.inference.storage.model.ModelStorageFactory in project ignite by apache.
the class IgniteModelStorageUtil method removeModelEntity.
/**
* Removes model with specified identifier from model storage.
*
* @param ignite Ignite instance.
* @param mdlId Model identifier.
*/
private static void removeModelEntity(Ignite ignite, UUID mdlId) {
ModelStorage storage = new ModelStorageFactory().getModelStorage(ignite);
storage.remove(IGNITE_MDL_FOLDER + "/" + mdlId);
}
use of org.apache.ignite.ml.inference.storage.model.ModelStorageFactory in project ignite by apache.
the class ModelStorageExample method main.
/**
* Run example.
*/
public static void main(String... args) throws IOException, ClassNotFoundException {
try (Ignite ignite = Ignition.start("examples/config/example-ignite-ml.xml")) {
System.out.println(">>> Ignite grid started.");
ModelStorage storage = new ModelStorageFactory().getModelStorage(ignite);
ModelDescriptorStorage descStorage = new ModelDescriptorStorageFactory().getModelDescriptorStorage(ignite);
System.out.println("Saving model into model storage...");
byte[] mdl = serialize((IgniteModel<byte[], byte[]>) i -> i);
storage.mkdirs("/");
storage.putFile("/my_model", mdl);
System.out.println("Saving model descriptor into model descriptor storage...");
ModelDescriptor desc = new ModelDescriptor("MyModel", "My Cool Model", new ModelSignature("", "", ""), new ModelStorageModelReader("/my_model"), new IgniteModelParser<>());
descStorage.put("my_model", desc);
System.out.println("List saved models...");
for (IgniteBiTuple<String, ModelDescriptor> model : descStorage) System.out.println("-> {'" + model.getKey() + "' : " + model.getValue() + "}");
System.out.println("Load saved model descriptor...");
desc = descStorage.get("my_model");
System.out.println("Build inference model...");
SingleModelBuilder mdlBuilder = new SingleModelBuilder();
try (Model<byte[], byte[]> infMdl = mdlBuilder.build(desc.getReader(), desc.getParser())) {
System.out.println("Make inference...");
for (int i = 0; i < 10; i++) {
Integer res = deserialize(infMdl.predict(serialize(i)));
System.out.println(i + " -> " + res);
}
}
} finally {
System.out.flush();
}
}
Aggregations