diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5356cf5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +keypoint.csv filter=lfs diff=lfs merge=lfs -text +point_history.csv filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore index 7f6b817..36055d2 100644 --- a/.gitignore +++ b/.gitignore @@ -129,3 +129,5 @@ dmypy.json .pyre/ .DS_Store + +.idea/ diff --git a/model/keypoint_classifier/keypoint.csv b/model/keypoint_classifier/keypoint.csv new file mode 100644 index 0000000..ffa81b1 --- /dev/null +++ b/model/keypoint_classifier/keypoint.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b26bd6a7cf83b5658ff19d998844a0208432ffbcf3f91acd1bbd4cd73ab54059 +size 3647517 diff --git a/model/keypoint_classifier/keypoint_classifier.hdf5 b/model/keypoint_classifier/keypoint_classifier.hdf5 new file mode 100644 index 0000000..7e022ac Binary files /dev/null and b/model/keypoint_classifier/keypoint_classifier.hdf5 differ diff --git a/model/keypoint_classifier/keypoint_classifier.py b/model/keypoint_classifier/keypoint_classifier.py new file mode 100644 index 0000000..3d05541 --- /dev/null +++ b/model/keypoint_classifier/keypoint_classifier.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import numpy as np +import tensorflow as tf + + +class KeyPointClassifier(object): + def __init__( + self, + model_path='model/keypoint_classifier/keypoint_classifier.tflite', + num_threads=1, + ): + self.interpreter = tf.lite.Interpreter(model_path=model_path, + num_threads=num_threads) + + self.interpreter.allocate_tensors() + self.input_details = self.interpreter.get_input_details() + self.output_details = self.interpreter.get_output_details() + + def __call__( + self, + landmark_list, + ): + input_details_tensor_index = self.input_details[0]['index'] + self.interpreter.set_tensor( + input_details_tensor_index, + np.array([landmark_list], dtype=np.float32)) + self.interpreter.invoke() + + output_details_tensor_index = self.output_details[0]['index'] + + result = self.interpreter.get_tensor(output_details_tensor_index) + + result_index = np.argmax(np.squeeze(result)) + + return result_index diff --git a/model/keypoint_classifier/keypoint_classifier.tflite b/model/keypoint_classifier/keypoint_classifier.tflite new file mode 100644 index 0000000..d5adccb Binary files /dev/null and b/model/keypoint_classifier/keypoint_classifier.tflite differ diff --git a/model/keypoint_classifier/keypoint_classifier_label.csv b/model/keypoint_classifier/keypoint_classifier_label.csv new file mode 100644 index 0000000..36eadbe --- /dev/null +++ b/model/keypoint_classifier/keypoint_classifier_label.csv @@ -0,0 +1,4 @@ +Open +Close +Pointer +OK diff --git a/model/point_history_classifier/point_history.csv b/model/point_history_classifier/point_history.csv new file mode 100644 index 0000000..715e74f --- /dev/null +++ b/model/point_history_classifier/point_history.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:13a9881cd5e047bd1e8317e217ad70eebf09d8635fe9b34c2f4385d016f22b0c +size 1751934 diff --git a/model/point_history_classifier/point_history_classifier.hdf5 b/model/point_history_classifier/point_history_classifier.hdf5 new file mode 100644 index 0000000..3d8cf30 Binary files /dev/null and b/model/point_history_classifier/point_history_classifier.hdf5 differ diff --git a/model/point_history_classifier/point_history_classifier.py b/model/point_history_classifier/point_history_classifier.py new file mode 100644 index 0000000..03cff40 --- /dev/null +++ b/model/point_history_classifier/point_history_classifier.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import numpy as np +import tensorflow as tf + + +class PointHistoryClassifier(object): + def __init__( + self, + model_path='model/point_history_classifier/point_history_classifier.tflite', + score_th=0.5, + invalid_value=0, + num_threads=1, + ): + self.interpreter = tf.lite.Interpreter(model_path=model_path, + num_threads=num_threads) + + self.interpreter.allocate_tensors() + self.input_details = self.interpreter.get_input_details() + self.output_details = self.interpreter.get_output_details() + + self.score_th = score_th + self.invalid_value = invalid_value + + def __call__( + self, + point_history, + ): + input_details_tensor_index = self.input_details[0]['index'] + self.interpreter.set_tensor( + input_details_tensor_index, + np.array([point_history], dtype=np.float32)) + self.interpreter.invoke() + + output_details_tensor_index = self.output_details[0]['index'] + + result = self.interpreter.get_tensor(output_details_tensor_index) + + result_index = np.argmax(np.squeeze(result)) + + if np.squeeze(result)[result_index] < self.score_th: + result_index = self.invalid_value + + return result_index diff --git a/model/point_history_classifier/point_history_classifier.tflite b/model/point_history_classifier/point_history_classifier.tflite new file mode 100644 index 0000000..7704cb2 Binary files /dev/null and b/model/point_history_classifier/point_history_classifier.tflite differ diff --git a/model/point_history_classifier/point_history_classifier_label.csv b/model/point_history_classifier/point_history_classifier_label.csv new file mode 100644 index 0000000..411a298 --- /dev/null +++ b/model/point_history_classifier/point_history_classifier_label.csv @@ -0,0 +1,4 @@ +Stop +Clockwise +Counter Clockwise +Move