Search in sources :

Example 1 with Persist

use of water.persist.Persist in project h2o-3 by h2oai.

the class ModelsHandler method exportMojo.

public ModelExportV3 exportMojo(int version, ModelExportV3 mexport) {
    Model model = getFromDKV("model_id", mexport.model_id.key());
    try {
        // Really file, not dir
        URI targetUri = FileUtils.getURI(mexport.dir);
        Persist p = H2O.getPM().getPersistForURI(targetUri);
        OutputStream os = p.create(targetUri.toString(), mexport.force);
        ModelMojoWriter mojo = model.getMojo();
        mojo.writeTo(os);
        // Send back
        mexport.dir = "file".equals(targetUri.getScheme()) ? new File(targetUri).getCanonicalPath() : targetUri.toString();
    } catch (IOException e) {
        throw new H2OIllegalArgumentException("dir", "exportModel", e);
    }
    return mexport;
}
Also used : Model(hex.Model) MojoModel(hex.genmodel.MojoModel) ModelMojoWriter(hex.ModelMojoWriter) Persist(water.persist.Persist) URI(java.net.URI)

Example 2 with Persist

use of water.persist.Persist in project h2o-3 by h2oai.

the class ModelsHandler method importModel.

public ModelsV3 importModel(int version, ModelImportV3 mimport) {
    ModelsV3 s = Schema.newInstance(ModelsV3.class);
    try {
        URI targetUri = FileUtils.getURI(mimport.dir);
        Persist p = H2O.getPM().getPersistForURI(targetUri);
        InputStream is = p.open(targetUri.toString());
        final AutoBuffer ab = new AutoBuffer(is);
        ab.sourceName = targetUri.toString();
        Model model = (Model) Keyed.readAll(ab);
        s.models = new ModelSchemaV3[] { (ModelSchemaV3) SchemaServer.schema(version, model).fillFromImpl(model) };
    } catch (FSIOException e) {
        throw new H2OIllegalArgumentException("dir", "importModel", mimport.dir);
    }
    return s;
}
Also used : Model(hex.Model) MojoModel(hex.genmodel.MojoModel) Persist(water.persist.Persist) URI(java.net.URI)

Example 3 with Persist

use of water.persist.Persist in project h2o-3 by h2oai.

the class ModelsHandler method exportModel.

public ModelExportV3 exportModel(int version, ModelExportV3 mexport) {
    Model model = getFromDKV("model_id", mexport.model_id.key());
    try {
        // Really file, not dir
        URI targetUri = FileUtils.getURI(mexport.dir);
        Persist p = H2O.getPM().getPersistForURI(targetUri);
        OutputStream os = p.create(targetUri.toString(), mexport.force);
        model.writeAll(new AutoBuffer(os, true)).close();
        // Send back
        mexport.dir = "file".equals(targetUri.getScheme()) ? new File(targetUri).getCanonicalPath() : targetUri.toString();
    } catch (IOException e) {
        throw new H2OIllegalArgumentException("dir", "exportModel", e);
    }
    return mexport;
}
Also used : Model(hex.Model) MojoModel(hex.genmodel.MojoModel) Persist(water.persist.Persist) URI(java.net.URI)

Example 4 with Persist

use of water.persist.Persist in project h2o-3 by h2oai.

the class ModelsHandler method exportModelDetails.

public ModelExportV3 exportModelDetails(int version, ModelExportV3 mexport) {
    Model model = getFromDKV("model_id", mexport.model_id.key());
    try {
        // Really file, not dir
        URI targetUri = FileUtils.getURI(mexport.dir);
        Persist p = H2O.getPM().getPersistForURI(targetUri);
        //Make model schema before exporting
        ModelSchemaV3 modelSchema = (ModelSchemaV3) SchemaServer.schema(version, model).fillFromImpl(model);
        //Output model details to JSON
        OutputStream os = p.create(targetUri.toString(), mexport.force);
        os.write(modelSchema.writeJSON(new AutoBuffer()).buf());
        // Send back
        mexport.dir = "file".equals(targetUri.getScheme()) ? new File(targetUri).getCanonicalPath() : targetUri.toString();
    } catch (IOException e) {
        throw new H2OIllegalArgumentException("dir", "exportModelDetails", e);
    }
    return mexport;
}
Also used : Model(hex.Model) MojoModel(hex.genmodel.MojoModel) Persist(water.persist.Persist) URI(java.net.URI)

Aggregations

Model (hex.Model)4 MojoModel (hex.genmodel.MojoModel)4 URI (java.net.URI)4 Persist (water.persist.Persist)4 ModelMojoWriter (hex.ModelMojoWriter)1