def test_unidirectional_lstm_converter(self): input_dim = (1, 8) output_dim = (1, 2) inputs = [('input', datatypes.Array(*input_dim))] outputs = [('output', datatypes.Array(*output_dim))] builder = NeuralNetworkBuilder(inputs, outputs) W_h = [ numpy.random.rand(2, 2), numpy.random.rand(2, 2), numpy.random.rand(2, 2), numpy.random.rand(2, 2) ] W_x = [ numpy.random.rand(2, 8), numpy.random.rand(2, 8), numpy.random.rand(2, 8), numpy.random.rand(2, 8) ] b = [ numpy.random.rand(2, 1), numpy.random.rand(2, 1), numpy.random.rand(2, 1), numpy.random.rand(2, 1) ] p = [ numpy.zeros(shape=(2, 1)), numpy.zeros(shape=(2, 1)), numpy.zeros(shape=(2, 1)) ] builder.add_unilstm(name='LSTM', W_h=W_h, W_x=W_x, b=b, hidden_size=2, input_size=8, input_names=['input'], output_names=['output'], inner_activation='SIGMOID', cell_state_update_activation='TANH', output_activation='TANH', peep=p, output_all=False, forget_bias=False, coupled_input_forget_gate=False, cell_clip_threshold=10000, reverse_input=False) context = ConvertContext() node = UniDirectionalLSTMLayerConverter.convert( context, builder.spec.neuralNetwork.layers[0], ['input', 'h_init', 'c_init'], ['output', 'h', 'c']) self.assertTrue(node is not None)
def test_unidirectional_lstm_converter(self): input_dim = (1, 8) output_dim = (1, 2) inputs = [('input', datatypes.Array(*input_dim))] outputs = [('output', datatypes.Array(*output_dim))] builder = NeuralNetworkBuilder(inputs, outputs) W_h = [ numpy.random.rand(2, 2), numpy.random.rand(2, 2), numpy.random.rand(2, 2), numpy.random.rand(2, 2) ] W_x = [ numpy.random.rand(2, 8), numpy.random.rand(2, 8), numpy.random.rand(2, 8), numpy.random.rand(2, 8) ] b = [ numpy.random.rand(2, 1), numpy.random.rand(2, 1), numpy.random.rand(2, 1), numpy.random.rand(2, 1) ] p = [ numpy.zeros(shape=(2, 1)), numpy.zeros(shape=(2, 1)), numpy.zeros(shape=(2, 1)) ] builder.add_unilstm(name='LSTM', W_h=W_h, W_x=W_x, b=b, hidden_size=2, input_size=8, input_names=['input'], output_names=['output'], inner_activation='SIGMOID', cell_state_update_activation='TANH', output_activation='TANH', peep=p, output_all=False, forget_bias=False, coupled_input_forget_gate=False, cell_clip_threshold=10000, reverse_input=False) model_onnx = convert_coreml(builder.spec) self.assertTrue(model_onnx is not None)