agent/DQ_agent.py
def load(self, dir_output: None, replay_size: int=50000, batch_size: int=32, callback: Callable=None) -> None:
        """
        Get the data from the human gameplay, created by play_human.py

        Args:
            dir_output: the directory where the data has been outputed
            replay_size: the number of random observations to make in case of no dir_output
            batch_size: the size of the replay history batches
            callback: an optional callback to get updates about the score, loss

        """
        if dir_output is None:
            # observe frames to fill the replay memory            
            self.observe(replay_size)
        else:
            frame_played = 0
            for game in sorted(listdir(dir_output)):
                state_path = dir_output + "/" + game + "/episode_0" + "/state2.npy"
                if os.path.isfile(state_path):
                    state = np.load(state_path)
                else:
                    print("No file stat2.npy found in", state_path)
                    continue
                score = 0    
                loss = 0      
                unorted_dir = [d for d in listdir(dir_output+"/"+game)]             
                for directory in sorted(unorted_dir, key=lambda x: int(x.split('_')[-1])):
                    # load file from the directory
                    path = dir_output + "/" + game + "/" + directory + "/"
                    next_state = np.load(path+"state2.npy")
                    action = np.load(path+"action.npy")
                    reward = np.load(path+"reward.npy")
                    # update score
                    score += reward
                    # push the memory onto the replay queue
                    self.queue.push(state, action, reward, False, next_state)
                    # set the state to the new state
                    state = next_state
                    # increment the frame counter
                    frame_played += 1
                    # update Q from replay
                    if frame_played % self.update_frequency == 0:
                        loss += self._replay(*self.queue.sample(size=batch_size))
                    # update Target Q from online Q
                    if frame_played % (self.target_update_freq//100) == 0:
                        self.target_model.set_weights(self.model.get_weights())

                # pass the score to the callback at the end of the episode
                if callable(callback):
                    callback(self, score, loss)

        Get the data from the human gameplay, created by play_human.py

        Args:
            dir_output: the directory where the data has been outputed
            replay_size: the number of random observations to make in case of no dir_output
            batch_size: the size of the replay history batches
            callback: an optional callback to get updates about the score, loss

        
Get the data from the human gameplay, created by play_human.py
Get the data from the human gameplay created by play_human . py
def load(self, dir_output: None, replay_size: int=50000, batch_size: int=32, callback: Callable=None) -> None:
        if dir_output is None:
            self.observe(replay_size)
        else:
            frame_played = 0
            for game in sorted(listdir(dir_output)):
                state_path = dir_output + "/" + game + "/episode_0" + "/state2.npy"
                if os.path.isfile(state_path):
                    state = np.load(state_path)
                else:
                    print("No file stat2.npy found in", state_path)
                    continue
                score = 0    
                loss = 0      
                unorted_dir = [d for d in listdir(dir_output+"/"+game)]             
                for directory in sorted(unorted_dir, key=lambda x: int(x.split('_')[-1])):
                    path = dir_output + "/" + game + "/" + directory + "/"
                    next_state = np.load(path+"state2.npy")
                    action = np.load(path+"action.npy")
                    reward = np.load(path+"reward.npy")
                    score += reward
                    self.queue.push(state, action, reward, False, next_state)
                    state = next_state
                    frame_played += 1
                    if frame_played % self.update_frequency == 0:
                        loss += self._replay(*self.queue.sample(size=batch_size))
                    if frame_played % (self.target_update_freq//100) == 0:
                        self.target_model.set_weights(self.model.get_weights())
                if callable(callback):
                    callback(self, score, loss)
def load ( self , dir_output : None , replay_size : int = 50000 , batch_size : int = 32 , callback : Callable = None ) -> None : if dir_output is None : self . observe ( replay_size ) else : frame_played = 0 for game in sorted ( listdir ( dir_output ) ) : state_path = dir_output + "/" + game + "/episode_0" + "/state2.npy" if os . path . isfile ( state_path ) : state = np . load ( state_path ) else : print ( "No file stat2.npy found in" , state_path ) continue score = 0 loss = 0 unorted_dir = [ d for d in listdir ( dir_output + "/" + game ) ] for directory in sorted ( unorted_dir , key = lambda x : int ( x . split ( '_' ) [ - 1 ] ) ) : path = dir_output + "/" + game + "/" + directory + "/" next_state = np . load ( path + "state2.npy" ) action = np . load ( path + "action.npy" ) reward = np . load ( path + "reward.npy" ) score += reward self . queue . push ( state , action , reward , False , next_state ) state = next_state frame_played += 1 if frame_played % self . update_frequency == 0 : loss += self . _replay ( * self . queue . sample ( size = batch_size ) ) if frame_played % ( self . target_update_freq // 100 ) == 0 : self . target_model . set_weights ( self . model . get_weights ( ) ) if callable ( callback ) : callback ( self , score , loss )
Get the data from the human gameplay, created by play_human.py
Get the data from the human gameplay created by play_human . py
"""
        Get the data from the human gameplay, created by play_human.py

        Args:
            dir_output: the directory where the data has been outputed
            replay_size: the number of random observations to make in case of no dir_output
            batch_size: the size of the replay history batches
            callback: an optional callback to get updates about the score, loss

        """ # observe frames to fill the replay memory             # load file from the directory # update score # push the memory onto the replay queue # set the state to the new state # increment the frame counter # update Q from replay # update Target Q from online Q # pass the score to the callback at the end of the episode
self
dir_output
None
the directory where the data has been outputed
the directory where the data has been outputed
replay_size
int
the number of random observations to make in case of no dir_output
the number of random observations to make in case of no dir_output
batch_size
int
the size of the replay history batches
the size of the replay history batches
callback
Callable
an optional callback to get updates about the score, loss
an optional callback to get updates about the score loss