keras:人类深度学习

  • r8_350378
    了解作者
  • 3MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-23 23:43
    上传日期
Keras:Python深度学习 正在施工:construction: 在不久的将来,该存储库将再次用于开发Keras代码库。 目前, 代码库是在上开发的,任何PR或问题都应指向那里。
keras-master.zip
内容介绍
# Copyright 2015 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. # ============================================================================== # pylint: disable=protected-access # pylint: disable=redefined-outer-name # pylint: disable=redefined-builtin # pylint: disable=g-classes-have-attributes """Keras backend API.""" import tensorflow.compat.v2 as tf import collections import itertools import json import os import sys import threading import warnings import weakref import numpy as np from tensorflow.core.protobuf import config_pb2 from tensorflow.python.eager import context from tensorflow.python.eager.context import get_config from tensorflow.python.framework import config from keras import backend_config from keras.distribute import distribute_coordinator_utils as dc from keras.engine import keras_tensor from keras.utils import control_flow_util from keras.utils import object_identity from keras.utils import tf_contextlib from keras.utils import tf_inspect from tensorflow.python.platform import tf_logging as logging from tensorflow.python.util.tf_export import keras_export from tensorflow.tools.docs import doc_controls py_all = all py_sum = sum py_any = any # INTERNAL UTILS # The internal graph maintained by Keras and used by the symbolic Keras APIs # while executing eagerly (such as the functional API for model-building). # This is thread-local to allow building separate models in different threads # concurrently, but comes at the cost of not being able to build one model # across threads. _GRAPH = threading.local() # A graph which is used for constructing functions in eager mode. _CURRENT_SCRATCH_GRAPH = threading.local() # This is a thread local object that will hold the default internal TF session # used by Keras. It can be set manually via `set_session(sess)`. _SESSION = threading.local() # A global dictionary mapping graph objects to an index of counters used # for various layer/optimizer names in each graph. # Allows to give unique autogenerated names to layers, in a graph-specific way. PER_GRAPH_OBJECT_NAME_UIDS = weakref.WeakKeyDictionary() # A global set tracking what object names have been seen so far. # Optionally used as an avoid-list when generating names OBSERVED_NAMES = set() # _DUMMY_EAGER_GRAPH.key is used as a key in _GRAPH_LEARNING_PHASES. # We keep a separate reference to it to make sure it does not get removed from # _GRAPH_LEARNING_PHASES. # _DummyEagerGraph inherits from threading.local to make its `key` attribute # thread local. This is needed to make set_learning_phase affect only the # current thread during eager execution (see b/123096885 for more details). class _DummyEagerGraph(threading.local): """_DummyEagerGraph provides a thread local `key` attribute. We can't use threading.local directly, i.e. without subclassing, because gevent monkey patches threading.local and its version does not support weak references. """ class _WeakReferencableClass: """This dummy class is needed for two reasons. - We need something that supports weak references. Basic types like string and ints don't. - We need something whose hash and equality are based on object identity to make sure they are treated as different keys to _GRAPH_LEARNING_PHASES. An empty Python class satisfies both of these requirements. """ pass def __init__(self): # Constructors for classes subclassing threading.local run once # per thread accessing something in the class. Thus, each thread will # get a different key. super(_DummyEagerGraph, self).__init__() self.key = _DummyEagerGraph._WeakReferencableClass() self.learning_phase_is_set = False _DUMMY_EAGER_GRAPH = _DummyEagerGraph() # This boolean flag can be set to True to leave variable initialization # up to the user. # Change its value via `manual_variable_initialization(value)`. _MANUAL_VAR_INIT = False # This list holds the available devices. # It is populated when `_get_available_gpus()` is called for the first time. # We assume our devices don't change henceforth. _LOCAL_DEVICES = None # The below functions are kept accessible from backend for compatibility. epsilon = backend_config.epsilon floatx = backend_config.floatx image_data_format = backend_config.image_data_format set_epsilon = backend_config.set_epsilon set_floatx = backend_config.set_floatx set_image_data_format = backend_config.set_image_data_format @keras_export('keras.backend.backend') @doc_controls.do_not_generate_docs def backend(): """Publicly accessible method for determining the current backend. Only exists for API compatibility with multi-backend Keras. Returns: The string "tensorflow". """ return 'tensorflow' @keras_export('keras.backend.cast_to_floatx') @tf.__internal__.dispatch.add_dispatch_support @doc_controls.do_not_generate_docs def cast_to_floatx(x): """Cast a Numpy array to the default Keras float type. Args: x: Numpy array or TensorFlow tensor. Returns: The same array (Numpy array if `x` was a Numpy array, or TensorFlow tensor if `x` was a tensor), cast to its new type. Example: >>> tf.keras.backend.floatx() 'float32' >>> arr = np.array([1.0, 2.0], dtype='float64') >>> arr.dtype dtype('float64') >>> new_arr = cast_to_floatx(arr) >>> new_arr array([1., 2.], dtype=float32) >>> new_arr.dtype dtype('float32') """ if isinstance(x, (tf.Tensor, tf.Variable, tf.SparseTensor)): return tf.cast(x, dtype=floatx()) return np.asarray(x, dtype=floatx()) @keras_export('keras.backend.get_uid') def get_uid(prefix=''): """Associates a string prefix with an integer counter in a TensorFlow graph. Args: prefix: String prefix to index. Returns: Unique integer ID. Example: >>> get_uid('dense') 1 >>> get_uid('dense') 2 """ graph = get_graph() if graph not in PER_GRAPH_OBJECT_NAME_UIDS: PER_GRAPH_OBJECT_NAME_UIDS[graph] = collections.defaultdict(int) layer_name_uids = PER_GRAPH_OBJECT_NAME_UIDS[graph] layer_name_uids[prefix] += 1 return layer_name_uids[prefix] @keras_export('keras.backend.reset_uids') def reset_uids(): """Resets graph identifiers. """ PER_GRAPH_OBJECT_NAME_UIDS.clear() OBSERVED_NAMES.clear() @keras_export('keras.backend.clear_session') def clear_session(): """Resets all state generated by Keras. Keras manages a global state, which it uses to implement the Functional model-building API and to uniquify autogenerated layer names. If you are creating many models in a loop, this global state will consume an increasing amount of memory over time, and you may want to clear it. Calling `clear_session()` releases the global state: this helps avoid clutter from old models and layers, especially when memory is limited. Example 1: calling `clear_session()` when creating models in a loop ```python for _ in range(100): # Without `clear_session()`, each iteration of this loop will # slightly increase the size of the global state managed by Keras model = tf.keras.Sequential([tf.keras.layers.Dense(10) for _ in range(10)]) for _ in range(100): # With `clear_session()` called at the beginning, # Keras starts with a blank state at each iteration # and memory consumption is constant over time. tf.keras.backend.clear_session() model = tf.keras.Sequential([tf.keras.layers.Dense(10) for _ in
评论
    相关推荐
    • 基于keras的口罩识别
      基于keras的口罩识别,其中包括了模型文件,直接python3 yolo_video.py --image就可以监测你的图片
    • mixture-of-experts:混合Keras专家层
      存储库包含实现专家模型的卷积和密集混合的Keras层。 专家层的密集混合物 文件DenseMoE.py包含一个DenseMoE.py层,该层实现了专家模型的密集混合: 该层可以与Dense层相同的方式使用。 它的一些主要论据如下: ...
    • keras:R与Keras的接口
      R与Keras的接口 是一种高级神经网络API,主要致力于实现快速实验。 能够以最小的延迟将想法...这意味着Keras基本上适合构建从存储网络到神经图灵机的任何深度学习模型。 有关完整的文档,请参阅软件包的网站,为 。
    • vizgradcam:vizgradcam是使用Keras模型可视化GradCAM的最快方法
      VizGradCam是在Keras模型中可视化GradCAM的最快方法。 GradCAM有助于提供经过训练的模型的视觉可解释性,并且可以作为确保工程师观察对某些推断结果有贡献的区域的重要步骤。 大多数教程或函数都具有类似的方法,...
    • deep_learning_using_keras_by_Fran-ois_Chollet-:此存储库包含FrançoisCho
      deep_learning_using_keras_by_François_Chollet- 该存储库包含FrançoisChollet的书中的学习内容
    • tensorkeras:该存储库包含有关Tensorflow和keras示例的代码
      张量 该存储库包含有关Tensorflow和keras示例的代码
    • AnomalyDetection-Keras
      存储库包含与我们的异常检测框架相关的代码,该框架使用针对在我们的污点状噪声损坏的图像上训练的自动编码器。 全文可在,并将很快在ICPR2020上发表。 下面的插图概述了使用我们的方法(AESc +染色)在MVTec AD...
    • 转移学习套件:Keras中的转移学习套件。 使用任何内置的Keras图像分类模型轻松进行转移学习!
      Keras的转移学习套件 消息 描述 该存储库用作Transfer Learning Suite。 目标是能够轻松使用任何内置的Keras图像分类模型执行转移学习! 欢迎提出任何改进此存储库的建议或您希望看到的任何新功能! 您也可以查看我...
    • keras-contrib:Keras社区的贡献
      随着Keras-Contrib中社区贡献的经过测试,使用,验证以及其效用得到证明,它们可以集成到Keras核心存储库中。 为了保持Keras简洁,干净且功能强大,只有最有用的功能才能使它进入Keras。 这个贡献库既是新功能的...
    • GaussDB_100_1.0.1-DATABASE-REDHAT-64bit.tar.gz
      guassdb100在redhat上安装包,单机部署的包,安装步骤请看我的文中介绍,经过大量实验搭建总结出来的文档