Merge changes from github.

PiperOrigin-RevId: 194031845
This commit is contained in:
Yifei Feng 2018-04-23 21:19:14 -07:00 committed by TensorFlower Gardener
parent 24b7c9a800
commit 22f3a97b8b
281 changed files with 4022 additions and 893 deletions

View File

@ -45,7 +45,7 @@
# /tensorflow/contrib/session_bundle/ @nfiedel @sukritiramesh
# /tensorflow/contrib/slim/ @sguada @thenbasilmanran
# /tensorflow/contrib/stateless/ @girving
# /tensorflow/contrib/tensor_forest/ @gilberthendry @thomascolthurst
# /tensorflow/contrib/tensor_forest/ @gilberthendry @thomascolthurst @yupbank
# /tensorflow/contrib/testing/ @dandelionmane
# /tensorflow/contrib/timeseries/ @allenlavoie
# /tensorflow/contrib/tpu/ @frankchn @saeta @jhseu

View File

@ -14,7 +14,7 @@ data flow graphs. The graph nodes represent mathematical operations, while
the graph edges represent the multidimensional data arrays (tensors) that flow
between them. This flexible architecture enables you to deploy computation to one
or more CPUs or GPUs in a desktop, server, or mobile device without rewriting
code. TensorFlow also includes TensorBoard, a data visualization toolkit.
code. TensorFlow also includes [TensorBoard](https://www.tensorflow.org/programmers_guide/summaries_and_tensorboard), a data visualization toolkit.
TensorFlow was originally developed by researchers and engineers
working on the Google Brain team within Google's Machine Intelligence Research

View File

@ -1,3 +1,61 @@
# Release 1.8.0
## Major Features And Improvements
* Can now pass `tf.contrib.distribute.MirroredStrategy()` to `tf.estimator.RunConfig()` to run an Estimator model on multiple GPUs on one machine.
* Add `tf.contrib.data.prefetch_to_device()`, which supports prefetching to GPU memory.
* Added Gradient Boosted Trees as pre-made Estimators: BoostedTreesClassifier, BoostedTreesRegressor.
* Add 3rd generation pipeline config for Cloud TPUs which improves performance and usability.
* `tf.contrib.bayesflow` is moving out to it's own repo.
* Added `tf.contrib.{proto,rpc}` to allow generic proto parsing and RPC communication.
## Bug Fixes and Other Changes
* `tf.data`:
* Add `tf.contrib.data.prefetch_to_device`, which enables prefetching dataset elements to GPU memory.
* Add `tf.contrib.data.AUTOTUNE`, which allows the tf.data runtime to automatically tune the prefetch buffer sizes based on your system and environment.
* Add `tf.contrib.data.make_csv_dataset` for building datasets of CSV files.
* Eager Execution:
* With eager execution Datasets can now be used as standard python iterators (`for batch in dataset:`). Both `Dataset.__iter__()` and `Dataset.make_one_shot_iterator()` can now be used to create iterators when eager execution is enabled.
* Automatic device placement has been enabled (i.e., use a GPU if available automatically, without requiring an explicit `with tf.device(“/gpu:0”)`) (Fixes #14133)
* `tf.GradientTape` has moved out of contrib.
* `tf.keras`:
* Added the fashion mnist dataset.
* New data preprocessing functions: `image/random_brightness`, `sequence/TimeseriesGenerator`, and `text/hashing_trick`.
* Accelerated Linear Algebra (XLA):
* Select and scatter in reference util and evaluator now use lexicographical order to break ties.
* TensorFlow Debugger (tfdbg) CLI:
* During tensor-filter operations, allow exclusion of nodes by regular expressions.
* Fix spurious background colors in some text terminals.
* `tf.contrib`:
* Add meta-distribution BatchReshape which reshapes batch dimensions.
* `tf.contrib.layers.recompute_grad` works for explicit gradient checkpointing on TPU.
* Add `tf.contrib.framework.argsort`.
* Allow `DNNBoostedTreeCombinedEstimator` to work with core versions of feature columns and losses.
* Add non-linear image warping ops: `tf.contrib.image.sparse_image_warp`, `tf.contrib.image.dense_image_warp`, and `tf.contrib.image.interpolate_spline`.
* Fix bug in `tf.contrib.opt.MultitaskOptimizerWrapper` where types of tensors were mismatched.
* Other:
* Low-level graph construction now calls the TensorFlow C API. This change should be invisible to most users, but can be disabled by setting the environment variable `TF_C_API_GRAPH_CONSTRUCTION=0` in this release. Future releases will remove the ability to disable this change. Please [file a bug](https://github.com/tensorflow/tensorflow/issues/new) if you find yourself using this escape hatch.
* Add description of shapes and a pointer to tutorial notebook in `tf.distributions.Distribution`.
* Update scatter operations:
* Add `tf.scatter_min` and `tf.scatter_max`
* Extend scatter operations to work with a scalar update parameter.
* Move cuDNN RNN ops to core for use in TensorFlow codebase only.
* Add `float64` support for `Conv2d`, `Conv2dBackpropInput`, and `Conv2dBackpropFilter`.
* Add `float64` support for `AvgPool`/`AvgPoolGrad`.
* Make graph name scope thread local so that they work correctly in multi-threaded environments.
* Update nsync synchronization library to avoid slow primitives on Linux.
* Removed need to put nsync/public on C include path when building custom ops.
* Add `tf.image.psnr`, `tf.image.ssim`, `tf.image.ssim_multiscale`, `tf.image.image_gradients`, `tf.image.sobel_edges`.
* Add links to https://js.tensorflow.org.
* Fix non-uniformity of orthogonal matrices.
* Fix bug where multi-image Estimator eval summaries were not displayed correctly.
## Thanks to our Contributors
This release contains contributions from many people at Google, as well as:
4d55397500, Aghasy, Alan Du, Alan Lee, Alan Yee, Alex Wiltschko, Animesh Karnewar, Ankit Gupta, Anton Matosov, Aris L, Ben Barsdell, Brent Yi, Brett Koonce, Carl Thomé, cbockman, Chikanaga Tomoyuki, Chris Tava, CéDric Deltheil, Dahan Gong, Dalmo Cirne, Daniel Erenrich, David Norman, DavidNorman, Edd Wilder-James, Fanjin Zeng, Felix Abecassis, fo40225, George Sterpu, Giovanni Terlingen, Gor Baghdasaryan, Guillaume Klein, Hanchen Li, Ilya Polenov, Jakub Kolodziejczyk, Jason Sadler, Jayaram Bobba, Jerry Liu, jinghuangintel, Jiongyan Zhang (张炯衍), Joel Shor, Jong Wook Kim, Julian Eisenschlos, Karl Lessard, Krish Ravindranath, Loo Rong Jie, Lukas Geiger, Luke Iwanski, Mahmoud Abuzaina, ManHyuk, Marvin Richter, Maximilian Mitchell, Mohammad Ashraf Bhuiyan, msofka, Mustafa Kasap, Nathan Burnham, Nathan Luehr, Naveen Marri, ngc92, nio1814, Oleg Zabluda, Ou Changkun, Panos Ipeirotis, Paul Van Eck, Peter Lee, Piotr Czapla, qjivy, Rholais Lii, Rodrigo Formigone, Russell Klopfer, ryantimjohn, Sang Han, SebastiáN RamíRez, shengfuintel, Siby Jose Plathottam, Silver Chan, Stanislaw Antol, Taehoon Lee, Tarang Chugh, Ted Chang, Thomas Bastiani, Xian Xu, Xiaoming (Jason) Cui, Yan Facai (颜发才), yaox12, Yashal Shakti Kanungo, Yong Tang, Yuan (Terry) Tang, Yuxin Wu, Ziyue(Louis) Lu
# Release 1.7.0
## Major Features And Improvements

View File

@ -2,11 +2,11 @@ workspace(name = "org_tensorflow")
http_archive(
name = "io_bazel_rules_closure",
sha256 = "6691c58a2cd30a86776dd9bb34898b041e37136f2dc7e24cadaeaf599c95c657",
strip_prefix = "rules_closure-08039ba8ca59f64248bb3b6ae016460fe9c9914f",
sha256 = "a38539c5b5c358548e75b44141b4ab637bba7c4dc02b46b1f62a96d6433f56ae",
strip_prefix = "rules_closure-dbb96841cc0a5fb2664c37822803b06dab20c7d1",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_closure/archive/08039ba8ca59f64248bb3b6ae016460fe9c9914f.tar.gz",
"https://github.com/bazelbuild/rules_closure/archive/08039ba8ca59f64248bb3b6ae016460fe9c9914f.tar.gz", # 2018-01-16
"https://mirror.bazel.build/github.com/bazelbuild/rules_closure/archive/dbb96841cc0a5fb2664c37822803b06dab20c7d1.tar.gz",
"https://github.com/bazelbuild/rules_closure/archive/dbb96841cc0a5fb2664c37822803b06dab20c7d1.tar.gz", # 2018-04-13
],
)

View File

@ -72,7 +72,7 @@ limitations under the License.
#ifdef SWIG
#define TF_CAPI_EXPORT
#else
#if defined(COMPILER_MSVC)
#if defined(_WIN32)
#ifdef TF_COMPILE_LIBRARY
#define TF_CAPI_EXPORT __declspec(dllexport)
#else
@ -80,7 +80,7 @@ limitations under the License.
#endif // TF_COMPILE_LIBRARY
#else
#define TF_CAPI_EXPORT __attribute__((visibility("default")))
#endif // COMPILER_MSVC
#endif // _WIN32
#endif // SWIG
#ifdef __cplusplus

View File

@ -184,6 +184,7 @@ library {
return std::move(functions[0]);
}
#if not defined(PLATFORM_WINDOWS)
// On success, returns a set of TF_Function instances encoding a dataset
// node stack that reads a Imagenet TFRecordFile dataset from `file_path`, and
// sets `dataset_name` to the created dataset name. The returned functions must
@ -7076,7 +7077,9 @@ library {
return CreateFunctionsFromTextProto(func_def, &mutate_proto_func, status);
#endif
}
#endif
#if not defined(PLATFORM_WINDOWS)
// On success, returns a set of TF_Function instances encoding a dataset
// node stack that reads an MNIST file dataset from `file_path`, and
// sets `dataset_name` to the created dataset name. The returned functions must
@ -8221,6 +8224,7 @@ library {
return CreateFunctionsFromTextProto(func_def, &mutate_proto_func, status);
#endif
}
#endif
// Adds the input functions to `graph`. On success, returns the created
// IteratorGetNext node.
@ -8314,6 +8318,13 @@ TF_Operation* TF_MakeFakeIteratorGetNextWithDatasets(TF_Graph* graph,
TF_Operation* TF_MakeFileBasedIteratorGetNextWithDatasets(
TF_Graph* graph, const char* file_path, int batch_size,
unsigned char is_mnist, TF_Status* status) {
#if defined(PLATFORM_WINDOWS)
// TODO(ashankar): get these functions working on Windows.
status->status = tensorflow::errors::Unimplemented(
"TF_MakeFileBasedIteratorGetNextWithDatasets in the experimental C API "
"is not implemented for Windows");
return nullptr;
#else
tensorflow::Status s;
std::string dataset_name;
@ -8355,4 +8366,5 @@ TF_Operation* TF_MakeFileBasedIteratorGetNextWithDatasets(
<< graph->graph.ToGraphDefDebug().DebugString();
return getnext_node;
#endif
}

View File

@ -35,7 +35,7 @@ limitations under the License.
#ifdef SWIG
#define TF_CAPI_EXPORT
#else
#if defined(COMPILER_MSVC)
#if defined(_WIN32)
#ifdef TF_COMPILE_LIBRARY
#define TF_CAPI_EXPORT __declspec(dllexport)
#else
@ -43,7 +43,7 @@ limitations under the License.
#endif // TF_COMPILE_LIBRARY
#else
#define TF_CAPI_EXPORT __attribute__((visibility("default")))
#endif // COMPILER_MSVC
#endif // _WIN32
#endif // SWIG
#ifdef __cplusplus

View File

@ -30,7 +30,7 @@ limitations under the License.
#ifdef SWIG
#define TF_CAPI_EXPORT
#else
#if defined(COMPILER_MSVC)
#if defined(_WIN32)
#ifdef TF_COMPILE_LIBRARY
#define TF_CAPI_EXPORT __declspec(dllexport)
#else
@ -38,7 +38,7 @@ limitations under the License.
#endif // TF_COMPILE_LIBRARY
#else
#define TF_CAPI_EXPORT __attribute__((visibility("default")))
#endif // COMPILER_MSVC
#endif // _WIN32
#endif // SWIG
#ifdef __cplusplus

View File

@ -31,7 +31,7 @@ namespace {
inline void* aligned_malloc(size_t size, int minimum_alignment) {
#if defined(__ANDROID__) || defined(OS_ANDROID) || defined(OS_CYGWIN)
return memalign(minimum_alignment, size);
#elif defined(COMPILER_MSVC)
#elif defined(_WIN32)
return _aligned_malloc(size, minimum_alignment);
#else // !__ANDROID__ && !OS_ANDROID && !OS_CYGWIN
void* ptr = nullptr;
@ -48,7 +48,7 @@ inline void* aligned_malloc(size_t size, int minimum_alignment) {
}
inline void aligned_free(void* aligned_memory) {
#if defined(COMPILER_MSVC)
#if defined(_WIN32)
_aligned_free(aligned_memory);
#else
free(aligned_memory);

View File

@ -360,11 +360,13 @@ class BinaryOpsTest(XLATestCase):
np.array([2, -1], dtype=dtype),
expected=np.array([[[[3, 1], [5, 3]]]], dtype=dtype))
self._testBinary(
math_ops.add,
np.array([0xffffffff, 0xfffffffff, 1, 1], dtype=np.int64),
np.array([1, 1, 0xffffffff, 0xfffffffff], dtype=np.int64),
expected=np.array([1 << 32, 1 << 36, 1 << 32, 1 << 36], dtype=np.int64))
if np.int64 in self.numeric_types:
self._testBinary(
math_ops.add,
np.array([0xffffffff, 0xfffffffff, 1, 1], dtype=np.int64),
np.array([1, 1, 0xffffffff, 0xfffffffff], dtype=np.int64),
expected=np.array([1 << 32, 1 << 36, 1 << 32, 1 << 36],
dtype=np.int64))
def testComplexOps(self):
for dtype in self.complex_types:

View File

@ -1160,7 +1160,6 @@ class EmbeddedComputationsTest(LocalComputationTest):
self._ExecuteAndCompareClose(
c, expected=np.sum(input_array, axis=tuple(dims)))
_ReduceAndTest(0)
_ReduceAndTest(0)
_ReduceAndTest(0, 1)
_ReduceAndTest(0, 2)

View File

@ -97,9 +97,9 @@ bool ShouldIncludeWinogradNonfusedAlgo(const Shape& input_shape,
const ConvolutionDimensionNumbers& dnums,
se::StreamExecutor* stream_exec) {
// Skip this check for cudnn7 and newer.
se::port::StatusOr<std::tuple<int, int, int>> version =
auto version =
stream_exec->AsDnn()->GetVersion();
if (version.ok() && std::get<0>(version.ValueOrDie()) >= 7) {
if (version.ok() && version.ValueOrDie().major_version() >= 7) {
return true;
}

View File

@ -50,6 +50,13 @@ using TypesF16F32 = ::testing::Types<Eigen::half, float>;
using TypesF16F32F64 = ::testing::Types<Eigen::half, float, double>;
using TypesF16F32F64CF64 =
::testing::Types<Eigen::half, float, double, complex64>;
#elif !defined(XLA_BACKEND_DOES_NOT_SUPPORT_FLOAT16) && \
defined(XLA_BACKEND_DOES_NOT_SUPPORT_FLOAT64) && \
defined(XLA_BACKEND_DOES_NOT_SUPPORT_COMPLEX)
using TypesF16F32 = ::testing::Types<Eigen::half, float>;
using TypesF16F32F64 = ::testing::Types<Eigen::half, float>;
using TypesF16F32F64CF64 =
::testing::Types<Eigen::half, float>;
#else
#error "Situation not handled yet"
#endif

View File

@ -146,7 +146,7 @@ class CallTreeTransformer(transformer.Base):
# Inspect the target function decorators. If any include a @convert
# or @graph_ready annotation, then they must be called as they are.
# TODO(mdan): This may be quite heavy.
# To parse and re-analize each function for every call site could be quite
# To parse and re-analyze each function for every call site could be quite
# wasteful. Maybe we could cache the parsed AST?
try:
target_node, _ = parser.parse_entity(target_entity)

View File

@ -34,7 +34,7 @@ class CallTreesTest(converter_test_base.TestCase):
def test_basic(self):
def test_fn_1(_):
raise ValueError('This should not be called in the compiled verison.')
raise ValueError('This should not be called in the compiled version.')
def renamed_test_fn_1(a):
return a + 1

View File

@ -28,7 +28,7 @@ from tensorflow.python.platform import test
# The Python parser only briefly captures decorators into the AST.
# The interpreter desugars them on load, and the decorated function loses any
# trace of the decorator (which is notmally what you would expect, since
# trace of the decorator (which is normally what you would expect, since
# they are meant to be transparent).
# However, decorators are still visible when you analyze the function
# from inside a decorator, before it was applied - as is the case

View File

@ -49,7 +49,7 @@ def convert(recursive=False, verbose=False, arg_types=None):
function is called. This means the parameter values are known at compilation.
Args:
recursive: Whether to recusrively convert any functions that the decorator
recursive: Whether to recursively convert any functions that the decorator
function may call.
verbose: Whether to output the compiled code in the logs.
arg_types: See to_graph.
@ -215,7 +215,7 @@ def to_graph(e,
Args:
e: A Python entity.
recursive: Whether to recusrively convert any functions that the decorator
recursive: Whether to recursively convert any functions that the decorator
function may call.
verbose: Whether to output the compiled code in the logs.
arg_values: A dict containing value hints for symbols like function

View File

@ -61,7 +61,7 @@ class ConversionMap(object):
This object is mutable, and is updated as functions are converted.
Attributes:
recursive: Whether to recusrively convert any functions that the decorator
recursive: Whether to recursively convert any functions that the decorator
function may call.
nocompile_decorators: tuple of decorator functions that toggle compilation
off.

View File

@ -162,11 +162,11 @@ class Scope(object):
self.parent.mark_returned(name)
class ActivityAnalizer(transformer.Base):
class ActivityAnalyzer(transformer.Base):
"""Annotates nodes with local scope information. See Scope."""
def __init__(self, context, parent_scope):
super(ActivityAnalizer, self).__init__(context)
super(ActivityAnalyzer, self).__init__(context)
self.scope = Scope(parent_scope)
self._in_return_statement = False
@ -356,4 +356,4 @@ class ActivityAnalizer(transformer.Base):
def resolve(node, context, parent_scope=None):
return ActivityAnalizer(context, parent_scope).visit(node)
return ActivityAnalyzer(context, parent_scope).visit(node)

View File

@ -108,7 +108,7 @@ class ScopeTest(test.TestCase):
self.assertFalse(QN('a') in child.referenced)
class ActivityAnalizerTest(test.TestCase):
class ActivityAnalyzerTest(test.TestCase):
def _parse_and_analyze(self, test_fn):
node, source = parser.parse_entity(test_fn)

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Annotations used by the static analizer."""
"""Annotations used by the static analyzer."""
from __future__ import absolute_import
from __future__ import division
@ -28,15 +28,15 @@ class NoValue(Enum):
class NodeAnno(NoValue):
"""Additionnal annotations used by the static analyzer.
"""Additional annotations used by the static analyzer.
These are in addition to the basic annotations declared in anno.py.
"""
# Symbols
# These flags are boolean.
IS_LOCAL = 'Symbol is local to the function scope being analized.'
IS_PARAM = 'Symbol is a parameter to the function being analized.'
IS_LOCAL = 'Symbol is local to the function scope being analyzed.'
IS_PARAM = 'Symbol is a parameter to the function being analyzed.'
IS_MODIFIED_SINCE_ENTRY = (
'Symbol has been explicitly replaced in the current function scope.')

View File

@ -77,7 +77,7 @@ def is_tf_print_compatible(value):
def dynamic_print(*values):
"""Implementartion of print using dynamic dispatch.
"""Implementation of print using dynamic dispatch.
The function attempts to use tf.Print if all the values are compatible.
Otherwise, it will fall back to py_func.

View File

@ -44,15 +44,13 @@ def expectation_importance_sampler(f,
n=None,
seed=None,
name='expectation_importance_sampler'):
r"""Monte Carlo estimate of `\\(E_p[f(Z)] = E_q[f(Z) p(Z) / q(Z)]\\)`.
r"""Monte Carlo estimate of \\(E_p[f(Z)] = E_q[f(Z) p(Z) / q(Z)]\\).
With `\\(p(z) := exp^{log_p(z)}\\)`, this `Op` returns
With \\(p(z) := exp^{log_p(z)}\\), this `Op` returns
```
\\(n^{-1} sum_{i=1}^n [ f(z_i) p(z_i) / q(z_i) ], z_i ~ q,\\)
\\(\approx E_q[ f(Z) p(Z) / q(Z) ]\\)
\\(= E_p[f(Z)]\\)
```
This integral is done in log-space with max-subtraction to better handle the
often extreme values that `f(z) p(z) / q(z)` can take on.
@ -121,14 +119,12 @@ def expectation_importance_sampler_logspace(
name='expectation_importance_sampler_logspace'):
r"""Importance sampling with a positive function, in log-space.
With `\\(p(z) := exp^{log_p(z)}\\)`, and `\\(f(z) = exp{log_f(z)}\\)`,
With \\(p(z) := exp^{log_p(z)}\\), and \\(f(z) = exp{log_f(z)}\\),
this `Op` returns
```
\\(Log[ n^{-1} sum_{i=1}^n [ f(z_i) p(z_i) / q(z_i) ] ], z_i ~ q,\\)
\\(\approx Log[ E_q[ f(Z) p(Z) / q(Z) ] ]\\)
\\(= Log[E_p[f(Z)]]\\)
```
This integral is done in log-space with max-subtraction to better handle the
often extreme values that `f(z) p(z) / q(z)` can take on.
@ -196,13 +192,11 @@ def _logspace_mean(log_values):
def expectation(f, samples, log_prob=None, use_reparametrization=True,
axis=0, keep_dims=False, name=None):
"""Computes the Monte-Carlo approximation of `\\(E_p[f(X)]\\)`.
"""Computes the Monte-Carlo approximation of \\(E_p[f(X)]\\).
This function computes the Monte-Carlo approximation of an expectation, i.e.,
```none
\\(E_p[f(X)] \approx= m^{-1} sum_i^m f(x_j), x_j\ ~iid\ p(X)\\)
```
where:
@ -216,8 +210,8 @@ def expectation(f, samples, log_prob=None, use_reparametrization=True,
parameterless distribution (e.g.,
`Normal(Y; m, s) <=> Y = sX + m, X ~ Normal(0,1)`), we can swap gradient and
expectation, i.e.,
`grad[ Avg{ \\(s_i : i=1...n\\) } ] = Avg{ grad[\\(s_i\\)] : i=1...n }` where
`S_n = Avg{\\(s_i\\)}` and `\\(s_i = f(x_i), x_i ~ p\\)`.
grad[ Avg{ \\(s_i : i=1...n\\) } ] = Avg{ grad[\\(s_i\\)] : i=1...n } where
S_n = Avg{\\(s_i\\)}` and `\\(s_i = f(x_i), x_i ~ p\\).
However, if p is not reparameterized, TensorFlow's gradient will be incorrect
since the chain-rule stops at samples of non-reparameterized distributions.
@ -296,7 +290,7 @@ def expectation(f, samples, log_prob=None, use_reparametrization=True,
Args:
f: Python callable which can return `f(samples)`.
samples: `Tensor` of samples used to form the Monte-Carlo approximation of
`\\(E_p[f(X)]\\)`. A batch of samples should be indexed by `axis`
\\(E_p[f(X)]\\). A batch of samples should be indexed by `axis`
dimensions.
log_prob: Python callable which can return `log_prob(samples)`. Must
correspond to the natural-logarithm of the pdf/pmf of each sample. Only
@ -317,7 +311,7 @@ def expectation(f, samples, log_prob=None, use_reparametrization=True,
Returns:
approx_expectation: `Tensor` corresponding to the Monte-Carlo approximation
of `\\(E_p[f(X)]\\)`.
of \\(E_p[f(X)]\\).
Raises:
ValueError: if `f` is not a Python `callable`.
@ -329,7 +323,7 @@ def expectation(f, samples, log_prob=None, use_reparametrization=True,
if not callable(f):
raise ValueError('`f` must be a callable function.')
if use_reparametrization:
return math_ops.reduce_mean(f(samples), axis=axis, keep_dims=keep_dims)
return math_ops.reduce_mean(f(samples), axis=axis, keepdims=keep_dims)
else:
if not callable(log_prob):
raise ValueError('`log_prob` must be a callable function.')
@ -349,7 +343,7 @@ def expectation(f, samples, log_prob=None, use_reparametrization=True,
# "Is there a floating point value of x, for which x-x == 0 is false?"
# http://stackoverflow.com/q/2686644
fx += stop(fx) * (logpx - stop(logpx)) # Add zeros_like(logpx).
return math_ops.reduce_mean(fx, axis=axis, keep_dims=keep_dims)
return math_ops.reduce_mean(fx, axis=axis, keepdims=keep_dims)
def _sample_mean(values):

View File

@ -45,7 +45,7 @@ from tensorflow.python.platform import googletest
def _squared_loss(label, unused_weights, predictions):
"""Unweighted loss implementation."""
loss = math_ops.reduce_sum(
math_ops.square(predictions - label), 1, keep_dims=True)
math_ops.square(predictions - label), 1, keepdims=True)
return loss

View File

@ -73,7 +73,7 @@ class OnlyOneDep(checkpointable.Checkpointable):
class SplitTests(test.TestCase):
@test_util.run_in_graph_and_eager_modes(assert_no_eager_garbage=True)
@test_util.run_in_graph_and_eager_modes()
def testSaveRestoreSplitDep(self):
save_checkpoint = checkpointable_utils.Checkpoint(
dep=SaveTensorSlicesAsDeps())

View File

@ -31,10 +31,14 @@ option(tensorflow_BUILD_PYTHON_TESTS "Build python unit tests " OFF)
option(tensorflow_BUILD_MORE_PYTHON_TESTS "Build more python unit tests for contrib packages" OFF)
option(tensorflow_BUILD_SHARED_LIB "Build TensorFlow as a shared library" OFF)
option(tensorflow_OPTIMIZE_FOR_NATIVE_ARCH "Enable compiler optimizations for the native processor architecture (if available)" ON)
option(tensorflow_WIN_CPU_SIMD_OPTIONS "Enables CPU SIMD instructions")
option(tensorflow_ENABLE_SNAPPY_SUPPORT "Enable SNAPPY compression support" ON)
option(tensorflow_DISABLE_EIGEN_FORCEINLINE "Disable forceinline, to speed up build on windows." OFF)
# SIMD, MKL and MKLDNN options
option(tensorflow_WIN_CPU_SIMD_OPTIONS "Enables CPU SIMD instructions" OFF)
option(tensorflow_ENABLE_MKL_SUPPORT "Enable Intel MKL support" OFF)
option(tensorflow_ENABLE_MKLDNN_SUPPORT "Enable Intel MKLDNN support, requires MKL enabled" OFF)
# GPU, CUDA and cuDNN options
option(tensorflow_ENABLE_GPU "Enable GPU support" OFF)
set(tensorflow_CUDA_VERSION "9.0" CACHE STRING "CUDA version to build against")
@ -124,8 +128,16 @@ endif()
add_definitions(-DEIGEN_AVOID_STL_ARRAY)
if(WIN32)
add_definitions(-DNOMINMAX -D_WIN32_WINNT=0x0A00 -DLANG_CXX11 -DCOMPILER_MSVC)
add_definitions(-DWIN32 -DOS_WIN -D_MBCS -DWIN64 -DWIN32_LEAN_AND_MEAN -DNOGDI -DPLATFORM_WINDOWS)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# 64 bits
add_definitions(-DWIN64)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
# 32 bits
# temporary fix for #18241
add_definitions(-DEIGEN_DEFAULT_DENSE_INDEX_TYPE=std::int64_t)
endif()
add_definitions(-DNOMINMAX -D_WIN32_WINNT=0x0A00 -DLANG_CXX11)
add_definitions(-DWIN32 -DOS_WIN -D_MBCS -DWIN32_LEAN_AND_MEAN -DNOGDI -DPLATFORM_WINDOWS)
add_definitions(-DTENSORFLOW_USE_EIGEN_THREADPOOL -DEIGEN_HAS_C99_MATH)
add_definitions(-DTF_COMPILE_LIBRARY)
add_definitions(/bigobj /nologo /EHsc /GF /MP /Gm-)
@ -162,12 +174,21 @@ endif()
# MSVC SIMD instructions
if (tensorflow_WIN_CPU_SIMD_OPTIONS)
include(CheckCXXCompilerFlag)
if (tensorflow_ENABLE_MKL_SUPPORT)
add_definitions(-DINTEL_MKL -DEIGEN_USE_VML)
if (NOT tensorflow_ENABLE_MKLDNN_SUPPORT)
add_definitions(-DINTEL_MKL_ML)
endif()
endif()
CHECK_CXX_COMPILER_FLAG("-fopenmp" COMPILER_OPT_OPENMP_SUPPORT)
if (COMPILER_OPT_OPENMP_SUPPORT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
endif()
if (WIN32)
CHECK_CXX_COMPILER_FLAG("${tensorflow_WIN_CPU_SIMD_OPTIONS}" COMPILER_OPT_WIN_CPU_SIMD_SUPPORTED)
CHECK_CXX_COMPILER_FLAG(${tensorflow_WIN_CPU_SIMD_OPTIONS} COMPILER_OPT_WIN_CPU_SIMD_SUPPORTED)
if(COMPILER_OPT_WIN_CPU_SIMD_SUPPORTED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${tensorflow_WIN_CPU_SIMD_OPTIONS}")
else()
message(FATAL_ERROR "${tensorflow_WIN_CPU_SIMD_OPTIONS} not supported")
endif()
endif()
endif()
@ -302,6 +323,43 @@ if(HAIKU)
list(APPEND tensorflow_EXTERNAL_LIBRARIES network)
endif()
if (tensorflow_ENABLE_MKL_SUPPORT)
if (WIN32)
find_path(MKL_HOME_PLATFORM mkl
PATHS ${MKL_HOME} ${MKL_HOME}/../ ${MKL_HOME}/../../
PATH_SUFFIXES windows)
set(MKL_INCLUDE_DIRS ${MKL_HOME_PLATFORM}/mkl/include)
set(MKL_LINK_DIRS
${MKL_HOME_PLATFORM}/mkl/lib/intel64
${MKL_HOME_PLATFORM}/tbb/lib/intel64/vc_mt
${MKL_HOME_PLATFORM}/compiler/lib/intel64
${MKL_HOME_PLATFORM}/mkl/tools/builder/lib)
set(MKL_REDIST_DLL_DIRS
${MKL_HOME_PLATFORM}/redist/intel64/mkl
${MKL_HOME_PLATFORM}/redist/intel64/tbb/vc_mt
${MKL_HOME_PLATFORM}/redist/intel64/compiler)
list(APPEND tensorflow_EXTERNAL_LIBRARIES
mkl_intel_lp64_dll mkl_sequential_dll mkl_core_dll mkl_rt mkl_cdll_intel64)
endif()
if (UNIX)
# Fix me: complete the path on linux
find_path(MKL_HOME_PLATFORM mkl
HINTS ${MKL_HOME} ${MKL_HOME}/../ ${MKL_HOME}/../../
PATH_SUFFIXES linux)
set(MKL_INCLUDE_DIRS ${MKL_HOME_PLATFORM}/mkl/include)
set(MKL_LINK_DIRS) # incompleted
set(MKL_REDIST_SO_DIRS) # incompleted
endif()
include_directories(${MKL_INCLUDE_DIRS})
link_directories(${MKL_LINK_DIRS})
if (tensorflow_ENABLE_MKLDNN_SUPPORT)
include(mkldnn)
list(APPEND tensorflow_EXTERNAL_LIBRARIES ${mkldnn_STATIC_LIBRARIES})
list(APPEND tensorflow_EXTERNAL_DEPENDENCIES mkldnn)
include_directories(${mkldnn_INCLUDE_DIRS})
endif()
endif (tensorflow_ENABLE_MKL_SUPPORT)
if (tensorflow_ENABLE_GPU)
if (NOT WIN32)
# Default install paths for cuda libraries in Linux

View File

@ -128,6 +128,18 @@ Step-by-step Windows build
D:\local\cuda\bin
```
* When building with MKL support after installing [MKL](https://software.intel.com/en-us/mkl) from INTEL, append its bin directories to your PATH environment variable.
In case TensorFlow fails to find the MKL dll's during initialization, check your PATH environment variable.
It should contain the directory of the MKL dlls. For example:
```
D:\Tools\IntelSWTools\compilers_and_libraries\windows\redist\intel64\mkl
D:\Tools\IntelSWTools\compilers_and_libraries\windows\redist\intel64\compiler
D:\Tools\IntelSWTools\compilers_and_libraries\windows\redist\intel64\tbb\vc_mt
```
* We assume that `cmake` and `git` are installed and in your `%PATH%`. If
for example `cmake` is not in your path and it is installed in
`C:\Program Files (x86)\CMake\bin\cmake.exe`, you can add this directory
@ -166,7 +178,15 @@ Step-by-step Windows build
More? -Dtensorflow_ENABLE_GPU=ON ^
More? -DCUDNN_HOME="D:\...\cudnn"
```
To build with MKL support add "^" at the end of the last line above following with:
```
More? -Dtensorflow_ENABLE_MKL_SUPPORT=ON ^
More? -DMKL_HOME="D:\...\compilers_and_libraries"
```
To enable SIMD instructions with MSVC, as AVX and SSE, define it as follows:
```
More? -Dtensorflow_WIN_CPU_SIMD_OPTIONS=/arch:AVX
```
@ -226,6 +246,7 @@ Step-by-step Windows build
```
ctest -C RelWithDebInfo
```
* `-Dtensorflow_BUILD_MORE_PYTHON_TESTS=(ON|OFF)`. Defaults to `OFF`. This enables python tests on
serveral major packages. This option is only valid if this and tensorflow_BUILD_PYTHON_TESTS are both set as `ON`.
After building the python wheel, you need to install the new wheel before running the tests.
@ -234,6 +255,12 @@ Step-by-step Windows build
ctest -C RelWithDebInfo
```
* `-Dtensorflow_ENABLE_MKL_SUPPORT=(ON|OFF)`. Defaults to `OFF`. Include MKL support. If MKL is enabled you need to install the [Intel Math Kernal Library](https://software.intel.com/en-us/mkl).
CMake will expect the location of MKL in -MKL_HOME=path_you_install_mkl.
* `-Dtensorflow_ENABLE_MKLDNN_SUPPORT=(ON|OFF)`. Defaults to `OFF`. Include MKL DNN support. MKL DNN is [Intel(R) Math Kernel Library for Deep Neural Networks (Intel(R) MKL-DNN)](https://github.com/intel/mkl-dnn). You have to add `-Dtensorflow_ENABLE_MKL_SUPPORT=ON` before including MKL DNN support.
4. Invoke MSBuild to build TensorFlow.
To build the C++ example program, which will be created as a `.exe`
@ -251,6 +278,7 @@ Step-by-step Windows build
D:\...\build> MSBuild /p:Configuration=Release tf_python_build_pip_package.vcxproj
```
Linux Continuous Integration build
==================================

View File

@ -14,8 +14,8 @@
# ==============================================================================
include (ExternalProject)
set(gemmlowp_URL https://github.com/google/gemmlowp/archive/6a2a90822e8546fc2bfa7044de0faf1c1cb4862f.zip)
set(gemmlowp_HASH SHA256=3447948d219f3270383766bbe08942888c0eb4e0ca6663c0e0548502ec5bb77d)
set(gemmlowp_URL https://github.com/google/gemmlowp/archive/38ebac7b059e84692f53e5938f97a9943c120d98.zip)
set(gemmlowp_HASH SHA256=b87faa7294dfcc5d678f22a59d2c01ca94ea1e2a3b488c38a95a67889ed0a658)
set(gemmlowp_BUILD ${CMAKE_CURRENT_BINARY_DIR}/gemmlowp/src/gemmlowp)
set(gemmlowp_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/gemmlowp/src/gemmlowp)

View File

@ -0,0 +1,44 @@
# 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.
# ==============================================================================
include (ExternalProject)
set(mkldnn_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/mkldnn/src/mkldnn/include)
set(mkldnn_URL https://github.com/01org/mkl-dnn.git)
set(mkldnn_BUILD ${CMAKE_CURRENT_BINARY_DIR}/mkldnn/src/mkldnn/src)
set(mkldnn_TAG 3063b2e4c943983f6bf5f2fb9a490d4a998cd291)
if(WIN32)
if(${CMAKE_GENERATOR} MATCHES "Visual Studio.*")
set(mkldnn_STATIC_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/mkldnn/src/mkldnn/src/Release/mkldnn.lib)
else()
set(mkldnn_STATIC_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/mkldnn/src/mkldnn/src/mkldnn.lib)
endif()
else()
set(mkldnn_STATIC_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/mkldnn/src/mkldnn/src/libmkldnn.a)
endif()
ExternalProject_Add(mkldnn
PREFIX mkldnn
GIT_REPOSITORY ${mkldnn_URL}
GIT_TAG ${mkldnn_TAG}
DOWNLOAD_DIR "${DOWNLOAD_LOCATION}"
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${mkldnn_STATIC_LIBRARIES}
INSTALL_COMMAND ""
CMAKE_CACHE_ARGS
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_VERBOSE_MAKEFILE:BOOL=OFF
-DMKLINC:STRING=${MKL_INCLUDE_DIRS}
)

View File

@ -15,32 +15,33 @@
include (ExternalProject)
set(png_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/external/png_archive)
set(png_URL https://storage.googleapis.com/libpng-public-archive/libpng-1.2.53.tar.gz)
set(png_HASH SHA256=e05c9056d7f323088fd7824d8c6acc03a4a758c4b4916715924edc5dd3223a72)
set(png_URL https://mirror.bazel.build/github.com/glennrp/libpng/archive/v1.6.34.tar.gz)
set(png_HASH SHA256=e45ce5f68b1d80e2cb9a2b601605b374bdf51e1798ef1c2c2bd62131dfcf9eef)
set(png_BUILD ${CMAKE_BINARY_DIR}/png/src/png)
set(png_INSTALL ${CMAKE_BINARY_DIR}/png/install)
if(WIN32)
if(${CMAKE_GENERATOR} MATCHES "Visual Studio.*")
set(png_STATIC_LIBRARIES
debug ${CMAKE_BINARY_DIR}/png/install/lib/libpng12_staticd.lib
optimized ${CMAKE_BINARY_DIR}/png/install/lib/libpng12_static.lib)
debug ${CMAKE_BINARY_DIR}/png/install/lib/libpng16_staticd.lib
optimized ${CMAKE_BINARY_DIR}/png/install/lib/libpng16_static.lib)
else()
if(CMAKE_BUILD_TYPE EQUAL Debug)
set(png_STATIC_LIBRARIES
${CMAKE_BINARY_DIR}/png/install/lib/libpng12_staticd.lib)
${CMAKE_BINARY_DIR}/png/install/lib/libpng16_staticd.lib)
else()
set(png_STATIC_LIBRARIES
${CMAKE_BINARY_DIR}/png/install/lib/libpng12_static.lib)
${CMAKE_BINARY_DIR}/png/install/lib/libpng16_static.lib)
endif()
endif()
else()
set(png_STATIC_LIBRARIES ${CMAKE_BINARY_DIR}/png/install/lib/libpng12.a)
set(png_STATIC_LIBRARIES ${CMAKE_BINARY_DIR}/png/install/lib/libpng16.a)
endif()
set(png_HEADERS
"${png_INSTALL}/include/libpng12/png.h"
"${png_INSTALL}/include/libpng12/pngconf.h"
"${png_INSTALL}/include/libpng16/png.h"
"${png_INSTALL}/include/libpng16/pngconf.h"
"${png_INSTALL}/include/libpng16/pnglibconf.h"
)
ExternalProject_Add(png

View File

@ -15,8 +15,8 @@
include (ExternalProject)
set(sqlite_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/external/sqlite)
set(sqlite_URL https://mirror.bazel.build/www.sqlite.org/2017/sqlite-amalgamation-3200000.zip)
set(sqlite_HASH SHA256=208780b3616f9de0aeb50822b7a8f5482f6515193859e91ed61637be6ad74fd4)
set(sqlite_URL https://mirror.bazel.build/www.sqlite.org/2018/sqlite-amalgamation-3230100.zip)
set(sqlite_HASH SHA256=4239a1f69e5721d07d9a374eb84d594225229e54be4ee628da2995f4315d8dfc)
set(sqlite_BUILD ${CMAKE_CURRENT_BINARY_DIR}/sqlite/src/sqlite)
set(sqlite_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/sqlite/install)

View File

@ -276,7 +276,7 @@ add_custom_command(OUTPUT __force_rebuild COMMAND ${CMAKE_COMMAND} -E echo)
add_custom_command(OUTPUT
${VERSION_INFO_CC}
COMMAND ${PYTHON_EXECUTABLE} ${tensorflow_source_dir}/tensorflow/tools/git/gen_git_source.py
--raw_generate ${VERSION_INFO_CC}
ARGS --raw_generate ${VERSION_INFO_CC} --source_dir ${tensorflow_source_dir} --git_tag_override=${GIT_TAG_OVERRIDE}
DEPENDS __force_rebuild)
set(tf_version_srcs ${tensorflow_source_dir}/tensorflow/core/util/version_info.cc)
@ -341,9 +341,3 @@ add_dependencies(tf_core_framework
tf_core_lib
proto_text
)
if(WIN32)
# Cmake > 3.6 will quote this as -D"__VERSION__=\"MSVC\"" which nvcc fails on.
# Instead of defining this global, limit it to tf_core_framework where its used.
target_compile_definitions(tf_core_framework PRIVATE __VERSION__="MSVC")
endif()

View File

@ -554,12 +554,13 @@ if(WIN32)
set(pywrap_tensorflow_deffile "${CMAKE_CURRENT_BINARY_DIR}/pywrap_tensorflow.def")
endif()
set_source_files_properties(${pywrap_tensorflow_deffile} PROPERTIES GENERATED TRUE)
math(EXPR tensorflow_target_bitness "${CMAKE_SIZEOF_VOID_P}*8")
add_custom_command(TARGET pywrap_tensorflow_internal_static POST_BUILD
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/create_def_file.py
--input "${pywrap_tensorflow_internal_static_dependencies}"
--output "${pywrap_tensorflow_deffile}"
--target _pywrap_tensorflow_internal.pyd
--bitness "${tensorflow_target_bitness}"
BYPRODUCTS ${pywrap_tensorflow_deffile} # Required for Ninja
)
endif(WIN32)
@ -589,6 +590,12 @@ add_library(pywrap_tensorflow_internal SHARED
${pywrap_tensorflow_deffile}
)
# There is a bug in GCC 5 resulting in undefined reference to a __cpu_model function when
# linking to the tensorflow library. Adding the following libraries fixes it.
if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0)
target_link_libraries(pywrap_tensorflow_internal PRIVATE gcc_s gcc)
endif()
if(WIN32)
add_dependencies(pywrap_tensorflow_internal pywrap_tensorflow_internal_static)
endif(WIN32)

View File

@ -52,12 +52,13 @@ if(WIN32)
set(tensorflow_deffile "${CMAKE_CURRENT_BINARY_DIR}/tensorflow.def")
endif()
set_source_files_properties(${tensorflow_deffile} PROPERTIES GENERATED TRUE)
math(EXPR tensorflow_target_bitness "${CMAKE_SIZEOF_VOID_P}*8")
add_custom_command(TARGET tensorflow_static POST_BUILD
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/create_def_file.py
--input "${tensorflow_static_dependencies}"
--output "${tensorflow_deffile}"
--target tensorflow.dll
--bitness "${tensorflow_target_bitness}"
)
endif(WIN32)

View File

@ -65,6 +65,12 @@ if (tensorflow_ENABLE_GPU)
file(GLOB tf_stream_executor_gpu_srcs
"${tensorflow_source_dir}/tensorflow/stream_executor/cuda/*.cc"
)
if (NOT tensorflow_BUILD_CC_TESTS)
file(GLOB tf_stream_executor_gpu_tests
"${tensorflow_source_dir}/tensorflow/stream_executor/cuda/*_test.cc"
)
list(REMOVE_ITEM tf_stream_executor_gpu_srcs ${tf_stream_executor_gpu_tests})
endif()
list(APPEND tf_stream_executor_srcs ${tf_stream_executor_gpu_srcs})
endif()

View File

@ -63,7 +63,7 @@ INCLUDE_RE = re.compile(r"^(TF_\w*)$|"
r"^(TFE_\w*)$|"
r"tensorflow::|"
r"functor::|"
r"nsync_|"
r"\?nsync_|"
r"perftools::gputools")
# We want to identify data members explicitly in the DEF file, so that no one
@ -87,6 +87,7 @@ def get_args():
required=True)
parser.add_argument("--output", help="output deffile", required=True)
parser.add_argument("--target", help="name of the target", required=True)
parser.add_argument("--bitness", help="build target bitness", required=True)
args = parser.parse_args()
return args
@ -125,7 +126,10 @@ def main():
# Header for the def file.
def_fp.write("LIBRARY " + args.target + "\n")
def_fp.write("EXPORTS\n")
def_fp.write("\t ??1OpDef@tensorflow@@UEAA@XZ\n")
if args.bitness == "64":
def_fp.write("\t??1OpDef@tensorflow@@UEAA@XZ\n")
else:
def_fp.write("\t??1OpDef@tensorflow@@UAE@XZ\n")
# Each symbols returned by undname matches the same position in candidates.
# We compare on undname but use the decorated name from candidates.

View File

@ -281,6 +281,21 @@ class CrfTest(test.TestCase):
self.assertEqual(list(tf_actual_max_sequence[:sequence_lengths]),
expected_max_sequence[:sequence_lengths])
def testCrfDecodeZeroSeqLength(self):
"""
Test that crf_decode works when sequence_length contains one or more zeros.
"""
with self.test_session() as sess:
inputs = constant_op.constant(np.ones([2, 10, 5],
dtype=np.float32))
transition_params = constant_op.constant(np.ones([5, 5],
dtype=np.float32))
sequence_lengths = constant_op.constant(np.zeros([2],
dtype=np.int32))
values = crf.crf_decode(inputs, transition_params, sequence_lengths)
tags, scores = sess.run(values)
self.assertEqual(len(tags.shape), 2)
self.assertEqual(len(scores.shape), 1)
if __name__ == "__main__":
test.main()

View File

@ -479,15 +479,17 @@ def crf_decode(potentials, transition_params, sequence_length):
initial_state = array_ops.slice(potentials, [0, 0, 0], [-1, 1, -1])
initial_state = array_ops.squeeze(initial_state, axis=[1]) # [B, O]
inputs = array_ops.slice(potentials, [0, 1, 0], [-1, -1, -1]) # [B, T-1, O]
# sequence length is not allowed to be less than zero
sequence_length_less_one = math_ops.maximum(0, sequence_length - 1)
backpointers, last_score = rnn.dynamic_rnn( # [B, T - 1, O], [B, O]
crf_fwd_cell,
inputs=inputs,
sequence_length=sequence_length - 1,
sequence_length=sequence_length_less_one,
initial_state=initial_state,
time_major=False,
dtype=dtypes.int32)
backpointers = gen_array_ops.reverse_sequence( # [B, T - 1, O]
backpointers, sequence_length - 1, seq_dim=1)
backpointers, sequence_length_less_one, seq_dim=1)
# Computes backward decoding. Extract tag indices from backpointers.
crf_bwd_cell = CrfDecodeBackwardRnnCell(num_tags)
@ -497,7 +499,7 @@ def crf_decode(potentials, transition_params, sequence_length):
decode_tags, _ = rnn.dynamic_rnn( # [B, T - 1, 1]
crf_bwd_cell,
inputs=backpointers,
sequence_length=sequence_length - 1,
sequence_length=sequence_length_less_one,
initial_state=initial_state,
time_major=False,
dtype=dtypes.int32)

View File

@ -358,7 +358,8 @@ class _CudnnRNN(base_layer.Layer):
"CUDA/CuDNN generations.")
# Initialize opaque params with a tensor.
self.kernel = vs.get_variable(
"opaque_kernel", initializer=opaque_params_t, validate_shape=False)
"opaque_kernel", dtype=self._plain_dtype,
initializer=opaque_params_t, validate_shape=False)
# Create saveable in the outer scope of the cudnn subgraph, such that
# alternative subgraph with platform-independent rnn cells can load the
# checkpoints directly.

View File

@ -4,7 +4,7 @@ licenses(["notice"]) # Apache 2.0
exports_files(["LICENSE"])
load("//tensorflow:tensorflow.bzl", "py_test", "tf_py_test")
load("//tensorflow:tensorflow.bzl", "cuda_py_test", "py_test", "tf_py_test")
py_test(
name = "batch_dataset_op_test",
@ -482,12 +482,11 @@ py_test(
],
)
py_test(
cuda_py_test(
name = "prefetching_ops_test",
size = "small",
srcs = ["prefetching_ops_test.py"],
srcs_version = "PY2AND3",
deps = [
additional_deps = [
"//tensorflow/contrib/data/python/ops:prefetching_ops",
"//tensorflow/core:protos_all_py",
"//tensorflow/python:client_testlib",

View File

@ -163,7 +163,7 @@ class DatasetSerializationTestBase(test.TestCase):
num_outputs,
sparse_tensors=False,
verify_exhausted=True):
"""Verifies that restoring into an already initilized iterator works.
"""Verifies that restoring into an already initialized iterator works.
Args:
ds_fn: See `run_core_tests`.

View File

@ -409,7 +409,7 @@ class ParallelInterleaveDatasetTest(test.TestCase):
def _testTwoThreadsNoContentionWithRaces(self, sloppy=False):
"""Tests where all the workers race in producing elements.
Note: this is in contrast with the prevous test which carefully sequences
Note: this is in contrast with the previous test which carefully sequences
the execution of the map functions.
Args:
@ -495,7 +495,7 @@ class ParallelInterleaveDatasetTest(test.TestCase):
def _testTwoThreadsNoContentionWithRacesAndBlocking(self, sloppy=False):
"""Tests where all the workers race in producing elements.
Note: this is in contrast with the prevous test which carefully sequences
Note: this is in contrast with the previous test which carefully sequences
the execution of the map functions.
@ -928,8 +928,7 @@ class DirectedInterleaveDatasetTest(test.TestCase):
sess.run(next_element)
def _normalize(self, vec):
batched = (len(vec.shape) == 2)
return vec / vec.sum(axis=1, keepdims=True) if batched else vec / vec.sum()
return vec / vec.sum()
def _chi2(self, expected, actual):
actual = np.asarray(actual)
@ -938,35 +937,43 @@ class DirectedInterleaveDatasetTest(test.TestCase):
chi2 = np.sum(diff * diff / expected, axis=0)
return chi2
def _testSampleFromDatasetsHelper(self, weights, num_datasets, num_samples):
# Create a dataset that samples each integer in `[0, num_datasets)`
# with probability given by `weights[i]`.
dataset = interleave_ops.sample_from_datasets([
dataset_ops.Dataset.from_tensors(i).repeat(None)
for i in range(num_datasets)
], weights)
dataset = dataset.take(num_samples)
iterator = dataset.make_one_shot_iterator()
next_element = iterator.get_next()
with self.test_session() as sess:
freqs = np.zeros([num_datasets])
for _ in range(num_samples):
freqs[sess.run(next_element)] += 1
with self.assertRaises(errors.OutOfRangeError):
sess.run(next_element)
return freqs
def testSampleFromDatasets(self):
random_seed.set_random_seed(1618)
random_seed.set_random_seed(1619)
num_samples = 10000
rand_probs = self._normalize(np.random.random_sample((10,)))
rand_probs2 = self._normalize(np.random.random_sample((15,)))
rand_probs = self._normalize(np.random.random_sample((15,)))
for probs in [[.5, .5], [.85, .05, .1], rand_probs, rand_probs2]:
# Use chi-squared test to assert that the observed distribution matches the
# expected distribution. Based on the implementation in
# "tensorflow/python/kernel_tests/multinomial_op_test.py".
for probs in [[.85, .05, .1], rand_probs]:
probs = np.asarray(probs)
classes = len(probs)
freqs = self._testSampleFromDatasetsHelper(probs, classes, num_samples)
self.assertLess(self._chi2(probs, freqs / num_samples), 1e-3)
# Create a dataset that samples each integer in `[0, probs.shape[0])`
# with probability given by `probs[i]`.
dataset = interleave_ops.sample_from_datasets([
dataset_ops.Dataset.from_tensors(i).repeat(None)
for i in range(probs.shape[0])
], probs)
dataset = dataset.take(num_samples)
iterator = dataset.make_one_shot_iterator()
next_element = iterator.get_next()
with self.test_session() as sess:
freqs = np.zeros_like(probs)
for _ in range(num_samples):
freqs[sess.run(next_element)] += 1
with self.assertRaises(errors.OutOfRangeError):
sess.run(next_element)
# Use chi-squared test to assert that the observed distribution
# matches the expected distribution. Based on the implementation
# in "tensorflow/python/kernel_tests/multinomial_op_test.py".
# Also check that `weights` as a dataset samples correctly.
probs_ds = dataset_ops.Dataset.from_tensors(probs).repeat()
freqs = self._testSampleFromDatasetsHelper(probs_ds, classes, num_samples)
self.assertLess(self._chi2(probs, freqs / num_samples), 1e-3)
def testErrors(self):

View File

@ -201,6 +201,14 @@ class StatsDatasetSerializationTest(
lambda x: array_ops.tile([x], ops.convert_to_tensor([x]))).apply(
stats_ops.bytes_produced_stats("bytes_produced"))
def test_bytes_produced_stats_invalid_tag_shape(self):
with self.assertRaisesRegexp(
ValueError, 'Shape must be rank 0 but is rank 1'):
self.run_core_tests(
lambda: dataset_ops.Dataset.range(100).apply(
stats_ops.bytes_produced_stats(["bytes_produced"])),
None, 100)
def testBytesStatsDatasetSaveableCore(self):
num_outputs = 100
self.run_core_tests(
@ -218,6 +226,14 @@ class StatsDatasetSerializationTest(
return dataset_ops.Dataset.range(num_elements).apply(
stats_ops.latency_stats(tag1)).apply(stats_ops.latency_stats(tag2))
def test_latency_stats_invalid_tag_shape(self):
with self.assertRaisesRegexp(
ValueError, 'Shape must be rank 0 but is rank 1'):
self.run_core_tests(
lambda: dataset_ops.Dataset.range(100).apply(
stats_ops.latency_stats(["record_latency", "record_latency_2"])),
None, 100)
def testLatencyStatsDatasetSaveableCore(self):
num_outputs = 100

View File

@ -200,10 +200,11 @@ def sample_from_datasets(datasets, weights=None, seed=None):
Args:
datasets: A list of @{tf.data.Dataset} objects with compatible structure.
weights: (Optional.) A list of `len(datasets)` floating-point values,
where `weights[i]` represents the probability with which an element
should be sampled from `datasets[i]`. Defaults to a uniform distribution
across `datasets`.
weights: (Optional.) A list of `len(datasets)` floating-point values where
`weights[i]` represents the probability with which an element should be
sampled from `datasets[i]`, or a @{tf.data.Dataset} object where each
element is such a list. Defaults to a uniform distribution across
`datasets`.
seed: (Optional.) A `tf.int64` scalar `tf.Tensor`, representing the
random seed that will be used to create the distribution. See
@{tf.set_random_seed} for behavior.
@ -219,24 +220,23 @@ def sample_from_datasets(datasets, weights=None, seed=None):
"""
num_datasets = len(datasets)
if weights is None:
weights = array_ops.ones(
[num_datasets], dtype=dtypes.float32, name="weights")
else:
weights = dataset_ops.Dataset.from_tensors([1.0] * num_datasets).repeat()
elif not isinstance(weights, dataset_ops.Dataset):
weights = ops.convert_to_tensor(weights, name="weights")
if weights.dtype not in (dtypes.float32, dtypes.float64):
raise TypeError("`weights` must be convertible to a tensor of "
"`tf.float32` or `tf.float64` elements.")
if not weights.shape.is_compatible_with([num_datasets]):
raise ValueError("`weights` must be a vector of length `len(datasets)`.")
weights = dataset_ops.Dataset.from_tensors(weights).repeat()
# The `stateless_multinomial()` op expects log-probabilities, as opposed to
# weights.
logits = math_ops.log(weights, name="logits")
def select_dataset(seed):
logits_ds = weights.map(lambda *p: math_ops.log(p, name="logits"))
def select_dataset(logits, seed):
return array_ops.squeeze(
stateless.stateless_multinomial([logits], 1, seed=seed), axis=[0, 1])
selector_input = random_ops.RandomDataset(seed).batch(2).map(select_dataset)
stateless.stateless_multinomial(logits, 1, seed=seed), axis=[0, 1])
selector_input = dataset_ops.Dataset.zip(
(logits_ds, random_ops.RandomDataset(seed).batch(2))).map(select_dataset)
return DirectedInterleaveDataset(selector_input, datasets)

View File

@ -114,11 +114,13 @@ class _PrefetchToDeviceIterator(object):
ret = remote_iterator.get_next()
return nest.flatten(sparse.serialize_sparse_tensors(ret))
iterator_device = gen_dataset_ops.iterator_get_device(
self._input_iterator._iterator_resource)
with ops.device(device):
self._buffering_resource = function_buffering_resource(
f=_prefetch_fn,
target_device=gen_dataset_ops.iterator_get_device(
self._input_iterator._iterator_resource),
target_device=iterator_device,
string_arg=input_iterator_handle,
buffer_size=buffer_size,
shared_name=shared_name)

View File

@ -57,7 +57,7 @@ class _ScanDataset(dataset_ops.Dataset):
self._output_shapes = None
self._output_types = None
# Iteratively rerun the scan function until reaching a fixed pont on
# Iteratively rerun the scan function until reaching a fixed point on
# `self._state_shapes`.
need_to_rerun = True
while need_to_rerun:

View File

@ -584,7 +584,6 @@ class DistributionShapeTest(test.TestCase):
def testDistributionShapeGetDimsStatic(self):
with self.test_session():
shaper = _DistributionShape(batch_ndims=0, event_ndims=0)
shaper = _DistributionShape(batch_ndims=0, event_ndims=0)
x = 1
self.assertAllEqual((_empty_shape, _empty_shape, _empty_shape),

View File

@ -102,7 +102,6 @@ class SaverTest(test.TestCase):
# Can still restore it.
saver.restore(ckpt_prefix)
self.assertEqual(v1.read_value().numpy(), 1.0)
self.assertEqual(v1.read_value().numpy(), 1.0)
# However, cannot restore it with default name.
with self.assertRaisesOpError('not found in checkpoint'):
saver = _saver.Saver([v1, v2]).restore(ckpt_prefix)

View File

@ -485,7 +485,7 @@ class _MultiLabelHead(head_lib._Head): # pylint:disable=protected-access
reduction=losses.Reduction.NONE)
# Averages loss over classes.
unweighted_loss = math_ops.reduce_mean(
unweighted_loss, axis=-1, keep_dims=True)
unweighted_loss, axis=-1, keepdims=True)
weights = head_lib._get_weights_and_check_match_logits( # pylint:disable=protected-access,
features=features, weight_column=self._weight_column, logits=logits)
training_loss = losses.compute_weighted_loss(

View File

@ -456,7 +456,7 @@ def _get_local_devices(device_type):
def _split_batch(features, labels, number_of_shards, device):
"""Split input features and labes into batches."""
"""Split input features and labels into batches."""
def ensure_divisible_by_shards(sequence):
batch_size = ops_lib.convert_to_tensor(sequence).get_shape()[0]
@ -602,7 +602,7 @@ def _local_device_setter(worker_device, ps_devices, ps_strategy):
def _scale_tower_loss(tower_spec, loss_reduction, number_of_towers):
"""Produce an EstimatorSpec with approproriately scaled loss."""
"""Produce an EstimatorSpec with appropriately scaled loss."""
if tower_spec.loss is None:
return tower_spec

View File

@ -54,10 +54,10 @@ def _covariance(x, diag):
diagonal matrix just the diagonal is returned.
"""
num_points = math_ops.to_float(array_ops.shape(x)[0])
x -= math_ops.reduce_mean(x, 0, keep_dims=True)
x -= math_ops.reduce_mean(x, 0, keepdims=True)
if diag:
cov = math_ops.reduce_sum(
math_ops.square(x), 0, keep_dims=True) / (num_points - 1)
math_ops.square(x), 0, keepdims=True) / (num_points - 1)
else:
cov = math_ops.matmul(x, x, transpose_a=True) / (num_points - 1)
return cov
@ -313,7 +313,7 @@ class GmmAlgorithm(object):
# TODO(xavigonzalvo): look into alternatives to log for
# reparametrization of variance parameters.
det_expanded = math_ops.reduce_sum(
math_ops.log(self._covs + 1e-3), 1, keep_dims=True)
math_ops.log(self._covs + 1e-3), 1, keepdims=True)
diff = shard - self._means
x2 = math_ops.square(diff)
cov_expanded = array_ops.expand_dims(1.0 / (self._covs + 1e-3), 2)
@ -351,7 +351,7 @@ class GmmAlgorithm(object):
shard_id: id of current shard_id.
"""
self._prior_probs[shard_id] = math_ops.reduce_logsumexp(
self._probs[shard_id], axis=1, keep_dims=True)
self._probs[shard_id], axis=1, keepdims=True)
def _define_expectation_operation(self, shard_id):
# Shape broadcasting.
@ -375,7 +375,7 @@ class GmmAlgorithm(object):
"""
# Soft assignment of each data point to each of the two clusters.
self._points_in_k[shard_id] = math_ops.reduce_sum(
self._w[shard_id], 0, keep_dims=True)
self._w[shard_id], 0, keepdims=True)
# Partial means.
w_mul_x = array_ops.expand_dims(
math_ops.matmul(
@ -454,7 +454,7 @@ class GmmAlgorithm(object):
for shard_id, prior_probs in enumerate(self._prior_probs):
op.append(prior_probs + math_ops.log(self._w[shard_id]))
self._scores = array_ops.squeeze(
math_ops.reduce_logsumexp(op, axis=2, keep_dims=True), axis=0)
math_ops.reduce_logsumexp(op, axis=2, keepdims=True), axis=0)
def gmm(inp,

View File

@ -374,11 +374,11 @@ class KMeansClustering(estimator.Estimator):
than `num_clusters`, a TensorFlow runtime error occurs.
distance_metric: The distance metric used for clustering. One of:
* `KMeansClustering.SQUARED_EUCLIDEAN_DISTANCE`: Euclidean distance
between vectors `u` and `v` is defined as `\\(||u - v||_2\\)`
between vectors `u` and `v` is defined as \\(||u - v||_2\\)
which is the square root of the sum of the absolute squares of
the elements' difference.
* `KMeansClustering.COSINE_DISTANCE`: Cosine distance between vectors
`u` and `v` is defined as `\\(1 - (u . v) / (||u||_2 ||v||_2)\\)`.
`u` and `v` is defined as \\(1 - (u . v) / (||u||_2 ||v||_2)\\).
random_seed: Python integer. Seed for PRNG used to initialize centers.
use_mini_batch: A boolean specifying whether to use the mini-batch k-means
algorithm. See explanation above.

View File

@ -118,12 +118,13 @@ from tensorflow.python.framework.smart_cond import smart_cond
from tensorflow.python.framework.smart_cond import smart_constant_value
from tensorflow.python.framework.tensor_spec import BoundedTensorSpec
from tensorflow.python.framework.tensor_spec import TensorSpec
from tensorflow.python.ops.array_ops import broadcast_to
from tensorflow.python.ops.init_ops import convolutional_delta_orthogonal
from tensorflow.python.ops.init_ops import convolutional_orthogonal_1d
from tensorflow.python.ops.init_ops import convolutional_orthogonal_2d
from tensorflow.python.ops.init_ops import convolutional_orthogonal_3d
from tensorflow.python.util.all_util import remove_undocumented
_allowed_symbols = ['nest']
_allowed_symbols = ['nest', 'broadcast_to']
remove_undocumented(__name__, allowed_exception_list=_allowed_symbols)

View File

@ -48,7 +48,7 @@ class LocalVariabletest(test.TestCase):
variables = variables_lib.local_variables()
self.assertEquals(2, len(variables))
self.assertRaises(errors_impl.OpError, sess.run, variables)
variables_lib.initialize_variables(variables).run()
variables_lib.variables_initializer(variables).run()
self.assertAllEqual(set([value0, value1]), set(sess.run(variables)))

View File

@ -65,7 +65,7 @@ def fused_conv2d_bias_activation(conv_input,
side_input_scale: A scalar `float32` that will be multiplied by side_input.
This is optional and defaults to 0.
side_input: A `Tensor` of the format specified by `data_format`.
This is useful for imlementing ResNet blocks.
This is useful for implementing ResNet blocks.
activation_mode: (optional) currently must be the default "Relu".
Note that in qint8 mode, it also clips to 127, so acts like ReluX.
data_format: Specifies the data format.

View File

@ -566,7 +566,7 @@ def GetInceptionFwdTest(input_size, filter_size, stride, padding,
return Test
def CalculateCovolvedOutputDim(input_dim, filter_dim, stride, padding_type):
def CalculateConvolvedOutputDim(input_dim, filter_dim, stride, padding_type):
"""Calculates the size of an output dimension of a strided convolution.
Given the sizes of the corresponding dimension of the input and filter shapes,
@ -827,10 +827,10 @@ class FusedConvInt8Tests(test.TestCase):
maxval=1.0,
dtype=dtypes.float32), -1.0, 1.0, dtypes.qint8)
output_height = CalculateCovolvedOutputDim(input_height, filter_height,
vertical_stride, padding_type)
output_width = CalculateCovolvedOutputDim(input_width, filter_width,
horizontal_stride, padding_type)
output_height = CalculateConvolvedOutputDim(input_height, filter_height,
vertical_stride, padding_type)
output_width = CalculateConvolvedOutputDim(input_width, filter_width,
horizontal_stride, padding_type)
print("output_height=", output_height, ", output_width=", output_width)
side_input, _, _ = gen_array_ops.quantize_v2(

View File

@ -161,7 +161,7 @@ def _sliced_wasserstein(a, b, random_sampling_count, random_projection_dim):
proj = random_ops.random_normal(
[array_ops.shape(a)[1], random_projection_dim])
proj *= math_ops.rsqrt(
math_ops.reduce_sum(math_ops.square(proj), 0, keep_dims=True))
math_ops.reduce_sum(math_ops.square(proj), 0, keepdims=True))
# Project both distributions and sort them.
proj_a = math_ops.matmul(a, proj)
proj_b = math_ops.matmul(b, proj)

View File

@ -64,11 +64,11 @@ def _statistics(x, axes):
y = math_ops.cast(x, dtypes.float32) if x.dtype == dtypes.float16 else x
# Compute true mean while keeping the dims for proper broadcasting.
shift = array_ops.stop_gradient(math_ops.reduce_mean(y, axes, keep_dims=True))
shift = array_ops.stop_gradient(math_ops.reduce_mean(y, axes, keepdims=True))
shifted_mean = math_ops.reduce_mean(y - shift, axes, keep_dims=True)
shifted_mean = math_ops.reduce_mean(y - shift, axes, keepdims=True)
mean = shifted_mean + shift
mean_squared = math_ops.reduce_mean(math_ops.square(y), axes, keep_dims=True)
mean_squared = math_ops.reduce_mean(math_ops.square(y), axes, keepdims=True)
mean = array_ops.squeeze(mean, axes)
mean_squared = array_ops.squeeze(mean_squared, axes)

View File

@ -42,11 +42,12 @@ If you've finished walking through the quick start guide, you may want to try bu
### Build libhexagon\_nn\_skel.so
Download Hexagon NN library from codeaurora.org and build it.
Download Hexagon NN library from codeaurora.org and build it. For Hexagon SDK 3.0, we need use the compatible version([721b2d58f](https://source.codeaurora.org/quic/hexagon_nn/nnlib/commit/?id=721b2d58f0f4e2d5b182f41e6b7c4db5356bf0fb)) of nnlib.
```shell
git clone https://source.codeaurora.org/quic/hexagon_nn/nnlib
cd nnlib
git reset 721b2d58f --hard
```
Just follow the instructions in `README.HOW_TO_BUILD`. You can find the file `libhexagon_nn_skel.so` in `hexagon_Release_dynamic_toolv72_v60/ship`.

View File

@ -53,7 +53,7 @@ void AdjustHsvInYiqGPU::operator()(OpKernelContext* ctx, int channel_count,
OP_REQUIRES_OK(ctx, ctx->allocate_temp(
DT_FLOAT, TensorShape({kChannelSize * kChannelSize}),
&tranformation_matrix));
// TODO(huangyp): It takes about 3.5 us to comute tranformation_matrix
// TODO(huangyp): It takes about 3.5 us to compute tranformation_matrix
// with one thread. Improve its performance if necessary.
internal::compute_tranformation_matrix_cuda<<<1, 1, 0, cu_stream>>>(
delta_h, scale_s, scale_v, tranformation_matrix.flat<float>().data(),

View File

@ -36,9 +36,9 @@ REGISTER_OP("AdjustHsvInYiq")
Adjust the YIQ hue of one or more images.
`images` is a tensor of at least 3 dimensions. The last dimension is
interpretted as channels, and must be three.
interpreted as channels, and must be three.
We used linear transfomation described in:
We used linear transformation described in:
beesbuzz.biz/code/hsv_color_transforms.php
The input image is considered in the RGB colorspace. Conceptually, the RGB
colors are first mapped into YIQ space, rotated around the Y channel by

View File

@ -137,7 +137,7 @@ row_to_col_match_indices: A vector of length num_rows, which is the number of
If `row_to_col_match_indices[i]` is not -1, row i is matched to column
`row_to_col_match_indices[i]`.
col_to_row_match_indices: A vector of length num_columns, which is the number
of columns of the input ditance matrix.
of columns of the input distance matrix.
If `col_to_row_match_indices[j]` is not -1, column j is matched to row
`col_to_row_match_indices[j]`.
)doc");

View File

@ -69,7 +69,7 @@ Outputs a single image random dot stereogram for export via encode_PNG/JPG OP.
Given the 2-D tensor 'depth_values' with encoded Z values, this operation will
encode 3-D data into a 2-D image. The output of this Op is suitable for the
encode_PNG/JPG ops. Be careful with image compression as this may corrupt the
encode 3-D data witin the image.
encode 3-D data within the image.
This Op is based upon:
'http://www.learningace.com/doc/4331582/b6ab058d1e206d68ab60e4e1ead2fe6e/sirds-paper'
@ -111,7 +111,7 @@ output_image_shape: Output size of returned image in X,Y, Channels 1-grayscale,
output_data_window: Size of "DATA" window, must be equal to or smaller than 'output_image_shape', will be centered
and use 'convergence_dots_size' for best fit to avoid overlap if possible
image:= A tensor of size 'output_image_shape' with the encloded 'depth_values'
image:= A tensor of size 'output_image_shape' with the encoded 'depth_values'
)doc");
} // namespace tensorflow

View File

@ -438,7 +438,7 @@ def bipartite_match(distance_mat,
of rows of the input `distance_matrix`. If `row_to_col_match_indices[i]`
is not -1, row i is matched to column `row_to_col_match_indices[i]`.
col_to_row_match_indices: A vector of length num_columns, which is the
number of columns of the input ditance matrix.
number of columns of the input distance matrix.
If `col_to_row_match_indices[j]` is not -1, column j is matched to row
`col_to_row_match_indices[j]`.
"""

View File

@ -45,7 +45,7 @@ def single_image_random_dot_stereograms(depth_values,
Given the 2-D tensor 'depth_values' with encoded Z values, this operation
will encode 3-D data into a 2-D image. The output of this Op is suitable
for the encode_PNG/JPG ops. Be careful with image compression as this may
corrupt the encode 3-D data witin the image.
corrupt the encode 3-D data within the image.
Based upon [this
paper](http://www.learningace.com/doc/4331582/b6ab058d1e206d68ab60e4e1ead2fe6e/sirds-paper).

View File

@ -613,19 +613,19 @@ class CategoricalLogitsNegativeLogProbLoss(DistributionNegativeLogProbLoss,
def multiply_fisher(self, vector):
probs = self._probs
return vector * probs - probs * math_ops.reduce_sum(
vector * probs, axis=-1, keep_dims=True)
vector * probs, axis=-1, keepdims=True)
def multiply_fisher_factor(self, vector):
probs = self._probs
sqrt_probs = self._sqrt_probs
return sqrt_probs * vector - probs * math_ops.reduce_sum(
sqrt_probs * vector, axis=-1, keep_dims=True)
sqrt_probs * vector, axis=-1, keepdims=True)
def multiply_fisher_factor_transpose(self, vector):
probs = self._probs
sqrt_probs = self._sqrt_probs
return sqrt_probs * vector - sqrt_probs * math_ops.reduce_sum(
probs * vector, axis=-1, keep_dims=True)
probs * vector, axis=-1, keepdims=True)
def multiply_fisher_factor_replicated_one_hot(self, index):
assert len(index) == 1, "Length of index was {}".format(len(index))

View File

@ -33,7 +33,6 @@ _allowed_symbols = [
"CategoricalLogitsNegativeLogProbLoss",
"OnehotCategoricalLogitsNegativeLogProbLoss",
"MultiBernoulliNegativeLogProbLoss",
"MultiBernoulliNegativeLogProbLoss",
"insert_slice_in_zeros",
]

View File

@ -660,7 +660,7 @@ class ReduceSumTest(Base):
sum_lt = ops.reduce_sum(self.original_lt, {('channel', 'hihowareyou')})
golden_lt = core.LabeledTensor(
math_ops.reduce_sum(
self.original_lt.tensor, 1, keep_dims=True),
self.original_lt.tensor, 1, keepdims=True),
[self.a0, ('channel', ['hihowareyou']), self.a2, self.a3])
self.assertLabeledTensorsEqual(sum_lt, golden_lt)
@ -668,7 +668,7 @@ class ReduceSumTest(Base):
sum_lt = ops.reduce_sum(self.original_lt, ('channel', 'hihowareyou'))
golden_lt = core.LabeledTensor(
math_ops.reduce_sum(
self.original_lt.tensor, 1, keep_dims=True),
self.original_lt.tensor, 1, keepdims=True),
[self.a0, ('channel', ['hihowareyou']), self.a2, self.a3])
self.assertLabeledTensorsEqual(sum_lt, golden_lt)

View File

@ -200,7 +200,7 @@ class SparseCrossOpTest(test.TestCase):
self._assert_sparse_tensor_equals(expected_out, sess.run(op))
def test_large_batch(self):
"""Tests with large batch size to force multithreding.
"""Tests with large batch size to force multithreading.
"""
batch_size = 5000
col1 = []

View File

@ -48,7 +48,7 @@ you should choose depends on (1) the feature type and (2) the model type.
recommended.
embedded_dept_column = embedding_column(
sparse_column_with_keys("department", ["math", "philosphy", ...]),
sparse_column_with_keys("department", ["math", "philosophy", ...]),
dimension=10)
* Wide (aka linear) models (`LinearClassifier`, `LinearRegressor`).

View File

@ -815,7 +815,7 @@ class _Transformer(object):
"""
def __init__(self, columns_to_tensors):
"""Initializes transfomer.
"""Initializes transformer.
Args:
columns_to_tensors: A mapping from feature columns to tensors. 'string'
@ -908,7 +908,7 @@ def _gather_feature_columns(feature_columns):
def _check_forbidden_sequence_columns(feature_columns):
"""Recursively cecks `feature_columns` for `_FORBIDDEN_SEQUENCE_COLUMNS`."""
"""Recursively checks `feature_columns` for `_FORBIDDEN_SEQUENCE_COLUMNS`."""
all_feature_columns = _gather_feature_columns(feature_columns)
for feature_column in all_feature_columns:
if isinstance(feature_column, _FORBIDDEN_SEQUENCE_COLUMNS):

View File

@ -932,7 +932,8 @@ def convolution(inputs,
variables_collections=None,
outputs_collections=None,
trainable=True,
scope=None):
scope=None,
conv_dims=None):
"""Adds an N-D convolution followed by an optional batch_norm layer.
It is required that 1 <= N <= 3.
@ -993,6 +994,10 @@ def convolution(inputs,
trainable: If `True` also add variables to the graph collection
`GraphKeys.TRAINABLE_VARIABLES` (see tf.Variable).
scope: Optional scope for `variable_scope`.
conv_dims: Optional convolution dimensionality, when set it would use the
corresponding convolution (e.g. 2 for Conv 2D, 3 for Conv 3D, ..). When
leaved to None it would select the convolution dimensionality based on
the input rank (i.e. Conv ND, with N = input_rank - 2).
Returns:
A tensor representing the output of the operation.
@ -1015,6 +1020,9 @@ def convolution(inputs,
inputs = ops.convert_to_tensor(inputs)
input_rank = inputs.get_shape().ndims
if conv_dims is not None and conv_dims + 2 != input_rank:
raise ValueError('Convolution expects input with rank %d, got %d' %
(conv_dims + 2, input_rank))
if input_rank == 3:
layer_class = convolutional_layers.Convolution1D
elif input_rank == 4:
@ -1061,10 +1069,134 @@ def convolution(inputs,
outputs = activation_fn(outputs)
return utils.collect_named_outputs(outputs_collections, sc.name, outputs)
@add_arg_scope
def convolution1d(inputs,
num_outputs,
kernel_size,
stride=1,
padding='SAME',
data_format=None,
rate=1,
activation_fn=nn.relu,
normalizer_fn=None,
normalizer_params=None,
weights_initializer=initializers.xavier_initializer(),
weights_regularizer=None,
biases_initializer=init_ops.zeros_initializer(),
biases_regularizer=None,
reuse=None,
variables_collections=None,
outputs_collections=None,
trainable=True,
scope=None):
return convolution(inputs,
num_outputs,
kernel_size,
stride,
padding,
data_format,
rate,
activation_fn,
normalizer_fn,
normalizer_params,
weights_initializer,
weights_regularizer,
biases_initializer,
biases_regularizer,
reuse,
variables_collections,
outputs_collections,
trainable,
scope,
conv_dims=1)
convolution2d = convolution
convolution3d = convolution
convolution1d.__doc__ = convolution.__doc__
@add_arg_scope
def convolution2d(inputs,
num_outputs,
kernel_size,
stride=1,
padding='SAME',
data_format=None,
rate=1,
activation_fn=nn.relu,
normalizer_fn=None,
normalizer_params=None,
weights_initializer=initializers.xavier_initializer(),
weights_regularizer=None,
biases_initializer=init_ops.zeros_initializer(),
biases_regularizer=None,
reuse=None,
variables_collections=None,
outputs_collections=None,
trainable=True,
scope=None):
return convolution(inputs,
num_outputs,
kernel_size,
stride,
padding,
data_format,
rate,
activation_fn,
normalizer_fn,
normalizer_params,
weights_initializer,
weights_regularizer,
biases_initializer,
biases_regularizer,
reuse,
variables_collections,
outputs_collections,
trainable,
scope,
conv_dims=2)
convolution2d.__doc__ = convolution.__doc__
@add_arg_scope
def convolution3d(inputs,
num_outputs,
kernel_size,
stride=1,
padding='SAME',
data_format=None,
rate=1,
activation_fn=nn.relu,
normalizer_fn=None,
normalizer_params=None,
weights_initializer=initializers.xavier_initializer(),
weights_regularizer=None,
biases_initializer=init_ops.zeros_initializer(),
biases_regularizer=None,
reuse=None,
variables_collections=None,
outputs_collections=None,
trainable=True,
scope=None):
return convolution(inputs,
num_outputs,
kernel_size,
stride,
padding,
data_format,
rate,
activation_fn,
normalizer_fn,
normalizer_params,
weights_initializer,
weights_regularizer,
biases_initializer,
biases_regularizer,
reuse,
variables_collections,
outputs_collections,
trainable,
scope,
conv_dims=3)
convolution3d.__doc__ = convolution.__doc__
@add_arg_scope
def convolution2d_in_plane(
@ -1411,7 +1543,7 @@ def dense_to_sparse(tensor, eos_token=0, outputs_collections=None, scope=None):
Args:
tensor: An `int` `Tensor` to be converted to a `Sparse`.
eos_token: An integer.
It is part of the target label that signfies the end of a sentence.
It is part of the target label that signifies the end of a sentence.
outputs_collections: Collection to add the outputs.
scope: Optional scope for name_scope.
"""
@ -1555,7 +1687,7 @@ def _inner_flatten(inputs, new_rank, output_collections=None, scope=None):
output_collections: Collection to which the outputs will be added.
scope: Optional scope for `name_scope`.
Returns:
A `Tensor` or `SparseTensor` conataining the same values as `inputs`, but
A `Tensor` or `SparseTensor` containing the same values as `inputs`, but
with innermost dimensions flattened to obtain rank `new_rank`.
Raises:

View File

@ -310,6 +310,17 @@ class BiasAddTest(test.TestCase):
class ConvolutionTest(test.TestCase):
def testInvalidShape(self):
with self.test_session():
images_2d = random_ops.random_uniform((5, 7, 9, 3), seed=1)
with self.assertRaisesRegexp(
ValueError, 'Convolution expects input with rank 5, got 4'):
layers_lib.convolution3d(images_2d, 32, 3)
images_3d = random_ops.random_uniform((5, 6, 7, 9, 3), seed=1)
with self.assertRaisesRegexp(
ValueError, 'Convolution expects input with rank 4, got 5'):
layers_lib.convolution2d(images_3d, 32, 3)
def testInvalidDataFormat(self):
height, width = 7, 9
with self.test_session():
@ -3155,7 +3166,7 @@ class RepeatTests(test.TestCase):
with self.test_session():
images = np.random.uniform(size=(5, height, width, 3)).astype(np.float32)
output = _layers.repeat(images, 3, layers_lib.conv2d, 32, [3, 3])
self.assertEqual(output.op.name, 'Repeat/convolution_3/Relu')
self.assertEqual(output.op.name, 'Repeat/convolution2d_3/Relu')
self.assertListEqual(output.get_shape().as_list(), [5, 3, 3, 32])
def testRepeatWithScope(self):
@ -3749,7 +3760,7 @@ class StackTests(test.TestCase):
layers_lib.convolution2d, [10, 20, 30],
kernel_size=[3, 3],
padding='SAME')
self.assertEqual(output.op.name, 'Stack/convolution_3/Relu')
self.assertEqual(output.op.name, 'Stack/convolution2d_3/Relu')
self.assertListEqual(output.get_shape().as_list(), [5, 3, 3, 30])
def testStackWithScope(self):

View File

@ -60,8 +60,8 @@ class RevBlockTest(test.TestCase):
sess.run(variables.global_variables_initializer())
x1, x2, x1_inv, x2_inv = sess.run([x1, x2, x1_inv, x2_inv])
self.assertAllClose(x1, x1_inv)
self.assertAllClose(x2, x2_inv)
self.assertAllClose(x1, x1_inv, atol=1e-5)
self.assertAllClose(x2, x2_inv, atol=1e-5)
def testBackwardForward(self):

View File

@ -294,7 +294,6 @@ class NPositiveIntegersTest(test.TestCase):
self.assertEqual(utils.n_positive_integers(2, 2), (2, 2))
self.assertEqual(utils.n_positive_integers(2, (2, 3)), (2, 3))
self.assertEqual(utils.n_positive_integers(3, (2, 3, 1)), (2, 3, 1))
self.assertEqual(utils.n_positive_integers(3, (2, 3, 1)), (2, 3, 1))
self.assertEqual(
utils.n_positive_integers(3, tensor_shape.TensorShape([2, 3, 1])),
(2, 3, 1))

View File

@ -36,7 +36,6 @@ from tensorflow.python.ops import control_flow_ops
from tensorflow.python.ops import data_flow_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import random_ops
from tensorflow.python.ops import random_ops
from tensorflow.python.platform import benchmark
from tensorflow.python.platform import flags
from tensorflow.python.platform import test

View File

@ -299,6 +299,7 @@ class RunConfig(ClusterConfig, core_run_config.RunConfig):
# so instead of breaking compatibility with that assumption, we
# just manually initialize this field:
self._train_distribute = None
self._device_fn = None
gpu_options = config_pb2.GPUOptions(
per_process_gpu_memory_fraction=gpu_memory_fraction)

View File

@ -90,7 +90,8 @@ $(wildcard tensorflow/contrib/lite/kernels/*.c) \
$(wildcard tensorflow/contrib/lite/kernels/internal/*.c) \
$(wildcard tensorflow/contrib/lite/kernels/internal/optimized/*.c) \
$(wildcard tensorflow/contrib/lite/kernels/internal/reference/*.c) \
$(wildcard tensorflow/contrib/lite/downloads/farmhash/src/farmhash.cc)
$(wildcard tensorflow/contrib/lite/downloads/farmhash/src/farmhash.cc) \
$(wildcard tensorflow/contrib/lite/downloads/fft2d/fftsg.c)
# Remove any duplicates.
CORE_CC_ALL_SRCS := $(sort $(CORE_CC_ALL_SRCS))
CORE_CC_EXCLUDE_SRCS := \

View File

@ -30,12 +30,15 @@ if [ ! -f $BZL_FILE_PATH ]; then
fi
EIGEN_URL="$(grep -o 'http.*bitbucket.org/eigen/eigen/get/.*tar\.gz' "${BZL_FILE_PATH}" | grep -v mirror.bazel | head -n1)"
GEMMLOWP_URL="$(grep -o 'https://mirror.bazel.build/github.com/google/gemmlowp/.*zip' "${BZL_FILE_PATH}" | head -n1)"
# TODO (yongtang): Replace the following with 'https://mirror.bazel.build/github.com/google/gemmlowp/.*zip' once
# the archive has been propagated in mirror.bazel.build.
GEMMLOWP_URL="$(grep -o 'https://github.com/google/gemmlowp/.*zip' "${BZL_FILE_PATH}" | head -n1)"
GOOGLETEST_URL="https://github.com/google/googletest/archive/release-1.8.0.tar.gz"
ABSL_URL="$(grep -o 'https://github.com/abseil/abseil-cpp/.*tar.gz' "${BZL_FILE_PATH}" | head -n1)"
NEON_2_SSE_URL="https://github.com/intel/ARM_NEON_2_x86_SSE/archive/master.zip"
FARMHASH_URL="https://mirror.bazel.build/github.com/google/farmhash/archive/816a4ae622e964763ca0862d9dbd19324a1eaf45.tar.gz"
FLATBUFFERS_URL="https://github.com/google/flatbuffers/archive/master.zip"
FFT2D_URL="https://mirror.bazel.build/www.kurims.kyoto-u.ac.jp/~ooura/fft.tgz"
# TODO(petewarden): Some new code in Eigen triggers a clang bug with iOS arm64,
# so work around it by patching the source.
@ -91,6 +94,7 @@ download_and_extract "${ABSL_URL}" "${DOWNLOADS_DIR}/absl"
download_and_extract "${NEON_2_SSE_URL}" "${DOWNLOADS_DIR}/neon_2_sse"
download_and_extract "${FARMHASH_URL}" "${DOWNLOADS_DIR}/farmhash"
download_and_extract "${FLATBUFFERS_URL}" "${DOWNLOADS_DIR}/flatbuffers"
download_and_extract "${FFT2D_URL}" "${DOWNLOADS_DIR}/fft2d"
replace_by_sed 's#static uint32x4_t p4ui_CONJ_XOR = vld1q_u32( conj_XOR_DATA );#static uint32x4_t p4ui_CONJ_XOR; // = vld1q_u32( conj_XOR_DATA ); - Removed by script#' \
"${DOWNLOADS_DIR}/eigen/Eigen/src/Core/arch/NEON/Complex.h"

View File

@ -326,10 +326,6 @@
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(inherited)",
../../../../../../,
../../../downloads/flatbuffers/include/,
../../../downloads/eigen/,
../../../downloads/,
);
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = YES;
@ -373,10 +369,6 @@
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(inherited)",
../../../../../../,
../../../downloads/flatbuffers/include/,
../../../downloads/eigen/,
../../../downloads/,
);
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;

View File

@ -29,7 +29,7 @@ interpreter->AllocateTensors();
float* input = interpreter->typed_input_tensor<float>(0);
// Fill `input`.
interpreter->Invoke();
float* output = interpreter->type_output_tensor<float>(0);
float* output = interpreter->typed_output_tensor<float>(0);
```
### Data Alignment

View File

@ -54,6 +54,9 @@ import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.NumberPicker;
import android.widget.ToggleButton;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
@ -82,6 +85,8 @@ public class Camera2BasicFragment extends Fragment
private boolean runClassifier = false;
private boolean checkedPermissions = false;
private TextView textView;
private ToggleButton toggle;
private NumberPicker np;
private ImageClassifier classifier;
/** Max preview width that is guaranteed by Camera2 API */
@ -289,6 +294,24 @@ public class Camera2BasicFragment extends Fragment
public void onViewCreated(final View view, Bundle savedInstanceState) {
textureView = (AutoFitTextureView) view.findViewById(R.id.texture);
textView = (TextView) view.findViewById(R.id.text);
toggle = (ToggleButton) view.findViewById(R.id.button);
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
classifier.setUseNNAPI(isChecked);
}
});
np = (NumberPicker) view.findViewById(R.id.np);
np.setMinValue(1);
np.setMaxValue(10);
np.setWrapSelectorWheel(true);
np.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal){
classifier.setNumThreads(newVal);
}
});
}
/** Load the model and labels. */

View File

@ -142,6 +142,16 @@ public abstract class ImageClassifier {
}
}
public void setUseNNAPI(Boolean nnapi) {
if (tflite != null)
tflite.setUseNNAPI(nnapi);
}
public void setNumThreads(int num_threads) {
if (tflite != null)
tflite.setNumThreads(num_threads);
}
/** Closes tflite to release resources. */
public void close() {
tflite.close();

View File

@ -22,24 +22,59 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<FrameLayout
android:id="@+id/control"
android:layout_width="match_parent"
android:layout_height="112dp"
android:layout_height="135dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="150dp"
android:layout_marginRight="150dp"
android:background="@color/control_background">
<TextView android:id="@+id/text"
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="80dp"
android:paddingLeft="20dp"
android:textColor="#FFF"
android:textSize="20sp"
android:textStyle="bold" />
</FrameLayout>
<RelativeLayout
android:id="@+id/control2"
android:layout_width="match_parent"
android:layout_height="135dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignTop="@+id/control"
android:layout_marginLeft="300dp"
android:layout_marginStart="300dp"
android:background="@color/control_background">
<ToggleButton
android:id="@+id/button"
android:textOff="@string/tflite"
android:textOn="@string/nnapi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<NumberPicker
android:id="@+id/np"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button"
android:visibility="visible" />
</RelativeLayout>
</RelativeLayout>

View File

@ -21,4 +21,6 @@
<string name="toggle_turn_on">NN:On</string>
<string name="toggle_turn_off">NN:Off</string>
<string name="toggle">Use NNAPI</string>
<string name="tflite">tflite</string>
<string name="nnapi">NNAPI</string>
</resources>

View File

@ -215,6 +215,13 @@ public final class Interpreter implements AutoCloseable {
}
}
public void setNumThreads(int num_threads) {
if (wrapper == null) {
throw new IllegalStateException("The interpreter has already been closed.");
}
wrapper.setNumThreads(num_threads);
}
/** Release resources associated with the {@code Interpreter}. */
@Override
public void close() {

View File

@ -153,6 +153,10 @@ final class NativeInterpreterWrapper implements AutoCloseable {
useNNAPI(interpreterHandle, useNNAPI);
}
void setNumThreads(int num_threads) {
numThreads(interpreterHandle, num_threads);
}
/** Gets index of an input given its name. */
int getInputIndex(String name) {
if (inputsIndexes == null) {
@ -324,6 +328,8 @@ final class NativeInterpreterWrapper implements AutoCloseable {
private static native void useNNAPI(long interpreterHandle, boolean state);
private static native void numThreads(long interpreterHandle, int num_threads);
private static native long createErrorReporter(int size);
private static native long createModel(String modelPathOrBuffer, long errorHandle);

View File

@ -320,6 +320,16 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_useNNAPI(JNIEnv* env,
interpreter->UseNNAPI(static_cast<bool>(state));
}
JNIEXPORT void JNICALL
Java_org_tensorflow_lite_NativeInterpreterWrapper_numThreads(JNIEnv* env,
jclass clazz,
jlong handle,
jint num_threads) {
tflite::Interpreter* interpreter = convertLongToInterpreter(env, handle);
if (interpreter == nullptr) return;
interpreter->SetNumThreads(static_cast<int>(num_threads));
}
JNIEXPORT jlong JNICALL
Java_org_tensorflow_lite_NativeInterpreterWrapper_createErrorReporter(
JNIEnv* env, jclass clazz, jint size) {

View File

@ -61,7 +61,7 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_getOutputNames(JNIEnv* env,
/*
* Class: org_tensorflow_lite_NativeInterpreterWrapper
* Method:
* Signature: (JZ)
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL
Java_org_tensorflow_lite_NativeInterpreterWrapper_useNNAPI(JNIEnv* env,
@ -69,6 +69,16 @@ Java_org_tensorflow_lite_NativeInterpreterWrapper_useNNAPI(JNIEnv* env,
jlong handle,
jboolean state);
/*
* Class: org_tensorflow_lite_NativeInterpreterWrapper
* Method:
* Signature: (JI)V
*/
JNIEXPORT void JNICALL
Java_org_tensorflow_lite_NativeInterpreterWrapper_numThreads(JNIEnv* env,
jclass clazz,
jlong handle,
jint num_threads);
/*
* Class: org_tensorflow_lite_NativeInterpreterWrapper
* Method:

View File

@ -176,7 +176,7 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
output);
} else {
context->ReportError(context,
"Inputs and outputs not all float|unit8 types.");
"Inputs and outputs not all float|uint8 types.");
return kTfLiteError;
}

View File

@ -106,6 +106,8 @@ void EvalFloat(TfLiteContext* context, TfLiteNode* node,
#undef TF_LITE_DIV
}
template <KernelType kernel_type>
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
auto* params = reinterpret_cast<TfLiteDivParams*>(node->builtin_data);
@ -118,7 +120,8 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
if (output->type == kTfLiteFloat32) {
EvalFloat<kernel_type>(context, node, params, data, input1, input2, output);
} else {
context->ReportError(context, "Inputs and outputs not all float types.");
context->ReportError(context,
"Div only supports FLOAT32 and quantized UINT8 now.");
return kTfLiteError;
}

View File

@ -4374,7 +4374,7 @@ inline void Softmax(const uint8* input_data, const Dims<4>& input_dims,
using FixedPointAccum = gemmlowp::FixedPoint<int32, kAccumulationIntegerBits>;
using FixedPoint0 = gemmlowp::FixedPoint<int32, 0>;
gemmlowp::ScopedProfilingLabel label("Softmax/8bit");
gemmlowp::ScopedProfilingLabel label("Softmax/8bit");
const int batches = MatchingArraySize(input_dims, 3, output_dims, 3);
const int height = MatchingArraySize(input_dims, 2, output_dims, 2);
const int width = MatchingArraySize(input_dims, 1, output_dims, 1);

View File

@ -1403,6 +1403,33 @@ inline void BroadcastMul(const uint8* input1_data, const Dims<4>& input1_dims,
output_data, output_dims);
}
inline void Div(const float* input1_data, const Dims<4>& input1_dims,
const float* input2_data, const Dims<4>& input2_dims,
float output_activation_min, float output_activation_max,
float* output_data, const Dims<4>& output_dims) {
const int batches =
MatchingArraySize(input1_dims, 3, input2_dims, 3, output_dims, 3);
const int height =
MatchingArraySize(input1_dims, 2, input2_dims, 2, output_dims, 2);
const int width =
MatchingArraySize(input1_dims, 1, input2_dims, 1, output_dims, 1);
const int depth =
MatchingArraySize(input1_dims, 0, input2_dims, 0, output_dims, 0);
for (int b = 0; b < batches; ++b) {
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
for (int c = 0; c < depth; ++c) {
output_data[Offset(output_dims, c, x, y, b)] =
ActivationFunctionWithMinMax(
input1_data[Offset(input1_dims, c, x, y, b)] /
input2_data[Offset(input2_dims, c, x, y, b)],
output_activation_min, output_activation_max);
}
}
}
}
}
// TODO(jiawen): We can implement BroadcastDiv on buffers of arbitrary
// dimensionality if the runtime code does a single loop over one dimension
// that handles broadcasting as the base case. The code generator would then
@ -1444,18 +1471,6 @@ void BroadcastDiv(const T* input1_data, const Dims<4>& input1_dims,
}
}
inline void Div(const float* input1_data, const Dims<4>& input1_dims,
const float* input2_data, const Dims<4>& input2_dims,
float output_activation_min, float output_activation_max,
float* output_data, const Dims<4>& output_dims) {
const int flat_size = MatchingFlatSize(input1_dims, input2_dims, output_dims);
for (int i = 0; i < flat_size; ++i) {
output_data[i] = ActivationFunctionWithMinMax(
input1_data[i] / input2_data[i], output_activation_min,
output_activation_max);
}
}
inline void Sub(const float* input1_data, const Dims<4>& input1_dims,
const float* input2_data, const Dims<4>& input2_dims,
float output_activation_min, float output_activation_max,

View File

@ -174,7 +174,8 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
EvalQuantized<kernel_type>(context, node, params, data, input1, input2,
output);
} else {
context->ReportError(context, "Inputs and outputs not all float types.");
context->ReportError(context,
"Inputs and outputs not all float|uint8 types.");
return kTfLiteError;
}

View File

@ -32,7 +32,7 @@ bool ResolveTensorFlowMerge::Run(Model* model, std::size_t op_index) {
}
// We need to yield until this Merge node has only 1 input, which will mean
// that that is the selected input. Other graph transformations on other nodes
// that is the selected input. Other graph transformations on other nodes
// such as ResolveTensorFlowSwitch, will take care of trimming the
// non-selected inputs, so that at some point there will be only 1 input left.
if (merge_op->inputs.size() > 1) {

View File

@ -152,9 +152,9 @@ enum class AxesOrder {
};
// The type of the scalars in an array.
// Note that that does not by itself tell whether the values in the array are
// real (are literally interpreted as real numbers) or quantized (only acquire
// a meaning as real numbers in conjunction with QuantizationParams).
// Note that the type does not by itself tell whether the values in the array
// are real (are literally interpreted as real numbers) or quantized (only
// acquire a meaning as real numbers in conjunction with QuantizationParams).
//
// In practice though:
// float values are always real

View File

@ -29,6 +29,7 @@ from tensorflow.python.ops import nn
from tensorflow.python.ops import nn_ops
from tensorflow.python.util.deprecation import deprecated
from tensorflow.python.util.deprecation import deprecated_args
from tensorflow.python.util.deprecation import deprecated_argument_lookup
__all__ = [
"absolute_difference", "add_loss", "cosine_distance",
@ -651,11 +652,9 @@ def cosine_distance(predictions,
ValueError: If `predictions` shape doesn't match `labels` shape, or
`weights` is `None`.
"""
if dim is not None:
if axis is not None:
raise ValueError("Cannot specify both 'axis' and 'dim'")
axis = dim
if axis is None and dim is None:
axis = deprecated_argument_lookup(
"axis", axis, "dim", dim)
if axis is None:
raise ValueError("You must specify 'axis'.")
with ops.name_scope(scope, "cosine_distance_loss",
[predictions, labels, weights]) as scope:

View File

@ -711,7 +711,7 @@ def _find_loss_augmented_facility_idx(pairwise_distances, labels, chosen_ids,
candidate_scores, margin_multiplier * nmi_scores)
argmax_index = math_ops.to_int32(
math_ops.argmax(candidate_scores, dimension=0))
math_ops.argmax(candidate_scores, axis=0))
return candidate_ids[argmax_index]
@ -811,7 +811,7 @@ def update_medoid_per_cluster(pairwise_distances, pairwise_distances_subset,
candidate_scores = math_ops.add(scores_fac, margin_multiplier * scores_margin)
argmax_index = math_ops.to_int32(
math_ops.argmax(candidate_scores, dimension=0))
math_ops.argmax(candidate_scores, axis=0))
best_medoid = math_ops.to_int32(cluster_member_ids[argmax_index])
chosen_ids = update_1d_tensor(chosen_ids, cluster_idx, best_medoid)

View File

@ -27,7 +27,9 @@ if [ ! -f $BZL_FILE_PATH ]; then
fi
EIGEN_URL="$(grep -o 'http.*bitbucket.org/eigen/eigen/get/.*tar\.gz' "${BZL_FILE_PATH}" | grep -v mirror.bazel | head -n1)"
GEMMLOWP_URL="$(grep -o 'https://mirror.bazel.build/github.com/google/gemmlowp/.*zip' "${BZL_FILE_PATH}" | head -n1)"
# TODO (yongtang): Replace the following with 'https://mirror.bazel.build/github.com/google/gemmlowp/.*zip' once
# the archive has been propagated in mirror.bazel.build.
GEMMLOWP_URL="$(grep -o 'https://github.com/google/gemmlowp/.*zip' "${BZL_FILE_PATH}" | head -n1)"
GOOGLETEST_URL="https://github.com/google/googletest/archive/release-1.8.0.tar.gz"
NSYNC_URL="$(grep -o 'https://mirror.bazel.build/github.com/google/nsync/.*tar\.gz' "${BZL_FILE_PATH}" | head -n1)"
PROTOBUF_URL="$(grep -o 'https://mirror.bazel.build/github.com/google/protobuf/.*tar\.gz' "${BZL_FILE_PATH}" | head -n1)"

View File

@ -348,7 +348,7 @@ def _freeze_graph_with_def_protos(input_graph_def, output_node_names,
input_saver_def, input_checkpoint):
"""Converts all variables in a graph and checkpoint into constants.
During this process, we need to retain certain initialzer nodes (e.g. table
During this process, we need to retain certain initializer nodes (e.g. table
initializer nodes). Instead of determining which dependencies
of the shared initializer node (e.g. group_deps) to keep, we
reconstruct the connections between the individual initializer nodes and

Some files were not shown because too many files have changed in this diff Show More