MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / __init__

Method __init__

examples/DeepQNetwork/atari.py:33–100  ·  view source on GitHub ↗

Args: rom_file: path to the rom frame_skip: skip every k frames and repeat the action viz: visualization to be done. Set to 0 to disable. Set to a positive number to be the delay between frames to show. Set

(self, rom_file, viz=0,
                 frame_skip=4, nullop_start=30,
                 live_lost_as_eoe=True, max_num_frames=0,
                 grayscale=True)

Source from the content-addressed store, hash-verified

31 """
32
33 def __init__(self, rom_file, viz=0,
34 frame_skip=4, nullop_start=30,
35 live_lost_as_eoe=True, max_num_frames=0,
36 grayscale=True):
37 """
38 Args:
39 rom_file: path to the rom
40 frame_skip: skip every k frames and repeat the action
41 viz: visualization to be done.
42 Set to 0 to disable.
43 Set to a positive number to be the delay between frames to show.
44 Set to a string to be a directory to store frames.
45 nullop_start: start with random number of null ops.
46 live_losts_as_eoe: consider lost of lives as end of episode. Useful for training.
47 max_num_frames: maximum number of frames per episode.
48 grayscale (bool): if True, return 2D image. Otherwise return HWC image.
49 """
50 super(AtariPlayer, self).__init__()
51 if not os.path.isfile(rom_file) and '/' not in rom_file:
52 rom_file = get_dataset_path('atari_rom', rom_file)
53 assert os.path.isfile(rom_file), \
54 "ROM {} not found. Please download at {}".format(rom_file, ROM_URL)
55
56 try:
57 ALEInterface.setLoggerMode(ALEInterface.Logger.Error)
58 except AttributeError:
59 if execute_only_once():
60 logger.warn("You're not using latest ALE")
61
62 # avoid simulator bugs: https://github.com/mgbellemare/Arcade-Learning-Environment/issues/86
63 with _ALE_LOCK:
64 self.ale = ALEInterface()
65 self.rng = get_rng(self)
66 self.ale.setInt(b"random_seed", self.rng.randint(0, 30000))
67 self.ale.setInt(b"max_num_frames_per_episode", max_num_frames)
68 self.ale.setBool(b"showinfo", False)
69
70 self.ale.setInt(b"frame_skip", 1)
71 self.ale.setBool(b'color_averaging', False)
72 # manual.pdf suggests otherwise.
73 self.ale.setFloat(b'repeat_action_probability', 0.0)
74
75 # viz setup
76 if isinstance(viz, six.string_types):
77 assert os.path.isdir(viz), viz
78 self.ale.setString(b'record_screen_dir', viz)
79 viz = 0
80 if isinstance(viz, int):
81 viz = float(viz)
82 self.viz = viz
83 if self.viz and isinstance(self.viz, float):
84 self.windowname = os.path.basename(rom_file)
85 cv2.namedWindow(self.windowname)
86
87 self.ale.loadROM(rom_file.encode('utf-8'))
88 self.width, self.height = self.ale.getScreenDims()
89 self.actions = self.ale.getMinimalActionSet()
90

Callers

nothing calls this directly

Calls 6

_restart_episodeMethod · 0.95
get_dataset_pathFunction · 0.90
execute_only_onceFunction · 0.90
get_rngFunction · 0.90
formatMethod · 0.80
basenameMethod · 0.80

Tested by

no test coverage detected