works but it need cleaning
This commit is contained in:
@@ -2,6 +2,7 @@ import keras
|
||||
import numpy as np
|
||||
from keras.models import Sequential
|
||||
from keras.layers import Input, Dense, Activation, Flatten, Dropout, ELU, Reshape, Lambda, Conv1D
|
||||
from keras.layers import Bidirectional, CuDNNLSTM
|
||||
from keras.layers.convolutional import Convolution2D, Convolution3D
|
||||
from keras.layers.pooling import MaxPooling2D, MaxPooling3D, AveragePooling3D
|
||||
from keras.models import Sequential, Model
|
||||
@@ -17,9 +18,11 @@ def bin_write(f, data):
|
||||
f.write(bin)
|
||||
|
||||
def create_model():
|
||||
x1 = Input((6, 16), name='x1')
|
||||
x1 = Input((3, 8), name='x1')
|
||||
conv = Conv1D(4, 2)(x1)
|
||||
model = Model([x1], [conv])
|
||||
lstm = Bidirectional(CuDNNLSTM(5, return_sequences=True))(conv)
|
||||
lstm2 = Bidirectional(CuDNNLSTM(5, return_sequences=False))(lstm)
|
||||
model = Model([x1], [lstm2])
|
||||
model.summary()
|
||||
|
||||
return model
|
||||
@@ -30,14 +33,16 @@ if __name__ == '__main__':
|
||||
model = create_model()
|
||||
model.save("net.hdf5")
|
||||
|
||||
x = np.random.rand(1,1,6,16)
|
||||
np.random.seed(2)
|
||||
x = np.random.rand(1,1,3,8)
|
||||
r = model.predict( x[0], batch_size=1)
|
||||
r = np.array([r])
|
||||
|
||||
r = np.array([r])
|
||||
x = x.transpose(0, 3, 1, 2)
|
||||
r = r.transpose(0, 3, 1, 2)
|
||||
#r = r.transpose(0, 3, 1, 2)
|
||||
print("in: ", np.shape(x))
|
||||
print("out: ", np.shape(r))
|
||||
print("output: ", r.tolist())
|
||||
|
||||
x = np.array(x.flatten(), dtype=np.float32)
|
||||
f = open("input.bin", mode='wb')
|
||||
|
||||
@@ -3,14 +3,20 @@
|
||||
|
||||
const char *input_bin = "../tests/simple/input.bin";
|
||||
const char *c0_bin = "../tests/simple/layers/conv1d_1.bin";
|
||||
const char *l1_bin = "../tests/simple/layers/bidirectional_1.bin";
|
||||
const char *l2_bin = "../tests/simple/layers/bidirectional_2.bin";
|
||||
const char *output_bin = "../tests/simple/output.bin";
|
||||
|
||||
int main() {
|
||||
|
||||
// Network layout
|
||||
tk::dnn::dataDim_t dim(1, 16, 1, 6);
|
||||
tk::dnn::dataDim_t dim(1, 8, 1, 3);
|
||||
tk::dnn::Network net(dim);
|
||||
tk::dnn::Conv2d l0(&net, 4, 1, 2, 1, 1, 0, 0, c0_bin);
|
||||
tk::dnn::LSTM l1(&net, 5, true, l1_bin);
|
||||
tk::dnn::LSTM l2(&net, 5, false, l2_bin);
|
||||
|
||||
net.print();
|
||||
|
||||
// Load input
|
||||
dnnType *data;
|
||||
|
||||
Reference in New Issue
Block a user