Comments (3)
One potential solution I've found is to manage the TrackableResources
directly myself.
Consider the following code:
prev_model = loaded_model
loaded_model = tf.saved_model.load("/tmp/test-model")
if prev_model:
lookups = filter(None, [
layer._trackable_children().get('lookup_table') if hasattr(layer, '_trackable_children') else None
for layer in prev_model._trackable_children().values()
])
for lookup in lookups:
tf.raw_ops.DestroyResourceOp(resource=lookup.resource_handle)
del prev_model
Doing that after reloading appears to clear the resources as expected and not cause memory to grow indefinitely.
from tf-keras.
For any future readers. V2:
def wipeit(model):
def _give_handles(m):
if hasattr(m, 'resource_handle'):
yield m.resource_handle
children = {}
try:
children = m._trackable_children()
except:
pass
for child in children.values():
yield from _give_handles(child)
for handle in _give_handles(model):
tf.raw_ops.DestroyResourceOp(resource=handle)
...
# during model load, after its loaded
prev_model = loaded_model
loaded_model = tf.saved_model.load(...)
if prev_model:
wipeit(prev_model)
del prev_model
from tf-keras.
@cjmcgraw thanks for filing the issue. This issues seems to be related to TF. This behavior can be reproduced without using any keras APIs. You can just use a lookup table and save and load the model -- the behavior would be the same.
from tf-keras.
Related Issues (20)
- Error while importing tf_keras HOT 11
- shape issue for y_pred for a custom made loss function HOT 3
- UNIMPLEMENTED: Cast string to float is not supported; CANCELLED: Function was cancelled before it was started HOT 3
- TextVectorization: output_mode={multi_hot, count} promise int arrays but output floats
- Cloning a TextVectorization Layer with Split Function Doesn't Work HOT 6
- Mirrored strategy model.load_weights() failure HOT 2
- sparse_categorical_crossentropy with ignore_class=-1 makes loss to `nan` HOT 3
- Importing `tf_keras` to use Keras 2 in TensorFlow 2.16 fails HOT 9
- Addition of Reflect Padding Functionality for tf.keras Convolutional Layers HOT 2
- AttributeError: module 'tf_keras.backend' has no attribute 'logsumexp' HOT 6
- Custom Keras RNN with constants changes constants shape when saving HOT 3
- ValueError: (F1Score|FBetaScore) expects 2D inputs with shape (batch_size, output_dim). HOT 8
- LSTM - different outputs for same weights across CPU and GPU, when using float32 + tf-keras + NVIDIA A100 HOT 4
- RetinaNet with custom backbone and custom dataset HOT 3
- IntegerLookup with XLA Compilation Fails to Enable JIT in TensorFlow 2.16.1 and Keras 3.2.1 HOT 3
- conda-forge release HOT 1
- Failed to build Python package due to missing layer/experimental build HOT 2
- TF-Keras mixed precision training leads to autograph errors HOT 4
- Showing warning just after importing tf_keras HOT 2
- Error loading the trained model. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tf-keras.