MCPcopy Create free account
hub / github.com/commaai/research / get_model

Function get_model

models/conditional.py:46–149  ·  view source on GitHub ↗
(sess, image_shape=(80, 160, 3), gf_dim=64, df_dim=64, batch_size=64,
              name="transition", gpu=0)

Source from the content-addressed store, hash-verified

44
45
46def get_model(sess, image_shape=(80, 160, 3), gf_dim=64, df_dim=64, batch_size=64,
47 name="transition", gpu=0):
48 K.set_session(sess)
49 checkpoint_dir = './results_' + name
50 with tf.variable_scope(name):
51 # sizes
52 ch = image_shape[2]
53 rows = [image_shape[0]/i for i in [16, 8, 4, 2, 1]]
54 cols = [image_shape[1]/i for i in [16, 8, 4, 2, 1]]
55
56 G = autoencoder.generator(batch_size*out_leng, gf_dim, ch, rows, cols)
57 G.compile("sgd", "mse")
58 E = autoencoder.encoder(batch_size*(time+out_leng), df_dim, ch, rows, cols)
59 E.compile("sgd", "mse")
60
61 G.trainable = False
62 E.trainable = False
63
64 # nets
65 T = transition(batch_size)
66 T.compile("sgd", "mse")
67 t_vars = T.trainable_weights
68 print "T.shape: ", T.output_shape
69
70 Img = Input(batch_shape=(batch_size, time+out_leng,) + image_shape)
71 Z = Input(batch_shape=(batch_size, time+out_leng, 2)) # controls signal
72 I = K.reshape(Img, (batch_size*(time+out_leng),)+image_shape)
73 code = E(I)[0]
74 code = K.reshape(code, (batch_size, time+out_leng, z_dim))
75 inp = K.concatenate([Z, code], axis=2)
76 target = code[:, time:, :]
77 out = T(inp)
78 G_dec = G(K.reshape(out, (batch_size*out_leng, z_dim)))
79
80 # costs
81 loss = tf.reduce_mean(tf.square(target - out))
82 print "Transition variables:"
83 for v in t_vars:
84 print v.name
85
86 t_optim = tf.train.AdamOptimizer(learning_rate, beta1=beta1).minimize(loss, var_list=t_vars)
87
88 tf.initialize_all_variables().run()
89
90 # summaries
91 sum_loss = tf.scalar_summary("loss", loss)
92 sum_e_mean = tf.histogram_summary("e_mean", code)
93 sum_out = tf.histogram_summary("out", out)
94 sum_dec = tf.image_summary("E", G_dec)
95
96 # saver
97 saver = tf.train.Saver()
98 t_sum = tf.merge_summary([sum_e_mean, sum_out, sum_dec, sum_loss])
99 writer = tf.train.SummaryWriter("/tmp/logs/"+name, sess.graph)
100
101 # functions
102 def train_d(images, z, counter, sess=sess):
103 return 0, 0, 0

Callers

nothing calls this directly

Calls 1

transitionFunction · 0.70

Tested by

no test coverage detected