bobby_jiang 发表于 2019-5-17 11:58
你按我的建议先做一下吧,目的是保证你的输入长和宽数据送入卷积。
这个方式我之前验证过可行的。 ...
Hhhhlnlnlnh 发表于 2019-5-18 23:04
我将模型的变成320000,再模型内部做reshape到(1600,200,1),这样转换之后pb模型可以正常使用,但rknn模型i ...
bobby_jiang 发表于 2019-5-21 10:30
你现在用的rknn-toolkit是什么版本?
另外,你把原始模型和rknn模型,还有代码都贴上来。 ...
- input_data = Input(name='the_input', shape=(320000, 1), dtype='float32')
- input_wavImage = Reshape((1600, 200, 1), name='Reshape')(input_data)
- layer_h1 = Conv2D(32, (3,3), use_bias=False, activation='relu', padding='same', kernel_initializer='he_normal')(input_wavImage) # 卷积层
- layer_h1 = Dropout(0.05)(layer_h1)
- layer_h2 = Conv2D(32, (3,3), use_bias=True, activation='relu', padding='same', kernel_initializer='he_normal')(layer_h1) # 卷积层
- layer_h3 = MaxPooling2D(pool_size=2, strides=None, padding="valid")(layer_h2) # 池化层
- #layer_h3 = Dropout(0.2)(layer_h2) # 随机中断部分神经网络连接,防止过拟合
- layer_h3 = Dropout(0.05)(layer_h3)
- layer_h4 = Conv2D(64, (3,3), use_bias=True, activation='relu', padding='same', kernel_initializer='he_normal')(layer_h3) # 卷积层
- layer_h4 = Dropout(0.1)(layer_h4)
- layer_h5 = Conv2D(64, (3,3), use_bias=True, activation='relu', padding='same', kernel_initializer='he_normal')(layer_h4) # 卷积层
- layer_h6 = MaxPooling2D(pool_size=2, strides=None, padding="valid")(layer_h5) # 池化层
- layer_h6 = Dropout(0.1)(layer_h6)
- layer_h7 = Conv2D(128, (3,3), use_bias=True, activation='relu', padding='same', kernel_initializer='he_normal')(layer_h6) # 卷积层
- layer_h7 = Dropout(0.15)(layer_h7)
- layer_h8 = Conv2D(128, (3,3), use_bias=True, activation='relu', padding='same', kernel_initializer='he_normal')(layer_h7) # 卷积层
- layer_h9 = MaxPooling2D(pool_size=2, strides=None, padding="valid")(layer_h8) # 池化层
- layer_h9 = Dropout(0.15)(layer_h9)
- layer_h10 = Conv2D(128, (3,3), use_bias=True, activation='relu', padding='same', kernel_initializer='he_normal')(layer_h9) # 卷积层
- layer_h10 = Dropout(0.2)(layer_h10)
- layer_h11 = Conv2D(128, (3,3), use_bias=True, activation='relu', padding='same', kernel_initializer='he_normal')(layer_h10) # 卷积层
- layer_h12 = MaxPooling2D(pool_size=1, strides=None, padding="valid")(layer_h11) # 池化层
- layer_h12 = Dropout(0.2)(layer_h12)
- layer_h13 = Conv2D(128, (3,3), use_bias=True, activation='relu', padding='same', kernel_initializer='he_normal')(layer_h12) # 卷积层
- layer_h13 = Dropout(0.2)(layer_h13)
- layer_h14 = Conv2D(128, (3,3), use_bias=True, activation='relu', padding='same', kernel_initializer='he_normal')(layer_h13) # 卷积层
- layer_h15 = MaxPooling2D(pool_size=1, strides=None, padding="valid")(layer_h14) # 池化层
- #test=Model(inputs = input_data, outputs = layer_h12)
- #test.summary()
- layer_h16 = Reshape((200, 3200))(layer_h15) #Reshape层
- #layer_h5 = LSTM(256, activation='relu', use_bias=True, return_sequences=True)(layer_h4) # LSTM层
- #layer_h6 = Dropout(0.2)(layer_h5) # 随机中断部分神经网络连接,防止过拟合
- layer_h16 = Dropout(0.3)(layer_h16)
- layer_h17 = Dense(128, activation="relu", use_bias=True, kernel_initializer='he_normal')(layer_h16) # 全连接层
- layer_h17 = Dropout(0.3)(layer_h17)
- layer_h18 = Dense(1422, use_bias=True, kernel_initializer='he_normal')(layer_h17) # 全连接层
复制代码
- from rknn.api import RKNN
- rknn = RKNN(verbose=True, verbose_file='./build.log')
- rknn.config()
- print('--> Loading model')
- rknn.load_tensorflow(tf_pb='./model.pb',
- inputs=['the_input'],
- outputs=['Activation0/truediv'],
- input_size_list=[[320000, 1]])
- print('done')
- # Build Model
- print('--> Building model')
- rknn.build(do_quantization=False)
- print('done')
- rknn.export_rknn('./model.rknn')
- rknn.release()
复制代码
- rknn = RKNN()
- rknn.load_rknn('./model.rknn')
- ret = rknn.init_runtime(target='rk3399pro')
- if ret != 0:
- print('Init runtime environment failed')
- exit(ret)
- print('done')
- # x_in.size = (1, 320000, 1)
- x_in, in_len = load_wav_input(filename)
- out = rknn.inference(inputs=[x_in], data_type='float32')
复制代码
protossw512 发表于 2019-5-21 06:05
对,因为它转换的时候和inference的时候长宽两个维度的顺序反了,所以可以正产转换,但是没办法读取来做i ...
欢迎光临 Toybrick (https://t.rock-chips.com/) | Powered by Discuz! X3.3 |