Skip to content

Commit

Permalink
Merge changes from github.
Browse files Browse the repository at this point in the history
Change: 124644444
  • Loading branch information
Vijay Vasudevan authored and tensorflower-gardener committed Jun 11, 2016
1 parent f34e397 commit 5a65d43
Show file tree
Hide file tree
Showing 28 changed files with 676 additions and 68 deletions.
2 changes: 1 addition & 1 deletion ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Installed version of CUDA and cuDNN:
If installed from binary pip package, provide:

1. Which pip package you installed.
2. The output from python -c "import tensorflow; print(tensorflow.__version__)".
2. The output from `python -c "import tensorflow; print(tensorflow.__version__)"`.

If installed from sources, provide the commit hash:

Expand Down
6 changes: 6 additions & 0 deletions grpc.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ cc_library(
"include",
".",
],
defines = [
"GPR_BACKWARDS_COMPATIBILITY_MODE",
],
copts = [
"-std=c99",
],
deps = [
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(SRCROOT)/../../makefile/gen/proto",
"$(SRCROOT)/../../makefile/downloads/eigen-eigen-f3a13643ac1f",
"$(SRCROOT)/../../makefile/downloads/eigen-eigen-d02e6a705c30",
"$(SRCROOT)/../../makefile/downloads",
"$(SRCROOT)/../../makefile/downloads/protobuf/src/",
"$(SRCROOT)/../../../..",
Expand All @@ -300,6 +300,12 @@
OTHER_LDFLAGS = (
"-force_load",
"$(SRCROOT)/../../makefile/gen/lib/libtensorflow-core.a",
"-Xlinker",
"-S",
"-Xlinker",
"-x",
"-Xlinker",
"-dead_strip",
);
PRODUCT_BUNDLE_IDENTIFIER = com.google.CameraExample;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -344,7 +350,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(SRCROOT)/../../makefile/gen/proto",
"$(SRCROOT)/../../makefile/downloads/eigen-eigen-f3a13643ac1f",
"$(SRCROOT)/../../makefile/downloads/eigen-eigen-d02e6a705c30",
"$(SRCROOT)/../../makefile/downloads",
"$(SRCROOT)/../../makefile/downloads/protobuf/src/",
"$(SRCROOT)/../../../..",
Expand All @@ -359,6 +365,12 @@
OTHER_LDFLAGS = (
"-force_load",
"$(SRCROOT)/../../makefile/gen/lib/libtensorflow-core.a",
"-Xlinker",
"-S",
"-Xlinker",
"-x",
"-Xlinker",
"-dead_strip",
);
PRODUCT_BUNDLE_IDENTIFIER = com.google.CameraExample;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
"$(SRCROOT)/../../../..",
"$(SRCROOT)/../../makefile/downloads/protobuf/src/",
"$(SRCROOT)/../../makefile/downloads",
"$(SRCROOT)/../../makefile/downloads/eigen-eigen-f3a13643ac1f",
"$(SRCROOT)/../../makefile/downloads/eigen-eigen-d02e6a705c30",
"$(SRCROOT)/../../makefile/gen/proto",
);
INFOPLIST_FILE = "$(SRCROOT)/RunModel-Info.plist";
Expand All @@ -289,6 +289,12 @@
OTHER_LDFLAGS = (
"-force_load",
"$(SRCROOT)/../../makefile/gen/lib/libtensorflow-core.a",
"-Xlinker",
"-S",
"-Xlinker",
"-x",
"-Xlinker",
"-dead_strip",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.google.TF-Test";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -304,7 +310,7 @@
"$(SRCROOT)/../../../..",
"$(SRCROOT)/../../makefile/downloads/protobuf/src/",
"$(SRCROOT)/../../makefile/downloads",
"$(SRCROOT)/../../makefile/downloads/eigen-eigen-f3a13643ac1f",
"$(SRCROOT)/../../makefile/downloads/eigen-eigen-d02e6a705c30",
"$(SRCROOT)/../../makefile/gen/proto",
);
INFOPLIST_FILE = "$(SRCROOT)/RunModel-Info.plist";
Expand All @@ -314,10 +320,16 @@
"$(SRCROOT)/../../makefile/gen/protobuf_ios/lib",
"$(SRCROOT)/../../makefile/gen/lib",
);
ONLY_ACTIVE_ARCH = NO;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = (
"-force_load",
"$(SRCROOT)/../../makefile/gen/lib/libtensorflow-core.a",
"-Xlinker",
"-S",
"-Xlinker",
"-x",
"-Xlinker",
"-dead_strip",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.google.TF-Test";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/contrib/learn/python/learn/io/data_feeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def _feed_dict_fn():
else:
if self.n_classes > 1:
if len(self.output_shape) == 2:
out.itemset((i, self.y[sample]), 1.0)
out.itemset((i, int(self.y[sample])), 1.0)
else:
for idx, value in enumerate(self.y[sample]):
out.itemset(tuple([i, idx, value]), 1.0)
Expand Down
29 changes: 19 additions & 10 deletions tensorflow/contrib/learn/python/learn/ops/batch_norm_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,31 @@ def batch_normalize(tensor_in,
initializer=init_ops.random_normal_initializer(1., 0.02))
beta = vs.get_variable("beta", [shape[-1]],
initializer=init_ops.constant_initializer(0.))
ema = moving_averages.ExponentialMovingAverage(decay=decay)
if convnet:
assign_mean, assign_var = nn.moments(tensor_in, [0, 1, 2])
else:
assign_mean, assign_var = nn.moments(tensor_in, [0])
ema_assign_op = ema.apply([assign_mean, assign_var])
ema_mean, ema_var = ema.average(assign_mean), ema.average(assign_var)
moving_mean = vs.get_variable(
'moving_mean',
shape=[shape[-1]],
initializer=init_ops.zeros_initializer,
trainable=False)
moving_var = vs.get_variable(
'moving_var',
shape=[shape[-1]],
initializer=init_ops.ones_initializer,
trainable=False)

def _update_mean_var():
"""Internal function that updates mean and variance during training."""
with ops.control_dependencies([ema_assign_op]):
return array_ops_.identity(assign_mean), array_ops_.identity(assign_var)
axis = [0, 1, 2] if convnet else [0]
mean, var = nn.moments(tensor_in, axis)
update_moving_mean = moving_averages.assign_moving_average(
moving_mean, mean, decay)
update_moving_var = moving_averages.assign_moving_average(
moving_var, var, decay)
with ops.control_dependencies([update_moving_mean, update_moving_var]):
return array_ops_.identity(mean), array_ops_.identity(var)

is_training = array_ops_.squeeze(ops.get_collection("IS_TRAINING"))
mean, variance = control_flow_ops.cond(is_training, _update_mean_var,
lambda: (ema_mean, ema_var))
lambda: (moving_mean, moving_var))
return nn.batch_norm_with_global_normalization(
tensor_in,
mean,
Expand Down
28 changes: 21 additions & 7 deletions tensorflow/contrib/makefile/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ HOST_OBJDIR := $(MAKEFILE_DIR)/gen/host_obj/
HOST_BINDIR := $(MAKEFILE_DIR)/gen/host_bin/
HOST_GENDIR := $(MAKEFILE_DIR)/gen/host_obj/

# Which Eigen version we're using.
EIGEN_HASH := d02e6a705c30
# Find the current Eigen version name from the Bazel build file
EIGEN_HASH := $(shell cat eigen.BUILD | grep archive_dir | head -1 | cut -f3 -d- | cut -f1 -d\")

# Settings for the host compiler.
HOST_CXX := gcc
Expand All @@ -56,9 +56,15 @@ HOST_LIBS := \

# If we're on Linux, also link in the dl library.
ifeq ($(HOST_OS),LINUX)
HOST_LIBS += -ldl
HOST_LIBS += -ldl -lpthread
endif

# If we're on a Pi, link in pthreads and dl
ifeq ($(HOST_OS),PI)
HOST_LIBS += -ldl -lpthread
endif


# proto_text is a tool that converts protobufs into a form we can use more
# compactly within TensorFlow. It's a bit like protoc, but is designed to
# produce a much more minimal result so we can save binary space.
Expand Down Expand Up @@ -125,13 +131,13 @@ ifeq ($(TARGET),LINUX)
endif
# If we're on Linux, also link in the dl library.
ifeq ($(TARGET),LINUX)
LIBS += -ldl
LIBS += -ldl -lpthread
endif
# If we're cross-compiling for the Raspberry Pi, use the right gcc.
ifeq ($(TARGET),PI)
CXX := arm-linux-gnueabihf-g++
LDFLAGS := -L$(GENDIR)protobuf_pi/lib/ -Wl,--no-whole-archive
LIBS += -ldl
CXXFLAGS += -D__ANDROID_TYPES_SLIM__
LDFLAGS := -Wl,--no-whole-archive
LIBS += -ldl -lpthread
LIBFLAGS += -Wl,--allow-multiple-definition -Wl,--whole-archive
endif

Expand Down Expand Up @@ -169,12 +175,16 @@ ifeq ($(TARGET),IOS)
-Wno-c++11-narrowing \
-mno-thumb \
-DTF_LEAN_BINARY \
-D__ANDROID_TYPES_SLIM__ \
-DMIN_LOG_LEVEL=0 \
-fno-exceptions \
-isysroot \
${IPHONEOS_SYSROOT}
LDFLAGS := -arch armv7 \
-miphoneos-version-min=${MIN_SDK_VERSION} \
-Xlinker -S \
-Xlinker -x \
-Xlinker -dead_strip \
-all_load \
-L$(GENDIR)protobuf_ios/lib \
-lz
Expand All @@ -186,6 +196,7 @@ ifeq ($(TARGET),IOS)
-Wno-c++11-narrowing \
-mno-thumb \
-DTF_LEAN_BINARY \
-D__ANDROID_TYPES_SLIM__ \
-DMIN_LOG_LEVEL=0 \
-fno-exceptions \
-isysroot \
Expand All @@ -205,6 +216,7 @@ ifeq ($(TARGET),IOS)
-D__thread= \
-Wno-c++11-narrowing \
-DTF_LEAN_BINARY \
-D__ANDROID_TYPES_SLIM__ \
-DMIN_LOG_LEVEL=0 \
-fno-exceptions \
-isysroot \
Expand All @@ -224,6 +236,7 @@ ifeq ($(TARGET),IOS)
-D__thread= \
-Wno-c++11-narrowing \
-DTF_LEAN_BINARY \
-D__ANDROID_TYPES_SLIM__ \
-DMIN_LOG_LEVEL=0 \
-fno-exceptions \
-isysroot \
Expand All @@ -243,6 +256,7 @@ ifeq ($(TARGET),IOS)
-D__thread= \
-Wno-c++11-narrowing \
-DTF_LEAN_BINARY \
-D__ANDROID_TYPES_SLIM__ \
-DMIN_LOG_LEVEL=0 \
-fno-exceptions \
-isysroot \
Expand Down
29 changes: 18 additions & 11 deletions tensorflow/contrib/makefile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ at `tensorflow/contrib/makefile/gen/bin/benchmark`. To run the executable, use:
tensorflow/contrib/makefile/gen/bin/benchmark --graph=tensorflow_inception_graph.pb
```

You should download the example graph from [http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz](http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz).
You should download the example graph from [https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip](https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip).

## Supported Systems

Expand Down Expand Up @@ -132,24 +132,31 @@ static library in a simple app.

## Raspberry Pi

The easiest way to build for the Raspberry Pi is to cross-compile from Linux.
To use this makefile to do that, you first need to install the right version of
the compiler to target the Pi, using a command like this on your Linux machine:
Building on the Raspberry Pi is similar to a normal Linux system, though we
recommend starting by compiling and installing protobuf:

```bash
sudo apt-get install g++-arm-linux-gnueabihf
cd tensorflow/contrib/makefile/downloads/protobuf/
./autogen.sh
./configure
make
sudo make install
cd ../../../../..
```

After that, run `tensorflow/contrib/makefile/compile_pi_protobuf.sh` to build a
version of the protobuf library aimed at the Pi. Then you should be able to run:
Once that's done, you can use make to build the library and example:

```bash
make -f tensorflow/contrib/makefile/Makefile TARGET=PI
make -f tensorflow/contrib/makefile/Makefile HOST_OS=PI TARGET=PI OPTFLAGS="-Os"
```

This will build the static library, and the example benchmark executable. You
can then copy the `tensorflow/contrib/makefile/gen/bin/benchmark` program over
to your Raspberry Pi, and run it there.
If you're only interested in building for Raspberry Pi's 2 and 3, you can supply
some extra optimization flags to give you code that will run faster:

```bash
make -f tensorflow/contrib/makefile/Makefile HOST_OS=PI TARGET=PI \
OPTFLAGS="-Os -mfpu=neon-vfpv4 -funsafe-math-optimizations -ftree-vectorize"
```

## Dependencies

Expand Down
7 changes: 6 additions & 1 deletion tensorflow/contrib/makefile/download_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ DOWNLOADS_DIR=tensorflow/contrib/makefile/downloads

mkdir ${DOWNLOADS_DIR}

EIGEN_HASH=d02e6a705c30
EIGEN_HASH=62a2305d5734
if [ -f eigen.BUILD ]; then
# Grab the current Eigen version name from the Bazel build file
EIGEN_HASH=$(cat eigen.BUILD | grep archive_dir | head -1 | cut -f3 -d- | cut -f1 -d\")
fi

curl "https://bitbucket.org/eigen/eigen/get/${EIGEN_HASH}.tar.gz" \
-o /tmp/eigen-${EIGEN_HASH}.tar.gz
tar xzf /tmp/eigen-${EIGEN_HASH}.tar.gz -C ${DOWNLOADS_DIR}
Expand Down
Loading

0 comments on commit 5a65d43

Please sign in to comment.