os.remove(file_path) break except PermissionError: debug_log('Permission error when removing the file') time.sleep(1) #NOTE: train #NOTE: create/load DQN and target DQN in main thread keras.backend.clear_session() agent = DQNAgent(INPUT_SHAPE, training=True, replay_memory=minibatch, copy_target_model=False ) agent.target_model = load_model(target_model_path) #NOTE: train newly loaded model on new data if len(minibatch) > 0: minibatch_history = agent.train_only(len(minibatch), len(minibatch)) if minibatch_history == None: debug_log('ERROR: Unable to train on iteration\'s data') replay_memory.extend(minibatch) else: debug_log('WARNING: Skipping minibatch training since no new data was found') #NOTE: train newly loaded model on random selection of old data agent.replay_memory = replay_memory sum_loss = 0 if len(replay_memory) > MIN_REPLAY_MEMORY_SIZE: train_loops = 50 for train_iteration in range(train_loops): history = agent.train_only(MINIBATCH_SIZE, MIN_REPLAY_MEMORY_SIZE )