-
Notifications
You must be signed in to change notification settings - Fork 4
/
sc2Processor.py
76 lines (50 loc) · 2.79 KB
/
sc2Processor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from rl.core import Processor
import numpy as np
class Sc2Processor(Processor):
def __init__(self, screen=16):
super(Processor, self).__init__()
self._SCREEN = screen
def process_state_batch(self, batch):
# reshape cause batch is (bs, 1, 2, screen, screen)
size_first_dim = len(batch)
return np.reshape(batch, (size_first_dim, 2, self._SCREEN, self._SCREEN))
# observation, reward, done, info = env.step(action)
def process_observation(self, observation):
# small_observation = observation[0].observation["feature_screen"][5]
# print(smallObservation, observation[0].reward, observation[0].last(), "lol")
# small_observation = small_observation.reshape(1, small_observation.shape[0], small_observation.shape[0], 1)
# print(smallObservation.shape)
# print(smallObservation, observation[0].reward, observation[0].last(), "lol")
# fix dim from 1 1 2 16 16 to 1 2 16 16
# observation = observation[0]
return observation
# assert observation.ndim == 3 # (height, width, channel)
# img = Image.fromarray(observation)
# img = img.resize(INPUT_SHAPE).convert('L') # resize and convert to grayscale
# processed_observation = np.array(img)
# assert processed_observation.shape == INPUT_SHAPE
# return processed_observation.astype('uint8') # saves storage in experience memory
class Sc2ProcessorFull(Processor):
def __init__(self, screen=16):
super(Processor, self).__init__()
self._SCREEN = screen
def process_state_batch(self, batch):
# reshape cause batch is (bs, 1, 2, screen, screen)
size_first_dim = len(batch)
return np.reshape(batch, (size_first_dim, 17, self._SCREEN, self._SCREEN))
# observation, reward, done, info = env.step(action)
def process_observation(self, observation):
# small_observation = observation[0].observation["feature_screen"][5]
# print(smallObservation, observation[0].reward, observation[0].last(), "lol")
# small_observation = small_observation.reshape(1, small_observation.shape[0], small_observation.shape[0], 1)
# print(smallObservation.shape)
# print(smallObservation, observation[0].reward, observation[0].last(), "lol")
# fix dim from 1 1 2 16 16 to 1 2 16 16
# observation = observation[0]
return observation
# assert observation.ndim == 3 # (height, width, channel)
# img = Image.fromarray(observation)
# img = img.resize(INPUT_SHAPE).convert('L') # resize and convert to grayscale
# processed_observation = np.array(img)
# assert processed_observation.shape == INPUT_SHAPE
# return processed_observation.astype('uint8') # saves storage in experience memory