wiwiewei18
commited on
Commit
•
d28974a
1
Parent(s):
05e3dfd
add source code
Browse files- .gitignore +21 -0
- Dockerfile +20 -0
- README.md +3 -3
- requirements.txt +0 -0
- run.py +3 -0
- taekwondo_motion_learning/__init__.py +33 -0
- taekwondo_motion_learning/image_classification.py +22 -0
- taekwondo_motion_learning/machine_learning/image_classification/predict.py +14 -0
- taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/args.yaml +98 -0
- taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/confusion_matrix.png +0 -0
- taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/confusion_matrix_normalized.png +0 -0
- taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/results.csv +51 -0
- taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/results.png +0 -0
- taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/train_batch0.jpg +0 -0
- taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/train_batch1.jpg +0 -0
- taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/train_batch2.jpg +0 -0
- taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/train_batch760.jpg +0 -0
- taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/train_batch761.jpg +0 -0
- taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/train_batch762.jpg +0 -0
- taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/weights/best.pt +3 -0
- taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/weights/last.pt +3 -0
- taekwondo_motion_learning/machine_learning/image_classification/train.py +10 -0
- taekwondo_motion_learning/machine_learning/image_classification/yolov8n-cls.pt +3 -0
- taekwondo_motion_learning/temp/.gitkeep +0 -0
.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.venv/
|
2 |
+
|
3 |
+
*.pyc
|
4 |
+
__pycache__/
|
5 |
+
|
6 |
+
instance/
|
7 |
+
|
8 |
+
.pytest_cache/
|
9 |
+
.coverage
|
10 |
+
htmlcov/
|
11 |
+
|
12 |
+
dist/
|
13 |
+
build/
|
14 |
+
*.egg-info/
|
15 |
+
|
16 |
+
taekwondo_motion_learning/machine_learning/image_classification/dataset/
|
17 |
+
|
18 |
+
# runs/
|
19 |
+
# yolov8n-cls.pt
|
20 |
+
# train.cache
|
21 |
+
# val.cache
|
Dockerfile
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
2 |
+
# you will also find guides on how best to write your Dockerfile
|
3 |
+
|
4 |
+
FROM python:3.9
|
5 |
+
|
6 |
+
WORKDIR /code
|
7 |
+
|
8 |
+
COPY ./requirements.txt /code/requirements.txt
|
9 |
+
|
10 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
11 |
+
|
12 |
+
RUN pip install gunicorn
|
13 |
+
|
14 |
+
RUN apt-get update && apt-get install -y libgl1-mesa-glx
|
15 |
+
|
16 |
+
COPY . .
|
17 |
+
|
18 |
+
RUN chmod 777 ./taekwondo_motion_learning/temp
|
19 |
+
|
20 |
+
CMD ["gunicorn", "-b", "0.0.0.0:7860", "run:app"]
|
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
title: Taekwondo Motion Learning
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
---
|
|
|
1 |
---
|
2 |
title: Taekwondo Motion Learning
|
3 |
+
emoji: 🏆
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: indigo
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
---
|
requirements.txt
ADDED
Binary file (82 Bytes). View file
|
|
run.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from taekwondo_motion_learning import create_app
|
2 |
+
|
3 |
+
app = create_app()
|
taekwondo_motion_learning/__init__.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask
|
2 |
+
import os
|
3 |
+
from flask_cors import CORS
|
4 |
+
|
5 |
+
def create_app(test_config=None):
|
6 |
+
# create and configure the app
|
7 |
+
app = Flask(__name__, instance_relative_config=True)
|
8 |
+
app.config.from_mapping(
|
9 |
+
SECRET_KEY='dev',
|
10 |
+
)
|
11 |
+
CORS(app)
|
12 |
+
|
13 |
+
if test_config is None:
|
14 |
+
# load the instance config, if it exists, when not testing
|
15 |
+
app.config.from_pyfile('config.py', silent=True)
|
16 |
+
else:
|
17 |
+
# load the test config if passed in
|
18 |
+
app.config.from_mapping(test_config)
|
19 |
+
|
20 |
+
# ensure the instance folder exists
|
21 |
+
try:
|
22 |
+
os.makedirs(app.instance_path)
|
23 |
+
except OSError:
|
24 |
+
pass
|
25 |
+
|
26 |
+
@app.route('/')
|
27 |
+
def index():
|
28 |
+
return 'Taekwondo Motion Learning backend app!'
|
29 |
+
|
30 |
+
from . import image_classification
|
31 |
+
app.register_blueprint(image_classification.bp)
|
32 |
+
|
33 |
+
return app
|
taekwondo_motion_learning/image_classification.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Blueprint, request
|
2 |
+
from werkzeug.utils import secure_filename
|
3 |
+
import os
|
4 |
+
import uuid
|
5 |
+
|
6 |
+
from taekwondo_motion_learning.machine_learning.image_classification import predict
|
7 |
+
|
8 |
+
bp = Blueprint('image_classification', __name__)
|
9 |
+
|
10 |
+
@bp.route('/classify-taekwondo-movement-image', methods=('POST',))
|
11 |
+
def classify_taekwondo_movement_image():
|
12 |
+
image = request.files['image']
|
13 |
+
uniqueId = uuid.uuid4()
|
14 |
+
savedImageDir = f"./taekwondo_motion_learning/temp/{secure_filename(str(uniqueId) + image.filename)}"
|
15 |
+
|
16 |
+
image.save(savedImageDir)
|
17 |
+
|
18 |
+
prediction = predict.classifyImage(savedImageDir)
|
19 |
+
|
20 |
+
os.remove(savedImageDir)
|
21 |
+
|
22 |
+
return prediction
|
taekwondo_motion_learning/machine_learning/image_classification/predict.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ultralytics import YOLO
|
2 |
+
import numpy as np
|
3 |
+
|
4 |
+
model = YOLO('./taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/weights/best.pt')
|
5 |
+
|
6 |
+
def classifyImage(image):
|
7 |
+
results = model(image)
|
8 |
+
classificationNames = results[0].names
|
9 |
+
probs = results[0].probs.data.tolist()
|
10 |
+
|
11 |
+
return {
|
12 |
+
"result": classificationNames[np.argmax(probs)],
|
13 |
+
"percentage": probs[np.argmax(probs)]*100
|
14 |
+
}
|
taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/args.yaml
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
task: classify
|
2 |
+
mode: train
|
3 |
+
model: yolov8n-cls.pt
|
4 |
+
data: ./dataset
|
5 |
+
epochs: 50
|
6 |
+
patience: 50
|
7 |
+
batch: 16
|
8 |
+
imgsz: 64
|
9 |
+
save: true
|
10 |
+
save_period: -1
|
11 |
+
cache: false
|
12 |
+
device: null
|
13 |
+
workers: 8
|
14 |
+
project: null
|
15 |
+
name: train
|
16 |
+
exist_ok: false
|
17 |
+
pretrained: true
|
18 |
+
optimizer: auto
|
19 |
+
verbose: true
|
20 |
+
seed: 0
|
21 |
+
deterministic: true
|
22 |
+
single_cls: false
|
23 |
+
rect: false
|
24 |
+
cos_lr: false
|
25 |
+
close_mosaic: 10
|
26 |
+
resume: false
|
27 |
+
amp: true
|
28 |
+
fraction: 1.0
|
29 |
+
profile: false
|
30 |
+
freeze: null
|
31 |
+
overlap_mask: true
|
32 |
+
mask_ratio: 4
|
33 |
+
dropout: 0.0
|
34 |
+
val: true
|
35 |
+
split: val
|
36 |
+
save_json: false
|
37 |
+
save_hybrid: false
|
38 |
+
conf: null
|
39 |
+
iou: 0.7
|
40 |
+
max_det: 300
|
41 |
+
half: false
|
42 |
+
dnn: false
|
43 |
+
plots: true
|
44 |
+
source: null
|
45 |
+
show: false
|
46 |
+
save_txt: false
|
47 |
+
save_conf: false
|
48 |
+
save_crop: false
|
49 |
+
show_labels: true
|
50 |
+
show_conf: true
|
51 |
+
vid_stride: 1
|
52 |
+
stream_buffer: false
|
53 |
+
line_width: null
|
54 |
+
visualize: false
|
55 |
+
augment: false
|
56 |
+
agnostic_nms: false
|
57 |
+
classes: null
|
58 |
+
retina_masks: false
|
59 |
+
boxes: true
|
60 |
+
format: torchscript
|
61 |
+
keras: false
|
62 |
+
optimize: false
|
63 |
+
int8: false
|
64 |
+
dynamic: false
|
65 |
+
simplify: false
|
66 |
+
opset: null
|
67 |
+
workspace: 4
|
68 |
+
nms: false
|
69 |
+
lr0: 0.01
|
70 |
+
lrf: 0.01
|
71 |
+
momentum: 0.937
|
72 |
+
weight_decay: 0.0005
|
73 |
+
warmup_epochs: 3.0
|
74 |
+
warmup_momentum: 0.8
|
75 |
+
warmup_bias_lr: 0.1
|
76 |
+
box: 7.5
|
77 |
+
cls: 0.5
|
78 |
+
dfl: 1.5
|
79 |
+
pose: 12.0
|
80 |
+
kobj: 1.0
|
81 |
+
label_smoothing: 0.0
|
82 |
+
nbs: 64
|
83 |
+
hsv_h: 0.015
|
84 |
+
hsv_s: 0.7
|
85 |
+
hsv_v: 0.4
|
86 |
+
degrees: 0.0
|
87 |
+
translate: 0.1
|
88 |
+
scale: 0.5
|
89 |
+
shear: 0.0
|
90 |
+
perspective: 0.0
|
91 |
+
flipud: 0.0
|
92 |
+
fliplr: 0.5
|
93 |
+
mosaic: 1.0
|
94 |
+
mixup: 0.0
|
95 |
+
copy_paste: 0.0
|
96 |
+
cfg: null
|
97 |
+
tracker: botsort.yaml
|
98 |
+
save_dir: runs\classify\train
|
taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/confusion_matrix.png
ADDED
taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/confusion_matrix_normalized.png
ADDED
taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/results.csv
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
epoch, train/loss, metrics/accuracy_top1, metrics/accuracy_top5, val/loss, lr/pg0, lr/pg1, lr/pg2
|
2 |
+
1, 0.29859, 0.34444, 1, 0.51269, 0.00012852, 0.00012852, 0.00012852
|
3 |
+
2, 0.2343, 0.51111, 1, 0.49288, 0.00025895, 0.00025895, 0.00025895
|
4 |
+
3, 0.16821, 0.47778, 1, 0.48214, 0.00038401, 0.00038401, 0.00038401
|
5 |
+
4, 0.10545, 0.47778, 1, 0.47167, 0.00050369, 0.00050369, 0.00050369
|
6 |
+
5, 0.06801, 0.5, 1, 0.46781, 0.000618, 0.000618, 0.000618
|
7 |
+
6, 0.04757, 0.57778, 1, 0.44524, 0.00064331, 0.00064331, 0.00064331
|
8 |
+
7, 0.0295, 0.58889, 1, 0.44106, 0.00064331, 0.00064331, 0.00064331
|
9 |
+
8, 0.01747, 0.56667, 1, 0.44738, 0.00062918, 0.00062918, 0.00062918
|
10 |
+
9, 0.01127, 0.6, 1, 0.442, 0.00061504, 0.00061504, 0.00061504
|
11 |
+
10, 0.01444, 0.64444, 1, 0.43844, 0.0006009, 0.0006009, 0.0006009
|
12 |
+
11, 0.00992, 0.67778, 1, 0.42865, 0.00058677, 0.00058677, 0.00058677
|
13 |
+
12, 0.00447, 0.65556, 1, 0.4159, 0.00057263, 0.00057263, 0.00057263
|
14 |
+
13, 0.00619, 0.68889, 1, 0.41002, 0.00055849, 0.00055849, 0.00055849
|
15 |
+
14, 0.00357, 0.7, 1, 0.41062, 0.00054435, 0.00054435, 0.00054435
|
16 |
+
15, 0.00721, 0.66667, 1, 0.42338, 0.00053022, 0.00053022, 0.00053022
|
17 |
+
16, 0.00325, 0.65556, 1, 0.42063, 0.00051608, 0.00051608, 0.00051608
|
18 |
+
17, 0.00573, 0.65556, 1, 0.41484, 0.00050194, 0.00050194, 0.00050194
|
19 |
+
18, 0.00326, 0.62222, 1, 0.42821, 0.0004878, 0.0004878, 0.0004878
|
20 |
+
19, 0.00296, 0.62222, 1, 0.43008, 0.00047367, 0.00047367, 0.00047367
|
21 |
+
20, 0.00593, 0.6, 1, 0.43857, 0.00045953, 0.00045953, 0.00045953
|
22 |
+
21, 0.00342, 0.6, 1, 0.44251, 0.00044539, 0.00044539, 0.00044539
|
23 |
+
22, 0.00599, 0.6, 1, 0.44457, 0.00043126, 0.00043126, 0.00043126
|
24 |
+
23, 0.00342, 0.61111, 1, 0.43735, 0.00041712, 0.00041712, 0.00041712
|
25 |
+
24, 0.00359, 0.62222, 1, 0.43189, 0.00040298, 0.00040298, 0.00040298
|
26 |
+
25, 0.00847, 0.61111, 1, 0.44664, 0.00038884, 0.00038884, 0.00038884
|
27 |
+
26, 0.00352, 0.63333, 1, 0.44122, 0.00037471, 0.00037471, 0.00037471
|
28 |
+
27, 0.00746, 0.62222, 1, 0.43953, 0.00036057, 0.00036057, 0.00036057
|
29 |
+
28, 0.00447, 0.61111, 1, 0.44261, 0.00034643, 0.00034643, 0.00034643
|
30 |
+
29, 0.00161, 0.57778, 1, 0.44196, 0.0003323, 0.0003323, 0.0003323
|
31 |
+
30, 0.00181, 0.61111, 1, 0.43578, 0.00031816, 0.00031816, 0.00031816
|
32 |
+
31, 0.0025, 0.62222, 1, 0.43366, 0.00030402, 0.00030402, 0.00030402
|
33 |
+
32, 0.00153, 0.62222, 1, 0.42898, 0.00028988, 0.00028988, 0.00028988
|
34 |
+
33, 0.00136, 0.6, 1, 0.43659, 0.00027575, 0.00027575, 0.00027575
|
35 |
+
34, 0.00152, 0.62222, 1, 0.43015, 0.00026161, 0.00026161, 0.00026161
|
36 |
+
35, 0.00183, 0.64444, 1, 0.42306, 0.00024747, 0.00024747, 0.00024747
|
37 |
+
36, 0.00155, 0.65556, 1, 0.42204, 0.00023334, 0.00023334, 0.00023334
|
38 |
+
37, 0.00124, 0.62222, 1, 0.43082, 0.0002192, 0.0002192, 0.0002192
|
39 |
+
38, 0.00343, 0.61111, 1, 0.42536, 0.00020506, 0.00020506, 0.00020506
|
40 |
+
39, 0.00264, 0.65556, 1, 0.41905, 0.00019092, 0.00019092, 0.00019092
|
41 |
+
40, 0.00499, 0.63333, 1, 0.42504, 0.00017679, 0.00017679, 0.00017679
|
42 |
+
41, 0.0033, 0.63333, 1, 0.42549, 0.00016265, 0.00016265, 0.00016265
|
43 |
+
42, 0.00221, 0.64444, 1, 0.42047, 0.00014851, 0.00014851, 0.00014851
|
44 |
+
43, 0.00219, 0.62222, 1, 0.42583, 0.00013437, 0.00013437, 0.00013437
|
45 |
+
44, 0.00073, 0.63333, 1, 0.43109, 0.00012024, 0.00012024, 0.00012024
|
46 |
+
45, 0.00217, 0.62222, 1, 0.4301, 0.0001061, 0.0001061, 0.0001061
|
47 |
+
46, 0.00246, 0.64444, 1, 0.42774, 9.1963e-05, 9.1963e-05, 9.1963e-05
|
48 |
+
47, 0.00104, 0.6, 1, 0.43763, 7.7826e-05, 7.7826e-05, 7.7826e-05
|
49 |
+
48, 0.00284, 0.58889, 1, 0.44167, 6.3689e-05, 6.3689e-05, 6.3689e-05
|
50 |
+
49, 0.00057, 0.58889, 1, 0.44289, 4.9552e-05, 4.9552e-05, 4.9552e-05
|
51 |
+
50, 0.00053, 0.58889, 1, 0.4336, 3.5414e-05, 3.5414e-05, 3.5414e-05
|
taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/results.png
ADDED
taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/train_batch0.jpg
ADDED
taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/train_batch1.jpg
ADDED
taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/train_batch2.jpg
ADDED
taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/train_batch760.jpg
ADDED
taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/train_batch761.jpg
ADDED
taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/train_batch762.jpg
ADDED
taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/weights/best.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f51a2bfb08564c93fa587a5038e8fae26b3a150bb7ba266195e68a2ad9fdca90
|
3 |
+
size 2964747
|
taekwondo_motion_learning/machine_learning/image_classification/runs/classify/train/weights/last.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:38047e7a80381d8a6f43cf7c6d7590f34d8c326a5464908c8fac19636b50640b
|
3 |
+
size 2966859
|
taekwondo_motion_learning/machine_learning/image_classification/train.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ultralytics import YOLO, settings
|
2 |
+
import shutil
|
3 |
+
|
4 |
+
shutil.rmtree('./runs', ignore_errors=True)
|
5 |
+
|
6 |
+
settings.update({'runs_dir': './runs'})
|
7 |
+
|
8 |
+
model = YOLO('yolov8n-cls.pt') # Pretrained model (recommended for training)
|
9 |
+
|
10 |
+
model.train(data='./dataset', epochs=50, imgsz=64)
|
taekwondo_motion_learning/machine_learning/image_classification/yolov8n-cls.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f5079cd980628313a2e62cd09d358e5c8debf0d8f75b6e8be7973d94e3a5da9f
|
3 |
+
size 5533216
|
taekwondo_motion_learning/temp/.gitkeep
ADDED
File without changes
|