-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
enable tfdv, remove hardcode as a sample for following PRs #3089
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,14 +12,81 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import base64 | ||
import tensorflow_data_validation as tfdv | ||
from IPython.display import display | ||
from IPython.display import HTML | ||
from tensorflow_metadata.proto.v0 import statistics_pb2 | ||
from typing import Text | ||
|
||
# The following variables are provided through dependency injection. These | ||
# variables come from the specified input path and arguments provided by the | ||
# API post request. | ||
# | ||
# source | ||
|
||
train_stats = tfdv.generate_statistics_from_csv(data_location=source) | ||
# train_stats = tfdv.generate_statistics_from_csv(data_location=source) | ||
# tfdv.visualize_statistics(train_stats) | ||
|
||
tfdv.visualize_statistics(train_stats) | ||
def get_statistics_html( | ||
lhs_statistics: statistics_pb2.DatasetFeatureStatisticsList | ||
) -> Text: | ||
"""Build the HTML for visualizing the input statistics using Facets. | ||
Args: | ||
lhs_statistics: A DatasetFeatureStatisticsList protocol buffer. | ||
Returns: | ||
HTML to be embedded for visualization. | ||
Raises: | ||
TypeError: If the input argument is not of the expected type. | ||
ValueError: If the input statistics protos does not have only one dataset. | ||
""" | ||
|
||
rhs_statistics = None | ||
lhs_name = 'lhs_statistics' | ||
rhs_name = 'rhs_statistics' | ||
|
||
if not isinstance(lhs_statistics, | ||
statistics_pb2.DatasetFeatureStatisticsList): | ||
raise TypeError( | ||
'lhs_statistics is of type %s, should be ' | ||
'a DatasetFeatureStatisticsList proto.' % type(lhs_statistics).__name__) | ||
|
||
if len(lhs_statistics.datasets) != 1: | ||
raise ValueError('lhs_statistics proto contains multiple datasets. Only ' | ||
'one dataset is currently supported.') | ||
|
||
if lhs_statistics.datasets[0].name: | ||
lhs_name = lhs_statistics.datasets[0].name | ||
|
||
# Add lhs stats. | ||
combined_statistics = statistics_pb2.DatasetFeatureStatisticsList() | ||
lhs_stats_copy = combined_statistics.datasets.add() | ||
lhs_stats_copy.MergeFrom(lhs_statistics.datasets[0]) | ||
lhs_stats_copy.name = lhs_name | ||
|
||
protostr = base64.b64encode( | ||
combined_statistics.SerializeToString()).decode('utf-8') | ||
|
||
# pylint: disable=line-too-long | ||
# Note that in the html template we currently assign a temporary id to the | ||
# facets element and then remove it once we have appended the serialized proto | ||
# string to the element. We do this to avoid any collision of ids when | ||
# displaying multiple facets output in the notebook. | ||
html_template = """<iframe id='facets-iframe' width="100%" height="500px"></iframe> | ||
<script> | ||
facets_iframe = document.getElementById('facets-iframe'); | ||
facets_html = '<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/1.3.3/webcomponents-lite.js"><\/script><link rel="import" href="https://raw.githubusercontent.com/PAIR-code/facets/master/facets-dist/facets-jupyter.html"><facets-overview proto-input="protostr"></facets-overview>'; | ||
facets_iframe.srcdoc = facets_html; | ||
facets_iframe.id = ""; | ||
setTimeout(() => { | ||
facets_iframe.setAttribute('height', facets_iframe.contentWindow.document.body.offsetHeight + 'px') | ||
}, 1500) | ||
</script>""" | ||
# pylint: enable=line-too-long | ||
html = html_template.replace('protostr', protostr) | ||
|
||
return html | ||
|
||
stats = tfdv.load_statistics(source) | ||
html = get_statistics_html(stats) | ||
display(HTML(html)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jingzhang36 you can try this way for TFMA. Essentially it just output htmls. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after TFDV fix got release, here it can be reverted and may move to a new type e.x. tfdvstats.py