Skip to content

Save Method

Functions

save(self, filename)

Save the Sequential model to a file.

Parameters:

Name Type Description Default
filename str

Path where the model should be saved.

required
Example
model.save('my_model.json')
Source code in microkeras/models/sequential/save.py
def save(self, filename):
    """
    Save the Sequential model to a file.

    Args:
        filename (str): Path where the model should be saved.

    Example:
        ```python
        model.save('my_model.json')
        ```
    """
    model_data = {
        'layers': []
    }
    for layer in self.layers:
        layer_data = {
            'type': 'Dense',
            'units': layer.units,
            'activation': layer.activation,
            'input_shape': layer.input_shape,
            'weights': layer.W.tolist(),
            'biases': layer.b.tolist()
        }
        model_data['layers'].append(layer_data)

    with open(filename, 'w') as f:
        json.dump(model_data, f)