-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest.py
52 lines (39 loc) · 1.39 KB
/
test.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
52
# Auto-encoder testing code
import numpy as np
from keras.models import Model
from keras.layers import Input, Conv3D, MaxPooling3D, UpSampling3D
from keras.callbacks import TensorBoard
import matplotlib.pyplot as plt
import h5py
from dataset.disp_fig import disp_fig
import random
input_vid = Input(shape=(8, 152, 152, 1))
# Encoder
x = Conv3D(5, (3, 3, 3), activation='relu', padding='same')(input_vid)
x = MaxPooling3D((2, 2, 2), padding='same')(x)
x = Conv3D(5, (3, 3, 3), activation='relu', padding='same')(x)
encoded = MaxPooling3D((2, 2, 2), padding='same')(x)
# Video Encoded
# Decoder
x = Conv3D(5, (3, 3, 3), activation='relu', padding='same')(encoded)
x = UpSampling3D((2, 2, 2))(x)
x = Conv3D(5, (3, 3, 3), activation='relu', padding='same')(x)
x = UpSampling3D((2, 2, 2))(x)
decoded = Conv3D(1, (3, 3, 3), activation='sigmoid', padding='same')(x)
autoencoder = Model(input_vid, decoded)
autoencoder.compile(optimizer='adam', loss='mean_squared_error')
# Print autoencoder details
autoencoder.summary()
# Load model weights
autoencoder.load_weights('autoencoder_weights.h5')
# Get any 50th video to test
with h5py.File('./X_train/49.h5', 'r') as hf:
X_test = hf['49'][:]
# Get decoded video frames from autoencoder
decoded_imgs = autoencoder.predict(X_test)
# Display source and decoded video frames
disp = disp_fig(X_test)
disp.figure()
disp = disp_fig(decoded_imgs)
disp.figure()
plt.show()