From de6200e7f58b616d6169cc35946e85323da66053 Mon Sep 17 00:00:00 2001 From: eqy Date: Sun, 15 Apr 2018 23:52:04 -0700 Subject: [PATCH 001/752] fix command line example package path --- tensorflow/contrib/lite/toco/g3doc/cmdline_examples.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/contrib/lite/toco/g3doc/cmdline_examples.md b/tensorflow/contrib/lite/toco/g3doc/cmdline_examples.md index 495014c6fc..f8327daa08 100644 --- a/tensorflow/contrib/lite/toco/g3doc/cmdline_examples.md +++ b/tensorflow/contrib/lite/toco/g3doc/cmdline_examples.md @@ -41,7 +41,7 @@ FlatBuffer to perform floating-point inference. ``` bazel run --config=opt \ - third_party/tensorflow/contrib/lite/toco:toco -- \ + //tensorflow/contrib/lite/toco:toco -- \ --savedmodel_directory=/tmp/saved_model \ --output_file=/tmp/foo.tflite ``` -- GitLab From cd2ba0c063ffd89f0310a6ab6482a5607e590cb1 Mon Sep 17 00:00:00 2001 From: Dan Osipov Date: Sun, 18 Mar 2018 18:50:34 -0700 Subject: [PATCH 002/752] Document additional argument --- tensorflow/python/ops/image_ops_impl.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tensorflow/python/ops/image_ops_impl.py b/tensorflow/python/ops/image_ops_impl.py index 8524c08f81..cee948fe43 100644 --- a/tensorflow/python/ops/image_ops_impl.py +++ b/tensorflow/python/ops/image_ops_impl.py @@ -984,6 +984,7 @@ def resize_image_aspect_with_pad(image, target_height, target_width, 3-D Tensor of shape `[height, width, channels]`. target_height: Target height. target_width: Target width. + method: Method to use for resizing image. See `resize_images()` Raises: ValueError: if `target_height` or `target_width` are zero or negative. -- GitLab From 96dc82647d0eb5d1903242c2dde1cf9dd5bb36f0 Mon Sep 17 00:00:00 2001 From: Dan Osipov Date: Sat, 28 Apr 2018 08:28:33 -0700 Subject: [PATCH 003/752] Rename API method --- tensorflow/python/ops/image_ops.py | 2 +- tensorflow/python/ops/image_ops_impl.py | 6 +++--- tensorflow/python/ops/image_ops_test.py | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tensorflow/python/ops/image_ops.py b/tensorflow/python/ops/image_ops.py index f11b6dcea6..091ec61b1f 100644 --- a/tensorflow/python/ops/image_ops.py +++ b/tensorflow/python/ops/image_ops.py @@ -36,7 +36,7 @@ See the @{$python/image} guide. @@resize_bilinear @@resize_nearest_neighbor @@resize_image_with_crop_or_pad -@@resize_image_aspect_with_pad +@@resize_image_with_pad @@central_crop @@pad_to_bounding_box @@crop_to_bounding_box diff --git a/tensorflow/python/ops/image_ops_impl.py b/tensorflow/python/ops/image_ops_impl.py index cee948fe43..5fe0b7a251 100644 --- a/tensorflow/python/ops/image_ops_impl.py +++ b/tensorflow/python/ops/image_ops_impl.py @@ -969,8 +969,8 @@ def resize_images(images, return images -@tf_export('image.resize_image_aspect_with_pad') -def resize_image_aspect_with_pad(image, target_height, target_width, +@tf_export('image.resize_image_with_pad') +def resize_image_with_pad(image, target_height, target_width, method=ResizeMethod.BILINEAR): """ Resizes and pads an image to a target width and height. @@ -996,7 +996,7 @@ def resize_image_aspect_with_pad(image, target_height, target_width, If `images` was 3-D, a 3-D float Tensor of shape `[new_height, new_width, channels]`. """ - with ops.name_scope(None, 'resize_image_aspect_with_pad', [image]): + with ops.name_scope(None, 'resize_image_with_pad', [image]): image = ops.convert_to_tensor(image, name='image') image_shape = image.get_shape() is_batch = True diff --git a/tensorflow/python/ops/image_ops_test.py b/tensorflow/python/ops/image_ops_test.py index 40a4d175ac..22d9ce4289 100644 --- a/tensorflow/python/ops/image_ops_test.py +++ b/tensorflow/python/ops/image_ops_test.py @@ -2458,9 +2458,9 @@ class ResizeImagesTest(test_util.TensorFlowTestCase): self.assertTrue(y.op.name.startswith("resize_images")) -class ResizeImageAspectWithPadTest(test_util.TensorFlowTestCase): +class ResizeImageWithPadTest(test_util.TensorFlowTestCase): - def _ResizeImageAspectWithPad(self, x, target_height, target_width, + def _ResizeImageWithPad(self, x, target_height, target_width, use_tensor_inputs): if use_tensor_inputs: target_height = ops.convert_to_tensor(target_height) @@ -2471,7 +2471,7 @@ class ResizeImageAspectWithPadTest(test_util.TensorFlowTestCase): x_tensor = x feed_dict = {} - y = image_ops.resize_image_aspect_with_pad(x_tensor, target_height, + y = image_ops.resize_image_with_pad(x_tensor, target_height, target_width) if not use_tensor_inputs: self.assertTrue(y.get_shape().is_fully_defined()) @@ -2491,7 +2491,7 @@ class ResizeImageAspectWithPadTest(test_util.TensorFlowTestCase): y = np.array(y).reshape(y_shape) for use_tensor_inputs in use_tensor_inputs_options: - y_tf = self._ResizeImageAspectWithPad(x, target_height, target_width, + y_tf = self._ResizeImageWithPad(x, target_height, target_width, use_tensor_inputs) self.assertAllClose(y, y_tf) @@ -2507,7 +2507,7 @@ class ResizeImageAspectWithPadTest(test_util.TensorFlowTestCase): for use_tensor_inputs in use_tensor_inputs_options: try: - self._ResizeImageAspectWithPad(x, target_height, target_width, + self._ResizeImageWithPad(x, target_height, target_width, use_tensor_inputs) except Exception as e: if err_msg not in str(e): @@ -2517,7 +2517,7 @@ class ResizeImageAspectWithPadTest(test_util.TensorFlowTestCase): def _assertShapeInference(self, pre_shape, height, width, post_shape): image = array_ops.placeholder(dtypes.float32, shape=pre_shape) - y = image_ops.resize_image_aspect_with_pad(image, height, width) + y = image_ops.resize_image_with_pad(image, height, width) self.assertEqual(y.get_shape().as_list(), post_shape) def testNoOp(self): -- GitLab From 533cb5caa4c88d3f76e1994e8f039ea04d342482 Mon Sep 17 00:00:00 2001 From: Dan Osipov Date: Sat, 28 Apr 2018 08:30:56 -0700 Subject: [PATCH 004/752] Remove assertions --- tensorflow/python/ops/image_ops_impl.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tensorflow/python/ops/image_ops_impl.py b/tensorflow/python/ops/image_ops_impl.py index 5fe0b7a251..e174feedb5 100644 --- a/tensorflow/python/ops/image_ops_impl.py +++ b/tensorflow/python/ops/image_ops_impl.py @@ -1066,16 +1066,6 @@ def resize_image_with_pad(image, target_height, target_width, _, resized_height, resized_width, _ = _ImageDimensions(resized, rank=4) - assert_ops = [] - assert_ops += _assert( - equal_(resized_height, target_height), ValueError, - 'resized height is not correct.') - assert_ops += _assert( - equal_(resized_width, target_width), ValueError, - 'resized width is not correct.') - - resized = control_flow_ops.with_dependencies(assert_ops, resized) - if not is_batch: resized = array_ops.squeeze(resized, squeeze_dims=[0]) -- GitLab From 764ea231d9b649ad167fd1ffd4f4c5c4e79642c7 Mon Sep 17 00:00:00 2001 From: Dan Osipov Date: Sat, 28 Apr 2018 08:32:36 -0700 Subject: [PATCH 005/752] Update docstring --- tensorflow/python/ops/image_ops_impl.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tensorflow/python/ops/image_ops_impl.py b/tensorflow/python/ops/image_ops_impl.py index e174feedb5..d5ac72bac6 100644 --- a/tensorflow/python/ops/image_ops_impl.py +++ b/tensorflow/python/ops/image_ops_impl.py @@ -976,8 +976,9 @@ def resize_image_with_pad(image, target_height, target_width, Resizes and pads an image to a target width and height. Resizes an image to a target width and height by keeping - the aspect ratio the same without distortion and padding - it evenly with zeros. + the aspect ratio the same without distortion. If the target + dimensions don't match the image dimensions, the image + is padded with zeroes prior to resizing. Args: image: 4-D Tensor of shape `[batch, height, width, channels]` or -- GitLab From 74171d402a52074806bc5f0d1a3ddae92212214f Mon Sep 17 00:00:00 2001 From: Dan Osipov Date: Tue, 8 May 2018 14:24:32 -0700 Subject: [PATCH 006/752] Fix bad merge --- tensorflow/python/ops/image_ops.py | 61 ------------------------------ 1 file changed, 61 deletions(-) diff --git a/tensorflow/python/ops/image_ops.py b/tensorflow/python/ops/image_ops.py index 091ec61b1f..343531ac55 100644 --- a/tensorflow/python/ops/image_ops.py +++ b/tensorflow/python/ops/image_ops.py @@ -17,67 +17,6 @@ """Image processing and decoding ops. See the @{$python/image} guide. -<<<<<<< HEAD -======= - -@@decode_bmp -@@decode_gif -@@decode_jpeg -@@decode_and_crop_jpeg -@@encode_jpeg -@@extract_jpeg_shape -@@decode_png -@@encode_png -@@is_jpeg -@@decode_image -@@resize_images -@@resize_area -@@resize_bicubic -@@resize_bilinear -@@resize_nearest_neighbor -@@resize_image_with_crop_or_pad -@@resize_image_with_pad -@@central_crop -@@pad_to_bounding_box -@@crop_to_bounding_box -@@extract_glimpse -@@crop_and_resize -@@flip_up_down -@@random_flip_up_down -@@flip_left_right -@@random_flip_left_right -@@transpose_image -@@rot90 - -@@rgb_to_grayscale -@@grayscale_to_rgb -@@hsv_to_rgb -@@rgb_to_hsv -@@rgb_to_yiq -@@yiq_to_rgb -@@rgb_to_yuv -@@yuv_to_rgb -@@convert_image_dtype -@@adjust_brightness -@@random_brightness -@@adjust_contrast -@@random_contrast -@@adjust_hue -@@random_hue -@@adjust_gamma -@@adjust_saturation -@@random_saturation -@@per_image_standardization -@@draw_bounding_boxes -@@non_max_suppression -@@sample_distorted_bounding_box -@@total_variation -@@psnr -@@ssim -@@ssim_multiscale -@@image_gradients -@@sobel_edges ->>>>>>> 88687fa... Add resize_image_aspect_with_pad method """ from __future__ import absolute_import from __future__ import division -- GitLab From 5e6b20e53720e8d00619d851ce983f8da77c5cf4 Mon Sep 17 00:00:00 2001 From: Soila Kavulya Date: Tue, 8 May 2018 14:54:53 -0700 Subject: [PATCH 007/752] Deploy TensorFlow ecosystem jars --- tensorflow/java/maven/pom.xml | 10 +- tensorflow/java/maven/release.sh | 1 + tensorflow/java/maven/run_inside_container.sh | 42 ++++- .../pom-spark.xml.template | 19 +++ .../spark-tensorflow-connector/update.py | 152 ++++++++++++++++++ .../tensorflow-hadoop/pom-hadoop.xml.template | 18 +++ .../java/maven/tensorflow-hadoop/update.py | 114 +++++++++++++ 7 files changed, 352 insertions(+), 4 deletions(-) create mode 100644 tensorflow/java/maven/spark-tensorflow-connector/pom-spark.xml.template create mode 100644 tensorflow/java/maven/spark-tensorflow-connector/update.py create mode 100644 tensorflow/java/maven/tensorflow-hadoop/pom-hadoop.xml.template create mode 100644 tensorflow/java/maven/tensorflow-hadoop/update.py diff --git a/tensorflow/java/maven/pom.xml b/tensorflow/java/maven/pom.xml index 0a09a5ea7c..21fed5a419 100644 --- a/tensorflow/java/maven/pom.xml +++ b/tensorflow/java/maven/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.tensorflow parentpom - 1.8.0 + 1.8.0-SNAPSHOT pom https://www.tensorflow.org @@ -32,6 +32,8 @@ libtensorflow_jni_gpu tensorflow proto + tensorflow-hadoop + spark-tensorflow-connector ossrh - https://oss.sonatype.org/content/repositories/snapshots + https://tap.jfrog.io/tap/public-snapshots + ossrh @@ -74,6 +77,7 @@ + diff --git a/tensorflow/java/maven/release.sh b/tensorflow/java/maven/release.sh index 9012ea14ea..6c51029198 100755 --- a/tensorflow/java/maven/release.sh +++ b/tensorflow/java/maven/release.sh @@ -48,6 +48,7 @@ fi set -ex docker run \ + $DOCKER_PROXY_RUN_ARGS \ -e TF_VERSION="${TF_VERSION}" \ -e DEPLOY_OSSRH="${DEPLOY_OSSRH:-true}" \ -e DEPLOY_BINTRAY="${DEPLOY_BINTRAY:-true}" \ diff --git a/tensorflow/java/maven/run_inside_container.sh b/tensorflow/java/maven/run_inside_container.sh index 6136ccfdfb..73f7ee94a0 100644 --- a/tensorflow/java/maven/run_inside_container.sh +++ b/tensorflow/java/maven/run_inside_container.sh @@ -32,11 +32,15 @@ if [[ "${TF_VERSION}" == *"-SNAPSHOT" ]]; then DEPLOY_BINTRAY="false" fi PROTOC_RELEASE_URL="https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3.3.0-linux-x86_64.zip" +TF_ECOSYSTEM_URL="https://github.com/tensorflow/ecosystem.git" + if [[ "${DEPLOY_BINTRAY}" != "true" && "${DEPLOY_OSSRH}" != "true" ]]; then echo "Must deploy to at least one of Bintray or OSSRH" >&2 exit 2 fi +IS_SNAPSHOT="true" + set -ex clean() { @@ -183,6 +187,41 @@ generate_java_protos() { rm -rf "${DIR}/proto/tmp" } + +download_tf_ecosystem() { + ECOSYSTEM_DIR="/tmp/tensorflow-ecosystem" + HADOOP_DIR="${DIR}/tensorflow-hadoop" + SPARK_DIR="${DIR}/spark-tensorflow-connector" + + # Clean any previous attempts + rm -rf "${ECOSYSTEM_DIR}" + + # Clone the TensorFlow ecosystem project + mkdir -p "${ECOSYSTEM_DIR}" + cd "${ECOSYSTEM_DIR}" + git clone "${TF_ECOSYSTEM_URL}" + + # Copy the TensorFlow Hadoop source + cp -r "${ECOSYSTEM_DIR}/ecosystem/hadoop/src" "${HADOOP_DIR}" + python ${HADOOP_DIR}/update.py --template ${HADOOP_DIR}/pom-hadoop.xml.template \ + --input_pom ${ECOSYSTEM_DIR}/ecosystem/hadoop/pom.xml \ + --output_pom ${HADOOP_DIR}/pom.xml \ + --version ${TF_VERSION} + + # Copy the TensorFlow Spark connector source + cp -r "${ECOSYSTEM_DIR}/ecosystem/spark/spark-tensorflow-connector/src" "${SPARK_DIR}" + python ${SPARK_DIR}/update.py --template ${SPARK_DIR}/pom-spark.xml.template \ + --input_pom ${ECOSYSTEM_DIR}/ecosystem/spark/spark-tensorflow-connector/pom.xml \ + --output_pom ${SPARK_DIR}/pom.xml \ + --version ${TF_VERSION} \ + --scala_version 2.11 + + # Cleanup + rm -rf "${ECOSYSTEM_DIR}" + + cd "${DIR}" +} + # Deploy artifacts using a specific profile. # Arguments: # profile - name of selected profile. @@ -240,7 +279,7 @@ cd "${DIR}" # Comment lines out appropriately if debugging/tinkering with the release # process. # gnupg2 is required for signing -apt-get -qq update && apt-get -qqq install -y gnupg2 +apt-get -qq update && apt-get -qqq install -y gnupg2 && apt-get -qqq install -y git clean update_version_in_pom download_libtensorflow @@ -248,6 +287,7 @@ download_libtensorflow_jni download_libtensorflow_jni_gpu update_tensorflow_android generate_java_protos +download_tf_ecosystem # Build the release artifacts mvn verify # Push artifacts to repository diff --git a/tensorflow/java/maven/spark-tensorflow-connector/pom-spark.xml.template b/tensorflow/java/maven/spark-tensorflow-connector/pom-spark.xml.template new file mode 100644 index 0000000000..d8a3d559be --- /dev/null +++ b/tensorflow/java/maven/spark-tensorflow-connector/pom-spark.xml.template @@ -0,0 +1,19 @@ + + 4.0.0 + TensorFlow TFRecord connector for Apache Spark DataFrames + spark-tensorflow-connector_${scala_version} + ${version} + jar + + https://github.com/tensorflow/ecosystem/ + + org.tensorflow + parentpom + ${version} + ../ + + + diff --git a/tensorflow/java/maven/spark-tensorflow-connector/update.py b/tensorflow/java/maven/spark-tensorflow-connector/update.py new file mode 100644 index 0000000000..6185ccbb00 --- /dev/null +++ b/tensorflow/java/maven/spark-tensorflow-connector/update.py @@ -0,0 +1,152 @@ +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Merge TensorFlow Spark connector pom from with deployment template. + +The TensorFlow Spark connector pom is here: https://github.com/tensorflow/ecosystem/tree/master/spark/spark-tensorflow-connector +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import argparse +import sys +import string +import xml.etree.ElementTree as ET + +POM_NAMESPACE = "http://maven.apache.org/POM/4.0.0" +SCALA_VERSION_TAG = "scala.binary.version" + + +def get_args(): + """Parse command line args.""" + parser = argparse.ArgumentParser() + parser.add_argument( + '--version', + required=True, + help='Version for the artifact.') + parser.add_argument( + '--scala_version', + required=True, + choices=['2.10', '2.11'], + help='Scala version for the artifact.') + parser.add_argument( + '--template', + required=True, + help='Path to the pom file template.') + parser.add_argument( + '--input_pom', + required=True, + help='Path to input pom file to merge with template.') + parser.add_argument( + '--output_pom', + required=True, + help='Path to output pom file.') + return parser.parse_args() + + +def load_pom(input_path): + """ Loads POM file to XML tree""" + ET.register_namespace("", POM_NAMESPACE) + tree = ET.parse(input_path) + return tree + + +def update_scala_version(tree, version, is_template=False): + """ Updates scala version in XML tree""" + + if is_template: + tag = "{%s}artifactId" % POM_NAMESPACE + nodes = tree.findall(tag) + + if nodes is None: + raise ValueError("Missing artifactId in template pom") + + for node in nodes: + template = string.Template(node.text) + + text = template.substitute({"scala_version": version}) + node.text = text + else: + # Update scala version property in pom + tag = "{%s}%s" % (POM_NAMESPACE, SCALA_VERSION_TAG) + nodes = nodes = list(tree.iter(tag)) + + if len(nodes) == 0: + raise ValueError("Missing %s property in Spark connector pom") + + for node in nodes: + node.text = version + + return tree + + +def update_version(tree, version): + """ Updates version tags in XML tree """ + version_tag = "{%s}version" % POM_NAMESPACE + nodes = list(tree.iter(version_tag)) + + if len(nodes) == 0: + raise ValueError("Missing version in template pom") + + for node in nodes: + node.text = version + + return tree + + +def merge_tags(template_root, pom_root): + """ Merge pom file from TensorFlow Spark connector with deployment template. + + Modify the TensorFlow Spark connector pom to inherit parent pom and version info and + other tags provided by deployment template. + + TODO: Figure out if there is a cleaner way of doing this. Inheritance is needed + for propagating the deployment profile. + + Args: + template_root: Root XML element for template file. + pom_root: Root XML element for TensorFlow Spark connector pom file. + + Return: + template_root: Root XML element with merged tree. + """ + template_tags = [child.tag for child in template_root] + template_tags.append("{%s}groupId" % POM_NAMESPACE) # skip groupId since it is inherited from parent + + for child in pom_root: + if child.tag not in template_tags: + template_root.append(child) + + return template_root + + +def main(): + args = get_args() + template_tree = load_pom(args.template) + pom_tree = load_pom(args.input_pom) + + template_tree = update_version(template_tree, args.version) + template_tree = update_scala_version(template_tree, args.scala_version, is_template=True) + pom_tree = update_scala_version(pom_tree, args.scala_version, is_template=False) + template_root = merge_tags(template_tree.getroot(), pom_tree.getroot()) + + with open(args.output_pom, "w") as f: + f.write(ET.tostring(template_root)) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tensorflow/java/maven/tensorflow-hadoop/pom-hadoop.xml.template b/tensorflow/java/maven/tensorflow-hadoop/pom-hadoop.xml.template new file mode 100644 index 0000000000..6a82c56cc7 --- /dev/null +++ b/tensorflow/java/maven/tensorflow-hadoop/pom-hadoop.xml.template @@ -0,0 +1,18 @@ + + 4.0.0 + TensorFlow TFRecord InputFormat/OutputFormat for Apache Hadoop + tensorflow-hadoop + ${version} + jar + + https://github.com/tensorflow/ecosystem/ + + org.tensorflow + parentpom + ${version} + ../ + + diff --git a/tensorflow/java/maven/tensorflow-hadoop/update.py b/tensorflow/java/maven/tensorflow-hadoop/update.py new file mode 100644 index 0000000000..503062608d --- /dev/null +++ b/tensorflow/java/maven/tensorflow-hadoop/update.py @@ -0,0 +1,114 @@ +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Merge TensorFlow Hadoop pom from with deployment template. + +The TensorFlow Hadoop pom is here: https://github.com/tensorflow/ecosystem/tree/master/hadoop +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import argparse +import sys +import xml.etree.ElementTree as ET + +POM_NAMESPACE = "http://maven.apache.org/POM/4.0.0" + + +def get_args(): + """Parse command line args.""" + parser = argparse.ArgumentParser() + parser.add_argument( + '--version', + required=True, + help='Version for the artifact.') + parser.add_argument( + '--template', + required=True, + help='Path to the pom file template.') + parser.add_argument( + '--input_pom', + required=True, + help='Path to input pom file to merge with template.') + parser.add_argument( + '--output_pom', + required=True, + help='Path to output pom file.') + return parser.parse_args() + + +def load_pom(input_path): + """ Loads POM file to XML tree""" + ET.register_namespace("", POM_NAMESPACE) + tree = ET.parse(input_path) + return tree + + +def update_version(tree, version): + """ Updates version tags in XML tree """ + version_tag = "{%s}version" % POM_NAMESPACE + nodes = list(tree.iter(version_tag)) + + if len(nodes) == 0: + raise ValueError("Missing version in template pom") + + for node in nodes: + node.text = version + + return tree + + +def merge_tags(template_root, pom_root): + """ Merge pom file from TensorFlow Hadoop with deployment template. + + Modify the TensorFlow Hadoop pom to inherit parent pom and version info and + other tags provided by deployment template. + + TODO: Figure out if there is a cleaner way of doing this. Inheritance is needed + for propagating the deployment profile. + + Args: + template_root: Root XML element for template file. + pom_root: Root XML element for TensorFlow Hadoop pom file. + + Return: + template_root: Root XML element with merged tree. + """ + template_tags = [child.tag for child in template_root] + template_tags.append("{%s}groupId" % POM_NAMESPACE) # skip groupId since it is inherited from parent + + for child in pom_root: + if child.tag not in template_tags: + template_root.append(child) + + return template_root + + +def main(): + args = get_args() + template_tree = load_pom(args.template) + pom_tree = load_pom(args.input_pom) + + template_tree = update_version(template_tree, args.version) + template_root = merge_tags(template_tree.getroot(), pom_tree.getroot()) + + with open(args.output_pom, "w") as f: + f.write(ET.tostring(template_root)) + + +if __name__ == '__main__': + sys.exit(main()) -- GitLab From f957cfbc4d27a57bf08d128b41042a16f1155ab0 Mon Sep 17 00:00:00 2001 From: Soila Kavulya Date: Tue, 8 May 2018 18:40:20 -0700 Subject: [PATCH 008/752] Add TensorFlow ecosystem Spark and Hadoop jars to Maven deployment --- tensorflow/java/maven/README.md | 6 +++++ tensorflow/java/maven/pom.xml | 8 +++--- tensorflow/java/maven/release.sh | 1 - tensorflow/java/maven/run_inside_container.sh | 26 ++++++++++--------- .../maven/spark-tensorflow-connector/pom.xml | 24 +++++++++++++++++ .../java/maven/tensorflow-hadoop/pom.xml | 24 +++++++++++++++++ 6 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 tensorflow/java/maven/spark-tensorflow-connector/pom.xml create mode 100644 tensorflow/java/maven/tensorflow-hadoop/pom.xml diff --git a/tensorflow/java/maven/README.md b/tensorflow/java/maven/README.md index c7e8f03806..fa756815a9 100644 --- a/tensorflow/java/maven/README.md +++ b/tensorflow/java/maven/README.md @@ -53,6 +53,12 @@ There are seven artifacts and thus `pom.xml`s involved in this release: 7. [`parentpom`](https://maven.apache.org/pom/index.html): Common settings shared by all of the above. +8. `tensorflow-hadoop`: The TensorFlow TFRecord InputFormat/OutputFormat for Apache Hadoop. + The source code for this package is available in the [TensorFlow Ecosystem](https://github.com/tensorflow/ecosystem/tree/master/hadoop) + +9. `spark-tensorflow-connector`: A Scala library for loading and storing TensorFlow TFRecord + using Apache Spark DataFrames. The source code for this package is available + in the [TensorFlow Ecosystem](https://github.com/tensorflow/ecosystem/tree/master/spark/spark-tensorflow-connector) ## Updating the release diff --git a/tensorflow/java/maven/pom.xml b/tensorflow/java/maven/pom.xml index 21fed5a419..7a95fb2556 100644 --- a/tensorflow/java/maven/pom.xml +++ b/tensorflow/java/maven/pom.xml @@ -6,7 +6,7 @@ 4.0.0 org.tensorflow parentpom - 1.8.0-SNAPSHOT + 1.8.0 pom https://www.tensorflow.org @@ -46,8 +46,7 @@ ossrh - https://tap.jfrog.io/tap/public-snapshots - + https://oss.sonatype.org/content/repositories/snapshots ossrh @@ -77,7 +76,6 @@ - + diff --git a/tensorflow/java/maven/release.sh b/tensorflow/java/maven/release.sh index 6c51029198..9012ea14ea 100755 --- a/tensorflow/java/maven/release.sh +++ b/tensorflow/java/maven/release.sh @@ -48,7 +48,6 @@ fi set -ex docker run \ - $DOCKER_PROXY_RUN_ARGS \ -e TF_VERSION="${TF_VERSION}" \ -e DEPLOY_OSSRH="${DEPLOY_OSSRH:-true}" \ -e DEPLOY_BINTRAY="${DEPLOY_BINTRAY:-true}" \ diff --git a/tensorflow/java/maven/run_inside_container.sh b/tensorflow/java/maven/run_inside_container.sh index 73f7ee94a0..3808104bc1 100644 --- a/tensorflow/java/maven/run_inside_container.sh +++ b/tensorflow/java/maven/run_inside_container.sh @@ -39,8 +39,6 @@ if [[ "${DEPLOY_BINTRAY}" != "true" && "${DEPLOY_OSSRH}" != "true" ]]; then exit 2 fi -IS_SNAPSHOT="true" - set -ex clean() { @@ -48,7 +46,9 @@ clean() { # (though if run inside a clean docker container, there won't be any dirty # artifacts lying around) mvn -q clean - rm -rf libtensorflow_jni/src libtensorflow_jni/target libtensorflow_jni_gpu/src libtensorflow_jni_gpu/target libtensorflow/src libtensorflow/target tensorflow-android/target + rm -rf libtensorflow_jni/src libtensorflow_jni/target libtensorflow_jni_gpu/src libtensorflow_jni_gpu/target \ + libtensorflow/src libtensorflow/target tensorflow-android/target \ + tensorflow-hadoop/src spark-tensorflow-connector/src } update_version_in_pom() { @@ -188,6 +188,9 @@ generate_java_protos() { } +# Download the TensorFlow ecosystem source from git. +# The pom files from this repo do not inherit from the parent pom so the maven version +# is updated for each module. download_tf_ecosystem() { ECOSYSTEM_DIR="/tmp/tensorflow-ecosystem" HADOOP_DIR="${DIR}/tensorflow-hadoop" @@ -203,18 +206,15 @@ download_tf_ecosystem() { # Copy the TensorFlow Hadoop source cp -r "${ECOSYSTEM_DIR}/ecosystem/hadoop/src" "${HADOOP_DIR}" - python ${HADOOP_DIR}/update.py --template ${HADOOP_DIR}/pom-hadoop.xml.template \ - --input_pom ${ECOSYSTEM_DIR}/ecosystem/hadoop/pom.xml \ - --output_pom ${HADOOP_DIR}/pom.xml \ - --version ${TF_VERSION} + cp "${ECOSYSTEM_DIR}/ecosystem/hadoop/pom.xml" "${HADOOP_DIR}" + cd "${HADOOP_DIR}" + update_version_in_pom # Copy the TensorFlow Spark connector source cp -r "${ECOSYSTEM_DIR}/ecosystem/spark/spark-tensorflow-connector/src" "${SPARK_DIR}" - python ${SPARK_DIR}/update.py --template ${SPARK_DIR}/pom-spark.xml.template \ - --input_pom ${ECOSYSTEM_DIR}/ecosystem/spark/spark-tensorflow-connector/pom.xml \ - --output_pom ${SPARK_DIR}/pom.xml \ - --version ${TF_VERSION} \ - --scala_version 2.11 + cp "${ECOSYSTEM_DIR}/ecosystem/spark/spark-tensorflow-connector/pom.xml" "${SPARK_DIR}" + cd "${SPARK_DIR}" + update_version_in_pom # Cleanup rm -rf "${ECOSYSTEM_DIR}" @@ -280,6 +280,7 @@ cd "${DIR}" # process. # gnupg2 is required for signing apt-get -qq update && apt-get -qqq install -y gnupg2 && apt-get -qqq install -y git + clean update_version_in_pom download_libtensorflow @@ -288,6 +289,7 @@ download_libtensorflow_jni_gpu update_tensorflow_android generate_java_protos download_tf_ecosystem + # Build the release artifacts mvn verify # Push artifacts to repository diff --git a/tensorflow/java/maven/spark-tensorflow-connector/pom.xml b/tensorflow/java/maven/spark-tensorflow-connector/pom.xml new file mode 100644 index 0000000000..8c962d111f --- /dev/null +++ b/tensorflow/java/maven/spark-tensorflow-connector/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + TensorFlow TFRecord connector for Apache Spark DataFrames + spark-tensorflow-connector + jar + + + https://github.com/tensorflow/ecosystem.git + git@github.com:tensorflow/ecosystem.git + scm:git:https://github.com/tensorflow/ecosystem.git + + + https://github.com/tensorflow/ecosystem/ + + org.tensorflow + parentpom + 1.8.0 + ../ + + diff --git a/tensorflow/java/maven/tensorflow-hadoop/pom.xml b/tensorflow/java/maven/tensorflow-hadoop/pom.xml new file mode 100644 index 0000000000..ee90d8c92b --- /dev/null +++ b/tensorflow/java/maven/tensorflow-hadoop/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + TensorFlow TFRecord InputFormat/OutputFormat for Apache Hadoop + tensorflow-hadoop + jar + + + https://github.com/tensorflow/ecosystem.git + git@github.com:tensorflow/ecosystem.git + scm:git:https://github.com/tensorflow/ecosystem.git + + + https://github.com/tensorflow/ecosystem/ + + org.tensorflow + parentpom + 1.8.0 + ../ + + -- GitLab From 90b01f238d83d833ce9a843845dd96bb816a6c76 Mon Sep 17 00:00:00 2001 From: Soila Kavulya Date: Tue, 8 May 2018 18:46:35 -0700 Subject: [PATCH 009/752] Delete templating approach for deploying TensorFlow ecosystem jars --- .../pom-spark.xml.template | 19 --- .../spark-tensorflow-connector/update.py | 152 ------------------ .../tensorflow-hadoop/pom-hadoop.xml.template | 18 --- .../java/maven/tensorflow-hadoop/update.py | 114 ------------- 4 files changed, 303 deletions(-) delete mode 100644 tensorflow/java/maven/spark-tensorflow-connector/pom-spark.xml.template delete mode 100644 tensorflow/java/maven/spark-tensorflow-connector/update.py delete mode 100644 tensorflow/java/maven/tensorflow-hadoop/pom-hadoop.xml.template delete mode 100644 tensorflow/java/maven/tensorflow-hadoop/update.py diff --git a/tensorflow/java/maven/spark-tensorflow-connector/pom-spark.xml.template b/tensorflow/java/maven/spark-tensorflow-connector/pom-spark.xml.template deleted file mode 100644 index d8a3d559be..0000000000 --- a/tensorflow/java/maven/spark-tensorflow-connector/pom-spark.xml.template +++ /dev/null @@ -1,19 +0,0 @@ - - 4.0.0 - TensorFlow TFRecord connector for Apache Spark DataFrames - spark-tensorflow-connector_${scala_version} - ${version} - jar - - https://github.com/tensorflow/ecosystem/ - - org.tensorflow - parentpom - ${version} - ../ - - - diff --git a/tensorflow/java/maven/spark-tensorflow-connector/update.py b/tensorflow/java/maven/spark-tensorflow-connector/update.py deleted file mode 100644 index 6185ccbb00..0000000000 --- a/tensorflow/java/maven/spark-tensorflow-connector/update.py +++ /dev/null @@ -1,152 +0,0 @@ -# Copyright 2017 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -""" -Merge TensorFlow Spark connector pom from with deployment template. - -The TensorFlow Spark connector pom is here: https://github.com/tensorflow/ecosystem/tree/master/spark/spark-tensorflow-connector -""" - -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -import argparse -import sys -import string -import xml.etree.ElementTree as ET - -POM_NAMESPACE = "http://maven.apache.org/POM/4.0.0" -SCALA_VERSION_TAG = "scala.binary.version" - - -def get_args(): - """Parse command line args.""" - parser = argparse.ArgumentParser() - parser.add_argument( - '--version', - required=True, - help='Version for the artifact.') - parser.add_argument( - '--scala_version', - required=True, - choices=['2.10', '2.11'], - help='Scala version for the artifact.') - parser.add_argument( - '--template', - required=True, - help='Path to the pom file template.') - parser.add_argument( - '--input_pom', - required=True, - help='Path to input pom file to merge with template.') - parser.add_argument( - '--output_pom', - required=True, - help='Path to output pom file.') - return parser.parse_args() - - -def load_pom(input_path): - """ Loads POM file to XML tree""" - ET.register_namespace("", POM_NAMESPACE) - tree = ET.parse(input_path) - return tree - - -def update_scala_version(tree, version, is_template=False): - """ Updates scala version in XML tree""" - - if is_template: - tag = "{%s}artifactId" % POM_NAMESPACE - nodes = tree.findall(tag) - - if nodes is None: - raise ValueError("Missing artifactId in template pom") - - for node in nodes: - template = string.Template(node.text) - - text = template.substitute({"scala_version": version}) - node.text = text - else: - # Update scala version property in pom - tag = "{%s}%s" % (POM_NAMESPACE, SCALA_VERSION_TAG) - nodes = nodes = list(tree.iter(tag)) - - if len(nodes) == 0: - raise ValueError("Missing %s property in Spark connector pom") - - for node in nodes: - node.text = version - - return tree - - -def update_version(tree, version): - """ Updates version tags in XML tree """ - version_tag = "{%s}version" % POM_NAMESPACE - nodes = list(tree.iter(version_tag)) - - if len(nodes) == 0: - raise ValueError("Missing version in template pom") - - for node in nodes: - node.text = version - - return tree - - -def merge_tags(template_root, pom_root): - """ Merge pom file from TensorFlow Spark connector with deployment template. - - Modify the TensorFlow Spark connector pom to inherit parent pom and version info and - other tags provided by deployment template. - - TODO: Figure out if there is a cleaner way of doing this. Inheritance is needed - for propagating the deployment profile. - - Args: - template_root: Root XML element for template file. - pom_root: Root XML element for TensorFlow Spark connector pom file. - - Return: - template_root: Root XML element with merged tree. - """ - template_tags = [child.tag for child in template_root] - template_tags.append("{%s}groupId" % POM_NAMESPACE) # skip groupId since it is inherited from parent - - for child in pom_root: - if child.tag not in template_tags: - template_root.append(child) - - return template_root - - -def main(): - args = get_args() - template_tree = load_pom(args.template) - pom_tree = load_pom(args.input_pom) - - template_tree = update_version(template_tree, args.version) - template_tree = update_scala_version(template_tree, args.scala_version, is_template=True) - pom_tree = update_scala_version(pom_tree, args.scala_version, is_template=False) - template_root = merge_tags(template_tree.getroot(), pom_tree.getroot()) - - with open(args.output_pom, "w") as f: - f.write(ET.tostring(template_root)) - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/tensorflow/java/maven/tensorflow-hadoop/pom-hadoop.xml.template b/tensorflow/java/maven/tensorflow-hadoop/pom-hadoop.xml.template deleted file mode 100644 index 6a82c56cc7..0000000000 --- a/tensorflow/java/maven/tensorflow-hadoop/pom-hadoop.xml.template +++ /dev/null @@ -1,18 +0,0 @@ - - 4.0.0 - TensorFlow TFRecord InputFormat/OutputFormat for Apache Hadoop - tensorflow-hadoop - ${version} - jar - - https://github.com/tensorflow/ecosystem/ - - org.tensorflow - parentpom - ${version} - ../ - - diff --git a/tensorflow/java/maven/tensorflow-hadoop/update.py b/tensorflow/java/maven/tensorflow-hadoop/update.py deleted file mode 100644 index 503062608d..0000000000 --- a/tensorflow/java/maven/tensorflow-hadoop/update.py +++ /dev/null @@ -1,114 +0,0 @@ -# Copyright 2017 The TensorFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -""" -Merge TensorFlow Hadoop pom from with deployment template. - -The TensorFlow Hadoop pom is here: https://github.com/tensorflow/ecosystem/tree/master/hadoop -""" - -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -import argparse -import sys -import xml.etree.ElementTree as ET - -POM_NAMESPACE = "http://maven.apache.org/POM/4.0.0" - - -def get_args(): - """Parse command line args.""" - parser = argparse.ArgumentParser() - parser.add_argument( - '--version', - required=True, - help='Version for the artifact.') - parser.add_argument( - '--template', - required=True, - help='Path to the pom file template.') - parser.add_argument( - '--input_pom', - required=True, - help='Path to input pom file to merge with template.') - parser.add_argument( - '--output_pom', - required=True, - help='Path to output pom file.') - return parser.parse_args() - - -def load_pom(input_path): - """ Loads POM file to XML tree""" - ET.register_namespace("", POM_NAMESPACE) - tree = ET.parse(input_path) - return tree - - -def update_version(tree, version): - """ Updates version tags in XML tree """ - version_tag = "{%s}version" % POM_NAMESPACE - nodes = list(tree.iter(version_tag)) - - if len(nodes) == 0: - raise ValueError("Missing version in template pom") - - for node in nodes: - node.text = version - - return tree - - -def merge_tags(template_root, pom_root): - """ Merge pom file from TensorFlow Hadoop with deployment template. - - Modify the TensorFlow Hadoop pom to inherit parent pom and version info and - other tags provided by deployment template. - - TODO: Figure out if there is a cleaner way of doing this. Inheritance is needed - for propagating the deployment profile. - - Args: - template_root: Root XML element for template file. - pom_root: Root XML element for TensorFlow Hadoop pom file. - - Return: - template_root: Root XML element with merged tree. - """ - template_tags = [child.tag for child in template_root] - template_tags.append("{%s}groupId" % POM_NAMESPACE) # skip groupId since it is inherited from parent - - for child in pom_root: - if child.tag not in template_tags: - template_root.append(child) - - return template_root - - -def main(): - args = get_args() - template_tree = load_pom(args.template) - pom_tree = load_pom(args.input_pom) - - template_tree = update_version(template_tree, args.version) - template_root = merge_tags(template_tree.getroot(), pom_tree.getroot()) - - with open(args.output_pom, "w") as f: - f.write(ET.tostring(template_root)) - - -if __name__ == '__main__': - sys.exit(main()) -- GitLab From 78da41f8f16871cd1328218cbabcfc82dbecf8a3 Mon Sep 17 00:00:00 2001 From: Sami Kama Date: Wed, 9 May 2018 14:12:54 -0700 Subject: [PATCH 010/752] Subgraph to graphdef --- .../contrib/tensorrt/convert/convert_nodes.cc | 60 +++++++++++++++++++ .../contrib/tensorrt/convert/convert_nodes.h | 4 ++ 2 files changed, 64 insertions(+) diff --git a/tensorflow/contrib/tensorrt/convert/convert_nodes.cc b/tensorflow/contrib/tensorrt/convert/convert_nodes.cc index 3767596f8c..9b9ce51097 100644 --- a/tensorflow/contrib/tensorrt/convert/convert_nodes.cc +++ b/tensorflow/contrib/tensorrt/convert/convert_nodes.cc @@ -53,8 +53,11 @@ limitations under the License. namespace tensorflow { namespace tensorrt { namespace convert { +using ::tensorflow::str_util::Split; + using ::tensorflow::strings::StrAppend; using ::tensorflow::strings::StrCat; + namespace { inline tensorflow::Status ConvertDType(tensorflow::DataType tf_dtype, @@ -2723,6 +2726,63 @@ tensorflow::Status ConvertSubGraphToTensorRTNodeDef( return tensorflow::Status::OK(); } +// This needs to be called before TensorRT nodes inserted in order to correctly +// get sizes from the original graph +tensorflow::Status ConvertSegmentToGraphDef( + tensorflow::tensorrt::convert::SubGraphParams& params, + tensorflow::GraphDef* segment_def, + std::unordered_map *input_placeholder_map + ) { + //std::unordered_map input_placeholder_map; + for (size_t i = 0; i < params.input_inds.size(); ++i) { + auto& inputs = params.input_inds.at(i); + auto input_node = params.graph.FindNodeId(inputs.first); + if (input_node) { + tensorflow::DataType input_type = tensorflow::DT_FLOAT; + tensorflow::PartialTensorShape partial_shape; + + if (params.graph_properties.HasOutputProperties(input_node->name())) { + auto output_params = + params.graph_properties.GetOutputProperties(input_node->name()); + auto out_shape = output_params.at(inputs.second); + input_type = out_shape.dtype(); + std::vector dims; + for (const auto d : out_shape.shape().dim()) { + dims.push_back(d.size()); + } + tensorflow::PartialTensorShape::MakePartialShape( + dims.data(), dims.size(), &partial_shape); + } + tensorflow::NodeDef dummy_placeholder; + string node_name("InputPH_"); + StrAppend(&node_name, i); + input_placeholder_map->insert({input_node->name(),node_name}); + tensorflow::NodeDefBuilder dph_builder(node_name, "Placeholder"); + auto status = dph_builder.Attr("shape", partial_shape) + .Attr("dtype", input_type) + .Finalize(&dummy_placeholder); + auto seg_node = segment_def->add_node(); + seg_node->CopyFrom(dummy_placeholder); + } + } + for (const auto node_id : params.subgraph_node_ids) { + const auto node = params.graph.FindNodeId(node_id); + if (node) { + auto snode = segment_def->add_node(); + snode->CopyFrom(node->def()); + // check node inputs to see if it was connected to input node and update + // it to point to placeholder if necessary + for (int i = 0; i < snode->input_size(); ++i) { + auto node_input = Split(snode->input(i), ":"); + string node_input_name = node_input[0]; + auto it = input_placeholder_map->find(node_input_name); + if (it != input_placeholder_map->end()) { + snode->set_input(i, it->second); + } + } + } + } +} } // namespace convert } // namespace tensorrt } // namespace tensorflow diff --git a/tensorflow/contrib/tensorrt/convert/convert_nodes.h b/tensorflow/contrib/tensorrt/convert/convert_nodes.h index 3f6592cd25..903867fa7f 100644 --- a/tensorflow/contrib/tensorrt/convert/convert_nodes.h +++ b/tensorflow/contrib/tensorrt/convert/convert_nodes.h @@ -85,6 +85,10 @@ tensorflow::Status ConvertSubGraphToTensorRTNodeDef(SubGraphParams& params); tensorflow::Status InjectCalibrationNode(SubGraphParams& params); tensorflow::Status ConvertCalibrationNodeToEngineNode(tensorflow::Graph& graph, tensorflow::Node* c_node); +tensorflow::Status ConvertSegmentToGraphDef( + tensorflow::tensorrt::convert::SubGraphParams& params, + tensorflow::GraphDef* segment_def, + std::unordered_map input_placeholder_map); } // namespace convert } // namespace tensorrt } // namespace tensorflow -- GitLab From b7c333dc75041b05ef4b0023db5dbbda4a817283 Mon Sep 17 00:00:00 2001 From: Dan Osipov Date: Wed, 16 May 2018 16:42:47 -0700 Subject: [PATCH 011/752] Resize first, pad second --- tensorflow/python/ops/image_ops_impl.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tensorflow/python/ops/image_ops_impl.py b/tensorflow/python/ops/image_ops_impl.py index d5ac72bac6..a070a4699f 100644 --- a/tensorflow/python/ops/image_ops_impl.py +++ b/tensorflow/python/ops/image_ops_impl.py @@ -1048,19 +1048,19 @@ def resize_image_with_pad(image, target_height, target_width, # Find the ratio by which the image must be adjusted # to fit within the target ratio = max_(f_width / f_target_width, f_height / f_target_height) - p_height_float = max_((f_target_height - (f_height / ratio)) * ratio / 2, 0) - p_width_float = max_((f_target_width - (f_width / ratio)) * ratio / 2, 0) - p_height = math_ops.cast(math_ops.ceil(p_height_float), dtype=dtypes.int32) - p_width = math_ops.cast(math_ops.ceil(p_width_float), dtype=dtypes.int32) + resized_height_float = f_height / ratio + resized_width_float = f_width / ratio + resized_height = math_ops.cast(math_ops.floor(p_height_float), dtype=dtypes.int32) + resized_width = math_ops.cast(math_ops.floor(p_width_float), dtype=dtypes.int32) - padded_height = height + (p_height * 2) - padded_width = width + (p_width * 2) + p_height = target_height - resized_height + p_weight = target_width - resized_width - # Pad first, then resize to meet requested dimensions + # Resize first, then pad to meet requested dimensions + resized = resize_images(image, [resized_height, resized_width], method) + padded = pad_to_bounding_box(image, p_height, p_width, - padded_height, padded_width) - - resized = resize_images(padded, [target_height, target_width], method) + target_height, target_width) if resized.get_shape().ndims is None: raise ValueError('resized contains no shape.') -- GitLab From 416bac50aaa684049bb3270d379316efc5b960c2 Mon Sep 17 00:00:00 2001 From: Lukas Geiger Date: Fri, 25 May 2018 01:06:33 +0200 Subject: [PATCH 012/752] [tfgan] Add possibility to export GANEstimator saved model --- tensorflow/contrib/gan/python/estimator/python/head_impl.py | 6 +++++- tensorflow/contrib/gan/python/estimator/python/head_test.py | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tensorflow/contrib/gan/python/estimator/python/head_impl.py b/tensorflow/contrib/gan/python/estimator/python/head_impl.py index ff903a78cc..5b5557bd8f 100644 --- a/tensorflow/contrib/gan/python/estimator/python/head_impl.py +++ b/tensorflow/contrib/gan/python/estimator/python/head_impl.py @@ -24,6 +24,7 @@ from tensorflow.contrib.gan.python import namedtuples as tfgan_tuples from tensorflow.contrib.gan.python import train as tfgan_train from tensorflow.python.estimator import model_fn as model_fn_lib from tensorflow.python.estimator.canned import head +from tensorflow.python.estimator.export import export_output from tensorflow.python.framework import ops from tensorflow.python.ops import metrics as metrics_lib @@ -182,7 +183,10 @@ class GANHead(head._Head): # pylint: disable=protected-access if mode == model_fn_lib.ModeKeys.PREDICT: return model_fn_lib.EstimatorSpec( mode=model_fn_lib.ModeKeys.PREDICT, - predictions=gan_model.generated_data) + predictions=gan_model.generated_data, + export_outputs={ + 'predict': export_output.PredictOutput(gan_model.generated_data) + }) elif mode == model_fn_lib.ModeKeys.EVAL: gan_loss = self.create_loss( features=None, mode=mode, logits=gan_model, labels=None) diff --git a/tensorflow/contrib/gan/python/estimator/python/head_test.py b/tensorflow/contrib/gan/python/estimator/python/head_test.py index 6587f1fc60..c121f322b5 100644 --- a/tensorflow/contrib/gan/python/estimator/python/head_test.py +++ b/tensorflow/contrib/gan/python/estimator/python/head_test.py @@ -71,13 +71,14 @@ class GANHeadTest(test.TestCase): return {} def _test_modes_helper(self, mode): - self.gan_head.create_estimator_spec( + return self.gan_head.create_estimator_spec( features=None, mode=mode, logits=get_gan_model()) def test_modes_predict(self): - self._test_modes_helper(model_fn_lib.ModeKeys.PREDICT) + spec = self._test_modes_helper(model_fn_lib.ModeKeys.PREDICT) + self.assertItemsEqual(('predict',), spec.export_outputs.keys()) def test_modes_eval(self): self._test_modes_helper(model_fn_lib.ModeKeys.EVAL) -- GitLab From 06ba7827cb4e781ab36e6bbc46cf34e3ea587335 Mon Sep 17 00:00:00 2001 From: Dan Osipov Date: Sun, 27 May 2018 10:33:27 -0700 Subject: [PATCH 013/752] Remove unused function --- tensorflow/python/ops/image_ops_impl.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tensorflow/python/ops/image_ops_impl.py b/tensorflow/python/ops/image_ops_impl.py index a070a4699f..6e72ebd634 100644 --- a/tensorflow/python/ops/image_ops_impl.py +++ b/tensorflow/python/ops/image_ops_impl.py @@ -1031,12 +1031,6 @@ def resize_image_with_pad(image, target_height, target_width, else: return max(x, y) - def equal_(x, y): - if _is_tensor(x) or _is_tensor(y): - return math_ops.equal(x, y) - else: - return x == y - _, height, width, _ = _ImageDimensions(image, rank=4) # convert values to float, to ease divisions -- GitLab From 7991324a664c4c187c6e7e76d1c7588d79530c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yan=20Facai=20=28=E9=A2=9C=E5=8F=91=E6=89=8D=29?= Date: Wed, 30 May 2018 17:40:14 +0800 Subject: [PATCH 014/752] ENH: add gradient for sparse_slice --- tensorflow/core/kernels/BUILD | 7 + .../core/kernels/sparse_slice_grad_op.cc | 120 ++++++++++++++++++ tensorflow/core/ops/sparse_ops.cc | 14 ++ 3 files changed, 141 insertions(+) create mode 100644 tensorflow/core/kernels/sparse_slice_grad_op.cc diff --git a/tensorflow/core/kernels/BUILD b/tensorflow/core/kernels/BUILD index 1bf6eafb58..dc1155077b 100644 --- a/tensorflow/core/kernels/BUILD +++ b/tensorflow/core/kernels/BUILD @@ -3886,6 +3886,7 @@ cc_library( ":sparse_reduce_op", ":sparse_reorder_op", ":sparse_reshape_op", + ":sparse_slice_grad_op", ":sparse_slice_op", ":sparse_softmax", ":sparse_sparse_binary_op_shared", @@ -3971,6 +3972,12 @@ tf_kernel_library( ], ) +tf_kernel_library( + name = "sparse_slice_grad_op", + prefix = "sparse_slice_grad_op", + deps = SPARSE_DEPS, +) + tf_kernel_library( name = "sparse_slice_op", prefix = "sparse_slice_op", diff --git a/tensorflow/core/kernels/sparse_slice_grad_op.cc b/tensorflow/core/kernels/sparse_slice_grad_op.cc new file mode 100644 index 0000000000..8d2c597c75 --- /dev/null +++ b/tensorflow/core/kernels/sparse_slice_grad_op.cc @@ -0,0 +1,120 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/core/framework/op_kernel.h" +#include "tensorflow/core/framework/register_types.h" +#include "tensorflow/core/framework/tensor.h" +#include "tensorflow/core/framework/tensor_util.h" +#include "tensorflow/core/framework/types.h" +#include "tensorflow/core/util/sparse/sparse_tensor.h" + +namespace tensorflow { + +template +class SparseSliceGradOp : public OpKernel { + public: + explicit SparseSliceGradOp(OpKernelConstruction *ctx) : OpKernel(ctx) {} + + void Compute(OpKernelContext *ctx) override { + const Tensor *backprop_val_grad, *input_indices, *output_indices, *input_start; + OP_REQUIRES_OK(ctx, ctx->input("backprop_val_grad", &backprop_val_grad)); + OP_REQUIRES_OK(ctx, ctx->input("input_indices", &input_indices)); + OP_REQUIRES_OK(ctx, ctx->input("input_start", &input_start)); + OP_REQUIRES_OK(ctx, ctx->input("output_indices", &output_indices)); + + OP_REQUIRES(ctx, + TensorShapeUtils::IsMatrix(input_indices->shape()) && + TensorShapeUtils::IsMatrix(output_indices->shape()), + errors::InvalidArgument( + "Input indices should be matrices but received shapes: ", + input_indices->shape().DebugString(), " and ", + output_indices->shape().DebugString())); + OP_REQUIRES( + ctx, TensorShapeUtils::IsVector(backprop_val_grad->shape()), + errors::InvalidArgument( + "Input backprop_val_grad should be a vector but received shape: ", + backprop_val_grad->shape().DebugString())); + OP_REQUIRES( + ctx, + input_indices->dim_size(1) == output_indices->dim_size(1), + errors::InvalidArgument("The input and output should have the same " + "ndims: got: ", input_indices->dim_size(1), " and ", + output_indices->dim_size(1))); + OP_REQUIRES( + ctx, output_indices->dim_size(0) <= input_indices->dim_size(0), + errors::InvalidArgument("# rows of output_indices should be not greater " + "than of input_indices, got ", + output_indices->dim_size(0), " and ", + input_indices->dim_size(0))); + OP_REQUIRES( + ctx, backprop_val_grad->NumElements() == output_indices->dim_size(0), + errors::InvalidArgument("# elements of backprop_val_grad and # rows of " + "output_indices should match (#nnz of sum): got ", + backprop_val_grad->NumElements(), " and ", + output_indices->dim_size(0))); + OP_REQUIRES(ctx, TensorShapeUtils::IsVector(input_start->shape()), + errors::InvalidArgument( + "Input start should be a vector but received shape ", + input_start->shape().DebugString())); + + const int num_dims = input_indices->dim_size(1); + const int64 input_nnz = input_indices->dim_size(0); + + Tensor *val_grad; + OP_REQUIRES_OK(ctx, + ctx->allocate_output(0, TensorShape({input_nnz}), &val_grad)); + + T *val_grad_flat = val_grad->flat().data(); + const T *backprop_val_grad_flat = backprop_val_grad->flat().data(); + memset(val_grad_flat, 0, sizeof(T) * input_nnz); + + // Fill gradients for position where indices of input and ouput are same. + const auto input_indices_mat = input_indices->matrix(); + const auto output_indices_mat = output_indices->matrix(); + const auto input_start_flat = input_start->flat(); + int64 j = 0; + for (int64 i = 0; i < input_nnz && j < backprop_val_grad->NumElements(); + ++i) { + bool isSame = true; + for (int d = 0; d < num_dims; ++d) { + const int64 a = input_indices_mat(i, d); + const int64 b = output_indices_mat(j, d); + const int64 offset = input_start_flat(d); + if (a != b + offset) { + isSame = false; + break; + } + } + if (isSame) { + val_grad_flat[i] = backprop_val_grad_flat[j]; + ++j; + } + } + OP_REQUIRES( + ctx, backprop_val_grad->NumElements() == j, + errors::Internal("Elements of backprop_val_grad aren't eaten up :", + "all: ", backprop_val_grad->NumElements(), + " , used: ", output_indices->dim_size(0))); + } +}; + +#define REGISTER_KERNELS(type) \ + REGISTER_KERNEL_BUILDER( \ + Name("SparseSliceGrad").Device(DEVICE_CPU).TypeConstraint("T"), \ + SparseSliceGradOp) + +TF_CALL_NUMBER_TYPES(REGISTER_KERNELS); +#undef REGISTER_KERNELS +} // namespace tensorflow diff --git a/tensorflow/core/ops/sparse_ops.cc b/tensorflow/core/ops/sparse_ops.cc index acc8c782ef..bc0cb2095d 100644 --- a/tensorflow/core/ops/sparse_ops.cc +++ b/tensorflow/core/ops/sparse_ops.cc @@ -302,6 +302,20 @@ REGISTER_OP("SparseSplit") return Status::OK(); }); +REGISTER_OP("SparseSliceGrad") + .Input("backprop_val_grad: T") + .Input("input_indices: int64") + .Input("input_start: int64") + .Input("output_indices: int64") + .Output("val_grad: T") + .Attr("T: numbertype") + .SetShapeFn([](InferenceContext* c) { + ShapeHandle indices; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 2, &indices)); + c->set_output(0, c->Vector(c->Dim(indices, 0))); + return Status::OK(); + }); + REGISTER_OP("SparseSlice") .Input("indices: int64") .Input("values: T") -- GitLab From b0ec8d2c467173ce5a43c13631bc51fd89f072e5 Mon Sep 17 00:00:00 2001 From: Soila Kavulya Date: Wed, 30 May 2018 19:23:08 -0700 Subject: [PATCH 015/752] Update artifactId for TensorFlow Hadoop and spark-connector jars --- tensorflow/java/maven/README.md | 4 ++-- .../java/maven/{tensorflow-hadoop => hadoop}/pom.xml | 4 ++-- tensorflow/java/maven/pom.xml | 4 ++-- tensorflow/java/maven/run_inside_container.sh | 10 ++++++---- .../pom.xml | 4 ++-- 5 files changed, 14 insertions(+), 12 deletions(-) rename tensorflow/java/maven/{tensorflow-hadoop => hadoop}/pom.xml (94%) rename tensorflow/java/maven/{spark-tensorflow-connector => spark-connector}/pom.xml (93%) diff --git a/tensorflow/java/maven/README.md b/tensorflow/java/maven/README.md index fa756815a9..3e030dcd09 100644 --- a/tensorflow/java/maven/README.md +++ b/tensorflow/java/maven/README.md @@ -53,10 +53,10 @@ There are seven artifacts and thus `pom.xml`s involved in this release: 7. [`parentpom`](https://maven.apache.org/pom/index.html): Common settings shared by all of the above. -8. `tensorflow-hadoop`: The TensorFlow TFRecord InputFormat/OutputFormat for Apache Hadoop. +8. `hadoop`: The TensorFlow TFRecord InputFormat/OutputFormat for Apache Hadoop. The source code for this package is available in the [TensorFlow Ecosystem](https://github.com/tensorflow/ecosystem/tree/master/hadoop) -9. `spark-tensorflow-connector`: A Scala library for loading and storing TensorFlow TFRecord +9. `spark-connector`: A Scala library for loading and storing TensorFlow TFRecord using Apache Spark DataFrames. The source code for this package is available in the [TensorFlow Ecosystem](https://github.com/tensorflow/ecosystem/tree/master/spark/spark-tensorflow-connector) diff --git a/tensorflow/java/maven/tensorflow-hadoop/pom.xml b/tensorflow/java/maven/hadoop/pom.xml similarity index 94% rename from tensorflow/java/maven/tensorflow-hadoop/pom.xml rename to tensorflow/java/maven/hadoop/pom.xml index ee90d8c92b..a872c20d3b 100644 --- a/tensorflow/java/maven/tensorflow-hadoop/pom.xml +++ b/tensorflow/java/maven/hadoop/pom.xml @@ -5,7 +5,7 @@ 4.0.0 TensorFlow TFRecord InputFormat/OutputFormat for Apache Hadoop - tensorflow-hadoop + hadoop jar @@ -21,4 +21,4 @@ 1.8.0 ../ - + \ No newline at end of file diff --git a/tensorflow/java/maven/pom.xml b/tensorflow/java/maven/pom.xml index 7a95fb2556..19287f8245 100644 --- a/tensorflow/java/maven/pom.xml +++ b/tensorflow/java/maven/pom.xml @@ -32,8 +32,8 @@ libtensorflow_jni_gpu tensorflow proto - tensorflow-hadoop - spark-tensorflow-connector + hadoop + spark-connector 4.0.0 TensorFlow TFRecord connector for Apache Spark DataFrames - spark-tensorflow-connector + spark-connector jar @@ -21,4 +21,4 @@ 1.8.0 ../ - + \ No newline at end of file -- GitLab From c47442d74edf0de11cad2975662a21bd27b9bf68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yan=20Facai=20=28=E9=A2=9C=E5=8F=91=E6=89=8D=29?= Date: Thu, 31 May 2018 10:45:28 +0800 Subject: [PATCH 016/752] ENH: add gradient in python side --- tensorflow/python/kernel_tests/BUILD | 1 + .../kernel_tests/sparse_slice_op_test.py | 22 ++++++++++++-- tensorflow/python/ops/sparse_grad.py | 30 +++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/tensorflow/python/kernel_tests/BUILD b/tensorflow/python/kernel_tests/BUILD index 83b353600a..82f3357515 100644 --- a/tensorflow/python/kernel_tests/BUILD +++ b/tensorflow/python/kernel_tests/BUILD @@ -892,6 +892,7 @@ tf_py_test( "//third_party/py/numpy", "//tensorflow/python:client_testlib", "//tensorflow/python:framework", + "//tensorflow/python:sparse_grad", "//tensorflow/python:sparse_ops", ], ) diff --git a/tensorflow/python/kernel_tests/sparse_slice_op_test.py b/tensorflow/python/kernel_tests/sparse_slice_op_test.py index da116601f8..38eed897cf 100644 --- a/tensorflow/python/kernel_tests/sparse_slice_op_test.py +++ b/tensorflow/python/kernel_tests/sparse_slice_op_test.py @@ -21,13 +21,15 @@ from __future__ import print_function import numpy as np from tensorflow.python.framework import sparse_tensor +from tensorflow.python.ops import gradient_checker from tensorflow.python.ops import sparse_ops +import tensorflow.python.ops.sparse_grad # pylint: disable=unused-import from tensorflow.python.platform import test class SparseSliceOpTest(test.TestCase): - def _SparseTensor_4x6(self): + def _SparseTensor_4x6(self, val_dtype=np.int64): # [0 | |2 | |4 |5 ] # [ |11| |13|14| ] # [20| | |23| |25] @@ -37,7 +39,7 @@ class SparseSliceOpTest(test.TestCase): [2, 3], [2, 5], [3, 0], [3, 2], [3, 3], [3, 5]]).astype( np.int64) val = np.array([0, 2, 4, 5, 11, 13, 14, 20, 23, 25, 30, 32, 33, 35]).astype( - np.int64) + val_dtype) shape = np.array([4, 6]).astype(np.int64) return sparse_tensor.SparseTensor(ind, val, shape) @@ -244,6 +246,22 @@ class SparseSliceOpTest(test.TestCase): self.assertAllEqual(sparse_tensor5.values.eval(), [5, 25, 35]) self.assertAllEqual(sparse_tensor5.dense_shape.eval(), [4, 1]) + def testGradients(self): + sp_input = self._SparseTensor_4x6(val_dtype=np.float32) + start_and_size = [([0, 0], [4, 2]), + ([0, 2], [5, 2]), + ([0, 4], [5, 3])] + + with self.test_session(use_gpu=False): + for start, size in start_and_size: + sp_output = sparse_ops.sparse_slice(sp_input, start, size) + nnz_in = len(sp_input.values.eval()) + nnz_out = len(sp_output.values.eval()) + + err = gradient_checker.compute_gradient_error( + [sp_input.values], [(nnz_in,)], sp_output.values, (nnz_out,)) + self.assertLess(err, 1e-3) + if __name__ == '__main__': test.main() diff --git a/tensorflow/python/ops/sparse_grad.py b/tensorflow/python/ops/sparse_grad.py index 97353d6c74..3ed94738e0 100644 --- a/tensorflow/python/ops/sparse_grad.py +++ b/tensorflow/python/ops/sparse_grad.py @@ -116,6 +116,36 @@ def _SparseReduceSumGrad(op, out_grad): None, None) +@ops.RegisterGradient("SparseSlice") +def _SparseSliceGrad(op, *grads): + """The backward operator for the SparseSlice op. + + The SparseAdd op calculates A + B, where A, B, and the sum are all represented + as `SparseTensor` objects. This op takes in the upstream gradient w.r.t. + non-empty values of the sum, and outputs the gradients w.r.t. the non-empty + values of A and B. + + Args: + op: the SparseAdd op + *grads: the incoming gradients, one element per output of `op` + + Returns: + Gradient for each of the 6 input tensors of SparseAdd: + (a_indices, a_values, a_shape, b_indices, b_values, b_shape, thresh) + The gradients for the indices, shapes, and the threshold are None. + """ + backprop_val_grad = grads[1] + input_indices = op.inputs[0] + input_start = op.inputs[3] + output_indices = op.outputs[0] + + val_grad = gen_sparse_ops.sparse_slice_grad( + backprop_val_grad, input_indices, input_start, output_indices) + val_grad.set_shape(op.inputs[1].get_shape()) + # (indices, values, shape, start, size) + return (None, val_grad, None, None, None) + + @ops.RegisterGradient("SparseTensorDenseMatMul") def _SparseTensorDenseMatMulGrad(op, grad): """Gradients for the dense tensor in the SparseTensorDenseMatMul op. -- GitLab From 86191c9f267fbd157c199c410e8d46574d034782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yan=20Facai=20=28=E9=A2=9C=E5=8F=91=E6=89=8D=29?= Date: Thu, 31 May 2018 12:27:39 +0800 Subject: [PATCH 017/752] DOC: add document --- .../base_api/api_def_SparseSliceGrad.pbtxt | 40 +++++++++++++++++++ .../python_api/api_def_SparseSliceGrad.pbtxt | 4 ++ tensorflow/python/ops/sparse_grad.py | 15 ++++--- 3 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 tensorflow/core/api_def/base_api/api_def_SparseSliceGrad.pbtxt create mode 100644 tensorflow/core/api_def/python_api/api_def_SparseSliceGrad.pbtxt diff --git a/tensorflow/core/api_def/base_api/api_def_SparseSliceGrad.pbtxt b/tensorflow/core/api_def/base_api/api_def_SparseSliceGrad.pbtxt new file mode 100644 index 0000000000..51af6adcf1 --- /dev/null +++ b/tensorflow/core/api_def/base_api/api_def_SparseSliceGrad.pbtxt @@ -0,0 +1,40 @@ +op { + graph_op_name: "SparseSliceGrad" + in_arg { + name: "backprop_val_grad" + description: <