movenet
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| movenet [2021/10/09 06:19] – créée serge | movenet [2021/12/16 09:07] (Version actuelle) – [Ressources] serge | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== MoveNet ====== | ====== MoveNet ====== | ||
| - | ** https:// | + | =====Ressources===== |
| + | | ||
| + | * https:// | ||
| + | =====Optimisation de Tensorflow ===== | ||
| + | Movenet appelle Tensorflow Lite, qui n'est pas optimisé pour GPU. Inutile d' | ||
| + | Il ne tourne que sur CPU, et demande à avoir AVX2 et FMA.\\ | ||
| + | Pour compiler Tensorflow, voir **[[linux_compiler_tensorflow_avec_bazel|]]** | ||
| + | |||
| + | Altrnatives, | ||
| + | * https:// | ||
| + | |||
| + | =====Exemple===== | ||
| + | * https:// | ||
| + | |||
| + | <file python movenet_test.py> | ||
| + | from time import time | ||
| + | import cv2 | ||
| + | import numpy as np | ||
| + | import tensorflow as tf | ||
| + | |||
| + | def draw(frame, keypoints_with_scores): | ||
| + | for item in keypoints_with_scores[0][0]: | ||
| + | if item[2] > 0.3: # confiance | ||
| + | x = int(item[1]*720) | ||
| + | y = int(item[0]*720) | ||
| + | cv2.circle(frame, | ||
| + | return frame | ||
| + | |||
| + | models = [ " | ||
| + | " | ||
| + | " | ||
| + | |||
| + | interpreter = tf.lite.Interpreter(model_path=models[0]) | ||
| + | interpreter.allocate_tensors() | ||
| + | |||
| + | cv2.namedWindow(' | ||
| + | cam = cv2.VideoCapture(2) | ||
| + | cam.set(cv2.CAP_PROP_FRAME_WIDTH, | ||
| + | cam.set(cv2.CAP_PROP_FRAME_HEIGHT, | ||
| + | |||
| + | t0 = time() | ||
| + | nbr = 0 | ||
| + | |||
| + | while 1: | ||
| + | |||
| + | nbr += 1 | ||
| + | ret, frame = cam.read() | ||
| + | |||
| + | if not ret: | ||
| + | continue | ||
| + | |||
| + | # Extraction d'une image carrée [rows, columns] | ||
| + | frame = frame[:, 280:1000] | ||
| + | |||
| + | image = tf.expand_dims(frame, | ||
| + | # Resize and pad the image to keep the aspect ratio and fit the expected size. | ||
| + | image = tf.image.resize_with_pad(image, | ||
| + | |||
| + | # TF Lite format expects tensor type of float32. | ||
| + | input_image = tf.cast(image, | ||
| + | input_details = interpreter.get_input_details() | ||
| + | output_details = interpreter.get_output_details() | ||
| + | |||
| + | interpreter.set_tensor(input_details[0][' | ||
| + | interpreter.invoke() | ||
| + | |||
| + | # Output is a [1, 1, 17, 3] numpy array. | ||
| + | keypoints_with_scores = interpreter.get_tensor(output_details[0][' | ||
| + | |||
| + | frame = draw(frame, keypoints_with_scores) | ||
| + | |||
| + | # Affichage de l' | ||
| + | cv2.imshow(' | ||
| + | |||
| + | # Calcul du FPS, affichage toutes les 10 s | ||
| + | if time() - t0 > 10: | ||
| + | print(" | ||
| + | t0, nbr = time(), 0 | ||
| + | |||
| + | # Pour quitter | ||
| + | if cv2.waitKey(1) == 27: | ||
| + | break | ||
| + | |||
| + | cv2.destroyAllWindows() | ||
| + | </ | ||
| + | |||
| + | =====Des essais amusants===== | ||
| + | * **[[https:// | ||
| + | |||
| + | |||
| + | |||
| + | {{tag> | ||
movenet.1633760387.txt.gz · Dernière modification : de serge
