Python keras.backend.set_session() Examples

The following are 30 code examples for showing how to use keras.backend.set_session(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module keras.backend , or try the search function .

Example 1
Project: mercari-price-suggestion   Author: aerdem4   File: nn_model.py    License: MIT License 6 votes vote down vote up
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 
Example 2
Project: reinforcement-learning   Author: rlcode   File: breakout_a3c.py    License: MIT License 6 votes vote down vote up
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) 
Example 3
Project: a-deep-rl-approach-for-sdn-routing-optimization   Author: knowledgedefinednetworking   File: CriticNetwork.py    License: MIT License 6 votes vote down vote up
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()) 
Example 4
Project: connect4-alpha-zero   Author: Zeta36   File: tf_util.py    License: MIT License 6 votes vote down vote up
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) 
Example 5
Project: dist-keras   Author: cerndb   File: workers.py    License: GNU General Public License v3.0 6 votes vote down vote up
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) 
Example 6
Project: costar_plan   Author: jhu-lcsr   File: actor_network.py    License: Apache License 2.0 6 votes vote down vote up
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) 
Example 7
Project: costar_plan   Author: jhu-lcsr   File: critic_network.py    License: Apache License 2.0 6 votes vote down vote up
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) 
Example 8
Project: costar_plan   Author: jhu-lcsr   File: cpu.py    License: Apache License 2.0 6 votes vote down vote up
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) 
Example 9
Project: talos   Author: autonomio   File: gpu_utils.py    License: MIT License 6 votes vote down vote up
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) 
Example 10
Project: keras-text-summarization   Author: chen0040   File: device_utils.py    License: MIT License 6 votes vote down vote up
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) 
Example 11
Project: videograph   Author: noureldien   File: exp_epic_kitchens.py    License: GNU General Public License v3.0 6 votes vote down vote up
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) 
Example 12
Project: videograph   Author: noureldien   File: exp_epic_kitchens.py    License: GNU General Public License v3.0 6 votes vote down vote up
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) 
Example 13
Project: openai_lab   Author: kengz   File: util.py    License: MIT License 6 votes vote down vote up
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 
Example 14
Project: keras-video-classifier   Author: chen0040   File: device_utils.py    License: MIT License 6 votes vote down vote up
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) 
Example 15
Project: mpi_learn   Author: vlimant   File: model.py    License: GNU General Public License v3.0 6 votes vote down vote up
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() 
Example 16
Project: ddan   Author: erlendd   File: fttl.py    License: MIT License 6 votes vote down vote up
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()) 
Example 17
Project: ddan   Author: erlendd   File: deepcoral.py    License: MIT License 6 votes vote down vote up
def __init__(self, nfeatures=50, arch=[8, 'act'], coral_layer_idx=[1],
        batch_size=16, supervised=False, confusion=1e4, confusion_incr=50, confusion_max=1e9,
        val_data=None, validate_every=1, 
        activations='relu', epochs=1000, optimizer=None, noise=0.0, droprate=0.0, verbose=True):

        self.batch_size = batch_size
        self.epochs = epochs
        self.validate_every = validate_every
        self.supervised = supervised
        self.verbose = verbose

        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, supervised, confusion, confusion_incr, 
            confusion_max, activations, noise, droprate, coral_layer_idx, optimizer)

        self.sess = tf.Session()
        K.set_session(self.sess)
        self.sess.run(tf.global_variables_initializer()) 
Example 18
Project: ddan   Author: erlendd   File: dann.py    License: MIT License 6 votes vote down vote up
def __init__(self, nfeatures=50, arch_shared=[32, 'act'], arch_domain=[8, 'act'], arch_clf=[], 
        batch_size=16, supervised=False, val_data=None, validate_every=1, 
        activations='relu', epochs=1000, optimizer=None, noise=0.0, droprate=0.0, stop_at_target_loss=0.0):

        self.batch_size = batch_size
        self.epochs = epochs
        self.validate_every = validate_every
        self.stop_at_target_loss = stop_at_target_loss

        if val_data is None:
            validate_every = 0
        else:
            self.Xval = val_data[0]
            self.yval = val_data[1]

        self._build_model(nfeatures, arch_shared, arch_domain, arch_clf, 
            activations, supervised, noise, droprate, optimizer)

        self.sess = tf.Session()
        K.set_session(self.sess)
        self.sess.run(tf.global_variables_initializer()) 
