Sequential Model
Importing Keras Sequential models as MultiLayerNetwork
Importing Keras Sequential Models
Define a Sequential Model in Keras
from keras.models import Sequential
from keras.layers import Dense
model = Sequential()
model.add(Dense(units=64, activation='relu', input_dim=100))
model.add(Dense(units=10, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])Saving the Model
# Option 1: Save full model — architecture, weights, and training config
model.save('full_model.h5')
# Option 2: Save architecture as JSON
model_json = model.to_json()
with open("model_config.json", "w") as f:
f.write(model_json)
# Option 3: Save weights only
model.save_weights('model_weights.h5')Loading the Model in Java
Load Full Model (Recommended)
Load from Separate Config and Weights Files
Load Configuration Only
Running Inference
Training After Import
KerasSequentialModel API Reference
KerasSequentialModel
Example: CNN for Image Classification
Example: LSTM for Sequence Classification
Troubleshooting
Last updated
Was this helpful?