@@ -14,17 +14,9 @@ def play_video(filename):
14
14
15
15
return embedded
16
16
17
- def preprocess_pong (image ):
18
- I = image [35 :195 ] # Crop
19
- I = I [::2 , ::2 , 0 ] # Downsample width and height by a factor of 2
20
- I [I == 144 ] = 0 # Remove background type 1
21
- I [I == 109 ] = 0 # Remove background type 2
22
- I [I != 0 ] = 1 # Set remaining elements (paddles, ball, etc.) to 1
23
- return I .astype (np .float ).reshape (80 , 80 , 1 )
24
17
25
- def new_preprocess_pong (image ):
18
+ def preprocess_pong (image ):
26
19
I = image [35 :195 ] # Crop
27
- # I = np.mean(I, axis=-1, keepdim=True)
28
20
I = I [::2 , ::2 , 0 ] # Downsample width and height by a factor of 2
29
21
I [I == 144 ] = 0 # Remove background type 1
30
22
I [I == 109 ] = 0 # Remove background type 2
@@ -41,6 +33,7 @@ def pong_change(prev, curr):
41
33
I = (I - I .min ()) / (I .max () - I .min () + 1e-10 )
42
34
return I
43
35
36
+
44
37
class Memory :
45
38
def __init__ (self ):
46
39
self .clear ()
@@ -54,15 +47,10 @@ def clear(self):
54
47
# Add observations, actions, rewards to memory
55
48
def add_to_memory (self , new_observation , new_action , new_reward ):
56
49
self .observations .append (new_observation )
57
- '''TODO: update the list of actions with new action'''
58
- self .actions .append (new_action ) # TODO
59
- # ['''TODO''']
60
- '''TODO: update the list of rewards with new reward'''
61
- self .rewards .append (new_reward ) # TODO
62
- # ['''TODO''']
63
-
64
- # Helper function to combine a list of Memory objects into a single Memory.
65
- # This will be very useful for batching.
50
+ self .actions .append (new_action )
51
+ self .rewards .append (new_reward )
52
+
53
+
66
54
def aggregate_memories (memories ):
67
55
batch_memory = Memory ()
68
56
@@ -72,6 +60,7 @@ def aggregate_memories(memories):
72
60
73
61
return batch_memory
74
62
63
+
75
64
def parallelized_collect_rollout (batch_size , envs , model , choose_action ):
76
65
77
66
assert len (envs ) == batch_size , "Number of parallel environments must be equal to the batch size."
0 commit comments