Here are trained how to save and load model AI, machine learning and depth into learn two differ slightly, because the depth of learning you want to save the entire network structure, slightly different
1. machine learning models use a way to preserve the python comes with pickle
import pickle
f = open('saved_model/rfc.pickle','wb') pickle.dump (rfc, f) # 1 is a trained model parameters f.close() #load model f = open('saved_model/rfc.pickle','rb') rfc1 = pickle.load(f) f.close()
2. Second way to save machine learning models using sklearn modules joblib
from sklearn.externals import joblib joblib.dump(rfc, 'saved_model/rfc.pkl') #load model rfc2 = joblib.load('saved_model/rfc.pkl')
3.tensorflow way to preserve the depth learning model
Save =========== model save_file = './model.ckpt' saver = tf.train.Saver() saver.save(sess, save_file) Model loads =========== saver = tf.train.Saver() with tf.Session() as sess: # Load the weights and bias # Load weights and bias term saver.restore(sess, save_file)