<jupyter_start><jupyter_text>Load New Image to Test Accuracy Save and Load models<jupyter_code>import numpy as np
import tensorflow as tf
from tensorflow import keras
def get_model():
    # Create a simple model.
    inputs = keras.Input(shape=(32,))
    outputs = keras.layers.Dense(1)(inputs)
    model = keras.Model(inputs, outputs)
    model.compile(optimizer="adam", loss="mean_squared_error")
    return model
model = get_model()

# Train the model.
test_input = np.random.random((128, 32))
test_target = np.random.random((128, 1))
model.fit(test_input, test_target)
# Calling `save('my_model')` creates a SavedModel folder `my_model`.
model.save("my_model.h5")
# It can be used to reconstruct the model identically.
reconstructed_model = keras.models.load_model("my_model.h5")
# Let's check:
np.testing.assert_allclose(
    model.predict(test_input), reconstructed_model.predict(test_input)
)

# The reconstructed model is already compiled and has retained the optimizer
# state, so training can resume:
reconstructed_model.fit(test_input, test_target)<jupyter_output>4/4 [==============================] - 0s 0s/step - loss: 1.1875
StarcoderdataJupyterStructuredCleanDedup