Starting November 15th, links to tfhub.dev will redirect to their counterparts on Kaggle Models.
Benefits of Kaggle Models Repository
We’re excited to join the Kaggle community, giving ML developers and learners even more opportunities to experiment and develop ML models in real-world use-cases. Users and developers will benefit from:
A broader, framework-agnostic model collection
Comments and feedback from the community
Better user interface, control over your user profile, and improved model usage statistics
Although no migration or code rewrites are explicitly required, we recommend replacing tfhub.dev links with their Kaggle Models counterparts before November 15th to improve code health and debuggability.
Publishing Models
How to join Early Access Model Publishing (EAP) on Kaggle Models:
Hi @lgusm
I’ve several tf.keras model in SavedFormat, uploaded in kaggle-dataset, for example. Now, if I move them ot kaggle-model, would it be possible to load the model from tf.hub API?
Hi @lgusm, I’ve published a model in kaggle-model hub, with various checkpoints i.e. TensorFlow (Keras V2), Keras V3, TFLite and ONNX; link here. With TensorFlow (Keras V2) checkpoints, I could sucessfully load SavedModel as follows
import tensorflow as tf
import tensorflow_hub as hub
keras_model = hub.KerasLayer(
"/kaggle/input/videoswin/tensorflow2/tiny/1/saved_model"
)
model = keras.Sequential(keras_model)
model(np.ones(shape=(1, 32, 224, 224, 3))) # OK
However, there are some potential issue
Would it be possible to load Keras V3 checkponts (.keras format) with hub.KerasLayer API?
With Keras V3, the following imports fails
import os
os.environ["KERAS_BACKEND"] = "tensorflow" # 'torch, 'jax'
import torch
import tensorflow as tf
import tensorflow_hub as hub
import keras
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[3], line 6
4 import torch
5 import tensorflow as tf
----> 6 import tensorflow_hub as hub
7 import keras
File /opt/conda/lib/python3.10/site-packages/tensorflow_estimator/python/estimator/canned/optimizers.py:35
24 import tensorflow as tf
26 _OPTIMIZER_CLS_NAMES = {
27 'Adagrad': tf.compat.v1.train.AdagradOptimizer,
28 'Adam': tf.compat.v1.train.AdamOptimizer,
(...)
31 'SGD': tf.compat.v1.train.GradientDescentOptimizer,
32 }
34 _OPTIMIZER_CLS_NAMES_V2 = {
---> 35 'Adagrad': tf.keras.optimizers.legacy.Adagrad,
36 'Adam': tf.keras.optimizers.legacy.Adam,
37 'Ftrl': tf.keras.optimizers.legacy.Ftrl,
38 'RMSProp': tf.keras.optimizers.legacy.RMSprop,
39 'SGD': tf.keras.optimizers.legacy.SGD,
40 }
42 # The default learning rate of 0.05 is a historical artifact of the initial
43 # implementation, but seems a reasonable choice.
44 _LEARNING_RATE = 0.05
----> 3 from keras.src.backend import _initialize_variables as initialize_variables
4 from keras.src.backend import track_variable
ImportError: cannot import name '_initialize_variables' from 'keras.src.backend' (/opt/conda/lib/python3.10/site-packages/keras/src/backend/__init__.py)