Ejemplo n.º 1
0
 def test_Malloc2(self):
     model = keras.models.Sequential()
     model.add(
         keras.layers.Conv2D(8, (3, 3),
                             padding='same',
                             input_shape=(32, 32, 3)))
     model.add(keras.layers.Activation('tanh'))
     model.add(keras.layers.Conv2D(8, (3, 3)))
     model.add(keras.layers.Activation('relu'))
     model.add(keras.layers.MaxPooling2D(pool_size=(2, 2)))
     model.add(keras.layers.Dropout(0.25))
     model.add(keras.layers.Conv2D(8, (3, 3), padding='same'))
     model.add(keras.layers.Activation('relu'))
     model.add(keras.layers.Conv2D(8, (3, 3)))
     model.add(keras.layers.Activation('relu'))
     model.add(keras.layers.MaxPooling2D(pool_size=(2, 2)))
     model.add(keras.layers.Dropout(0.25))
     model.add(keras.layers.Flatten())
     model.add(keras.layers.Dense(20))
     model.add(keras.layers.Activation('relu'))
     model.add(keras.layers.Dropout(0.5))
     model.add(keras.layers.Dense(10))
     model.add(keras.layers.Activation('softmax'))
     name = 'test___Malloc2' + str(int(time.time()))
     keras2c_main.k2c(model, name, malloc=True)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 2
0
 def test_UpSampling3D(self):
     inshp = (4, 5, 10, 3)
     a = keras.layers.Input(inshp)
     b = keras.layers.UpSampling3D((3, 4, 2))(a)
     model = keras.models.Model(a, b)
     name = 'test___UpSampling3D' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 3
0
 def test_GlobalMaxPooling3D(self):
     inshp = (31, 21, 6, 7)
     a = keras.layers.Input(inshp)
     b = keras.layers.GlobalMaxPooling3D()(a)
     model = keras.models.Model(inputs=a, outputs=b)
     name = 'test___GlobalMaxPooling3D' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 4
0
 def test_PReLU(self):
     inshp = (3, 6, 9, 3)
     a = keras.layers.Input(inshp)
     b = keras.layers.PReLU(alpha_initializer='glorot_uniform')(a)
     model = keras.models.Model(inputs=a, outputs=b)
     name = 'test___PReLU' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 5
0
 def test_ThresholdedReLU(self):
     inshp = (3, 6, 19, 11)
     theta = 0.3
     a = keras.layers.Input(inshp)
     b = keras.layers.ThresholdedReLU(theta=theta)(a)
     model = keras.models.Model(inputs=a, outputs=b)
     name = 'test___ThresholdedReLU' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 6
0
 def test_Dense1(self):
     inshp = (21, 4, 9)
     units = 45
     a = keras.layers.Input(inshp)
     b = keras.layers.Dense(units, activation='relu')(a)
     model = keras.models.Model(inputs=a, outputs=b)
     name = 'test___Dense1' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 7
0
 def test_TimeDistributed3(self):
     model = keras.models.Sequential()
     model.add(keras.layers.Dense(10, input_shape=(8, 5)))
     model.add(keras.layers.TimeDistributed(
         keras.layers.Dense(7, use_bias=True)))
     model.build()
     name = 'test___TimeDistributed3' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 8
0
 def test_Permute(self):
     inshp = (6, 12, 9)
     a = keras.layers.Input(inshp)
     b = keras.layers.Permute((3, 1, 2))(a)
  #   c = keras.layers.Dense(20)(b)
     model = keras.models.Model(inputs=a, outputs=b)
     name = 'test___permute' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 9
0
 def test_ELU(self):
     inshp = (13, 6, 9, 13)
     alpha = 1.3
     a = keras.layers.Input(inshp)
     b = keras.layers.ELU(alpha=alpha)(a)
     model = keras.models.Model(inputs=a, outputs=b)
     name = 'test___ELU' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 10
0
 def test_Dense2_Activation(self):
     inshp = (40, 30)
     units = 500
     a = keras.layers.Input(inshp)
     b = keras.layers.Dense(units, activation='tanh', use_bias=False)(a)
     c = keras.layers.Activation('exponential')(b)
     model = keras.models.Model(inputs=a, outputs=c)
     name = 'test___Dense2' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 11
