Open matt7salomon opened 3 days ago
@matt7salomon : You can use our DAI tools which will allow you to generate pytorch models: https://www.google.com/search?client=safari&rls=en&q=h2o+Driverless+AI&ie=UTF-8&oe=UTF-8 . Currently, we don't support pytorch on our opensource platform.
Thanks but my code seem to be able to get the structure transferred from h2o to pytroch and not the weights and biases but i dont need those. I am trying to train in torch again using the same structure and same parameters. I should be able to get all the model info from h2o connection.
@matt7salomon : Sorry I misunderstood your question.
To get the weight and biases exposed to the returned model, you need to set the parameter export_weights_and_biases=True like this:
dlmodel = H2ODeepLearningEstimator(hidden=[17,191], epochs=1, balance_classes=False, reproducible=True, seed=1234, export_weights_and_biases=True)
The weights and biases will come back as H2O frames. Here is an example of this:
==================================================================== covtype = h2o.upload_file(pyunit_utils.locate("smalldata/covtype/covtype.20k.data")) covtype[54] = covtype[54].asfactor()
dlmodel = H2ODeepLearningEstimator(hidden=[17,191], epochs=1, balance_classes=False, reproducible=True, seed=1234, export_weights_and_biases=True) dlmodel.train(x=list(range(54)),y=54,training_frame=covtype) print(dlmodel)
weights1 = dlmodel.weights(0) weights2 = dlmodel.weights(1) weights3 = dlmodel.weights(2)
biases1 = dlmodel.biases(0) biases2 = dlmodel.biases(1) biases3 = dlmodel.biases(2)
w1c = weights1.ncol w1r = weights1.nrow assert w1c == 52, "wrong dimensionality! expected {0}, but got {1}.".format(52, w1c) assert w1r == 17, "wrong dimensionality! expected {0}, but got {1}.".format(17, w1r)
w2c = weights2.ncol w2r = weights2.nrow assert w2c == 17, "wrong dimensionality! expected {0}, but got {1}.".format(17, w2c) assert w2r == 191, "wrong dimensionality! expected {0}, but got {1}.".format(191, w2r)
w3c = weights3.ncol w3r = weights3.nrow assert w3c == 191, "wrong dimensionality! expected {0}, but got {1}.".format(191, w3c) assert w3r == 7, "wrong dimensionality! expected {0}, but got {1}.".format(7, w3r)
b1c = biases1.ncol b1r = biases1.nrow assert b1c == 1, "wrong dimensionality! expected {0}, but got {1}.".format(1, b1c) assert b1r == 17, "wrong dimensionality! expected {0}, but got {1}.".format(17, b1r)
b2c = biases2.ncol b2r = biases2.nrow assert b2c == 1, "wrong dimensionality! expected {0}, but got {1}.".format(1, b2c) assert b2r == 191, "wrong dimensionality! expected {0}, but got {1}.".format(191, b2r)
b3c = biases3.ncol b3r = biases3.nrow assert b3c == 1, "wrong dimensionality! expected {0}, but got {1}.".format(1, b3c) assert b3r == 7, "wrong dimensionality! expected {0}, but got {1}.".format(7, b3r)
If you already have your model trained without setting that parameter, you can still get the weights and biases via mojo. Here is an example of how to do that:
assumed that you have model:
The model_mojo will be a zip file. Unzip the file and you will find the weights and biases information in the file model.ini.
Here is an example of my model.ini
My organization only allows pytroch models to go into production. I wrote the following code to convert my trained h2o model into pytorch but it errors out.
Here is my h2o mode summary: