-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathutil.py
37 lines (25 loc) · 777 Bytes
/
util.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
import audiovisual_stream
import chainer.serializers
import librosa
import numpy
import skvideo.io
def load_audio(data):
return librosa.load(data, 16000)[0][None, None, None, :]
def load_model():
model = audiovisual_stream.ResNet18().to_gpu()
chainer.serializers.load_npz('./model', model)
return model
def load_video(data):
videoCapture = skvideo.io.VideoCapture(data, (456, 256))
videoCapture.open()
x = []
while True:
retval, image = videoCapture.read()
if retval:
x.append(numpy.rollaxis(image, 2))
else:
break
return numpy.array(x, 'float32')
def predict_trait(data, model):
x = [load_audio(data), load_video(data)]
return model(x)