Merge branch 'master' of github.com:Tocard-Inc/Deep-Learning

This commit is contained in:
Laureηt 2022-04-13 09:14:11 +02:00
commit fb68c035cb
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
4 changed files with 57 additions and 6 deletions

View file

@ -11,5 +11,5 @@
"source.organizeImports": true "source.organizeImports": true
} }
}, },
"jupyter.jupyterServerType": "remote" "jupyter.jupyterServerType": "local"
} }

40
src/live.py Normal file
View file

@ -0,0 +1,40 @@
import subprocess
import numpy as np
import PIL
import ppadb.client
import ppadb.command.serial
import ppadb.device
import tensorflow
from keras import models
import utils
RESIZED_SIZE = (100, 50, 3)
LABELS = ['octane', 'werewolf', 'breakout', 'aftershock']
# Load model
model = models.load_model('../models/model')
utils.startup(need_focus=False)
running = True
while running:
utils.screenshot(filename='live', folder='../models')
# Lecture de l'image
img = PIL.Image.open('../models/live')
# print(f"img.size = {img.size}")
# Redimensionnement de l'image
img = img.resize(RESIZED_SIZE[:-1], PIL.Image.ANTIALIAS)
# print(f"img.size = {img.size}")
X = np.asarray(img)
Y = model.evaluate(X)
print(f"Model detected : {LABELS[Y]}")

View file

@ -549,6 +549,16 @@
"\n", "\n",
"plot_training_analysis()\n" "plot_training_analysis()\n"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Save the weights\n",
"model.save('../models/model')"
]
} }
], ],
"metadata": { "metadata": {

View file

@ -118,7 +118,7 @@ def start_scrpy() -> None:
) )
def startup() -> None: def startup(need_focus=True) -> None:
subprocess.call(("sudo modprobe v4l2loopback").split()) subprocess.call(("sudo modprobe v4l2loopback").split())
@ -127,7 +127,7 @@ def startup() -> None:
users = detect_game(device, users) users = detect_game(device, users)
start_game(device, users) start_game(device, users)
while not (is_zen_mode(device) and is_focused(device) and is_v4l2_loaded()): while need_focus and not (is_zen_mode(device) and is_focused(device) and is_v4l2_loaded()):
time.sleep(DELAY_DETECT) time.sleep(DELAY_DETECT)
time.sleep(DELAY_DETECT) time.sleep(DELAY_DETECT)
@ -135,11 +135,12 @@ def startup() -> None:
start_scrpy() start_scrpy()
def screenshot() -> uuid.UUID: def screenshot(filename=None, folder=DATA_FOLDER) -> uuid.UUID:
if filename == None:
filename = uuid.uuid1() filename = uuid.uuid1()
subprocess.Popen( subprocess.Popen(
f"ffmpeg -f video4linux2 -i /dev/video2 -frames:v 1 -filter:v crop=400:150:45:30 {DATA_FOLDER}/{filename}.jpg".split(), f"ffmpeg -f video4linux2 -i /dev/video2 -frames:v 1 -filter:v crop=400:150:45:30 {folder}/{filename}.jpg".split(),
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
) )