Here is the simple test test I tried:
print(tf.keras._version_)
inputs = tf.keras.layers.Input(shape=(48, 48, 3))
x = tf.keras.layers.Conv2D(filters=64, kernel_size=(3, 3), strides=(2, 2), padding=‘valid’, activation=‘relu’, name=‘block1_conv1’)(inputs)
x = tf.keras.layers.MaxPool2D(pool_size=(2, 2), strides=(2, 2), name=‘block1_pool’)(x)
x = tf.keras.layers.Flatten(name=‘flatten’)(x)
x = tf.keras.layers.Dense(units=1024, activation=‘relu’, name=‘fc1’)(x)
outputs = tf.keras.layers.Dense(100, activation=‘softmax’, name=‘predictions’)(x)
model = tf.keras.Model(inputs=inputs, outputs=outputs, name=‘Simple’)
model.summary()
model.save(“Simple.h5”)
And the output:
Keras: 3.13.0
2026-01-16 06:49:51.010420: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 AVX_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
Model: “Simple”
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓
┃ Layer (type) ┃ Output Shape ┃ Param # ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩
│ input_layer (InputLayer) │ (None, 48, 48, 3) │ 0 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ block1_conv1 (Conv2D) │ (None, 23, 23, 64) │ 1,792 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ block1_pool (MaxPooling2D) │ (None, 11, 11, 64) │ 0 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ flatten (Flatten) │ (None, 7744) │ 0 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ fc1 (Dense) │ (None, 1024) │ 7,930,880 │
├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤
│ predictions (Dense) │ (None, 100) │ 102,500 │
└──────────────────────────────────────┴─────────────────────────────┴─────────────────┘
Total params: 8,035,172 (30.65 MB)
Trainable params: 8,035,172 (30.65 MB)
Non-trainable params: 0 (0.00 B)
WARNING:absl:You are saving your model as an HDF5 file via model.save() or keras.saving.save_model(model). This file format is considered legacy. We recommend using instead the native Keras format, e.g. model.save('my_model.keras') or keras.saving.save_model(model, 'my_model.keras').
The Java Code:
public class Main {
public static void main(String\[\] args) throws Exception {
String modelPath = "Simple.h5";
ComputationGraph model = KerasModelImport.importKerasModelAndWeights(modelPath, false);
model.init();
System.out.println(model.summary());
}
}