pliers.extractors.TFHubExtractor

class pliers.extractors.TFHubExtractor(url_or_path, features=None, transform_out=None, transform_inp=None, output_key=None, keras_kwargs=None)[source]

Bases: Extractor

A generic class for Tensorflow Hub extractors :param url_or_path: url or path to TFHub model. You can

browse models at https://tfhub.dev/.

Parameters
  • features (optional) –

    list of feature names matching output dimensions

    For example, for a classification model with 1000 output classes this must be a list containing 1000 items. (e.g. EfficientNet B6, https://tfhub.dev/tensorflow/efficientnet/b6/classification/1),

    Alternatively, the model output can be packed into a single feature (i.e. a vector) by passing a single-element list or a string. For example, for a model that outputs a 768-dimensional encoding, the value ‘encoding’ will result in a 1-d array wrapped in a list named ‘encoding’.

    If no value is passed, the extractor will automatically compute the number of features in the model output and return an equal number of features in pliers, labeling each feature with a generic prefix + its positional index in the model output (feature_0, feature_1, … ,feature_n).

    Note that for saved models, the feature names are inferred from the output signature, but can be over-ridden.

  • transform_out (optional) – function to transform model output for compatibility with extractor result

  • transform_inp (optional) – function to transform Stim.data for compatibility with model input format

  • output_key (str) – key to desired in output in dictionary. Set to None if the output is not a dictionary, or to output all keys in dictionary.

  • keras_kwargs (dict) – arguments to hub.KerasLayer call

__init__(url_or_path, features=None, transform_out=None, transform_inp=None, output_key=None, keras_kwargs=None)[source]
transform(stim, *args, **kwargs)

Executes the transformation on the passed stim(s).

Parameters
  • stims (str, Stim, list) –

    One or more stimuli to process. Must be one of:

    • A string giving the path to a file that can be read in as a Stim (e.g., a .txt file, .jpg image, etc.)

    • A Stim instance of any type.

    • An iterable of stims, where each element is either a string or a Stim.

  • validation (str) –

    String specifying how validation errors should be handled. Must be one of:

    • ’strict’: Raise an exception on any validation error

    • ’warn’: Issue a warning for all validation errors

    • ’loose’: Silently ignore all validation errors

  • args – Optional positional arguments to pass onto the internal _transform call.

  • kwargs – Optional positional arguments to pass onto the internal _transform call.