-
Notifications
You must be signed in to change notification settings - Fork 0
/
die_types.py
180 lines (162 loc) · 6.16 KB
/
die_types.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import imgaug
import numpy as np
XWING_GREEN_DIE_HSV_RANGE = (( 60, 30, 60), ( 90, 255, 255))
XWING_RED_DIE_HSV_RANGE_1 = (( 0, 140, 60), ( 10, 255, 255))
XWING_RED_DIE_HSV_RANGE_2 = ((150, 80, 60), (180, 255, 255))
XWING_RED_GD_DIE_HSV_RANGE_1 = (( 0, 60, 20), ( 10, 255, 255))
XWING_RED_GD_DIE_HSV_RANGE_2 = ((155, 60, 20), (185, 255, 255))
# WIP, can't really get these working acceptably
XWING_RED_BLACK_DIE_HSV_RANGE_1 = ((150, 20, 0), (180, 255, 255))
XWING_RED_BLACK_DIE_HSV_RANGE_2 = (( 80, 0, 10), (180, 255, 50))
BLUE_CASINO_DIE_HSV_RANGE = (( 90, 130, 35), (120, 255, 255))
WHITE_DOTS_HSV_RANGE = (( 0, 0, 120), (255, 30, 255))
D8_BLUE_DIE_HSV_RANGE = ((80, 130, 0), (130, 255, 255))
CXD6_PINK_DIE_HSV_RANGE = ((120, 60, 55), (255, 255, 255))
# Need two ranges since sometimes we get a fairly high specular reflection on these metal dice
D8_ORANGE_DIE_HSV_RANGE_1 = (( 0, 125, 100), ( 20, 255, 255))
D8_ORANGE_DIE_HSV_RANGE_2 = (( 0, 80, 160), ( 20, 255, 255))
class XwingImgTransform:
def __init__(self):
self.aug = imgaug.augmenters.Sequential([
imgaug.augmenters.Sometimes(0.2, imgaug.augmenters.CoarseDropout((0.01, 0.05), size_percent=(0.10, 0.25))),
imgaug.augmenters.Affine(
scale = (0.8, 1.1),
translate_percent = {"x": (-0.1, 0.1), "y": (-0.1, 0.1)},
rotate = (0, 360),
order = 1,
cval = (0, 255),
),
#imgaug.augmenters.Sometimes(0.25, imgaug.augmenters.GaussianBlur(sigma=[1.0, 1.8])),
imgaug.augmenters.Sometimes(0.5, imgaug.augmenters.Add((0, 100))),
imgaug.augmenters.Sometimes(0.5, imgaug.augmenters.Multiply((0.9, 1.5))),
imgaug.augmenters.Sometimes(0.3, imgaug.augmenters.Grayscale([0.5, 1.0])),
])
def __call__(self, img):
img = np.array(img)
return self.aug.augment_image(img)
class GenericD6ImgTransform:
def __init__(self):
self.aug = imgaug.augmenters.Sequential([
imgaug.augmenters.Sometimes(0.2, imgaug.augmenters.CoarseDropout((0.01, 0.05), size_percent=(0.10, 0.3))),
imgaug.augmenters.Sometimes(0.5, imgaug.augmenters.Multiply((0.8, 1.2))),
imgaug.augmenters.Sometimes(0.3, imgaug.augmenters.Add((-20, 20))),
imgaug.augmenters.Sometimes(0.1, imgaug.augmenters.AddToHue((-255, 255))),
imgaug.augmenters.Affine(
scale = (0.9, 1.0),
translate_percent = {"x": (-0.05, 0.05), "y": (-0.05, 0.05)},
rotate = (0, 360),
order = 1,
cval = (0, 255),
),
imgaug.augmenters.Sometimes(0.1, imgaug.augmenters.Grayscale([0.5, 1.0])),
])
def __call__(self, img):
img = np.array(img)
return self.aug.augment_image(img)
class CasinoImgTransform:
def __init__(self):
self.aug = imgaug.augmenters.Sequential([
imgaug.augmenters.Sometimes(0.4, imgaug.augmenters.CoarseDropout((0.01, 0.05), size_percent=(0.10, 0.25))),
imgaug.augmenters.Sometimes(0.75, imgaug.augmenters.Affine(
scale = (0.7, 1.2),
translate_percent = {"x": (-0.35, 0.35), "y": (-0.35, 0.35)},
rotate = (0, 360),
order = 1,
cval = (0, 255),
)),
#imgaug.augmenters.Sometimes(0.25, imgaug.augmenters.GaussianBlur(sigma=[1.0, 1.8])),
imgaug.augmenters.Sometimes(0.5, imgaug.augmenters.Add((0, 100))),
imgaug.augmenters.Sometimes(0.5, imgaug.augmenters.Multiply((0.9, 1.5))),
imgaug.augmenters.Sometimes(0.3, imgaug.augmenters.Grayscale([0.5, 1.0])),
imgaug.augmenters.AddToHueAndSaturation((-15, 15)),
])
def __call__(self, img):
img = np.array(img)
return self.aug.augment_image(img)
# NOTE: Could use namedtuples for each of the elements here, but good enough for now
params = {
"xwing_red": {
"hsv_ranges": [XWING_RED_DIE_HSV_RANGE_1, XWING_RED_DIE_HSV_RANGE_2],
"rect_width": 84,
"rect_height": 84,
"classes_count": 4, # blank, focus, hit, crit
"expected_distribution": {"blank": 2.0/8.0, "focus": 2.0/8.0, "hit": 3.0/8.0, "crit": 1.0/8.0},
"training": {
"image_transform": XwingImgTransform(),
"lr": 0.01,
"momentum": 0.9,
"lr_reduction_steps": 30,
"total_steps": 60,
},
},
"xwing_green": {
"hsv_ranges": [XWING_GREEN_DIE_HSV_RANGE],
"rect_width": 84,
"rect_height": 84,
"classes_count": 3, # blank, focus, evade
"expected_distribution": {"blank": 3.0/8.0, "focus": 2.0/8.0, "evade": 3.0/8.0},
"training": {
"image_transform": XwingImgTransform(),
"lr": 0.01,
"momentum": 0.9,
"lr_reduction_steps": 30,
"total_steps": 60,
},
},
"xwing_red_gd": {
"hsv_ranges": [XWING_RED_GD_DIE_HSV_RANGE_1, XWING_RED_GD_DIE_HSV_RANGE_2],
"rect_width": 84,
"rect_height": 84,
"classes_count": 4, # blank, focus, hit, crit
"expected_distribution": {"blank": 2.0/8.0, "focus": 2.0/8.0, "hit": 3.0/8.0, "crit": 1.0/8.0},
"training": {
"image_transform": XwingImgTransform(),
"lr": 0.01,
"momentum": 0.9,
"lr_reduction_steps": 30,
"total_steps": 60,
},
},
"casino_blue": {
"hsv_ranges": [WHITE_DOTS_HSV_RANGE],
"rect_width": 100,
"rect_height": 100,
"classes_count": 6, # 1-6
"expected_distribution": {"one": 1.0/6.0, "two": 1.0/6.0, "three": 1.0/6.0, "four": 1.0/6.0, "five": 1.0/6.0, "six": 1.0/6.0},
"training": {
"image_transform": CasinoImgTransform(),
"lr": 0.01,
"momentum": 0.9,
"lr_reduction_steps": 40,
"total_steps": 80,
},
},
"d8_blue": {
"hsv_ranges": [D8_BLUE_DIE_HSV_RANGE],
"rect_width": 84,
"rect_height": 84,
"classes_count": 8, # 1-8
"expected_distribution": {"one": 1.0/8.0, "two": 1.0/8.0, "three": 1.0/8.0, "four": 1.0/8.0, "five": 1.0/8.0, "six": 1.0/8.0, "seven": 1.0/8.0, "eight": 1.0/8.0},
"training": {
"image_transform": XwingImgTransform(), # TODO
"lr": 0.01,
"momentum": 0.9,
"lr_reduction_steps": 30,
"total_steps": 120,
},
},
"generic_d6": {
"hsv_ranges": [CXD6_PINK_DIE_HSV_RANGE],
"rect_width": 84,
"rect_height": 84,
"classes_count": 6, # 1-6
"expected_distribution": {"one": 1.0/6.0, "two": 1.0/6.0, "three": 1.0/6.0, "four": 1.0/6.0, "five": 1.0/6.0, "six": 1.0/6.0},
"training": {
"image_transform": GenericD6ImgTransform(),
"lr": 0.01,
"momentum": 0.9,
"lr_reduction_steps": 30,
"total_steps": 60,
},
},
}