예제 #1
0
 def __init__(self, logging=True, confirm=True):
     log_help = "\nexport NSPR_LOG_MODULES=timestamp,nsHttp:5,nsSocketTransport:5,nsStreamPump:5,nsHostResolver:5\n"
     log_help += "export NSPR_LOG_FILE={}\n".format(FFLOG)
     if confirm:
         print(log_help)
         ans = input("Have you set the environment variables for Firefox httplogging [y]? ")
         print()
         if ans != 'y':
             sys.exit(0)
     self.logger = simple_logger.SimpleLogger()
     if logging:
         self.logger.activate()
     else:
         self.logger.deactivate()
예제 #2
0
                    type=int,
                    default=3000)

args = parser.parse_args()

if args.test_checkpoints:

    checkpoint_ix = ast.literal_eval(args.checkpoint_range)

else:
    checkpoint_ix = [0]

model_name = args.modelname
test_checkpoints = args.test_checkpoints

sl = simple_logger.SimpleLogger(f"eval_csv/{model_name}.csv",
                                ['checkpoint', 'score', 'episodes', 'steps'])

# All the evaluations will be evaluated on MineRLObtainDiamondVectorObf-v0 environment
MINERL_GYM_ENV = os.getenv('MINERL_GYM_ENV', 'MineRLTreechop-v0')
MINERL_MAX_EVALUATION_EPISODES = args.no_episodes  #int(os.getenv('MINERL_MAX_EVALUATION_EPISODES', 10))

# Parallel testing/inference, **you can override** below value based on compute
# requirements, etc to save OOM in this phase.
EVALUATION_THREAD_COUNT = args.no_cpu  #int(os.getenv('EPISODES_EVALUATION_THREAD_COUNT', 4))

device = "cuda" if torch.cuda.is_available() else "cpu"


class EpisodeDone(Exception):
    pass
예제 #3
0
    def run_agent_on_episode(self, single_episode_env: Episode, index):
        """Runs the agent on a SINGLE episode.

        Args:
            single_episode_env (Episode): The episode on which to run the agent.
        """
        reward_sum = 0
        counter = 0
        er = EpisodeRecorder()

        max_steps = args.max_steps
        seeds = [
            2, 12345, 45678, 303544, 744421, 816128, 406373, 99999, 88888,
            76543, 67345, 11342, 24337, 45547, 82666, 128939, 494668, 927113,
            869989, 873766, 708928, 786039, 371309, 281286
        ]

        with torch.no_grad():
            seed = random.sample(seeds, 1)
            single_episode_env.seed(seed)
            obs = single_episode_env.reset()
            er.record_frame(obs['pov'])
            done = False
            state = self.model.get_zero_state(1, device=device)
            s = torch.zeros((1, 1, 64), dtype=torch.float32, device=device)
            while not done:

                # what is happening here?
                spatial = torch.tensor(
                    obs["pov"], device=device,
                    dtype=torch.float32).unsqueeze(0).unsqueeze(0).transpose(
                        2, 4)

                #cv2.imshow("xdd", obs["pov"])
                # cv2.waitKey(30)
                #nonspatial = torch.cat([torch.tensor(obs["vector"], device=device, dtype=torch.float32),
                #                       torch.ones((2,), device=device,dtype=torch.float32)], dim=0).unsqueeze(0).unsqueeze(0)

                nonspatial = torch.zeros((1, 1, 64))

                s, state = self.model.sample(
                    spatial, nonspatial, s, state,
                    torch.zeros((1, 1, 64), dtype=torch.float32,
                                device=device))

                action = transform_int_to_actions([int(s)])

                for i in range(1):
                    obs, reward, done, _ = single_episode_env.step(action)
                    er.record_frame(obs['pov'])

                    counter += 1

                    reward_sum += reward
                    if reward > 0:
                        rewards.append(reward)
                    if done:
                        break
                    if max_steps and counter > max_steps:
                        done = True

        if args.save_vids:
            er.save_vid(
                f'train/{model_name}/eval_vids/checkpoint={self.checkpoint_number}/episode={index}_seed={seed}.avi'
            )
            sl = simple_logger.SimpleLogger(
                f"eval_csv/{model_name}.csv",
                ['checkpoint', 'score', 'episodes', 'steps'])
        sl.log([self.checkpoint_number, reward_sum, 1, max_steps])
예제 #4
0
import keywords
import ocr
import os
import re
import requests
import simple_logger
import sys
import time
import urllib
import utils
import website_fetcher
import goslate

# import ngrams

logger = simple_logger.SimpleLogger()
logger.activate()

#############
# ARGUMENTS #
#############

# header data for google search
HEADERS = {
    'user-agent':
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0',
}

# regular expression for extracting urls
GOOGLERX = re.compile("""http[s]?://[^\s'"]*""")