forked from ClarityCoders/Fall-Guys-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
training.py
36 lines (28 loc) · 1023 Bytes
/
training.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
from fastai.vision.all import *
import time
import cv2
from utils.grabscreen import grab_screen
def label_func(x): return x.parent.name
def run():
path = Path("E:/DoorDash/")
fnames = get_image_files(path)
print(f"Total Images:{len(fnames)}")
dls = ImageDataLoaders.from_path_func(path, fnames, label_func,bs=40, num_workers=0)
learn = cnn_learner(dls, resnet18, metrics=error_rate)
print("Loaded")
learn.fine_tune(4, base_lr=1.0e-02)
learn.export()
# start_time = time.time()
# test = learn.predict('g1-j5.png')
# print("--- %s seconds ---" % (time.time() - start_time))
# print(test)
start_time = time.time()
image = grab_screen(region=(50, 100, 799, 449))
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image = cv2.Canny(image, threshold1=200, threshold2=300)
image = cv2.resize(image, (224, 224))
test = learn.predict(image)
print("--- %s seconds ---" % (time.time() - start_time))
print(test)
if __name__ == '__main__':
run()