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


Python backend.set_session方法代码示例

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


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

示例1: __init__

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import set_session [as 别名]
def __init__(self, train_df, word_count, batch_size, epochs):
        tf.set_random_seed(4)
        session_conf = tf.ConfigProto(intra_op_parallelism_threads=2, inter_op_parallelism_threads=8)
        backend.set_session(tf.Session(graph=tf.get_default_graph(), config=session_conf))

        self.batch_size = batch_size
        self.epochs = epochs

        self.max_name_seq = 10
        self.max_item_desc_seq = 75
        self.max_text = word_count + 1
        self.max_brand = np.max(train_df.brand_name.max()) + 1
        self.max_condition = np.max(train_df.item_condition_id.max()) + 1
        self.max_subcat0 = np.max(train_df.subcat_0.max()) + 1
        self.max_subcat1 = np.max(train_df.subcat_1.max()) + 1
        self.max_subcat2 = np.max(train_df.subcat_2.max()) + 1 
开发者ID:aerdem4,项目名称:mercari-price-suggestion,代码行数:18,代码来源:nn_model.py

示例2: __init__

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import set_session [as 别名]
def __init__(self, action_size):
        # environment settings
        self.state_size = (84, 84, 4)
        self.action_size = action_size

        self.discount_factor = 0.99
        self.no_op_steps = 30

        # optimizer parameters
        self.actor_lr = 2.5e-4
        self.critic_lr = 2.5e-4
        self.threads = 8

        # create model for actor and critic network
        self.actor, self.critic = self.build_model()

        # method for training actor and critic network
        self.optimizer = [self.actor_optimizer(), self.critic_optimizer()]

        self.sess = tf.InteractiveSession()
        K.set_session(self.sess)
        self.sess.run(tf.global_variables_initializer())

        self.summary_placeholders, self.update_ops, self.summary_op = self.setup_summary()
        self.summary_writer = tf.summary.FileWriter('summary/breakout_a3c', self.sess.graph) 
开发者ID:rlcode,项目名称:reinforcement-learning,代码行数:27,代码来源:breakout_a3c.py

示例3: __init__

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import set_session [as 别名]
def __init__(self, sess, state_size, action_size, DDPG_config):
        self.HIDDEN1_UNITS = DDPG_config['HIDDEN1_UNITS']
        self.HIDDEN2_UNITS = DDPG_config['HIDDEN2_UNITS']

        self.sess = sess
        self.BATCH_SIZE = DDPG_config['BATCH_SIZE']
        self.TAU = DDPG_config['TAU']
        self.LEARNING_RATE = DDPG_config['LRC']
        self.action_size = action_size

        self.h_acti = relu
        if DDPG_config['HACTI'] == 'selu':
            self.h_acti = selu

        K.set_session(sess)

        #Now create the model
        self.model, self.action, self.state = self.create_critic_network(state_size, action_size)
        self.target_model, self.target_action, self.target_state = self.create_critic_network(state_size, action_size)
        self.action_grads = tf.gradients(self.model.output, self.action)  #GRADIENTS for policy update
        self.sess.run(tf.global_variables_initializer()) 
开发者ID:knowledgedefinednetworking,项目名称:a-deep-rl-approach-for-sdn-routing-optimization,代码行数:23,代码来源:CriticNetwork.py

示例4: set_session_config

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import set_session [as 别名]
def set_session_config(per_process_gpu_memory_fraction=None, allow_growth=None):
    """

    :param allow_growth: When necessary, reserve memory
    :param float per_process_gpu_memory_fraction: specify GPU memory usage as 0 to 1

    :return:
    """
    import tensorflow as tf
    import keras.backend as K

    config = tf.ConfigProto(
        gpu_options=tf.GPUOptions(
            per_process_gpu_memory_fraction=per_process_gpu_memory_fraction,
            allow_growth=allow_growth,
        )
    )
    sess = tf.Session(config=config)
    K.set_session(sess) 
开发者ID:Zeta36,项目名称:connect4-alpha-zero,代码行数:21,代码来源:tf_util.py

示例5: prepare_model

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import set_session [as 别名]
def prepare_model(self):
        """Prepares the model for training."""
        # Set the Keras directory.
        set_keras_base_directory()
        if K.backend() == 'tensorflow':
            # set GPU option allow_growth to False for GPU-enabled tensorflow
            config = tf.ConfigProto()
            config.gpu_options.allow_growth = False
            sess = tf.Session(config=config)
            K.set_session(sess)

        # Deserialize the Keras model.
        self.model = deserialize_keras_model(self.model)
        self.optimizer = deserialize(self.optimizer)
        # Compile the model with the specified loss and optimizer.
        self.model.compile(loss=self.loss, loss_weights = self.loss_weights, 
            optimizer=self.optimizer, metrics=self.metrics) 
