本文整理匯總了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)
示例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)
示例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")
示例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)
示例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
示例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)