Keras Model
AI & Machine LearningKERAS saves a Keras whole model, including configuration/weights and potentially training state. Custom layers/functions may need their definitions and a compatible Keras environment.
- What it is used for
- Combined model configuration and weight storage
- What the file contains
- Binary data
All sections, questions and sources
Content reviewed: · Editor:Kai
Opening steps
Choose your environment or purpose to see its steps.
Menu labels and support vary by app, OS and version. Preserve the original before making changes.
Troubleshooting by symptom
- Unknown custom layer: obtain trusted definitions/registration instructions.
- Version/backend mismatch: compare producer environment and operator support.
- Safe loading rejects it: investigate instead of blindly disabling safe_mode.
- Custom-layer identity error: match trusted definitions and registered names.
- Compilation-related failure: choose settings appropriate to inference or training resumption.
- Changing backend fails: inspect custom-operation portability.
KERAS → inference export / weights
- Load in a matching environment and inspect architecture/I/O.
- Use supported export/weight saving and compare outputs with the source.
- Compare output shapes, values and timing with the same input before/after export; retain definitions and export settings.
Weights-only files omit architecture; inference exports may omit training-resumption state.
Handling custom objects
Names alone do not ensure identical custom behavior; obtain trusted implementations and versions together.
Ask the producer for a compatible save method before weakening protections to deserialize unknown code.
Source for these steps:Keras Project · Whole model saving & loading / Keras Project · Weights-only saving & loading
Checking model reproducibility
Record model, preprocessing, labels and backend versions together; input processing can change predictions despite identical weights.
Inference validation differs from continuing training; verify that the necessary optimizer and other state was saved.
Source for these steps:Keras Project · Whole model saving & loading / Keras Project · Weights-only saving & loading
Related-format differences
| Format | Main role | What to check |
|---|---|---|
| KERAS | Whole-model save | Custom definitions/backend |
| weights.h5 | Weights-only storage | Requires matching architecture |
| TFLITE | On-device inference | Different purpose from training serialization |
Handling and security
safe_mode is not a universal security guarantee. Verify model/custom-code origin and avoid running unknown code to satisfy loading.
Questions and answers
Can training always resume?
Check stored state and environment compatibility.
Are custom layers automatically available?
Definitions/registration may still be needed.
Should I disable safe_mode?
Do not disable it for unknown models; investigate provenance/cause.
Does compile=False remove the weights?
It skips compilation during loading; verify training setup separately.
Does safe_mode=True guarantee safety?
It chiefly restricts unsafe lambda deserialization; provenance and custom code still matter.
Format facts: name, steward and MIME type
- Formal name
- Keras whole-model saving format
- Steward / specification
- Keras Project
- MIME type
- Depends on the producer or server; an extension alone does not establish a MIME type.
Primary and official sources
- Project documentationWhole model saving & loading
Documents whole-model storage, custom objects and safe mode.
Keras Project · Link checked: - Project documentationWeights-only saving & loading
Distinguishes weights-only storage from whole models.
Keras Project · Link checked: