-
Notifications
You must be signed in to change notification settings - Fork 9
/
model_interpreter_test.py
110 lines (81 loc) · 4.01 KB
/
model_interpreter_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import numpy as np
import tensorflow as tf
import tensorflow.contrib.slim as slim
import network_utils as nut
import utils as ut
import re
import os
from Bunch import Bunch
from model_interpreter import *
def _log_graph():
path = '/tmp/interpreter'
with tf.Session() as sess:
tf.global_variables_initializer()
tf.summary.FileWriter(path, sess.graph)
ut.print_color(os.path.abspath(path), color=33)
def _test_parameter_reuse_conv():
input = tf.placeholder(tf.float32, (2, 120, 120, 4), name='input')
model = build_autoencoder(input, '8c3s2-16c3s2-32c3s2-1c3-f4')
input = tf.placeholder(tf.float32, (2, 120, 120, 4), name='input')
model = build_autoencoder(input, '8c3s2-16c3s2-32c3s2-1c3-f4')
l2_loss(input, model.decode)
input = tf.placeholder(tf.float32, (2, 120, 120, 4), name='input')
model = build_autoencoder(input, model.config)
l2_loss(input, model.decode)
def _test_parameter_reuse_decoder():
input = tf.placeholder(tf.float32, (2, 120, 120, 4), name='input')
model = build_autoencoder(input, '8c3s2-16c3s2-32c3s2-16c3-f4')
input = tf.placeholder(tf.float32, (2, 120, 120, 4), name='input')
model = build_autoencoder(input, '8c3s2-16c3s2-32c3s2-16c3-f4')
input_enc = tf.placeholder(tf.float32, (2, 120, 120, 4), name='input_encoder')
encoder = build_encoder(input_enc, model.config, reuse=True)
input_dec = tf.placeholder(tf.float32, (2, 4), name='input_decoder')
decoder = build_decoder(input_dec, model.config, reuse=True)
l2_loss(input, model.decode)
l2_loss(encoder, model.encode)
l2_loss(decoder, model.decode)
def _test_armgax_ae():
input = tf.placeholder(tf.float32, (2, 120, 120, 4), name='input')
model = build_autoencoder(input, '8c3-ap2-16c3-ap2-32c3-ap2-16c3-f4')
input = tf.placeholder(tf.float32, (2, 120, 120, 4), name='input')
model = build_autoencoder(input, '8c3-ap2-16c3-ap2-32c3-ap2-16c3-f4')
input_enc = tf.placeholder(tf.float32, (2, 120, 120, 4), name='input_encoder')
encoder = build_encoder(input_enc, model.config, reuse=True)
input_dec = tf.placeholder(tf.float32, (2, 4), name='input_decoder')
decoder = build_decoder(input_dec, model.config, reuse=True)
l2_loss(input, model.decode)
l2_loss(encoder, model.encode)
l2_loss(decoder, model.decode)
def _test_multiple_decoders_unpool_wiring():
input = tf.placeholder(tf.float32, (2, 16, 16, 3), name='input')
model1 = build_autoencoder(input, '8c3-ap2-f4')
model2 = build_autoencoder(input, model1.config)
enc_1 = tf.placeholder(tf.float32, (2, 4), name='enc_1')
enc_2 = tf.placeholder(tf.float32, (2, 4), name='enc_2')
decoder1 = build_decoder(enc_1, model1.config, reuse=True, masks=model1.mask_list)
decoder2 = build_decoder(enc_2, model2.config, reuse=True, masks=model2.mask_list)
def _visualize_models():
input = tf.placeholder(tf.float32, (128, 160, 120, 4), name='input_fc')
model = build_autoencoder(input, 'f100-f3')
loss= l2_loss(input, model.decode, name='Loss_reconstruction_FC')
input = tf.placeholder(tf.float32, (128, 160, 120, 4), name='input_conv')
model = build_autoencoder(input, '16c3s2-32c3s2-32c3s2-16c3-f3')
loss= l2_loss(input, model.decode, name='Loss_reconstruction_conv')
input = tf.placeholder(tf.float32, (128, 160, 120, 4), name='input_wwae')
model = build_autoencoder(input, '16c3-ap2-32c3-ap2-16c3-f3')
loss= l2_loss(input, model.decode, name='Loss_reconstruction_WWAE')
def _test_stacked_ae():
input = tf.placeholder(tf.float32, (2, 16, 16, 3), name='input')
model1 = build_autoencoder(input, 'f500-f100-f5')
losses = build_stacked_losses(model1)
if __name__ == '__main__':
# print(re.match('\d+c\d+(s\d+)?[r|s|i|t]?', '8c3s2'))
# model = build_autoencoder(tf.placeholder(tf.float32, (2, 16, 16, 3), name='input'), '8c3s2-16c3s2-30c3s2-16c3-f4')
# _test_multiple_decoders_unpool_wiring()
# _visualize_models()
x = _test_stacked_ae()
# build_autoencoder(tf.placeholder(tf.float32, (2, 16, 16, 3), name='input'), '10c3-f100-f10')
# _test_parameter_reuse_conv()
# _test_parameter_reuse_decoder()
# _test_armgax_ae()
_log_graph()