MCPcopy Create free account
hub / github.com/deepdrive/deepdrive / Agent

Class Agent

tensorflow_agent/agent.py:21–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19
20
21class Agent(object):
22 def __init__(self, action_space, tf_session, env, should_record_recovery_from_random_actions=True,
23 should_record=False, net_path=None, use_frozen_net=False, random_action_count=0,
24 non_random_action_count=5, path_follower=False, recording_dir=c.RECORDING_DIR):
25 np.random.seed(c.RNG_SEED)
26 self.action_space = action_space
27 self.previous_action = None
28 self.step = 0
29 self.env = env
30
31 # State for toggling random actions
32 self.should_record_recovery_from_random_actions = should_record_recovery_from_random_actions
33 self.random_action_count = random_action_count
34 self.non_random_action_count = non_random_action_count
35 self.semirandom_sequence_step = 0
36 self.action_count = 0
37 self.recorded_obz_count = 0
38 self.performing_random_actions = False
39 self.path_follower_mode = path_follower
40 self.recording_dir = recording_dir
41
42 # Recording state
43 self.should_record = should_record
44 self.sess_dir = os.path.join(recording_dir, datetime.now().strftime(c.DIR_DATE_FORMAT))
45 self.obz_recording = []
46
47 if should_record_recovery_from_random_actions:
48 log.info('Mixing in random actions to increase data diversity (these are not recorded).')
49 if should_record:
50 log.info('Recording driving data to %s', self.sess_dir)
51
52 # Net
53 self.sess = tf_session
54 self.use_frozen_net = use_frozen_net
55 if net_path is not None:
56 self.load_net(net_path, use_frozen_net)
57 else:
58 self.net = None
59 self.net_input_placeholder = None
60 self.sess = None
61
62 def act(self, obz, reward, done):
63 if obz is not None:
64 log.debug('steering %r', obz['steering'])
65 log.debug('throttle %r', obz['throttle'])
66 obz = self.preprocess_obz(obz)
67
68 if self.should_record_recovery_from_random_actions:
69 action = self.toggle_random_action()
70 self.action_count += 1
71 elif self.net is not None:
72 if obz is None or not obz['cameras']:
73 y = None
74 else:
75 image = obz['cameras'][0]['image']
76 y = self.get_net_out(image)
77 action = self.get_next_action(obz, y)
78 else:

Callers 1

runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected