diff options
author | A. Unique TensorFlower <nobody@tensorflow.org> | 2016-05-31 15:37:00 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2016-05-31 16:47:28 -0700 |
commit | 55cfca671da036d312078ae8c591dbdf589efc14 (patch) | |
tree | 3bef2b5e8b88b3a15f010aceca54067ea16fc041 | |
parent | 775a7490047299f2b64bf4fafcb6504852b8082d (diff) |
Creating SLIM directory, adding queues.
Change: 123697059
-rw-r--r-- | tensorflow/BUILD | 1 | ||||
-rw-r--r-- | tensorflow/contrib/slim/BUILD | 42 | ||||
-rw-r--r-- | tensorflow/contrib/slim/__init__.py | 27 | ||||
-rw-r--r-- | tensorflow/contrib/slim/python/ops/queues.py | 73 |
4 files changed, 143 insertions, 0 deletions
diff --git a/tensorflow/BUILD b/tensorflow/BUILD index 004839dfa0..a8153c06b6 100644 --- a/tensorflow/BUILD +++ b/tensorflow/BUILD @@ -85,6 +85,7 @@ filegroup( "//tensorflow/contrib/quantization/kernels:all_files", "//tensorflow/contrib/quantization/tools:all_files", "//tensorflow/contrib/skflow:all_files", + "//tensorflow/contrib/slim:all_files", "//tensorflow/contrib/tensor_forest:all_files", "//tensorflow/contrib/testing:all_files", "//tensorflow/contrib/util:all_files", diff --git a/tensorflow/contrib/slim/BUILD b/tensorflow/contrib/slim/BUILD new file mode 100644 index 0000000000..6e4358a08a --- /dev/null +++ b/tensorflow/contrib/slim/BUILD @@ -0,0 +1,42 @@ +# Description: +# Contains the Slim library, including common neural networks and examples. + +licenses(["notice"]) # Apache 2.0 + +exports_files(["LICENSE"]) + +package(default_visibility = ["//tensorflow:__subpackages__"]) + +py_library( + name = "queues", + srcs = ["python/ops/queues.py"], + srcs_version = "PY2AND3", + deps = [ + "//tensorflow/python:ops", + "//tensorflow/python:training", + ], +) + +py_library( + name = "slim", + srcs = [ + "__init__.py", + ], + srcs_version = "PY2AND3", + visibility = ["//tensorflow:__subpackages__"], + deps = [ + ":queues", + ], +) + +filegroup( + name = "all_files", + srcs = glob( + ["**/*"], + exclude = [ + "**/METADATA", + "**/OWNERS", + ], + ), + visibility = ["//tensorflow:__subpackages__"], +) diff --git a/tensorflow/contrib/slim/__init__.py b/tensorflow/contrib/slim/__init__.py new file mode 100644 index 0000000000..db1de17de0 --- /dev/null +++ b/tensorflow/contrib/slim/__init__.py @@ -0,0 +1,27 @@ +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +"""TODO(nsilberman): Documentation. +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +# pylint: disable=unused-import,line-too-long,g-importing-member,wildcard-import +from tensorflow.contrib.slim.python.ops import queues +from tensorflow.python.util.all_util import make_all +# pylint: enable=unused-import,line-too-long,g-importing-member,wildcard-import + +__all__ = make_all(__name__) diff --git a/tensorflow/contrib/slim/python/ops/queues.py b/tensorflow/contrib/slim/python/ops/queues.py new file mode 100644 index 0000000000..193aeff6ed --- /dev/null +++ b/tensorflow/contrib/slim/python/ops/queues.py @@ -0,0 +1,73 @@ +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +"""Contains a helper context for running queue runners. + +@@NestedQueueRunnerError +@@QueueRunners +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +from contextlib import contextmanager +import threading + + +from tensorflow.python.framework import ops +from tensorflow.python.training import coordinator + +__all__ = [ + 'NestedQueueRunnerError', + 'QueueRunners', +] + +_queue_runner_lock = threading.Lock() + + +class NestedQueueRunnerError(Exception): + pass + + +@contextmanager +def QueueRunners(session): + """Creates a context manager that handles starting and stopping queue runners. + + Args: + session: the currently running session. + + Yields: + a context in which queues are run. + + Raises: + NestedQueueRunnerError: if a QueueRunners context is nested within another. + """ + if not _queue_runner_lock.acquire(False): + raise NestedQueueRunnerError('QueueRunners cannot be nested') + + coord = coordinator.Coordinator() + threads = [] + for qr in ops.get_collection(ops.GraphKeys.QUEUE_RUNNERS): + threads.extend(qr.create_threads(session, + coord=coord, + daemon=True, + start=True)) + try: + yield + finally: + coord.request_stop() + coord.join(threads, stop_grace_period_secs=120) + + _queue_runner_lock.release() |