提交 5de90856 编写于 作者: V Vijay Vasudevan

TensorFlow: Upstream changes to git.

Change 109738410
	Don't crash if an attribute contains an invalid shape

	Using GetAttr to retrieve a TensorShape caused a process crash if the shape
	contained negative entries or was too large.  Instead, produce useful error
	messages (and Python exceptions).

	Fixes https://github.com/tensorflow/tensorflow/issues/449.
Change 109737915
	TensorFlow: fix build failures and some warnings when built with clang
	on OS X.
Change 109737559
	Fix bad paragraphing
Change 109735757
	Fix OSX installation instructions.
Change 109733797
	Adds buttons to toggle the display of all runs.

Base CL: 109739474
上级 2d116358
......@@ -30,11 +30,6 @@ string SummarizeString(const string& str) {
return strings::StrCat("\"", str_util::CEscape(str), "\"");
}
string SummarizeShape(const TensorShapeProto& proto) {
TensorShape shape(proto);
return shape.ShortDebugString();
}
string SummarizeTensor(const TensorProto& tensor_proto) {
Tensor t;
if (!t.FromProto(tensor_proto)) {
......@@ -59,7 +54,7 @@ string SummarizeAttrValue(const AttrValue& attr_value) {
case AttrValue::kType:
return DataType_Name(attr_value.type());
case AttrValue::kShape:
return SummarizeShape(attr_value.shape());
return TensorShape::ShortDebugString(attr_value.shape());
case AttrValue::kTensor:
return SummarizeTensor(attr_value.tensor());
case AttrValue::kList: {
......@@ -92,7 +87,8 @@ string SummarizeAttrValue(const AttrValue& attr_value) {
} else if (attr_value.list().shape_size() > 0) {
for (int i = 0; i < attr_value.list().shape_size(); ++i) {
if (i > 0) strings::StrAppend(&ret, ", ");
strings::StrAppend(&ret, SummarizeShape(attr_value.list().shape(i)));
strings::StrAppend(
&ret, TensorShape::ShortDebugString(attr_value.list().shape(i)));
}
} else if (attr_value.list().tensor_size() > 0) {
for (int i = 0; i < attr_value.list().tensor_size(); ++i) {
......
......@@ -129,7 +129,8 @@ DEFINE_GET_ATTR(bool, b, "bool", push_back, v, ;)
DEFINE_GET_ATTR(DataType, type, "type", emplace_back, static_cast<DataType>(v),
;)
DEFINE_GET_ATTR(TensorShapeProto, shape, "shape", emplace_back, v, ;)
DEFINE_GET_ATTR(TensorShape, shape, "shape", emplace_back, TensorShape(v), ;)
DEFINE_GET_ATTR(TensorShape, shape, "shape", emplace_back, TensorShape(v),
TF_RETURN_IF_ERROR(TensorShape::IsValidShape(v));)
DEFINE_GET_ATTR(Tensor, tensor, "tensor", emplace_back, t, Tensor t;
if (!t.FromProto(v)) {
return errors::InvalidArgument(
......
......@@ -15,6 +15,7 @@ limitations under the License.
#include "tensorflow/core/public/tensor_shape.h"
#include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/lib/strings/strcat.h"
#include "tensorflow/core/platform/logging.h"
......@@ -34,6 +35,23 @@ bool TensorShape::IsValid(const TensorShapeProto& proto) {
return true;
}
Status TensorShape::IsValidShape(const TensorShapeProto& proto) {
int64 num_elements = 1;
for (const auto& d : proto.dim()) {
if (d.size() < 0) {
return errors::InvalidArgument("Shape ", ShortDebugString(proto),
" has negative dimensions");
}
num_elements *= d.size();
if (num_elements > kMaxElements) {
return errors::InvalidArgument("Shape ", ShortDebugString(proto),
" is too large (more than ", kMaxElements,
" entries)");
}
}
return Status::OK();
}
TensorShape::TensorShape(const TensorShapeProto& proto) {
dim_sizes_.reserve(proto.dim_size());
num_elements_ = 1;
......@@ -141,6 +159,17 @@ string TensorShape::ShortDebugString() const {
"[", str_util::Join(gtl::ArraySlice<int64>(dim_sizes_), ","), "]");
}
string TensorShape::ShortDebugString(const TensorShapeProto& proto) {
string s = "[";
bool first = true;
for (const auto& d : proto.dim()) {
strings::StrAppend(&s, first ? "" : ",", d.size());
first = false;
}
strings::StrAppend(&s, "]");
return s;
}
bool TensorShapeUtils::StartsWith(const TensorShape& shape,
const TensorShape& prefix) {
if (shape.dims() < prefix.dims()) return false;
......
......@@ -16,6 +16,8 @@ limitations under the License.
#ifndef TENSORFLOW_LIB_GTL_EDIT_DISTANCE_H_
#define TENSORFLOW_LIB_GTL_EDIT_DISTANCE_H_
#include <numeric>
#include "tensorflow/core/lib/gtl/array_slice.h"
#include "tensorflow/core/lib/gtl/inlined_vector.h"
......
......@@ -20,13 +20,15 @@ limitations under the License.
#include <condition_variable>
#include <mutex>
#include "tensorflow/core/platform/default/thread_annotations.h"
namespace tensorflow {
enum LinkerInitialized { LINKER_INITIALIZED };
// A class that wraps around the std::mutex implementation, only adding an
// additional LinkerInitialized constructor interface.
class mutex : public std::mutex {
class LOCKABLE mutex : public std::mutex {
public:
mutex() {}
// The default implementation of std::mutex is safe to use after the linker
......
......@@ -28,8 +28,8 @@ namespace tensorflow {
class RandomAccessFile;
class Thread;
class ThreadOptions;
class WritableFile;
struct ThreadOptions;
/// \brief An interface used by the tensorflow implementation to
/// access operating system functionality like the filesystem etc.
......
......@@ -25,6 +25,7 @@ limitations under the License.
#include "tensorflow/core/lib/gtl/inlined_vector.h"
#include "tensorflow/core/lib/strings/strcat.h"
#include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/public/status.h"
namespace tensorflow {
......@@ -49,6 +50,10 @@ class TensorShape {
/// Returns `true` iff `proto` is a valid tensor shape.
static bool IsValid(const TensorShapeProto& proto);
/// Returns `OK` iff `proto` is a valid tensor shape, and a descriptive error
/// status otherwise.
static Status IsValidShape(const TensorShapeProto& proto);
/// Clear a tensor shape
void Clear();
......@@ -118,8 +123,13 @@ class TensorShape {
/// For error messages.
string DebugString() const;
// TODO(vrv): Remove this, this is the same as DebugString().
string ShortDebugString() const;
// TODO(vrv): Consolidate DebugString() and ShortDebugString() into one
// function that is not verbose and works for scalars.
/// Same as `TensorShape(proto).ShortDebugString()` but doesn't crash for
/// invalid protos.
static string ShortDebugString(const TensorShapeProto& proto);
private:
// Recalculates the dimensions of this tensor after they are modified.
......
......@@ -251,6 +251,10 @@ $ python /usr/local/lib/python2.7/dist-packages/tensorflow/models/image/mnist/co
## Installing from sources {#source}
When installing from source you will build a pip wheel that you then install
using pip. You'll need pip for that, so install it as described
[above](#pip_install).
### Clone the TensorFlow repository
```bash
......@@ -264,7 +268,6 @@ depends on.
#### Install Bazel
Follow instructions [here](http://bazel.io/docs/install.html) to install the
dependencies for Bazel. Then download bazel version 0.1.1 using the
[installer for your system](https://github.com/bazelbuild/bazel/releases) and
......@@ -278,8 +281,8 @@ $ ./PATH_TO_INSTALL.SH --user
Remember to replace `PATH_TO_INSTALL.SH` with the location where you
downloaded the installer.
Finally, follow the instructions in that script to place `bazel` into your binary
path.
Finally, follow the instructions in that script to place `bazel` into your
binary path.
#### Install other dependencies
......@@ -416,25 +419,33 @@ given necessary bazel new feature support.
### Installation for Mac OS X
Mac needs the same set of dependencies as Linux, but the installation
process for those dependencies is different. Here is a set of useful links
to help with installing the dependencies on Mac OS X :
We recommend using [homebrew](http://brew.sh) to install the bazel and SWIG
dependencies, and installing python dependencies using easy_install or pip.
#### Bazel
#### Dependencies
Look for installation instructions for Mac OS X on
[this](http://bazel.io/docs/install.html) page.
Follow instructions [here](http://bazel.io/docs/install.html) to install the
dependencies for Bazel. You can then use homebrew to install bazel and SWIG:
#### SWIG
```bash
$ brew install bazel swig
```
[Mac OS X installation](http://www.swig.org/Doc3.0/Preface.html#Preface_osx_installation).
You can install the python dependencies using easy_install or pip. Using
easy_install, run
Notes : You need to install
[PCRE](ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/) and *NOT* PCRE2.
```bash
$ sudo easy_install -U six
$ sudo easy_install -U numpy
$ sudo easy_install wheel
```
#### Numpy
We also recommend the [ipython](https://ipython.org) enhanced python shell, so
best install that too:
Follow installation instructions [here](http://docs.scipy.org/doc/numpy/user/install.html).
```bash
$ sudo easy_install ipython
```
#### Configure the installation {#configure_osx}
......@@ -514,13 +525,13 @@ If, during `pip install`, you encounter an error like:
IOError: [Errno 2] No such file or directory: '/tmp/pip-o6Tpui-build/setup.py'
```
Solution: upgrade your version of `pip`:
Solution: upgrade your version of pip:
```bash
pip install --upgrade pip
```
This may require `sudo`, depending on how `pip` is installed.
This may require `sudo`, depending on how pip is installed.
#### SSLError: SSL_VERIFY_FAILED
......
......@@ -538,6 +538,13 @@ class PlaceholderTest(tf.test.TestCase):
" must be nonnegative"):
tf.fill(shape, 7).eval()
def testBadShape(self):
with self.test_session():
a = tf.placeholder(tf.float32, shape=(-1, 10))
s = tf.shape(a)
with self.assertRaisesOpError(r"Shape \[-1,10\] has negative dimensions"):
s.eval()
if __name__ == "__main__":
tf.test.main()
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/paper-button/paper-button.html">
<link rel="import" href="../../bower_components/paper-checkbox/paper-checkbox.html">
<link rel="import" href="../imports/lodash.html">
<link rel="import" href="../tf-dashboard-common/scrollbar-style.html">
......@@ -47,6 +48,13 @@ Properties out:
class-scale="[[classScale]]"
hide-missing-tooltips
></tf-multi-checkbox>
<paper-button
class="x-button"
id="toggle-all"
on-tap="_toggleAll"
>
Toggle All Runs
</paper-button>
<style>
:host {
display: flex;
......@@ -58,7 +66,6 @@ Properties out:
width: 100%;
flex-grow: 0;
flex-shrink: 0;
padding-left: 35px;
padding-right: 16px;
padding-bottom: 6px;
box-sizing: border-box;
......@@ -70,6 +77,13 @@ Properties out:
flex-shrink: 1;
height: 0px; /* hackhack So the flex-grow takes over and gives it space */
}
.x-button {
width: calc(50% - .9em);
font-size: 14px;
background-color: var(--paper-grey-500);
margin-top: 5px;
color: white;
}
.x-tooltip {
display: flex;
flex-direction: row;
......@@ -96,6 +110,13 @@ Properties out:
classScale: Object, // map from run name to color class (css)
closestRun: {type: String, value: null}, // which run has a value closest to mouse coordinate
},
_toggleAll: function() {
if (this.outSelected.length > 0) {
this.outSelected = [];
} else {
this.outSelected = this.runs.slice();
}
},
_arrayify: function(item) {
return [item];
},
......
......@@ -48,8 +48,7 @@ tf-x-type-selector is a simple component that creates buttons labeled "step" and
}
#buttons p {
text-align: center;
font-size: 12px;
color: var(--paper-grey-800);
margin: 0;
}
</style>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册