aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow')
-rw-r--r--tensorflow/cc/BUILD1
-rw-r--r--tensorflow/cc/ops/standard_ops.h1
-rw-r--r--tensorflow/core/BUILD2
-rw-r--r--tensorflow/core/kernels/BUILD8
-rw-r--r--tensorflow/core/kernels/attention_ops.cc2
-rw-r--r--tensorflow/core/ops/attention_ops.cc69
-rw-r--r--tensorflow/core/ops/image_ops.cc61
-rw-r--r--tensorflow/core/ops/ops.pbtxt9
-rw-r--r--tensorflow/python/BUILD7
-rw-r--r--tensorflow/python/kernel_tests/attention_ops_test.py2
-rw-r--r--tensorflow/python/ops/attention_ops.py52
-rw-r--r--tensorflow/python/ops/image_ops.py26
12 files changed, 91 insertions, 149 deletions
diff --git a/tensorflow/cc/BUILD b/tensorflow/cc/BUILD
index 32267108d2..e7e82f6fe2 100644
--- a/tensorflow/cc/BUILD
+++ b/tensorflow/cc/BUILD
@@ -29,7 +29,6 @@ tf_gen_op_wrappers_cc(
name = "cc_ops",
op_lib_names = [
"array_ops",
- "attention_ops",
"candidate_sampling_ops",
"control_flow_ops",
"data_flow_ops",
diff --git a/tensorflow/cc/ops/standard_ops.h b/tensorflow/cc/ops/standard_ops.h
index 72d8ae2771..e9aa7a060e 100644
--- a/tensorflow/cc/ops/standard_ops.h
+++ b/tensorflow/cc/ops/standard_ops.h
@@ -20,7 +20,6 @@ limitations under the License.
#define TENSORFLOW_CC_OPS_STANDARD_OPS_H_
#include "tensorflow/cc/ops/array_ops.h"
-#include "tensorflow/cc/ops/attention_ops.h"
#include "tensorflow/cc/ops/const_op.h"
#include "tensorflow/cc/ops/data_flow_ops.h"
#include "tensorflow/cc/ops/image_ops.h"
diff --git a/tensorflow/core/BUILD b/tensorflow/core/BUILD
index 2498e817ad..7d01035d0d 100644
--- a/tensorflow/core/BUILD
+++ b/tensorflow/core/BUILD
@@ -297,7 +297,6 @@ cc_binary(
tf_gen_op_libs(
op_lib_names = [
"array_ops",
- "attention_ops",
"candidate_sampling_ops",
"control_flow_ops",
"ctc_ops",
@@ -338,7 +337,6 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
":array_ops_op_lib",
- ":attention_ops_op_lib",
":candidate_sampling_ops_op_lib",
":control_flow_ops_op_lib",
":ctc_ops_op_lib",
diff --git a/tensorflow/core/kernels/BUILD b/tensorflow/core/kernels/BUILD
index 6e12154b08..5bf96d3fbb 100644
--- a/tensorflow/core/kernels/BUILD
+++ b/tensorflow/core/kernels/BUILD
@@ -525,14 +525,12 @@ tf_kernel_libraries(
"sample_distorted_bounding_box_op",
],
deps = [
- "//third_party/eigen3",
- "//tensorflow/core:protos_all_cc",
"//tensorflow/core:framework",
+ "//tensorflow/core:image_ops_op_lib",
"//tensorflow/core:lib",
"//tensorflow/core:lib_internal",
- # TODO(josh11b): Merge these ops libs
- "//tensorflow/core:image_ops_op_lib",
- "//tensorflow/core:attention_ops_op_lib",
+ "//tensorflow/core:protos_all_cc",
+ "//third_party/eigen3",
],
)
diff --git a/tensorflow/core/kernels/attention_ops.cc b/tensorflow/core/kernels/attention_ops.cc
index 768df239d6..55a497db1a 100644
--- a/tensorflow/core/kernels/attention_ops.cc
+++ b/tensorflow/core/kernels/attention_ops.cc
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
-// See docs in ../ops/attention_ops.cc.
+// See docs in ../ops/image_ops.cc.
#define EIGEN_USE_THREADS
diff --git a/tensorflow/core/ops/attention_ops.cc b/tensorflow/core/ops/attention_ops.cc
deleted file mode 100644
index 13c25847af..0000000000
--- a/tensorflow/core/ops/attention_ops.cc
+++ /dev/null
@@ -1,69 +0,0 @@
-/* Copyright 2015 Google Inc. 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.h"
-
-namespace tensorflow {
-
-// Tout = extract_glimpse(Tin, size, offsets) extract the glimpse of size size
-// centered at location offsets from the input tensor Tin
-//
-// REQUIRES: Tin.dims() == 4
-//
-REGISTER_OP("ExtractGlimpse")
- .Input("input: float")
- .Input("size: int32")
- .Input("offsets: float")
- .Output("glimpse: float")
- .Attr("centered: bool = true")
- .Attr("normalized: bool = true")
- .Attr("uniform_noise: bool = true")
- .Doc(R"doc(
-Extracts a glimpse from the input tensor.
-
-Returns a set of windows called glimpses extracted at location `offsets`
-from the input tensor. If the windows only partially overlaps the inputs, the
-non overlapping areas will be filled with random noise.
-
-The result is a 4-D tensor of shape `[batch_size, glimpse_height,
-glimpse_width, channels]`. The channels and batch dimensions are the same as that
-of the input tensor. The height and width of the output windows are
-specified in the `size` parameter.
-
-The argument `normalized` and `centered` controls how the windows are built:
-* If the coordinates are normalized but not centered, 0.0 and 1.0
- correspond to the minimum and maximum of each height and width dimension.
-* If the coordinates are both normalized and centered, they range from -1.0 to
- 1.0. The coordinates (-1.0, -1.0) correspond to the upper left corner, the
- lower right corner is located at (1.0, 1.0) and the center is at (0, 0).
-* If the coordinates are not normalized they are interpreted as numbers of pixels.
-
-input: A 4-D float tensor of shape `[batch_size, height, width, channels]`.
-size: A 1-D tensor of 2 elements containing the size of the glimpses to extract.
- The glimpse height must be specified first, following by the glimpse width.
-offsets: A 2-D integer tensor of shape `[batch_size, 2]` containing the x, y
- locations of the center of each window.
-glimpse: A tensor representing the glimpses `[batch_size, glimpse_height,
- glimpse_width, channels]`.
-centered: indicates if the offset coordinates are centered relative to
- the image, in which case the (0, 0) offset is relative to the center of the
- input images. If false, the (0,0) offset corresponds to the upper left corner
- of the input images.
-normalized: indicates if the offset coordinates are normalized.
-uniform_noise: indicates if the noise should be generated using a
- uniform distribution or a gaussian distribution.
-)doc");
-
-} // namespace tensorflow
diff --git a/tensorflow/core/ops/image_ops.cc b/tensorflow/core/ops/image_ops.cc
index 99c90a811b..64553c6bb5 100644
--- a/tensorflow/core/ops/image_ops.cc
+++ b/tensorflow/core/ops/image_ops.cc
@@ -492,4 +492,65 @@ use_image_if_no_bounding_boxes: Controls behavior if no bounding boxes supplied.
If true, assume an implicit bounding box covering the whole input. If false,
raise an error.
)doc");
+
+
+// --------------------------------------------------------------------------
+
+// glimpse = extract_glimpse(input, size, offsets) extract the glimpse
+// of size `size` centered at location `offsets` from the input tensor
+// `input`.
+//
+// REQUIRES: input.dims() == 4
+//
+REGISTER_OP("ExtractGlimpse")
+ .Input("input: float")
+ .Input("size: int32")
+ .Input("offsets: float")
+ .Output("glimpse: float")
+ .Attr("centered: bool = true")
+ .Attr("normalized: bool = true")
+ .Attr("uniform_noise: bool = true")
+ .Doc(R"doc(
+Extracts a glimpse from the input tensor.
+
+Returns a set of windows called glimpses extracted at location
+`offsets` from the input tensor. If the windows only partially
+overlaps the inputs, the non overlapping areas will be filled with
+random noise.
+
+The result is a 4-D tensor of shape `[batch_size, glimpse_height,
+glimpse_width, channels]`. The channels and batch dimensions are the
+same as that of the input tensor. The height and width of the output
+windows are specified in the `size` parameter.
+
+The argument `normalized` and `centered` controls how the windows are
+built:
+
+* If the coordinates are normalized but not centered, 0.0 and 1.0
+ correspond to the minimum and maximum of each height and width
+ dimension.
+* If the coordinates are both normalized and centered, they range from
+ -1.0 to 1.0. The coordinates (-1.0, -1.0) correspond to the upper
+ left corner, the lower right corner is located at (1.0, 1.0) and the
+ center is at (0, 0).
+* If the coordinates are not normalized they are interpreted as
+ numbers of pixels.
+
+input: A 4-D float tensor of shape `[batch_size, height, width, channels]`.
+size: A 1-D tensor of 2 elements containing the size of the glimpses
+ to extract. The glimpse height must be specified first, following
+ by the glimpse width.
+offsets: A 2-D integer tensor of shape `[batch_size, 2]` containing
+ the x, y locations of the center of each window.
+glimpse: A tensor representing the glimpses `[batch_size,
+ glimpse_height, glimpse_width, channels]`.
+centered: indicates if the offset coordinates are centered relative to
+ the image, in which case the (0, 0) offset is relative to the center
+ of the input images. If false, the (0,0) offset corresponds to the
+ upper left corner of the input images.
+normalized: indicates if the offset coordinates are normalized.
+uniform_noise: indicates if the noise should be generated using a
+ uniform distribution or a gaussian distribution.
+)doc");
+
} // namespace tensorflow
diff --git a/tensorflow/core/ops/ops.pbtxt b/tensorflow/core/ops/ops.pbtxt
index d6f4a2f780..3bed7f782d 100644
--- a/tensorflow/core/ops/ops.pbtxt
+++ b/tensorflow/core/ops/ops.pbtxt
@@ -3230,22 +3230,18 @@ op {
name: "ExtractGlimpse"
input_arg {
name: "input"
- description: "A 4-D float tensor of shape `[batch_size, height, width, channels]`."
type: DT_FLOAT
}
input_arg {
name: "size"
- description: "A 1-D tensor of 2 elements containing the size of the glimpses to extract.\nThe glimpse height must be specified first, following by the glimpse width."
type: DT_INT32
}
input_arg {
name: "offsets"
- description: "A 2-D integer tensor of shape `[batch_size, 2]` containing the x, y\nlocations of the center of each window."
type: DT_FLOAT
}
output_arg {
name: "glimpse"
- description: "A tensor representing the glimpses `[batch_size, glimpse_height,\nglimpse_width, channels]`."
type: DT_FLOAT
}
attr {
@@ -3254,7 +3250,6 @@ op {
default_value {
b: true
}
- description: "indicates if the offset coordinates are centered relative to\nthe image, in which case the (0, 0) offset is relative to the center of the\ninput images. If false, the (0,0) offset corresponds to the upper left corner\nof the input images."
}
attr {
name: "normalized"
@@ -3262,7 +3257,6 @@ op {
default_value {
b: true
}
- description: "indicates if the offset coordinates are normalized."
}
attr {
name: "uniform_noise"
@@ -3270,10 +3264,9 @@ op {
default_value {
b: true
}
- description: "indicates if the noise should be generated using a\nuniform distribution or a gaussian distribution."
}
summary: "Extracts a glimpse from the input tensor."
- description: "Returns a set of windows called glimpses extracted at location `offsets`\nfrom the input tensor. If the windows only partially overlaps the inputs, the\nnon overlapping areas will be filled with random noise.\n\nThe result is a 4-D tensor of shape `[batch_size, glimpse_height,\nglimpse_width, channels]`. The channels and batch dimensions are the same as that\nof the input tensor. The height and width of the output windows are\nspecified in the `size` parameter.\n\nThe argument `normalized` and `centered` controls how the windows are built:\n* If the coordinates are normalized but not centered, 0.0 and 1.0\n correspond to the minimum and maximum of each height and width dimension.\n* If the coordinates are both normalized and centered, they range from -1.0 to\n 1.0. The coordinates (-1.0, -1.0) correspond to the upper left corner, the\n lower right corner is located at (1.0, 1.0) and the center is at (0, 0).\n* If the coordinates are not normalized they are interpreted as numbers of pixels."
+ description: "Returns a set of windows called glimpses extracted at location\n`offsets` from the input tensor. If the windows only partially\noverlaps the inputs, the non overlapping areas will be filled with\nrandom noise.\n\nThe result is a 4-D tensor of shape `[batch_size, glimpse_height,\nglimpse_width, channels]`. The channels and batch dimensions are the\nsame as that of the input tensor. The height and width of the output\nwindows are specified in the `size` parameter.\n\nThe argument `normalized` and `centered` controls how the windows are"
}
op {
name: "FFT2D"
diff --git a/tensorflow/python/BUILD b/tensorflow/python/BUILD
index b7ae7b9fae..1ffa9a531e 100644
--- a/tensorflow/python/BUILD
+++ b/tensorflow/python/BUILD
@@ -449,11 +449,6 @@ tf_gen_op_wrapper_py(
)
tf_gen_op_wrapper_py(
- name = "attention_ops",
- require_shape_functions = True,
-)
-
-tf_gen_op_wrapper_py(
name = "candidate_sampling_ops",
hidden = [
"AllCandidateSampler",
@@ -720,7 +715,6 @@ py_library(
srcs = [
"ops/array_grad.py",
"ops/array_ops.py",
- "ops/attention_ops.py",
"ops/candidate_sampling_ops.py",
"ops/clip_ops.py",
"ops/control_flow_grad.py",
@@ -729,7 +723,6 @@ py_library(
"ops/data_flow_ops.py",
"ops/embedding_ops.py",
"ops/gen_array_ops.py",
- "ops/gen_attention_ops.py",
"ops/gen_control_flow_ops.py",
"ops/gen_ctc_ops.py",
"ops/gen_data_flow_ops.py",
diff --git a/tensorflow/python/kernel_tests/attention_ops_test.py b/tensorflow/python/kernel_tests/attention_ops_test.py
index f17df8e768..a8bc893294 100644
--- a/tensorflow/python/kernel_tests/attention_ops_test.py
+++ b/tensorflow/python/kernel_tests/attention_ops_test.py
@@ -13,7 +13,7 @@
# limitations under the License.
# ==============================================================================
-"""Tests for tensorflow.python.ops.attention_ops."""
+"""Tests for image.extract_glimpse()."""
from __future__ import absolute_import
from __future__ import division
diff --git a/tensorflow/python/ops/attention_ops.py b/tensorflow/python/ops/attention_ops.py
deleted file mode 100644
index 5195672726..0000000000
--- a/tensorflow/python/ops/attention_ops.py
+++ /dev/null
@@ -1,52 +0,0 @@
-# Copyright 2015 Google Inc. 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.
-# ==============================================================================
-
-"""Operations for implementing attention.
-"""
-from __future__ import absolute_import
-from __future__ import division
-from __future__ import print_function
-
-from tensorflow.python.framework import ops
-from tensorflow.python.framework import tensor_shape
-from tensorflow.python.framework import tensor_util
-from tensorflow.python.ops import gen_attention_ops
-# pylint: disable=wildcard-import
-from tensorflow.python.ops.gen_attention_ops import *
-# pylint: enable=wildcard-import
-
-
-# TODO(bsteiner): Implement the gradient function for extract_glimpse
-ops.NoGradient("ExtractGlimpse")
-
-
-@ops.RegisterShape("ExtractGlimpse")
-def _ExtractGlimpseShape(op):
- """Shape function for ExtractGlimpse op."""
- input_shape = op.inputs[0].get_shape().with_rank(4)
- unused_size_shape = op.inputs[1].get_shape().merge_with(
- tensor_shape.vector(2))
- offsets_shape = op.inputs[2].get_shape().merge_with(
- input_shape[:1].concatenate([2]))
- offsets_shape = offsets_shape
- size_value = tensor_util.constant_value(op.inputs[1])
- if size_value is not None:
- height = size_value[0]
- width = size_value[1]
- else:
- height = None
- width = None
- return [tensor_shape.TensorShape(
- [input_shape[0], height, width, input_shape[3]])]
diff --git a/tensorflow/python/ops/image_ops.py b/tensorflow/python/ops/image_ops.py
index 82df16e7c4..53eb4504b2 100644
--- a/tensorflow/python/ops/image_ops.py
+++ b/tensorflow/python/ops/image_ops.py
@@ -169,19 +169,21 @@ from tensorflow.python.ops import gen_nn_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import random_ops
-
# pylint: disable=wildcard-import
-from tensorflow.python.ops.attention_ops import *
from tensorflow.python.ops.gen_image_ops import *
# pylint: enable=wildcard-import
from tensorflow.python.util.all_util import make_all
+
+
ops.NoGradient('RandomCrop')
ops.NoGradient('RGBToHSV')
ops.NoGradient('HSVToRGB')
ops.NoGradient('DrawBoundingBoxes')
ops.NoGradient('SampleDistortedBoundingBox')
+# TODO(bsteiner): Implement the gradient function for extract_glimpse
+ops.NoGradient("ExtractGlimpse")
def _ImageDimensions(images):
@@ -1209,6 +1211,26 @@ def _random_crop_shape(op):
return [tensor_shape.TensorShape(output_shape)]
+@ops.RegisterShape("ExtractGlimpse")
+def _ExtractGlimpseShape(op):
+ """Shape function for ExtractGlimpse op."""
+ input_shape = op.inputs[0].get_shape().with_rank(4)
+ unused_size_shape = op.inputs[1].get_shape().merge_with(
+ tensor_shape.vector(2))
+ offsets_shape = op.inputs[2].get_shape().merge_with(
+ input_shape[:1].concatenate([2]))
+ offsets_shape = offsets_shape
+ size_value = tensor_util.constant_value(op.inputs[1])
+ if size_value is not None:
+ height = size_value[0]
+ width = size_value[1]
+ else:
+ height = None
+ width = None
+ return [tensor_shape.TensorShape(
+ [input_shape[0], height, width, input_shape[3]])]
+
+
__all__ = make_all(__name__)
# ResizeMethod is not documented, but is documented in functions that use it.
__all__.append('ResizeMethod')