blobcity / autoai

Python based framework for Automatic AI for Regression and Classification over numerical data. Performs model search, hyper-parameter tuning, and high-quality Jupyter Notebook code generation.
Apache License 2.0
175 stars 42 forks source link

Save and Load a Trained Model #20

Closed Thilakraj1998 closed 3 years ago

Thilakraj1998 commented 3 years ago

Add functionality to save and load a trained model by using pickle or Keras function for appropriate model type, i.e. either Sci-kit learn model or Tensorflow model .

file to refer : https://github.com/blobcity/autoai/blob/main/blobcity/store/Model.py

Add function save and load in the Model.py file Required functionality for save function:

  1. takes single string argument, which is path to save model, along with filename for example:

        save("path/filename")   
  2. If path not specified in argument, utilize default path and default name to save in working directory. And print/log of absolute path for the file.
  3. identify type of model saving strategy to use, i.e. whether use pickle or Keras to save model.

Required functionality for load function:

  1. takes single string argument, which is path of saved model file:

         load("path/filename.pkl")   or  load("path/filename.h5") 
  2. on the basis of file extension use appropriate loading strategy either pickle or Keras load functions
  3. return the model.
sreyan-ghosh commented 3 years ago

Hi, can you assign this to me, please?

I'm hoping a simple pickle.dumps('my_model.pkl') does the job. The final addition would look something like this:

def save(self, path_pref='./'):
  final_path = os.path.join(path_pref, 'my_model.pkl')
  pickle.dump(self.model, open(final_path, 'wb'))
  # print(final_path)
  return final_path

Is this fine?

aadityasinha-dotcom commented 3 years ago

Can I work on this issue?

sreyan-ghosh commented 3 years ago

Hi, I have updated my fork of this repo as per the changes made to the issue. I have done it using pickle and h5 files and also included type checking for Keras models in the case of .h5 files.

Also, a doubt, I don't see TensorFlow or Keras in the requirements.txt so how do we load the .h5 file? Should I add TensorFlow to the requirements.txt file?