0

Currently I am loading a previously trained model using

with tf.Session() as sess:
    saver.restore(sess, tf.train.latest_checkpoint('./'))

which loads the file recorded in the file "checkpoint" that was created when saving the model. However, the file "checkpoint" always refers to the last trained model, so if I want to load another model I have to manually edit the "checkpoint" file to change the model name.

My question is, how can I restore a trained model different from the last one I created, without manually editing the "checkpoint" file?

Miguel
  • 356
  • 1
  • 15

1 Answers1

2

You can use jsonpickle to save variables and models and later load them. For example:

sklearn_model = RandomForestClassifier()
sklearn_model.fit(x,y)
model_object = jsonpickle.pickler.Pickler.flatten(sklearn_model)
model = jsonpickle.unpickler.Unpickler.restore(model_object)
model.predict(new_x)

All you need now is to save the model whenever you want, and load it as needed. the model_object is a JSON code that can be saved to a file. You can read more about the package here

Roee Anuar
  • 3,071
  • 1
  • 19
  • 33