1

I am trying to export the weights and biases of a "model" in which I did not originally train the model with "export_weights_and_biases = TRUE"

Therefore, I'd like to try to checkpoint the model and try to export_weights_and_biases = TRUE in a new "model2".

However, despite not changing any of the parameters - and ensuring that nfolds=10 just as in the original "model", the checkpoint model continues to return a parameter change error almost immediately (h2o version 3.10.4.6):

water.exceptions.H2OIllegalArgumentException: Cannot change parameter: '_nfolds': 10 -> 0

water.exceptions.H2OIllegalArgumentException: Cannot change parameter: '_nfolds': 10 -> 0
    at hex.deeplearning.DeepLearningModel$DeepLearningParameters$Sanity.checkIfParameterChangeAllowed(DeepLearningModel.java:2078)
    at hex.deeplearning.DeepLearning$DeepLearningDriver.buildModel(DeepLearning.java:249)
    at hex.deeplearning.DeepLearning$DeepLearningDriver.computeImpl(DeepLearning.java:211)
    at hex.ModelBuilder$Driver.compute2(ModelBuilder.java:169)
    at hex.deeplearning.DeepLearning$DeepLearningDriver.compute2(DeepLearning.java:204)
    at water.H2O$H2OCountedCompleter.compute(H2O.java:1241)
    at jsr166y.CountedCompleter.exec(CountedCompleter.java:468)
    at jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:263)
    at jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:974)
    at jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1477)
    at jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)

Error: water.exceptions.H2OIllegalArgumentException: Cannot change parameter: '_nfolds': 10 -> 0

Any ideas how to resolve this issue? All I'm trying to do is obtain all the weights and biases of my original "model".

Thank you!

ogukku
  • 53
  • 7

1 Answers1

1

I resolved this on my own:

1) Checkpoint can only be done if original model:

  • used no CV
  • or used CV but had fold assignment set to Modulo
  • and of course if other certain parameters are not changed such as nfolds.

2) Would still like to know how it would be possible to extract the weights and biases of my model if possible. Thank you.

ogukku
  • 53
  • 7
  • Assuming `model.dl` is a pointer to your deep learning model, you can do `model.dl@model$weights` and `model.dl@model$biases` to extract a list containing information about the weights and biases respectively. Then, loop through the list to extract the `name` attribute of the list (which returns the frame id) and use `h2o.getFrame()` to return the frame itself. – mauna Jun 03 '17 at 17:02
  • Thank you Mauna +1. Your solution works if I set export_weights_and_biases=TRUE which I did not do in my original model. Hence my attempt to checkpoint my model so I can set it = TRUE. However b/c I did not use Modulo CV, I'm unable to checkpoint. – ogukku Jun 03 '17 at 17:40
  • Any suggestion to extract weights and biases from a model in which the model's export_weights_and_biases argument was not set to TRUE? – ogukku Jun 03 '17 at 17:41
  • I can't think of any way other than re-training the model. Here's the idea: Use `h2o.loadModel()` to load the model into `model.dl`. Then you can use `model.dl@parameters` to get a list of the current parameters set and add set export_weights_and_biases to TRUE. Finally, use `do.call()` on `h2o.deeplearning()` and the updated list of parameters to retrain the model. – mauna Jun 03 '17 at 18:15
  • Thank you. I will give this a shot. While I have not tried do.call, I have tried to retrain new models with all the parameters, seed, and the dataset exactly as in the original model - but I'm unable to get h2o to reproduce a model with the same generalizability of the original model. In fact, all the retrained models have 100% failed miserably to generalize well - yet all models train, validate and test well. I think I was just lucky with my original model - and I really need to extract the weights and biases somehow. I've read it might be possible to do with POJO but I'm not certain. – ogukku Jun 03 '17 at 21:17
  • POJO gives you a java file. So you could download your original model as a POJO, open it in a text editor and copy paste the parts about the weights and biases. – mauna Jun 04 '17 at 01:17
  • Thank you, Mauna. For people at my level, you've been super helpful. I.e. "If you forget to export_weights_and_biases=true and your checkpoint fails you too, then POJO is for you." – ogukku Jun 04 '17 at 01:40
  • @ogukku Could you provide any additional info in your answer about where you found that information? Having similar problem and would like to read more about it. – lampShadesDrifter Dec 13 '17 at 20:26