如何将此代码从千层面转换为keras模型?

时间:2019-04-11 14:55:58

标签: python tensorflow keras theano lasagne

我正在尝试将用千层面写的https://github.com/YerevaNN/Spoken-language-identification/blob/master/theano/networks/tc_net_rnn_onernn.py中的代码转换为我在keras中的模型。

我目前在喀拉拉邦的模特是

input1 = Input(shape=input_shape_stft)

conv1=Conv2D(16, kernel_size=(7,7), strides=1, activation='relu')(input1)
pool1=MaxPooling2D(pool_size=(3,3), strides=2)(conv1)

conv2=Conv2D(32, kernel_size=(5,5), strides=1, activation='relu')(pool1)
pool2=MaxPooling2D(pool_size=(3,3), strides=2)(conv2)

conv3=Conv2D(32, kernel_size=(3,3), strides=1, activation='relu')(pool2)
pool3=MaxPooling2D(pool_size=(3,3), strides=2)(conv3)

conv4=Conv2D(32, kernel_size=(3,3), strides=1, activation='relu')(pool3)
pool4=MaxPooling2D(pool_size=(3,3), strides=2)(conv4)

permute=Permute((3,1,2))(pool4)

我正在尝试添加此代码

network = layers.MaxPool2DLayer(incoming=network, pool_size=(3, 3), stride=2, pad=2)

output = layers.get_output(network)
output = output.transpose((0, 3, 1, 2))
########up to here it is my code###########

output = output.flatten(ndim=3)

        # NOTE: these constants are shapes of last pool layer, it can be symbolic 
        # explicit values are better for optimizations
num_channels = 32 
filter_W = 54
filter_H = 8


        # InputLayer       
network = layers.InputLayer(shape=(None, filter_W, num_channels * filter_H), input_var=output)

        # GRULayer
network = layers.GRULayer(incoming=network, num_units=self.num_units, only_return_final=True)

        # Last layer: classification
network = layers.DenseLayer(incoming=network, num_units=176, nonlinearity=softmax)

但是我对维数(从theano到tensorflow)以及从Lasagne到Keras的TransposeFlatten层感到困惑。

谁编写了代码,还提供了此架构图像https://github.com/YerevaNN/yerevann.github.io/blob/master/public/2016-06-26/cnn-one-rnn.png

谢谢。

0 个答案:

没有答案