-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
60 lines (46 loc) · 1.2 KB
/
utils.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
import gym
import torch
import torchvision.transforms as transforms
import random
from PIL import Image
import numpy as np
from collections import deque
def np_to_pil(img):
arr = img.astype(np.uint8)
arr = arr[55:215,...]
new_image = Image.fromarray(arr)
return new_image
#(210, 160, 3)
#(168, 160) to crop off the plate
preprocess = transforms.Compose([
transforms.Grayscale(num_output_channels = 1),
transforms.Resize(size = (84, 84), interpolation = 1),
])
GrayScale = transforms.Grayscale(num_output_channels = 1)
class ReplayBuffer:
def __init__(self, CAPACITY):
self.capacity = CAPACITY
self.memory = []
def store(self, transition):
self.memory.append(transition)
if len(self.memory) > self.capacity:
del self.memory[0]
def sample(self, batch_size):
return random.sample(self.memory, batch_size)
def __len__(self):
return len(self.memory)
def check_serve(action, pass_time):
FIRE = [1, 10, 11, 12, 13, 14, 15, 16, 17]
if pass_time < 0:
return -1
elif action in FIRE:
return 1
else:
return 2 if pass_time < 10 else 3
def check_end(AGENT, OPPO):
if AGENT >= 4 and AGENT - OPPO >= 2:
return True
elif OPPO >= 4 and OPPO - AGENT >= 2:
return True
else:
return False