Esempio n. 1
0
    def extract_features(
        self,
        features: features_lib.FeatureConnector,
    ) -> features_lib.FeatureConnector:
        """Returns the `tfds.features.FeaturesDict`.

    Extract the subset of features

    Args:
      features: Features on which extract the sub-set

    Returns:
      features_subset: A subset of the features
    """
        with utils.try_reraise(
                'Provided PartialDecoding specs does not match actual features: '
        ):

            # Convert non-features into features
            expected_feature = _normalize_feature_item(
                feature=features,
                expected_feature=self._feature_specs,
            )
            # Get the intersection of `features` and `expected_feature`
            return _extract_features(
                feature=features,
                expected_feature=features_dict.to_feature(expected_feature),
            )
    def __init__(self, feature, length=None, **kwargs):
        """Construct a sequence dict.

    Args:
      feature: `dict`, the features to wrap
      length: `int`, length of the sequence if static and known in advance
      **kwargs: `dict`, constructor kwargs of `tfds.features.FeaturesDict`
    """
        # Convert {} => FeaturesDict, tf.int32 => Tensor(shape=(), dtype=tf.int32)
        self._feature = features_dict.to_feature(feature)
        self._length = length
        super(Sequence, self).__init__(**kwargs)
Esempio n. 3
0
    def __init__(
        self,
        feature: feature_lib.FeatureConnectorArg,
        length: Optional[int] = None,
    ):
        """Construct a sequence dict.

    Args:
      feature: The features to wrap (any feature supported)
      length: `int`, length of the sequence if static and known in advance
    """
        # Convert {} => FeaturesDict, tf.int32 => Tensor(shape=(), dtype=tf.int32)
        self._feature = features_dict.to_feature(feature)
        self._length = length
        super(Sequence, self).__init__()