Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow list of lists in converter #6373

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions tfx/components/example_gen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def pyval_to_feature(pyval: List[Any]) -> feature_pb2.Feature:
value=[v.encode(_DEFAULT_ENCODING) for v in pyval]
)
)
elif isinstance(pyval[0], list) and isinstance(pyval[0][0], (int, float, str)):
return feature_pb2.FeatureList(
feature=[pyval_to_feature(sublist) for sublist in pyval]
)
raise RuntimeError(
f'Value type {type(pyval[0])} is not supported.'
)
Expand Down Expand Up @@ -128,8 +132,22 @@ def dict_to_example(instance: Dict[str, Any]) -> example_pb2.Example:
feature[key] = pyval_to_feature(pyval)
else:
raise RuntimeError(f'Value type {type(value[0])} is not supported.')

return example_pb2.Example(features=feature_pb2.Features(feature=feature))

feature_lists = {
k:v for k,v in feature.items()
if isinstance(v, feature_pb2.FeatureList)
}

if not feature_lists:
return example_pb2.Example(features=feature_pb2.Features(feature=feature))
else:
for k in feature_lists.keys():
feature.remove(k)

context = feature_pb2.Features(feature=feature)
feature_lists = feature_pb2.FeatureLists(feature_list=feature_lists)

return example_pb2.SequenceExample(context=context, feature_lists=feature_lists)


def generate_output_split_names(
Expand Down
Loading