Example 19
Project: ddan   Author: erlendd   File: ddcn.py    License: MIT License 6 votes vote down vote up
def __init__(self, nfeatures=50, arch=[8, 'act'], mmd_layer_idx=[1],
        batch_size=16, supervised=False, confusion=0.0, confusion_incr=1e-3, confusion_max=1,
        val_data=None, validate_every=1, 
        activations='relu', epochs=1000, optimizer=None, noise=0.0, droprate=0.0, verbose=True):

        self.batch_size = batch_size
        self.epochs = epochs
        self.validate_every = validate_every
        self.supervised = supervised
        self.verbose = verbose

        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, supervised, confusion, confusion_incr, 
            confusion_max, activations, noise, droprate, mmd_layer_idx, optimizer)

        self.sess = tf.Session()
        K.set_session(self.sess)
        self.sess.run(tf.global_variables_initializer()) 
Example 20
Project: vergeml   Author: mme   File: libraries.py    License: MIT License 5 votes vote down vote up
def setup(env):
        stderr = sys.stderr
        sys.stderr = open(os.devnull, "w")
        # pylint: disable=W0612
        try:
            import keras
        except Exception as e:
            raise e
        finally:
            sys.stderr = stderr

        from keras import backend as K
        if K.backend() == 'tensorflow':
            TensorFlowLibrary.setup(env)
            K.set_session(TensorFlowLibrary.create_session(env)) 
Example 21
Project: spark-deep-learning   Author: databricks   File: keras_utils.py    License: Apache License 2.0 5 votes vote down vote up
def __enter__(self):
        # pylint: disable=attribute-defined-outside-init
        self.old_session = K.get_session()
        self.g = self.requested_graph or tf.Graph()     # pylint: disable=invalid-name
        self.current_session = tf.Session(graph=self.g)
        # pylint: enable=attribute-defined-outside-init
        K.set_session(self.current_session)
        return self.current_session, self.g 
Example 22
Project: spark-deep-learning   Author: databricks   File: keras_utils.py    License: Apache License 2.0 5 votes vote down vote up
def __exit__(self, exc_type, exc_val, exc_tb):
        # Restore the previous session
        K.set_session(self.old_session) 
Example 23
Project: spark-deep-learning   Author: databricks   File: builder.py    License: Apache License 2.0 5 votes vote down vote up
def __enter__(self):
        self.sess.__enter__()
        if self.using_keras:
            K.set_session(self.sess)
        return self 
Example 24
Project: spark-deep-learning   Author: databricks   File: builder.py    License: Apache License 2.0 5 votes vote down vote up
def __exit__(self, *args):
        if self.using_keras:
            K.set_session(self.keras_prev_sess)
        self.sess.__exit__(*args) 
Example 25
Project: reinforcement-learning-kr   Author: rlcode   File: breakout_dqn.py    License: MIT License 5 votes vote down vote up
def __init__(self, action_size):
        self.render = False
        self.load_model = False
        # 상태와 행동의 크기 정의
        self.state_size = (84, 84, 4)
        self.action_size = action_size
        # DQN 하이퍼파라미터
        self.epsilon = 1.
        self.epsilon_start, self.epsilon_end = 1.0, 0.1
        self.exploration_steps = 1000000.
        self.epsilon_decay_step = (self.epsilon_start - self.epsilon_end) \
                                  / self.exploration_steps
        self.batch_size = 32
        self.train_start = 50000
        self.update_target_rate = 10000
        self.discount_factor = 0.99
        # 리플레이 메모리, 최대 크기 400000
        self.memory = deque(maxlen=400000)
        self.no_op_steps = 30
        # 모델과 타겟모델을 생성하고 타겟모델 초기화
        self.model = self.build_model()
        self.target_model = self.build_model()
        self.update_target_model()

        self.optimizer = self.optimizer()

        # 텐서보드 설정
        self.sess = tf.InteractiveSession()
        K.set_session(self.sess)

        self.avg_q_max, self.avg_loss = 0, 0
        self.summary_placeholders, self.update_ops, self.summary_op = \
            self.setup_summary()
        self.summary_writer = tf.summary.FileWriter(
            'summary/breakout_dqn', self.sess.graph)
        self.sess.run(tf.global_variables_initializer())

        if self.load_model:
            self.model.load_weights("./save_model/breakout_dqn.h5")

    # Huber Loss를 이용하기 위해 최적화 함수를 직접 정의 
