Skip to content

Commit 1752dcc

Browse files
authored
Merge pull request #130 from Pbatch/pb_onnx
Upgrade number detector to v8
2 parents 44272e2 + 3dcf599 commit 1752dcc

7 files changed

Lines changed: 20 additions & 29 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
**/__pycache__
22
.idea/
3-
clashroyalebuildabot/data/screenshots
3+
clashroyalebuildabot/screenshots
4+
clashroyalebuildabot/labels
5+
clashroyalebuildabot/logs
46
.venv
57
.vscode
68
*.egg-info

clashroyalebuildabot/data/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@
111111
KING_HP_X = 188
112112
LEFT_PRINCESS_HP_X = 74
113113
RIGHT_PRINCESS_HP_X = 266
114-
ALLY_PRINCESS_HP_Y = 401
115-
ENEMY_PRINCESS_HP_Y = 93
114+
ALLY_PRINCESS_HP_Y = 403
115+
ENEMY_PRINCESS_HP_Y = 95
116116
ALLY_KING_LEVEL_Y = 487
117117
ENEMY_KING_LEVEL_Y = 19
118118
KING_LEVEL_X = 134
-5.58 MB
Binary file not shown.

clashroyalebuildabot/state/number_detector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def run(self, image):
114114
crops[i] = self._preprocess(crop)
115115

116116
# Inference
117-
pred = self.sess.run([self.output_name], {self.input_name: crops})[0]
117+
pred = self._infer(crops.astype(np.float16)).astype(np.float32)
118118

119119
# Forced post-processing
120120
pred = self.nms(pred)

clashroyalebuildabot/state/onnx_detector.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,16 @@ def _nms(boxes, scores, thresh):
4545

4646
return keep
4747

48-
def nms(self, prediction, conf_thres=0.35, iou_thres=0.45, yolov8=False):
48+
def nms(self, prediction, conf_thres=0.35, iou_thres=0.45):
4949
"""
5050
Runs Non-Maximum Suppression (NMS) on inference results
5151
"""
5252
output = [np.zeros((0, 6))] * len(prediction)
5353
for i in range(len(prediction)):
54-
if yolov8:
55-
x = prediction[i]
56-
else:
57-
# Mask out predictions below the confidence threshold
58-
mask = prediction[i, :, 4] > conf_thres
59-
x = prediction[i][mask]
60-
61-
if not x.shape[0]:
62-
continue
54+
x = prediction[i]
6355

6456
# Calculate the best scores
65-
if yolov8:
66-
# score = class confidence
67-
scores = x[:, 4:]
68-
else:
69-
# score = object confidence * class confidence
70-
scores = x[:, 4:5] * x[:, 5:]
57+
scores = x[:, 4:]
7158
best_scores_idx = np.argmax(scores, axis=1).reshape(-1, 1)
7259
best_scores = np.take_along_axis(scores, best_scores_idx, axis=1)
7360

clashroyalebuildabot/state/unit_detector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def run(self, image):
116116
pred = self._infer(np_image.astype(np.float16)).astype(np.float32)
117117

118118
# Forced post-processing
119-
pred = np.array(self.nms(pred, yolov8=True)[0])
119+
pred = np.array(self.nms(pred)[0])
120120
pred[:, [0, 2]] *= width / UNIT_SIZE
121121
pred[:, [1, 3]] *= height / UNIT_SIZE
122122

example/windows_main.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import ctypes
33
import msvcrt
44
import time
5+
6+
from clashroyalebuildabot.data.cards import Cards
57
from custom_bot import CustomBot
68
from rich.console import Console
79
from rich.panel import Panel
@@ -128,14 +130,14 @@ def print_title(console):
128130
def start_bot():
129131
try:
130132
card_names = [
131-
"minions",
132-
"archers",
133-
"arrows",
134-
"giant",
135-
"minipekka",
136-
"fireball",
137-
"knight",
138-
"musketeer",
133+
Cards.MINIONS,
134+
Cards.ARCHERS,
135+
Cards.ARROWS,
136+
Cards.GIANT,
137+
Cards.MINIPEKKA,
138+
Cards.FIREBALL,
139+
Cards.KNIGHT,
140+
Cards.MUSKETEER,
139141
]
140142
bot = CustomBot(card_names, debug=False)
141143
bot.run()

0 commit comments

Comments
 (0)