Skip to content

Commit 2fb97d4

Browse files
authored
Merge pull request #11 from xinzha623/master
Project import generated by Copybara.
2 parents 8caa2c6 + 6682cbf commit 2fb97d4

File tree

113 files changed

+6907
-3311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+6907
-3311
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ distributed manner, using the same metrics defined in their trainer. These
88
metrics can be computed over different slices of data and visualized in Jupyter
99
notebooks.
1010

11+
![TFMA Slicing Metrics Browser](g3doc/images/tfma-slicing-metrics-browser.gif)
12+
1113
Caution: TFMA may introduce backwards incompatible changes before version 1.0.
1214

1315
## Installation
@@ -42,6 +44,11 @@ By default, Apache Beam runs in local mode but can also run in distributed mode
4244
using [Google Cloud Dataflow](https://cloud.google.com/dataflow/). TFMA is
4345
designed to be extensible for other Apache Beam runners.
4446

47+
## Getting Started
48+
49+
For instructions on using TFMA, see the [get started
50+
guide](g3doc/get_started.md) and try out the extensive [end-to-end example](examples/chicago_taxi/README.md).
51+
4552
## Compatible Versions
4653

4754
The following table is the TFMA package versions that are compatible with each
@@ -50,7 +57,8 @@ combinations may also work.
5057

5158
|tensorflow-model-analysis |tensorflow |apache-beam[gcp]|
5259
|---------------------------|--------------|----------------|
53-
|GitHub master |1.7 |2.4.0 |
60+
|GitHub master |1.9 |2.5.0 |
61+
|0.9.0 |1.9 |2.5.0 |
5462
|0.6.0 |1.6 |2.4.0 |
5563

5664
## Questions

RELEASE.md

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
1-
# Current version (not yet released; still in development)
1+
# Release 0.9.0
22

33
## Major Features and Improvements
44

5+
* Add a TFMA unit test library for unit testing your the exported model and
6+
associated metrics computations.
57
* Add `tfma.export.make_export_strategy` which is analogous to
68
`tf.contrib.learn.make_export_strategy`.
79
* Add `tfma.exporter.FinalExporter` and `tfma.exporter.LatestExporter` which
810
are analogous to `tf.estimator.FinalExporter` and
911
`tf.estimator.LastExporter`.
1012
* Add `tfma.export.build_parsing_eval_input_receiver_fn` which is analogous to
1113
`tf.estimator.export.build_parsing_serving_input_receiver_fn`.
12-
* Add a new post export metric
13-
`tfma.post_export_metrics.post_export_metrics.auc()`.
14+
* Add integration testing for DNN-based estimators.
15+
* Add new post export metrics:
16+
* AUC (`tfma.post_export_metrics.post_export_metrics.auc`)
17+
* Precision/Recall at K
18+
(`tfma.post_export_metrics.post_export_metrics.precision_recall_at_k`)
19+
* Confusion matrix at thresholds
20+
(`tfma.post_export_metrics.post_export_metrics.confusion_matrix_at_thresholds`)
1421

1522
## Bug fixes and other changes
1623

17-
* Peak memory usage for large DataFlow jobs should be lower with a fix in when
18-
we compact batches of metrics during the combine phase of metrics
19-
computation.
20-
* Remove batch size override in `chicago_taxi` example.
24+
* Peak memory usage for large DataFlow jobs should be lower with a fix in when
25+
we compact batches of metrics during the combine phase of metrics
26+
computation.
27+
* Remove batch size override in `chicago_taxi` example.
28+
* Added dependency on `protobuf>=3.6.0<4` for protocol buffers.
29+
* Updated SparseTensor code to work with SparseTensors of any dimension.
30+
Previously on SparseTensors with dimension 2 (batch_size x values) were
31+
supported in the features dictionary.
32+
* Updated code to work with SparseTensors and dense Tensors of variable
33+
lengths across batches.
2134

2235
## Breaking changes
2336

@@ -27,9 +40,19 @@
2740
tag, as opposed to the "serving" tag before.
2841
* EvalSavedModels now include version metadata about the TFMA version that
2942
they were exported with.
43+
* Metrics and plot outputs now are converted into proto and serialized.
44+
Metrics and plots produced by TFMA 0.6.0 will not be compatible with later
45+
versions.
46+
* Requires pre-installed TensorFlow >=1.9,<2.
47+
* TFMA now uses the TensorFlow Estimator functionality for exporting models of
48+
different modes behind the scenes. There are no user-facing changes
49+
API-wise, but EvalSavedModels produced by earlier versions of TFMA will not
50+
be compatible with this version of TFMA.
51+
* tf.contrib.learn Estimators are no longer supported by TFMA. Only
52+
tf.estimator Estimators are supported.
3053
* Metrics and plot outputs now include version metadata about the TFMA version
31-
that they were exported with. Metrics and plots produced by TFMA 0.6.0 will
32-
not be compatible with later versions.
54+
that they were exported with. Metrics and plots produced by earlier versions
55+
of TFMA will not be compatible with this version of TFMA.
3356

3457
## Deprecations
3558

WORKSPACE

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ workspace(name = "org_tensorflow_model_analysis")
22

33
http_archive(
44
name = "io_bazel_rules_closure",
5-
sha256 = "6691c58a2cd30a86776dd9bb34898b041e37136f2dc7e24cadaeaf599c95c657",
6-
strip_prefix = "rules_closure-08039ba8ca59f64248bb3b6ae016460fe9c9914f",
5+
sha256 = "424dce95fddfea8dcf8012a4749fd7166a3009d8d7c32942f19dff12d0bbc2e8",
6+
strip_prefix = "rules_closure-35ffe0eec59ce21ea6b04a8e3345cfcfcf20f5ed",
77
urls = [
8-
"https://mirror.bazel.build/github.com/bazelbuild/rules_closure/archive/08039ba8ca59f64248bb3b6ae016460fe9c9914f.tar.gz",
9-
"https://github.com/bazelbuild/rules_closure/archive/08039ba8ca59f64248bb3b6ae016460fe9c9914f.tar.gz", # 2018-01-16
8+
"https://mirror.bazel.build/github.com/bazelbuild/rules_closure/archive/35ffe0eec59ce21ea6b04a8e3345cfcfcf20f5ed.tar.gz",
9+
"https://github.com/bazelbuild/rules_closure/archive/35ffe0eec59ce21ea6b04a8e3345cfcfcf20f5ed.tar.gz", # 2018-04-12
1010
],
1111
)
1212

@@ -15,9 +15,9 @@ closure_repositories()
1515

1616
http_archive(
1717
name = "org_tensorflow_tensorboard",
18-
sha256 = "a943c0242a07da4d445135ffc9a7c7cb987d9bd948ae733695bc16095dceec20",
19-
strip_prefix = "tensorboard-2fdb2199553729a6c5b42b7eb0305a101b454add",
20-
urls = ["https://github.com/tensorflow/tensorboard/archive/2fdb2199553729a6c5b42b7eb0305a101b454add.zip"],
18+
sha256 = "bd5ce4676158c8e00de43e763e1e6e699b97cade0ce841d5e4b896e3e733dbec",
19+
strip_prefix = "tensorboard-270d34d1e2b0fc9401db0549004e4a0f0f1ffd2d",
20+
urls = ["https://github.com/tensorflow/tensorboard/archive/270d34d1e2b0fc9401db0549004e4a0f0f1ffd2d.zip"], # 2018-04-17
2121
)
2222

2323
load("@org_tensorflow_tensorboard//third_party:workspace.bzl", "tensorboard_workspace")

examples/chicago_taxi/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The Chicago Taxi example demonstrates the end-to-end workflow and steps of how
44
to transform data, train a model, analyze and serve it. It uses:
55

66
* [TensorFlow Transform](https://www.tensorflow.org/tfx/transform) for feature preprocessing,
7-
* TensorFlow [Estimators](https://www.tensorflow.org/programmers_guide/estimators)
7+
* TensorFlow [Estimators](https://www.tensorflow.org/guide/estimators)
88
for training,
99
* [TensorFlow Model Analysis](https://www.tensorflow.org/tfx/model_analysis) and Jupyter for evaluation, and
1010
* [TensorFlow Serving](https://www.tensorflow.org/serving) for serving.
@@ -145,7 +145,7 @@ bash ./train_local.sh
145145
</pre>
146146

147147
The model leverages TensorFlow’s
148-
[Estimators](/programmers_guide/estimators) and is created in the
148+
[Estimators](/guide/estimators) and is created in the
149149
`build_estimator` function in `model.py`. The trainer's input takes the
150150
materialized, transformed examples from the previous step. Notice the pattern of
151151
sharing schema information between preprocessing and training using `taxi.py`
@@ -397,7 +397,7 @@ notebook and set up the output directory to see the results.
397397
To serve the model from the cloud, run:
398398

399399
<pre class="devsite-terminal devsite-click-to-copy">
400-
bash ./start_model_server_mlengine.sh
400+
bash ./start_model_server_cloud.sh
401401
</pre>
402402

403403
To send a request to the cloud:

examples/chicago_taxi/setup.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
import setuptools
1616

1717
if __name__ == '__main__':
18-
setuptools.setup(name='chicago_taxi_setup', version='1.0',
19-
packages=setuptools.find_packages(),
20-
install_requires=[
21-
'jupyter==1.0',
22-
'tensorflow==1.6.0',
23-
'tensorflow-model-analysis==0.6.0',
24-
'tensorflow-serving-api==1.6.0',
25-
'tensorflow-transform==0.6.0'])
18+
setuptools.setup(
19+
name='chicago_taxi_setup',
20+
version='1.0',
21+
packages=setuptools.find_packages(),
22+
install_requires=[
23+
'jupyter==1.0', 'tensorflow==1.9.0',
24+
'tensorflow-model-analysis==0.9.0', 'tensorflow-serving-api==1.9.0',
25+
'tensorflow-transform==0.8.0'
26+
])

g3doc/get_started.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,11 @@ with beam.Pipeline(runner=...) as p:
124124
result = tfma.load_eval_result(output_path='/path/to/out')
125125
tfma.view.render_slicing_metrics(result)
126126
```
127+
## End-to-end example
128+
129+
Try the extensive [end-to-end example](../examples/chicago_taxi/README.md)
130+
featuring [TensorFlow Transform](https://github.com/tensorflow/transform) for feature
131+
preprocessing,
132+
[TensorFlow Estimators](https://www.tensorflow.org/programmers_guide/estimators) for
133+
training, [TensorFlow Model Analysis](https://github.com/tensorflow/model-analysis) and Jupyter for
134+
evaluation, and [TensorFlow Serving](https://github.com/tensorflow/serving) for serving.
2.13 MB
Loading

setup.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,16 @@ def run(self):
243243
'tensorflow_model_analysis/static/vulcanized_template.html',
244244
]),],
245245
'install_requires': [
246-
'apache-beam[gcp]>=2.4,<3',
246+
'apache-beam[gcp]>=2.5,<3',
247247
'grpc-google-iam-v1==0.11.1',
248248
'numpy>=1.10,<2',
249249
'jupyter>=1.0,<2',
250250
'ipywidgets>=7.0,<8',
251-
# Protobuf libraries < 3.5.2 do not have 'cpp' implementation of
252-
# protobufs for Windows and Mac.
253-
'protobuf>=3.5.2,<4',
251+
# TF now requires protobuf>=3.6.0.
252+
'protobuf>=3.6.0,<4',
254253
# For apitools.
255254
'six>=1.9,<2',
256-
'tensorflow-transform>=0.6,<1',
255+
'tensorflow-transform>=0.8,<1',
257256
],
258257
'python_requires':
259258
'>=2.7,<3',

tensorflow_model_analysis/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ py_library(
2727
],
2828
)
2929

30+
py_library(
31+
name = "util",
32+
srcs = ["util.py"],
33+
deps = ["//tensorflow_model_analysis:expect_six_installed"],
34+
)
35+
3036
py_library(
3137
name = "version",
3238
srcs = ["version.py"],

tensorflow_model_analysis/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616

1717
from tensorflow_model_analysis import view
18+
from tensorflow_model_analysis.api import tfma_unit as test
1819
from tensorflow_model_analysis.api.model_eval_lib import * # pylint: disable=wildcard-import
1920
from tensorflow_model_analysis.constants import DATA_CENTRIC_MODE
2021
from tensorflow_model_analysis.constants import MODEL_CENTRIC_MODE

tensorflow_model_analysis/api/BUILD

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ py_library(
2020
py_test(
2121
name = "model_eval_lib_test",
2222
srcs = ["model_eval_lib_test.py"],
23+
shard_count = 3,
2324
deps = [
2425
":model_eval_lib",
2526
"//tensorflow_model_analysis:expect_tensorflow_installed",
@@ -29,6 +30,38 @@ py_test(
2930
"//tensorflow_model_analysis/eval_saved_model/example_trainers:fixed_prediction_estimator",
3031
"//tensorflow_model_analysis/eval_saved_model/example_trainers:linear_classifier",
3132
"//tensorflow_model_analysis/eval_saved_model/post_export_metrics",
33+
"//tensorflow_model_analysis/proto:metrics_for_slice_py_pb2",
3234
"//tensorflow_model_analysis/slicer",
3335
],
3436
)
37+
38+
py_library(
39+
name = "tfma_unit_non_testonly",
40+
srcs = ["tfma_unit.py"],
41+
deps = [
42+
"//tensorflow_model_analysis:expect_apache_beam_installed",
43+
"//tensorflow_model_analysis/api/impl:evaluate",
44+
"//tensorflow_model_analysis/eval_saved_model:load",
45+
"//tensorflow_model_analysis/eval_saved_model:testutil_non_testonly",
46+
"//tensorflow_model_analysis/slicer",
47+
],
48+
)
49+
50+
py_library(
51+
name = "tfma_unit",
52+
testonly = 1,
53+
deps = ["tfma_unit_non_testonly"],
54+
)
55+
56+
py_test(
57+
name = "tfma_unit_test",
58+
srcs = ["tfma_unit_test.py"],
59+
deps = [
60+
":tfma_unit",
61+
"//tensorflow_model_analysis:expect_apache_beam_installed",
62+
"//tensorflow_model_analysis:expect_tensorflow_installed",
63+
"//tensorflow_model_analysis/eval_saved_model/example_trainers:fixed_prediction_estimator",
64+
"//tensorflow_model_analysis/eval_saved_model/example_trainers:fixed_prediction_estimator_extra_fields",
65+
"//tensorflow_model_analysis/eval_saved_model/post_export_metrics",
66+
],
67+
)

tensorflow_model_analysis/api/impl/BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ py_library(
1414
"//tensorflow_model_analysis/eval_saved_model:util",
1515
"//tensorflow_model_analysis/eval_saved_model/post_export_metrics:metric_keys",
1616
"//tensorflow_model_analysis/extractors:feature_extractor",
17+
"//tensorflow_model_analysis/proto:metrics_for_slice_py_pb2",
1718
"//tensorflow_model_analysis/slicer",
1819
],
1920
)
2021

2122
py_test(
2223
name = "evaluate_test",
2324
srcs = ["evaluate_test.py"],
25+
shard_count = 4,
2426
deps = [
2527
":evaluate",
2628
"//tensorflow_model_analysis:expect_apache_beam_installed", # b/73825929
@@ -30,6 +32,7 @@ py_test(
3032
"//tensorflow_model_analysis/eval_saved_model/example_trainers:linear_classifier",
3133
"//tensorflow_model_analysis/eval_saved_model/post_export_metrics",
3234
"//tensorflow_model_analysis/eval_saved_model/post_export_metrics:metric_keys",
35+
"//tensorflow_model_analysis/proto:metrics_for_slice_py_pb2",
3336
"//third_party/tensorflow/core:protos_all_py_pb2",
3437
],
3538
)
@@ -42,6 +45,9 @@ py_library(
4245
"//tensorflow_model_analysis:expect_apache_beam_installed", # b/73825929
4346
"//tensorflow_model_analysis:expect_tensorflow_installed",
4447
"//tensorflow_model_analysis:version",
48+
"//tensorflow_model_analysis/api/impl:evaluate",
49+
"//tensorflow_model_analysis/eval_saved_model/post_export_metrics",
50+
"//tensorflow_model_analysis/proto:metrics_for_slice_py_pb2",
4551
"//tensorflow_model_analysis/slicer",
4652
"//third_party/py/numpy",
4753
],
@@ -52,7 +58,9 @@ py_test(
5258
srcs = ["serialization_test.py"],
5359
deps = [
5460
":serialization",
61+
"//tensorflow_model_analysis:types",
5562
"//tensorflow_model_analysis/eval_saved_model:testutil",
63+
"//tensorflow_model_analysis/eval_saved_model/post_export_metrics:metric_keys",
5664
],
5765
)
5866

tensorflow_model_analysis/api/impl/evaluate.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,15 @@ def _Aggregate( # pylint: disable=invalid-name
368368
add_metrics_callbacks,
369369
desired_batch_size = None,
370370
):
371-
return (slice_result
372-
| 'CombinePerKey' >> beam.CombinePerKey(
373-
_AggregateCombineFn(
374-
eval_saved_model_path=eval_saved_model_path,
375-
add_metrics_callbacks=add_metrics_callbacks,
376-
shared_handle=shared.Shared(),
377-
desired_batch_size=desired_batch_size)))
371+
return (
372+
slice_result
373+
| 'CombinePerKey' >> beam.CombinePerKey(
374+
_AggregateCombineFn(
375+
eval_saved_model_path=eval_saved_model_path,
376+
add_metrics_callbacks=add_metrics_callbacks,
377+
shared_handle=shared.Shared(),
378+
desired_batch_size=desired_batch_size))
379+
)
378380

379381

380382
@beam.typehints.with_input_types(beam.typehints.Tuple[

0 commit comments

Comments
 (0)