Example 26
Project: reinforcement-learning-kr   Author: rlcode   File: breakout_a3c.py    License: MIT License 5 votes vote down vote up
def __init__(self, action_size):
        # 상태크기와 행동크기를 갖고옴
        self.state_size = (84, 84, 4)
        self.action_size = action_size
        # A3C 하이퍼파라미터
        self.discount_factor = 0.99
        self.no_op_steps = 30
        self.actor_lr = 2.5e-4
        self.critic_lr = 2.5e-4
        # 쓰레드의 갯수
        self.threads = 8

        # 정책신경망과 가치신경망을 생성
        self.actor, self.critic = self.build_model()
        # 정책신경망과 가치신경망을 업데이트하는 함수 생성
        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)

    # 쓰레드를 만들어 학습을 하는 함수 
Example 27
Project: reinforcement-learning-kr   Author: rlcode   File: play_dqn_model.py    License: MIT License 5 votes vote down vote up
def __init__(self, action_size):
        self.state_size = (84, 84, 4)
        self.action_size = action_size
        self.no_op_steps = 20

        self.model = self.build_model()

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

        self.avg_q_max, self.avg_loss = 0, 0
        self.sess.run(tf.global_variables_initializer()) 
Example 28
Project: deep-smoke-machine   Author: CMU-CREATE-Lab   File: config_utils.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __config_gpu_for_keras():
    import tensorflow as tf
    import keras.backend as K

    gpu_core_id = __parse_gpu_id()

    K.clear_session()
    config = tf.ConfigProto()
    config.gpu_options.visible_device_list = str(gpu_core_id)
    config.gpu_options.allow_growth = True
    session = tf.Session(config=config)
    K.set_session(session)

    # set which device to be used
    const.GPU_CORE_ID = gpu_core_id 
Example 29
Project: timeception   Author: noureldien   File: config_utils.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __config_gpu_for_keras():
    import tensorflow as tf
    import keras.backend as K

    gpu_core_id = __parse_gpu_id()

    K.clear_session()
    config = tf.ConfigProto()
    config.gpu_options.visible_device_list = str(gpu_core_id)
    config.gpu_options.allow_growth = True
    session = tf.Session(config=config)
    K.set_session(session)

    # set which device to be used
    const.GPU_CORE_ID = gpu_core_id 
Example 30
Project: reinforcement-learning   Author: rlcode   File: breakout_ddqn.py    License: MIT License 5 votes vote down vote up
def __init__(self, action_size):
        self.render = False
        self.load_model = False
        # environment settings
        self.state_size = (84, 84, 4)
        self.action_size = action_size
        # parameters about epsilon
        self.epsilon = 1.
        self.epsilon_start, self.epsilon_end = 1.0, 0.1
        self.exploration_steps = 1000000.
        self.epsilon_decay_step = (self.epsilon_start - self.epsilon_end) \
                                  / self.exploration_steps
        # parameters about training
        self.batch_size = 32
        self.train_start = 50000
        self.update_target_rate = 10000
        self.discount_factor = 0.99
        self.memory = deque(maxlen=400000)
        self.no_op_steps = 30
        # build
        self.model = self.build_model()
        self.target_model = self.build_model()
        self.update_target_model()

        self.optimizer = self.optimizer()

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

        self.avg_q_max, self.avg_loss = 0, 0
        self.summary_placeholders, self.update_ops, self.summary_op = \
            self.setup_summary()
        self.summary_writer = tf.summary.FileWriter(
            'summary/breakout_ddqn', self.sess.graph)
        self.sess.run(tf.global_variables_initializer())

        if self.load_model:
            self.model.load_weights("./save_model/breakout_ddqn.h5")

    # if the error is in [-1, 1], then the cost is quadratic to the error
    # But outside the interval, the cost is linear to the error