Save the date! Google I/O returns May 18-20 Register now

hub.load

Resolves a handle and loads the resulting module.

Used in the notebooks

Used in the tutorials

This is the preferred API to load a Hub module in low-level TensorFlow 2. Users of higher-level frameworks like Keras should use the framework's corresponding wrapper, like hub.KerasLayer.

This function is roughly equivalent to the TF2 function tf.saved_model.load() on the result of hub.resolve(handle). Calling this function requires TF 1.14 or newer. It can be called both in eager and graph mode.

This function can handle the deprecated TF1 Hub format to the extent that tf.saved_model.load() in TF2 does. In particular, the returned object has attributes

  • .variables: a list of variables from the loaded object;
  • .signatures: a dict of TF2 ConcreteFunctions, keyed by signature names, that take tensor kwargs and return a tensor dict. However, the information imported by hub.Module into the collections of a tf.Graph is lost (e.g., regularization losses and update ops).

handle (string) the Module handle to resolve; see hub.resolve().
tags A set of strings specifying the graph variant to use, if loading from a v1 module.
options Optional, tf.saved_model.LoadOptions object that specifies options for loading. This argument can only be used from TensorFlow 2.3 onwards.

A trackable object (see tf.saved_model.load() documentation for details).

NotImplementedError If the code is running against incompatible (1.x) version of TF.