当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow_backend.set_session方法代码示例

本文整理汇总了Python中keras.backend.tensorflow_backend.set_session方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow_backend.set_session方法的具体用法?Python tensorflow_backend.set_session怎么用?Python tensorflow_backend.set_session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在keras.backend.tensorflow_backend的用法示例。


在下文中一共展示了tensorflow_backend.set_session方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from keras.backend import tensorflow_backend [as 别名]
# 或者: from keras.backend.tensorflow_backend import set_session [as 别名]
def __init__(self, mode, config, model_dir):
        """
        mode: Either "training" or "inference"
        config: A Sub-class of the Config class
        model_dir: Directory to save training logs and trained weights
        """
        assert mode in ['training', 'inference']
        if mode == 'training':
            import keras.backend.tensorflow_backend as KTF
            config = tf.ConfigProto()
            config.gpu_options.allow_growth = True
            session = tf.Session(config=config)
            KTF.set_session(session)
        self.mode = mode
        self.config = config
        self.model_dir = model_dir
        self.set_log_dir()
        self.keras_model = self.build(mode=mode, config=config) 
开发者ID:SunskyF,项目名称:EasyPR-python,代码行数:20,代码来源:model.py

示例2: detect

# 需要导入模块: from keras.backend import tensorflow_backend [as 别名]
# 或者: from keras.backend.tensorflow_backend import set_session [as 别名]
def detect(self, src, model_dir):
        first = self.eval_sess is None
        if first:
            # if first load
            config = tf.ConfigProto()
            config.gpu_options.allow_growth = True
            self.eval_sess = tf.Session(graph=self.graph, config=config)
        with self.graph.as_default():
            if first:
                plate_config = PlateInferenceConfig()
                # plate_config.display()
                self.model = modellib.MaskRCNN(mode="inference", config=plate_config, model_dir=model_dir)
            KTF.set_session(self.eval_sess)
            model_path = self.model.find_last()[1]
            self.model.load_weights(model_path, by_name=True)
            result = self.model.detect([src])
        return self._post_process(result, src) 
开发者ID:SunskyF,项目名称:EasyPR-python,代码行数:19,代码来源:plate_detect.py

示例3: main_alpha_zero_train

# 需要导入模块: from keras.backend import tensorflow_backend [as 别名]
# 或者: from keras.backend.tensorflow_backend import set_session [as 别名]
def main_alpha_zero_train():
    """
    Main option to train the alpha zero model from start
    :return:
    """
    import tensorflow as tf
    from keras.backend.tensorflow_backend import set_session
    from reinforcement_learning_train.alpha_zero.train_module import fit_train
    from reinforcement_learning_train.util.action_encoder import ActionEncoder
    from reinforcement_learning_train.alpha_zero.deep_net_architecture import PawnNet, PawnNetZero
    from reinforcement_learning_train.util.alphazero_util import action_spaces_new
    from collections import deque

    # config = tf.ConfigProto()
    # config.gpu_options.allow_growth = True  # dynamically grow the memory used on the GPU
    # config.log_device_placement = True  # to log device placement (on which device the operation ran)
    # # (nothing gets printed in Jupyter, only if you run it standalone)
    # sess = tf.Session(config=config)
    # set_session(sess)  # set this TensorFlow session as the default session for Keras
    all_action_spaces = action_spaces_new()

    deepnet_model = PawnNetZero(len(all_action_spaces))
    global_list_training = deque(maxlen=9000)
    ae = ActionEncoder()
    ae.fit(list_all_action=all_action_spaces)
    print(deepnet_model.model.summary())
    fit_train(global_list_training,ae, deepnet_model)
    deepnet_model.model.save("best_model.hdf5") 
开发者ID:haryoa,项目名称:evo-pawness,代码行数:30,代码来源:main.py

示例4: main_alpha_zero_train_continue

# 需要导入模块: from keras.backend import tensorflow_backend [as 别名]
# 或者: from keras.backend.tensorflow_backend import set_session [as 别名]
def main_alpha_zero_train_continue():
    """
    Main option to play to continue training the model of alpha zero
    :return:
    """
    from collections import deque

    from keras.models import load_model
    from reinforcement_learning_train.alpha_zero.train_module import fit_train
    from reinforcement_learning_train.util.action_encoder import ActionEncoder
    from reinforcement_learning_train.alpha_zero.deep_net_architecture import PawnNet, PawnNetZero
    from reinforcement_learning_train.util.alphazero_util import action_spaces_new
    import pickle

    # config = tf.ConfigProto()
    # config.gpu_options.allow_growth = True  # dynamically grow the memory used on the GPU
    # config.log_device_placement = True  # to log device placement (on which device the operation ran)
    # # (nothing gets printed in Jupyter, only if you run it standalone)
    # sess = tf.Session(config=config)
    # set_session(sess)  # set this TensorFlow session as the default session for Keras
    all_action_spaces = action_spaces_new()

    MODEL_PATH = "checkpoint.hdf5"
    BEST_MODEL = "best_model.hdf5"
    GLOBAL_LIST_TRAINING_PATH = "global_list_training.p"
    # Import Model
    deepnet_model = PawnNetZero(len(all_action_spaces))
    deepnet_model.model = load_model(MODEL_PATH)
    best_model = load_model(BEST_MODEL)
    global_list_training = pickle.load(open(GLOBAL_LIST_TRAINING_PATH, "rb"))
    print("GLOBAL LIST SHAPE : {}".format(len(global_list_training)))
    ae = ActionEncoder()
    ae.fit(list_all_action=all_action_spaces)
    fit_train(global_list_training, ae, deepnet_model, best_model=best_model) 
开发者ID:haryoa,项目名称:evo-pawness,代码行数:36,代码来源:main.py

示例5: check_weights_size

# 需要导入模块: from keras.backend import tensorflow_backend [as 别名]
# 或者: from keras.backend.tensorflow_backend import set_session [as 别名]
def check_weights_size(model_path, weights_size):

    # Memory fraction
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=settings.TRAINER_MEMORY_FRACTION)
    backend.set_session(tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)))

    # create a model and save serialized weights' size
    trainer = ARTDQNTrainer(model_path)
    weights_size.value = len(trainer.serialize_weights())


# Runs trainer process 
开发者ID:Sentdex,项目名称:Carla-RL,代码行数:14,代码来源:trainer.py

示例6: setup_session

# 需要导入模块: from keras.backend import tensorflow_backend [as 别名]
# 或者: from keras.backend.tensorflow_backend import set_session [as 别名]
def setup_session():
    import tensorflow as tf
    from keras.backend import tensorflow_backend
    config = tf.ConfigProto(gpu_options=tf.GPUOptions(allow_growth=True))
    session = tf.Session(config=config)
    tensorflow_backend.set_session(session) 
开发者ID:DeNA,项目名称:SRCNNKit,代码行数:8,代码来源:pred.py


注:本文中的keras.backend.tensorflow_backend.set_session方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。