How to deploy mlflow model with data preprocessing(text data) - mlflow

I have developed keras text classification model. I have preprocessed data(tokenization). I have logged trained model successfully(mlflow.keras.log_model). I have served model using mlflow serve. Now while doing prediction on text data I need to do preprocessing using same tokenizer object used for training.
How to preprocess test data and get predictions from served model.

You can log a custom python model:
https://www.mlflow.org/docs/latest/models.html#custom-python-models

Related

Does mlflow support to save model to .h5?

I can input my Keras data (model, kappa, loss, epoch, ...) into MLflow now.
My original model is H5, but the model saved in MLflow under artifacts/model/data/model/saved_model.pb is PB.
Is it possible to save .h5 in MLflow?
You can save and log a model along with its parameters and metrics. Both preserve the Keras HDF5 format, as noted in MLflow Keras documentation.

export an unfitted model to ONNX

I am building an API for training models, and figured I wanted to use ONNX to send the models back and forth.
I am testing with a sklearn XGboost model, and it seems that it is a requirement to fit the model before I can export it to onnx.
I want to define a custom or standard sklearn model, convert to onnx for transport, reopen and train, save in ONNX
Is this feasable at all?
My end goal is to have an API that can accept any sklearn, tensorflow or similar model in an untrained state and then train on the server.
Onnx is used to deliver model results, including pre and post-processing or other manipulations, "in production".
The assumption is the model is already trained and you only need to "predict" (or whatever similar action) on new data.
Sound like what you need is a Python (or other) code that will receive your API calls, translate them into the appropriate models, train the models, and then, if you want to be independent from an MLOps point of view, transform the result into Onnx.

Is there a way to create and train a model without transfer learning using tensorflow object-detection api?

I'm using faster_rcnn_resnet50 to train a model which will detect corrosions in images and I want to train a model from scratch instead of using transfer learning.
I don't know if this right but the reason I want to do this is that the already existing weights (which are trained on COCO) will affect my model trained on corrosion images.
One way I would like to do this is randomize or unfreeze the weights of the feature extractor on the resnet50 and then train the model on my images.
but there's no function or an option in the resnet50 config file to randomize or unfreeze weights.
I've made a new labelmap with a single label and tried it with transfer learning. It's working but I would like to have a model is trained just on my images and the previous weights shouldn't affect my predictions.
This is the first time I'm working with object detection and transfer learning. Will the weights of the pre-trained model on COCO affect my model which is trained on custom images of corrosion? How do you use tensorflow object-detection API without transfer learning?

LSTM model weights to train data for text classification

I built a LSTM model for text classification using Keras. Now I have new data to be trained. instead of appending to the original data and retrain the model, I thought of training the data using the model weights. i.e. making the weights to get trained with the new data.
However, irrespective of the volume i train, the model is not predicting the correct classification (even if i give the same sentence for prediction). What could be the reason?
Kindly help me.
Are you using the following to save the trained model?
model.save('model.h5')
model.save_weights('model_weights.h5')
And the following to load it?
from keras.models import load_model
model = load_model('model.h5') # Load the architecture
model = model.load_weights('model_weights.h5') # Set the weights
# train on new data
model.compile...
model.fit...
The model loaded is the exact same as the model being saved here. If you are doing this, then there must be something different in the data (in comparison with what it is trained on).

Keras Embedding Layer

I am using Keras newsgroup example code for text classification. I have saved the trained model using the h5py library. Will the embedding layer also get saved or should I write some extra code when loading the model to use the embedding layer?
Embedding layer is part of the model so it will be saved with the model. Check out this on saving the model.
Also one important addition, the Keras Embedding layer will be initialized with the random values at the very start of the training process, and the parameters will be learned in the training phase.

Resources