0
 def test_repeat_vector(self):
     inshp = (13,)
     a = keras.layers.Input(inshp)
     b = keras.layers.RepeatVector(23)(a)
     c = keras.layers.ActivityRegularization(l1=.5, l2=.3)(b)
     d = keras.layers.Dense(20)(c)
     model = keras.models.Model(inputs=a, outputs=d)
     name = 'test___repeat_vector' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 12
0
    def test_TimeDistributed1(self):

        inputs = keras.layers.Input(shape=(8, 5))
        outputs = keras.layers.TimeDistributed(
            keras.layers.Dense(7, use_bias=True,))(inputs)
        model = keras.models.Model(inputs, outputs)
        model.build((None, 8, 5))
        name = 'test___TimeDistributed1' + str(int(time.time()))
        keras2c_main.k2c(model, name)
        rcode = build_and_run(name)
        self.assertEqual(rcode, 0)
Ejemplo n.º 13
0
 def test_TimeDistributed6(self):
     model = keras.models.Sequential()
     model.add(keras.layers.Dense(10, input_shape=(4, 7, 8, 5)))
     model.add(keras.layers.TimeDistributed(
         keras.layers.Conv2D(7, kernel_size=2)))
     model.add(keras.layers.Dense(10))
     model.build()
     name = 'test___TimeDistributed6' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 14
0
 def test_Dropout_Reshape_Flatten(self):
     inshp = (10, 40, 30)
     a = keras.layers.Input(inshp)
     b = keras.layers.Flatten()(a)
     c = keras.layers.Dropout(.4)(b)
     d = keras.layers.Reshape((20, 30, 20))(c)
     model = keras.models.Model(inputs=a, outputs=d)
     name = 'test___flatten_dropout_reshape' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 15
0
 def test_Subtract1(self):
     inshp1 = (10, 8, 2, 3)
     inshp2 = (10, 8, 2, 3)
     a = keras.layers.Input(inshp1)
     b = keras.layers.Input(inshp2)
     c = keras.layers.Subtract()([a, b])
     model = keras.models.Model(inputs=[a, b], outputs=c)
     name = 'test___Subtract1' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 16
0
 def test_ZeroPad1D(self):
     inshp = (10, 12)
     pad_top = 3
     pad_bottom = 1
     a = keras.layers.Input(inshp)
     b = keras.layers.ZeroPadding1D(padding=(pad_top, pad_bottom))(a)
     model = keras.models.Model(inputs=a, outputs=b)
     name = 'test___ZeroPad1D' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 17
0
 def test_Cropping1D(self):
     inshp = (10, 12)
     crop_top = 3
     crop_bottom = 1
     a = keras.layers.Input(inshp)
     b = keras.layers.Cropping1D(cropping=(crop_top, crop_bottom))(a)
     model = keras.models.Model(inputs=a, outputs=b)
     name = 'test___Cropping1D' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 18
0
 def test_Bidirectional1(self):
     model = keras.models.Sequential()
     model.add(keras.layers.Bidirectional(keras.layers.LSTM(10, return_sequences=True),
                                          input_shape=(5, 10), merge_mode='concat'))
     model.add(keras.layers.Bidirectional(keras.layers.LSTM(10, return_sequences=True),
                                          merge_mode='mul'))
     model.add(keras.layers.Dense(5))
     model.build()
     name = 'test___Bidirectional1' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 19
0
 def test_Dot2(self):
     dotaxes = (2, 2)
     inshape1 = (5, 9)
     inshape2 = (9, 9)
     i1 = keras.layers.Input(inshape1)
     i2 = keras.layers.Input(inshape2)
     d = keras.layers.Dot(axes=dotaxes, normalize=True)([i1, i2])
     model = keras.models.Model(inputs=[i1, i2], outputs=d)
     name = 'test___Dot2' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 20
0
 def test_ProfilePredictor(self):
     inshp = (8, 32)
     inp = keras.layers.Input(inshp)
     a = keras.layers.Dense(20, activation='relu')(inp)
     a = keras.layers.Dense(20, activation='relu')(a)
     a = keras.layers.LSTM(20, activation='relu')(a)
     outp = keras.layers.Dense(30)(a)
     model = keras.models.Model(inp, outp)
     name = 'test___ProfilePredictor' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 21