开发者ID:cerndb,项目名称:dist-keras,代码行数:19,代码来源:workers.py

示例6: __init__

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import set_session [as 别名]
def __init__(self, sess, state_size, action_size, BATCH_SIZE, TAU, LEARNING_RATE, convolutional=False, output_activation='sigmoid'):
        self.sess = sess
        self.BATCH_SIZE = BATCH_SIZE
        self.TAU = TAU
        self.LEARNING_RATE = LEARNING_RATE
        self.convolutional = convolutional
        self.output_activation = output_activation

        #K.set_session(sess)

        #Now create the model
        self.model , self.weights, self.state = self.create_actor_network(state_size, action_size)   
        self.target_model, self.target_weights, self.target_state = self.create_actor_network(state_size, action_size) 
        self.action_gradient = tf.placeholder(tf.float32,[None, action_size])
        self.params_grad = tf.gradients(self.model.output, self.weights, -self.action_gradient)
        grads = zip(self.params_grad, self.weights)
        self.optimize = tf.train.AdamOptimizer(LEARNING_RATE).apply_gradients(grads)
        init_op = tf.global_variables_initializer()
        self.sess.run(init_op) 
开发者ID:jhu-lcsr,项目名称:costar_plan,代码行数:21,代码来源:actor_network.py

示例7: __init__

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import set_session [as 别名]
def __init__(self, sess, state_size, action_size, BATCH_SIZE, TAU, LEARNING_RATE, convolutional=False):
        self.sess = sess
        self.BATCH_SIZE = BATCH_SIZE
        self.TAU = TAU
        self.LEARNING_RATE = LEARNING_RATE
        self.action_size = action_size
        self.convolutional = convolutional
        
        #K.set_session(sess)

        #Now create the model
        self.model, self.action, self.state = self.create_critic_network(state_size, action_size)  
        self.target_model, self.target_action, self.target_state = self.create_critic_network(state_size, action_size)  
        self.action_grads = tf.gradients(self.model.output, self.action)  #GRADIENTS for policy update
        init_op = tf.global_variables_initializer()
        self.sess.run(init_op) 
开发者ID:jhu-lcsr,项目名称:costar_plan,代码行数:18,代码来源:critic_network.py

示例8: ConfigureGPU

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import set_session [as 别名]
def ConfigureGPU(args):
    cpu = True if 'cpu' in args and args['cpu'] else False

    fraction = 1
    if 'gpu_fraction' in args and args['gpu_fraction']:
        fraction = args['gpu_fraction']

    if fraction < 1. or cpu:
        import tensorflow as tf
        import keras.backend as K
        
        if cpu:
            config = tf.ConfigProto(
                device_count={'GPU': 0}
            )
            sess = tf.Session(config=config)
        else:
            gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=fraction)
            sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
        K.set_session(sess) 
开发者ID:jhu-lcsr,项目名称:costar_plan,代码行数:22,代码来源:cpu.py

示例9: parallel_gpu_jobs

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import set_session [as 别名]
def parallel_gpu_jobs(allow_growth=True, fraction=.5):

    '''Sets the max used memory as a fraction for tensorflow
    backend

    allow_growth :: True of False

    fraction :: a float value (e.g. 0.5 means 4gb out of 8gb)

    '''

    import keras.backend as K
    import tensorflow as tf

    gpu_options = tf.GPUOptions(allow_growth=allow_growth,
                                  per_process_gpu_memory_fraction=fraction)
    config = tf.ConfigProto(gpu_options=gpu_options)
    session = tf.Session(config=config)
    K.set_session(session) 
开发者ID:autonomio,项目名称:talos,代码行数:21,代码来源:gpu_utils.py

示例10: init_devices

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import set_session [as 别名]
def init_devices(device_type=None):
    if device_type is None:
        device_type = 'cpu'

    num_cores = 4

    if device_type == 'gpu':
        num_GPU = 1
        num_CPU = 1
    else:
        num_CPU = 1
        num_GPU = 0

    config = tf.ConfigProto(intra_op_parallelism_threads=num_cores,
                            inter_op_parallelism_threads=num_cores, allow_soft_placement=True,
                            device_count={'CPU': num_CPU, 'GPU': num_GPU})
    session = tf.Session(config=config)
    K.set_session(session) 
开发者ID:chen0040,项目名称:keras-text-summarization,代码行数:20,代码来源:device_utils.py

