This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathtrain_pace_network.py
51 lines (44 loc) · 1.69 KB
/
train_pace_network.py
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
51
# Copyright (c) 2018-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
import torch
from long_term.pace_network import PaceNetwork
from long_term.dataset_locomotion import dataset, actions_valid
from long_term.locomotion_utils import build_extra_features, compute_splines
torch.manual_seed(1234)
if __name__ == '__main__':
dataset.compute_positions()
build_extra_features(dataset)
compute_splines(dataset)
model = PaceNetwork()
if torch.cuda.is_available():
model.cuda()
chunk_length = 1000
batch_size = 40
sequences_train = []
sequences_valid = []
n_discarded = 0
for subject in dataset.subjects():
for action in dataset[subject].keys():
if 'sidestep' in action:
# We don't really want those
continue
if dataset[subject][action]['spline'].size() < chunk_length:
n_discarded += 1
continue
train = True
for action_valid in actions_valid:
if action.startswith(action_valid):
train = False
break
if train:
sequences_train.append((subject, action))
else:
sequences_valid.append((subject, action))
print('%d sequences were discarded for being too short.' % n_discarded)
print('Training on %d sequences, validating on %d sequences.' % (len(sequences_train), len(sequences_valid)))
model.train(dataset, sequences_train, sequences_valid, batch_size, chunk_length)
model.save_weights('weights_pace_network.bin')