Embed all given tensors into an nfeatures-dim space.
(self, x, nfeatures=2)
| 198 | |
| 199 | class EmbeddingModel(ModelDesc): |
| 200 | def embed(self, x, nfeatures=2): |
| 201 | """Embed all given tensors into an nfeatures-dim space. """ |
| 202 | list_split = 0 |
| 203 | if isinstance(x, list): |
| 204 | list_split = len(x) |
| 205 | x = tf.concat(x, 0) |
| 206 | |
| 207 | # pre-process MNIST dataflow data |
| 208 | x = tf.expand_dims(x, 3) |
| 209 | x = x * 2 - 1 |
| 210 | |
| 211 | # the embedding network |
| 212 | net = slim.layers.conv2d(x, 20, 5, scope='conv1') |
| 213 | net = slim.layers.max_pool2d(net, 2, scope='pool1') |
| 214 | net = slim.layers.conv2d(net, 50, 5, scope='conv2') |
| 215 | net = slim.layers.max_pool2d(net, 2, scope='pool2') |
| 216 | net = slim.layers.flatten(net, scope='flatten3') |
| 217 | net = slim.layers.fully_connected(net, 500, scope='fully_connected4') |
| 218 | embeddings = slim.layers.fully_connected(net, nfeatures, activation_fn=None, scope='fully_connected5') |
| 219 | |
| 220 | # if "x" was a list of tensors, then split the embeddings |
| 221 | if list_split > 0: |
| 222 | embeddings = tf.split(embeddings, list_split, 0) |
| 223 | |
| 224 | return embeddings |
| 225 | |
| 226 | def optimizer(self): |
| 227 | lr = tf.get_variable('learning_rate', initializer=1e-4, trainable=False) |
no outgoing calls
no test coverage detected