Exemplo n.º 1
0
def runCentralServer(slaveIds = [], actionset = [], *kw, **kws):
    global CENTRAL_ACTION_SET, PENSIEVE_IPC_QUEUES
    CENTRAL_ACTION_SET = actionset
    masterQueue = mp.Queue()
    slaveQueues = {x:mp.Queue() for x in slaveIds}
    PENSIEVE_IPC_QUEUES = [masterQueue, slaveQueues]

    p = mp.Process(target=_runCentralServer, args=(actionset, )+kw, kwargs=kws)
    p.start()
    return p
Exemplo n.º 2
0
 def __init__(self, actionset = [], infoDept=S_LEN, *arg, **kwarg):
     assert PensiveLearner.__instance == None
     PensiveLearner.__instance = self
     self.recv, self.send = mp.Queue(), mp.Queue()
     self._vActionset = actionset
     self._vInfoDept = infoDept
     self._vRunning = True
     p = mp.Process(target=self.handle, args= (self.send, self.recv, actionset, infoDept)+arg, kwargs=kwarg)
     p.start()
     self.proc = p
     atexit.register(self.cleanup)
Exemplo n.º 3
0
 def __init__(self, videoInfo, agent, log_file_path=LOG_FILE, *kw, **kws):
     assert AbrPensieveClass.__instance == None
     self.recv = mp.Queue()
     self.send = mp.Queue()
     self.proc = mp.Process(
         target=self.handle,
         args=(self.send, self.recv, videoInfo, agent, log_file_path) + kw,
         kwargs=kws)
     self.proc.start()
     AbrPensieveClass.__instance = self
     self.count = 0
     self.agents = []
     atexit.register(self.cleanup)
Exemplo n.º 4
0
    def __init__(self,
                 actionset=[],
                 infoDept=S_LEN,
                 infoDim=S_INFO,
                 log_path=None,
                 summary_dir=None,
                 nn_model=None,
                 readOnly=False,
                 master=False,
                 ipcQueues=None):
        assert summary_dir
        assert readOnly

        assert master == (ipcQueues is not None)

        self.master = master
        cprint.cyan("!!CREATING OBJECT!!")
        if not master:
            cprint.blue("!!SLAVE!!")
            self.recv, self.send = [mp.Queue(), mp.Queue()]
            self.proc = mp.Process(
                target=PensiveLearner,
                args=(actionset, infoDept, infoDim, log_path, summary_dir,
                      nn_model, readOnly, True, [self.send, self.recv]))
            self.proc.start()
            while True:
                cmd = self.recv.get()
                if cmd == "ready":
                    break
            return

        cprint.red("!!MASTER!!")

        self.recv, self.send = ipcQueues

        #         myprint("Pensieproc init Params:", actionset, infoDept, log_path, summary_dir, nn_model)

        self.pid = os.getpid()
        self.summary_dir = summary_dir
        self.nn_model = None if not nn_model else os.path.join(
            self.summary_dir, nn_model)

        self.a_dim = len(actionset)
        self._vActionset = actionset

        self._vInfoDim = infoDim
        self._vInfoDept = infoDept

        self._vReadOnly = readOnly

        if not os.path.exists(self.summary_dir):
            os.makedirs(self.summary_dir)

        self.sess = tf.Session()

        self.actor = a3c.ActorNetwork(
            self.sess,
            state_dim=[self._vInfoDim, self._vInfoDept],
            action_dim=self.a_dim,
            learning_rate=ACTOR_LR_RATE)

        self.critic = a3c.CriticNetwork(
            self.sess,
            state_dim=[self._vInfoDim, self._vInfoDept],
            action_dim=self.a_dim,
            learning_rate=CRITIC_LR_RATE)

        self.summary_ops, self.summary_vars = a3c.build_summaries()

        self.sess.run(tf.global_variables_initializer())
        self.writer = tf.summary.FileWriter(
            self.summary_dir, self.sess.graph)  # training monitor
        self.saver = tf.train.Saver()  # save neural net parameters

        # restore neural net parameters
        self.epoch = 0
        if self.nn_model is None and self.master:
            nn_model, epoch = guessSavedSession(self.summary_dir)
            if nn_model:
                self.nn_model = nn_model
                self.epoch = epoch

        if self.nn_model is not None:  # nn_model is the path to file
            self.saver.restore(self.sess, self.nn_model)
            cprint.red("Model restored with `" + self.nn_model + "'")

        try:
            self.runCmd()
        except Exception as ex:
            track = tb.format_exc()
            cprint.red(track)