示例11: __start_train_model_on_video_frames_videograph

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import set_session [as 别名]
def __start_train_model_on_video_frames_videograph(n_epochs, n_timesteps, n_centroids, timestamp, is_resume_training, start_epoch_num):
    # configure the gpu to be used by keras
    gpu_core_id = 3
    device_id = '/gpu:%d' % gpu_core_id

    # with graph.as_default():
    # with session.as_default():

    graph = tf.Graph()
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    config.allow_soft_placement = True
    sess = tf.Session(config=config, graph=graph)
    K.set_session(sess)
    with sess:
        with tf.device(device_id):
            __train_model_on_video_frames_videograph(n_epochs, n_timesteps, n_centroids, timestamp, is_resume_training, start_epoch_num) 
开发者ID:noureldien,项目名称:videograph,代码行数:19,代码来源:exp_epic_kitchens.py

示例12: __start_train_model_on_video_frames_backbone_i3d_keras

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import set_session [as 别名]
def __start_train_model_on_video_frames_backbone_i3d_keras(n_epochs, starting_epoch_num, n_frames_per_video, n_instances, instance_num):
    # configure the gpu to be used by keras
    gpu_core_id = instance_num - 1
    device_id = '/gpu:%d' % gpu_core_id

    assert instance_num in [1, 2, 3], 'Sorry, wrong instance number: %d' % (instance_num)

    graph = tf.Graph()
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    config.allow_soft_placement = True
    sess = tf.Session(config=config, graph=graph)
    K.set_session(sess)
    with sess:
        with tf.device(device_id):
            __train_model_on_video_frames_backbone_i3d_keras(n_epochs, starting_epoch_num, n_frames_per_video, n_instances, instance_num) 
开发者ID:noureldien,项目名称:videograph,代码行数:18,代码来源:exp_epic_kitchens.py

示例13: configure_hardware

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import set_session [as 别名]
def configure_hardware(RAND_SEED):
    '''configure rand seed, GPU'''
    from keras import backend as K
    if K.backend() == 'tensorflow':
        K.tf.set_random_seed(RAND_SEED)
    else:
        K.theano.tensor.shared_randomstreams.RandomStreams(seed=RAND_SEED)

    if K.backend() != 'tensorflow':
        # GPU config for tf only
        return

    process_num = PARALLEL_PROCESS_NUM if args.param_selection else 1
    tf = K.tf
    gpu_options = tf.GPUOptions(
        allow_growth=True,
        per_process_gpu_memory_fraction=1./float(process_num))
    config = tf.ConfigProto(
        gpu_options=gpu_options,
        allow_soft_placement=True)
    sess = tf.Session(config=config)
    K.set_session(sess)
    return sess 
开发者ID:kengz,项目名称:openai_lab,代码行数:25,代码来源:util.py

示例14: build_model

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import set_session [as 别名]
def build_model(self, local_session = True):
        import keras.backend as K

        if local_session:
            graph = K.tf.Graph()
            session = K.tf.Session(graph=graph, config=K.tf.ConfigProto(
                allow_soft_placement=True, log_device_placement=False,
                gpu_options=K.tf.GPUOptions(
                        per_process_gpu_memory_fraction=1./self.comm.Get_size()) ) )

            with graph.as_default():
                with session.as_default():
                    import keras.backend as K
                    ret_model = self.build_model_aux()
                    ret_model.session = session
                    ret_model.graph = graph
                    return ret_model
        else:
            K.set_session( K.tf.Session( config=K.tf.ConfigProto(
                allow_soft_placement=True, log_device_placement=False,
                gpu_options=K.tf.GPUOptions(
                    per_process_gpu_memory_fraction=1./self.comm.Get_size()) ) ) )
            return self.build_model_aux() 
开发者ID:vlimant,项目名称:mpi_learn,代码行数:25,代码来源:model.py

示例15: __init__

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import set_session [as 别名]
def __init__(self, nfeatures=50, arch=[8, 'act', 8, 'act'], fine_tune_layers=[2, 3], batch_size=16, 
        val_data=None, validate_every=1, activations='relu', epochs=5000, epochs_finetune=5000, optimizer=None, optimizer_finetune=None,
        noise=0.0, droprate=0.0, verbose=True, stop_at_target_loss=0):

        self.batch_size = batch_size
        self.validate_every = validate_every
        self.epochs = epochs
        self.epochs_finetune = epochs_finetune
        self.verbose = verbose
        self.stop_at_target_loss = stop_at_target_loss
        if val_data is None:
            self.validate_every = 0
        else:
            self.Xval = val_data[0]
            self.yval = val_data[1]

        self._build_model(nfeatures, arch, activations, noise, droprate, optimizer, optimizer_finetune, fine_tune_layers)

        self.sess = tf.Session()
        K.set_session(self.sess)
        self.sess.run(tf.global_variables_initializer()) 
开发者ID:erlendd,项目名称:ddan,代码行数:23,代码来源:fttl.py


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