0
 def test_Embedding1(self):
     inshp = (10, 20)
     input_dim = 20
     output_dim = 30
     a = keras.layers.Input(inshp)
     b = keras.layers.Activation('relu')(a)
     c = keras.layers.Embedding(
         input_dim=input_dim, output_dim=output_dim)(b)
     model = keras.models.Model(inputs=a, outputs=c)
     name = 'test___Embedding1' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 22
0
 def test_LSTM1(self):
     inshp = (23, 32)
     units = 19
     a = keras.layers.Input(inshp)
     b = keras.layers.LSTM(units,
                           activation='relu',
                           return_sequences=False,
                           recurrent_activation='hard_sigmoid')(a)
     model = keras.models.Model(inputs=a, outputs=b)
     name = 'test___LSTM1' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 23
0
 def test_SimpleRNN2(self):
     inshp = (34, 17)
     units = 40
     a = keras.layers.Input(inshp)
     b = keras.layers.SimpleRNN(units,
                                go_backwards=True,
                                return_sequences=True,
                                activation='tanh')(a)
     model = keras.models.Model(inputs=a, outputs=b)
     name = 'test___SimpleRNN2' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 24
0
 def test_GRU1(self):
     inshp = (12, 46)
     units = 17
     a = keras.layers.Input(inshp)
     b = keras.layers.GRU(units,
                          activation='softmax',
                          recurrent_activation='softsign',
                          return_sequences=False)(a)
     model = keras.models.Model(inputs=a, outputs=b)
     name = 'test___GRU1' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 25
0
 def test_SimpleRNN1(self):
     inshp = (4, 4, 46)
     units = 17
     a = keras.layers.Input(batch_shape=inshp)
     b = keras.layers.SimpleRNN(units,
                                activation='relu',
                                return_sequences=False,
                                stateful=True)(a)
     model = keras.models.Model(inputs=a, outputs=b)
     name = 'test___SimpleRNN1' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 26
0
def main(args=sys.argv[1:]):

    args = parse_args(args)
    if args.malloc:
        malloc = True
    else:
        malloc = False
    if args.num_tests:
        num_tests = args.num_tests
    else:
        num_tests = 10

    k2c(args.model_path, args.function_name, malloc, num_tests)
Ejemplo n.º 27
0
 def test_Add1(self):
     inshp1 = (10, 8, 12)
     inshp2 = (10, 8, 12)
     inshp3 = (10, 8, 12)
     a = keras.layers.Input(inshp1)
     b = keras.layers.Input(inshp2)
     c = keras.layers.Input(inshp3)
     d = keras.layers.Add()([a, b, c])
     model = keras.models.Model(inputs=[a, b, c], outputs=d)
     name = 'test___Add1' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 28
0
 def test_Concatenate3(self):
     inshp1 = (2, 3, 6, 3)
     inshp2 = (3, 3, 6, 3)
     inshp3 = (1, 3, 6, 3)
     axis = 1
     a = keras.layers.Input(inshp1)
     b = keras.layers.Input(inshp2)
     c = keras.layers.Input(inshp3)
     d = keras.layers.Concatenate(axis=axis)([a, b, c])
     model = keras.models.Model([a, b, c], d)
     name = 'test___Concatenate3' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 29
0
 def test_LSTM2(self):
     inshp = (4, 80)
     units = 23
     a = keras.layers.Input(inshp)
     b = keras.layers.LSTM(units,
                           go_backwards=True,
                           return_sequences=True,
                           activation='sigmoid',
                           recurrent_activation='tanh')(a)
     model = keras.models.Model(inputs=a, outputs=b)
     name = 'test___LSTM2' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)
Ejemplo n.º 30
0
 def test_ReLU(self):
     inshp = (12, 7, 9, 21)
     max_value = 1.0
     negative_slope = 1.0
     threshold = 0.3
     a = keras.layers.Input(inshp)
     b = keras.layers.ReLU(max_value=max_value,
                           negative_slope=negative_slope,
                           threshold=threshold)(a)
     model = keras.models.Model(inputs=a, outputs=b)
     name = 'test___ReLU' + str(int(time.time()))
     keras2c_main.k2c(model, name)
     rcode = build_and_run(name)
     self.assertEqual(rcode, 0)