Make a set of tests to do basic Lstm cell.
(options)
| 3383 | |
| 3384 | @register_make_test_function() |
| 3385 | def make_lstm_tests(options): |
| 3386 | """Make a set of tests to do basic Lstm cell.""" |
| 3387 | |
| 3388 | test_parameters = [ |
| 3389 | { |
| 3390 | "dtype": [tf.float32], |
| 3391 | "num_batchs": [1], |
| 3392 | "time_step_size": [1], |
| 3393 | "input_vec_size": [3], |
| 3394 | "num_cells": [4], |
| 3395 | "split_tflite_lstm_inputs": [False], |
| 3396 | }, |
| 3397 | ] |
| 3398 | |
| 3399 | def build_graph(parameters): |
| 3400 | """Build a simple graph with BasicLSTMCell.""" |
| 3401 | |
| 3402 | num_batchs = parameters["num_batchs"] |
| 3403 | time_step_size = parameters["time_step_size"] |
| 3404 | input_vec_size = parameters["input_vec_size"] |
| 3405 | num_cells = parameters["num_cells"] |
| 3406 | inputs_after_split = [] |
| 3407 | for i in xrange(time_step_size): |
| 3408 | one_timestamp_input = tf.placeholder( |
| 3409 | dtype=parameters["dtype"], |
| 3410 | name="split_{}".format(i), |
| 3411 | shape=[num_batchs, input_vec_size]) |
| 3412 | inputs_after_split.append(one_timestamp_input) |
| 3413 | # Currently lstm identifier has a few limitations: only supports |
| 3414 | # forget_bias == 0, inner state activation == tanh. |
| 3415 | # TODO(zhixianyan): Add another test with forget_bias == 1. |
| 3416 | # TODO(zhixianyan): Add another test with relu as activation. |
| 3417 | lstm_cell = tf.contrib.rnn.BasicLSTMCell( |
| 3418 | num_cells, forget_bias=0.0, state_is_tuple=True) |
| 3419 | cell_outputs, _ = rnn.static_rnn( |
| 3420 | lstm_cell, inputs_after_split, dtype=tf.float32) |
| 3421 | out = cell_outputs[-1] |
| 3422 | return inputs_after_split, [out] |
| 3423 | |
| 3424 | def build_inputs(parameters, sess, inputs, outputs): |
| 3425 | """Feed inputs, assign variables, and freeze graph.""" |
| 3426 | |
| 3427 | with tf.variable_scope("", reuse=True): |
| 3428 | kernel = tf.get_variable("rnn/basic_lstm_cell/kernel") |
| 3429 | bias = tf.get_variable("rnn/basic_lstm_cell/bias") |
| 3430 | kernel_values = create_tensor_data( |
| 3431 | parameters["dtype"], [kernel.shape[0], kernel.shape[1]], -1, 1) |
| 3432 | bias_values = create_tensor_data(parameters["dtype"], [bias.shape[0]], 0, |
| 3433 | 1) |
| 3434 | sess.run(tf.group(kernel.assign(kernel_values), bias.assign(bias_values))) |
| 3435 | |
| 3436 | num_batchs = parameters["num_batchs"] |
| 3437 | time_step_size = parameters["time_step_size"] |
| 3438 | input_vec_size = parameters["input_vec_size"] |
| 3439 | input_values = [] |
| 3440 | for _ in xrange(time_step_size): |
| 3441 | tensor_data = create_tensor_data(parameters["dtype"], |
| 3442 | [num_batchs, input_vec_size], 0, 1) |
nothing calls this directly
no test coverage detected