@@ -336,33 +336,24 @@ def save_weights(self, filepath, overwrite=True, max_shard_size=None):
336
336
Example:
337
337
338
338
```python
339
- # Create a big model with about 272MB of weights.
340
- model = keras.Sequential()
341
- model.add(keras.Input(shape=(1024,)))
342
- for _ in range(5):
343
- model.add(keras.layers.Dense(4096))
339
+ # Instantiate a EfficientNetV2L model with about 454MB of weights.
340
+ model = keras.applications.EfficientNetV2L(weights=None)
344
341
345
342
# Save the weights in a single file.
346
343
model.save_weights("model.weights.h5")
347
344
348
- # Save the weights in sharded files. Use `max_shard_size=0.1 ` means each
349
- # sharded file will be at most ~100MB .
350
- model.save_weights("model.weights.json", max_shard_size=0.1 )
345
+ # Save the weights in sharded files. Use `max_shard_size=0.25 ` means
346
+ # each sharded file will be at most ~250MB .
347
+ model.save_weights("model.weights.json", max_shard_size=0.25 )
351
348
352
349
# Load the weights in a new model with the same architecture.
353
- loaded_model = keras.Sequential()
354
- loaded_model.add(keras.Input(shape=(1024,)))
355
- for _ in range(5):
356
- loaded_model.add(keras.layers.Dense(4096))
350
+ loaded_model = keras.applications.EfficientNetV2L(weights=None)
357
351
loaded_model.load_weights("model.weights.h5")
358
352
x = keras.random.uniform((1, 1024))
359
353
assert np.allclose(model.predict(x), loaded_model.predict(x))
360
354
361
355
# Load the sharded weights in a new model with the same architecture.
362
- loaded_model = keras.Sequential()
363
- loaded_model.add(keras.Input(shape=(1024,)))
364
- for _ in range(5):
365
- loaded_model.add(keras.layers.Dense(4096))
356
+ loaded_model = keras.applications.EfficientNetV2L(weights=None)
366
357
loaded_model.load_weights("model.weights.json")
367
358
x = keras.random.uniform((1, 1024))
368
359
assert np.allclose(model.predict(x), loaded_model.predict(x))
0 commit comments