THE FILE FIELD GUIDE
.keras

Keras Model

AI & Machine Learning

KERAS 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.

Identify the purpose and distribution

Distinguish whole-model saves from weights-only files.

  1. Read the publisher instructions and license; record the producer, version and purpose.
  2. Check the Keras version, backend and custom layers in the producer documentation.
  3. Retain the original and assemble configuration and companions in a working copy.
Inspect with the matching environment

Successful loading and correct inference are separate checks.

  1. Prepare the trusted model and required registered custom objects in a compatible Keras environment.
  2. Keep safe_mode enabled and decide whether compilation is needed for the intended use.
  3. Inspect the restored input shape and layers.
Test with a known input

Match the input contract and compare with a reference.

  1. Prepare known input with the model’s preprocessing and compare inference output.
  2. For training resumption, inspect optimizer, loss, metrics and restart conditions.
  3. Check cross-environment predictions within an appropriate numerical tolerance.

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

  1. Load in a matching environment and inspect architecture/I/O.
  2. Use supported export/weight saving and compare outputs with the source.
  3. 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

Related-format differences
FormatMain roleWhat to check
KERASWhole-model saveCustom definitions/backend
weights.h5Weights-only storageRequires matching architecture
TFLITEOn-device inferenceDifferent 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: