forked from smellslikeml/ActionAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain.py
More file actions
50 lines (39 loc) · 1.46 KB
/
Copy pathtrain.py
File metadata and controls
50 lines (39 loc) · 1.46 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Training - run this script after preprocessing your image data!
If you are on a Jetson Nano, import TRTPoseExtractor from transformer and modify the actionModel function to use this instead.
ie.
from transformer import PoseExtractor
def actionModel(classifier):
pipeline = Pipeline([
('pose_extractor', TRTPoseExtractor()),
...
])
return pipeline
"""
import pandas as pd
from sklearn.pipeline import Pipeline
from transformer import PoseExtractor
def actionModel(classifier):
pipeline = Pipeline([
('pose_extractor', PoseExtractor()),
('classifier', classifier)])
return pipeline
def trainModel(csv_path, pipeline):
df = pd.read_csv(csv_path)
X = df['image'].values
y = df['label']
pipeline = pipeline.fit(X, y)
return pipeline.get_params()['steps'][1][1]
if __name__ == '__main__':
import pickle
import argparse
import importlib
parser = argparse.ArgumentParser(description='Train pose classifier')
parser.add_argument('--config', type=str, default='conf',
help="name of config .py file inside config/ directory, default: 'conf'")
args = parser.parse_args()
config = importlib.import_module('config.' + args.config)
pipeline = actionModel(config.classifier())
model = trainModel(config.csv_path, pipeline)
# Dump the model to file
pickle.dump(model, open(config.classifier_model, 'wb'), protocol=2)