-
Notifications
You must be signed in to change notification settings - Fork 114
/
example.py
33 lines (25 loc) · 1.01 KB
/
example.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
import numpy as np
from classifiers import *
from pipeline import *
from tensorflow.keras.preprocessing.image import ImageDataGenerator
# 1 - Load the model and its pretrained weights
classifier = Meso4()
classifier.load('weights/Meso4_DF.h5')
# 2 - Minimial image generator
# We did use it to read and compute the prediction by batchs on test videos
# but do as you please, the models were trained on 256x256 images in [0,1]^(n*n)
dataGenerator = ImageDataGenerator(rescale=1./255)
generator = dataGenerator.flow_from_directory(
'test_images',
target_size=(256, 256),
batch_size=1,
class_mode='binary',
subset='training')
# 3 - Predict
X, y = generator.next()
print('Predicted :', classifier.predict(X), '\nReal class :', y)
# 4 - Prediction for a video dataset
classifier.load('weights/Meso4_F2F.h5')
predictions = compute_accuracy(classifier, 'test_videos')
for video_name in predictions:
print('`{}` video class prediction :'.format(video_name), predictions[video_name][0])