0
$\begingroup$

I have a basic question that I can't seem to find an answer to.

I built and trained with good results (above 90% accuracy) a NLP Log classifier that takes in a UTF-8 payload and classifies it into 32 distinct categories but I am having a hard time writing a simple script that loads all the necessary info from my training and testing session (model.h5 and ?).

This is the structure of my code.

# load data logs and split it 80-20 for training and testing
vocab_size = 500
tokenizer = text.Tokenizer(num_words=vocab_size)
tokenize.fit_to_text(trainRawLogs)
x_train = tokenize.text_to_matrix(trainRawLogs)
x_test = tokenize.text_to_matrix(testRawLogs)

encoder = labelBinarizer()
encoder.fit(trainRawLogs)

#Model build is simple ReLu - Softmax

model.compile..

model.fit..

model.evaluate..

Now here is my question.

Out of all of this process what do I need to save to build a lightweight classifier? The model? The model and the labels? Anything else? I tried loading the model

$\endgroup$
1
$\begingroup$

In keras you have the option to save the entire model state including the optimizer parameters or simply the model weights. In the first case all you need to do is:

model.save(model_path)  
model = load_model(model_path)  

In the second case you have to first create your model and then load the weights:

model.save_weights(model_weight_path)  

In case model is not already specified:

model = Sequential()  
model.add()  
...  

model.load_weights(model_weight_path)

https://keras.io/getting-started/faq/#how-can-i-save-a-keras-model

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.