如何在一个python脚本中创建两个openai基线deepq代理?

时间:2018-06-08 02:21:13

标签: deep-learning reinforcement-learning openai-gym

我试图在一个python文件中创建两个deepq代理,比如

import gym
import itertools
import numpy as np
import tensorflow as tf
import tensorflow.contrib.layers as layers

import baselines.common.tf_util as U

from baselines import logger
from baselines import deepq
from baselines.deepq.replay_buffer import ReplayBuffer
from baselines.deepq.utils import ObservationInput
from baselines.common.schedules import LinearSchedule

def model1(inpt, num_actions, scope, reuse=False):
    """This model takes as input an observation and returns values of all actions."""
    with tf.variable_scope(scope, reuse=reuse):
        out = inpt
        out = layers.fully_connected(out, num_outputs=64, activation_fn=tf.nn.tanh)
        out = layers.fully_connected(out, num_outputs=num_actions, activation_fn=None)
        return out

def model2(inpt, num_actions, scope, reuse=False):
    """This model takes as input an observation and returns values of all actions."""
    with tf.variable_scope(scope, reuse=reuse):
        out = inpt
        out = layers.fully_connected(out, num_outputs=64, activation_fn=tf.nn.tanh)
        out = layers.fully_connected(out, num_outputs=num_actions, activation_fn=None)
        return out

但是,稍后当我宣布像

这样的代理人时
        act1, train1, update_target1, debug1 = deepq.build_train(
        make_obs_ph=lambda name: ObservationInput(gym.spaces.Box(low=-1, high=1, shape=(8,)), name=name),
        q_func=model1,
        num_actions=3,
        optimizer=tf.train.AdamOptimizer(learning_rate=5e-4))

    act2, train2, update_target2, debug2 = deepq.build_train(
        make_obs_ph=lambda name: ObservationInput(gym.spaces.Box(low=-1, high=1, shape=(8,)), name=name),
        q_func=model2,
        num_actions=3,
        optimizer=tf.train.AdamOptimizer(learning_rate=5e-4))

我收到一条错误消息“ValueError:变量deepq / eps已经存在,不允许。您是不是要在VarScope中设置reuse = True或reuse = tf.AUTO_REUSE?”

那么,我怎样才能在一个文件中包含这两个deepq代理?

0 个答案:

没有答案