首页 文章

持久化h2o mojo时出错(版本3.20.0.1)

提问于
浏览
0

我一直有问题坚持使用最新的h2o发布mojos . 该代码已适用于旧版本(3.10)

这是一个抛出的示例代码和异常 .

public static Schema[] getAllSchemas() {
        ServiceLoader<Schema> schemaLoader = 
        ServiceLoader.load(Schema.class);
        List<Schema> allSchemas = new ArrayList<>();
        for (Schema schema : schemaLoader) {
            allSchemas.add(schema);
        }
        return allSchemas.toArray(new Schema[allSchemas.size()]);
   }

   public static byte[] extractIce(Model model) throws IOException {
       final UUID uuid = UUID.randomUUID();
       String tempFile = "/tmp/" + uuid;
       model.exportMojo(tempFile, true);
       final byte[] bytes = IOUtils.toByteArray(new 
                                   FileInputStream(tempFile)); 
       return bytes; 
    }


   public static void main (String []args) {
      H2OApp.main();
      SchemaServer.registerAllSchemasIfNecessary(getAllSchemas());
      // get the model that needs to be persisted
      // Model model = getH2OModel();
      byte[] extractIce(model);
   }

这是被抛出的例外 .

Caused by: java.lang.IllegalArgumentException: Cannot find Builder for algo url name drf
   at hex.ModelBuilder.ensureBuilderIndex(ModelBuilder.java:141) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at hex.ModelBuilder.havePojo(ModelBuilder.java:120) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at hex.Model.havePojo(Model.java:118) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at water.api.schemas3.ModelSchemaV3.fillFromImpl(ModelSchemaV3.java:73) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at water.api.schemas3.ModelSchemaV3.fillFromImpl(ModelSchemaV3.java:21) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at hex.ModelMojoWriter.writeModelDetails(ModelMojoWriter.java:277) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at hex.ModelMojoWriter.writeTo(ModelMojoWriter.java:178) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at hex.ModelMojoWriter.writeTo(ModelMojoWriter.java:169) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at hex.ModelMojoWriter.writeTo(ModelMojoWriter.java:161) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]

1 回答

  • 0

    以防万一有人遇到同样的问题 . 在H2OApp启动后立即调用以下方法(registerSchemasAndAlgos),我能够坚持mojos .

    import hex.api.RegisterAlgos;
    import water.api.RequestServer;
    import water.api.Schema;
    import water.api.SchemaServer;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.ServiceLoader;
    
    public void registerSchemasAndAlgos() {
        // schemas
        SchemaServer.registerAllSchemasIfNecessary(getAllSchemas());
    
        // algos
        RegisterAlgos algos = new RegisterAlgos();
        algos.registerEndPoints(new RequestServer.DummyRestApiContext());
    }
    
    public void registerAlgos() {
        RegisterAlgos algos = new RegisterAlgos();
        algos.registerEndPoints(new RequestServer.DummyRestApiContext());
    }
    
    public Schema[] getAllSchemas() {
        ServiceLoader<Schema> schemaLoader = ServiceLoader.load(Schema.class);
        List<Schema> allSchemas = new ArrayList<>();
        for (Schema schema : schemaLoader) {
            allSchemas.add(schema);
        }
        return allSchemas.toArray(new Schema[allSchemas.size()]);
    }
    

相关问题