【发布时间】:2018-12-20 07:22:12
【问题描述】:
我一直在寻找使用 Tensorflow 实现深度学习模型的信息,最后我在这里问,因为我无法挖掘出来。这可能是一个非常基本的问题,但我会感谢您的友好回复。
import tensorflow as tf
import random
import os
import numpy as np
import time
import random
import csv
from random import shuffle
np.random.seed(1117)
# for reproduct
# parameters
learning_rate = 1E-5 * 5
batch_size_SE = 2500
batch_size_STOI = 50
spl = 5
frames = 50
con_frame = 50
feature_dim = 256
nb_epoch = 50
layer_width = 2048
training_length = 500
validation_length = 50
keep_prob = tf.placeholder(tf.float32)
# SE_input/output placeholders
X = tf.placeholder(tf.float32, [batch_size_SE, feature_dim*(2*spl+1)])
Y = tf.placeholder(tf.float32, [batch_size_SE, feature_dim])
# STOI_input/output placeholders
STOI_feature = tf.placeholder(tf.float32, [batch_size_STOI, feature_dim*frames*2])
STOI_target = tf.placeholder(tf.float32, [batch_size_STOI, 1])
#########################Speech enhancement DNN#########################
# SE_1st Hidden layer
W11 = tf.get_variable("W11", shape=[(2*spl+1)*feature_dim,layer_width], initializer=tf.contrib.layers.xavier_initializer())
b11 = tf.Variable(tf.random_normal([layer_width]))
L11 = tf.nn.relu(tf.matmul(X, W11) + b11)
L11 = tf.nn.dropout(L11, keep_prob=keep_prob)
# SE_2nd Hidden layer
W12 = tf.get_variable("W12", shape=[layer_width,layer_width], initializer=tf.contrib.layers.xavier_initializer())
b12 = tf.Variable(tf.random_normal([layer_width]))
L12 = tf.nn.relu(tf.matmul(L11, W12)+ b12)
L12 = tf.nn.dropout(L12, keep_prob=keep_prob)
# SE_3rd Hidden layer
W13 = tf.get_variable("W23", shape=[layer_width, layer_width], initializer=tf.contrib.layers.xavier_initializer())
b13 = tf.Variable(tf.random_normal([layer_width]))
L13 = tf.nn.relu(tf.matmul(L12, W13) + b13)
L13 = tf.nn.dropout(L13, keep_prob=keep_prob)
# SE_4th Hidden layer
W14 = tf.get_variable("W14", shape=[layer_width,layer_width], initializer=tf.contrib.layers.xavier_initializer())
b14 = tf.Variable(tf.random_normal([layer_width]))
L14 = tf.nn.relu(tf.matmul(L13, W14)+ b14)
L14 = tf.nn.dropout(L14, keep_prob=keep_prob)
# enhanced_speech_output layer
W15 = tf.get_variable("W15", shape=[layer_width,feature_dim], initializer=tf.contrib.layers.xavier_initializer())
b15 = tf.Variable(tf.random_normal([feature_dim]))
SE_hypothesis = tf.matmul(L14, W15) + b15
#########################STOI estimation DNN#########################
# STOI_1st Hidden layer
W21 = tf.get_variable("W21", shape=[feature_dim*frames*2,layer_width], initializer=tf.contrib.layers.xavier_initializer())
b21 = tf.Variable(tf.random_normal([layer_width]))
L21 = tf.nn.relu(tf.matmul(X, W21) + b21)
L21 = tf.nn.dropout(L21, keep_prob=keep_prob)
# STOI_2nd Hidden layer
W22 = tf.get_variable("W22", shape=[layer_width,layer_width], initializer=tf.contrib.layers.xavier_initializer())
b22 = tf.Variable(tf.random_normal([layer_width]))
L22 = tf.nn.relu(tf.matmul(L1, W22)+ b22)
L22 = tf.nn.dropout(L22, keep_prob=keep_prob)
# STOI_3rd Hidden layer
W23 = tf.get_variable("W23", shape=[layer_width, layer_width], initializer=tf.contrib.layers.xavier_initializer())
b23 = tf.Variable(tf.random_normal([layer_width]))
L23 = tf.nn.relu(tf.matmul(L22, W23) + b23)
L23 = tf.nn.dropout(L23, keep_prob=keep_prob)
# STOI_4th Hidden layer
W24 = tf.get_variable("W24", shape=[layer_width,layer_width], initializer=tf.contrib.layers.xavier_initializer())
b24 = tf.Variable(tf.random_normal([layer_width]))
L24 = tf.nn.relu(tf.matmul(L23, W24)+ b24)
L24 = tf.nn.dropout(L24, keep_prob=keep_prob)
# enhanced_speech_output layer
W25 = tf.get_variable("W25", shape=[layer_width,1], initializer=tf.contrib.layers.xavier_initializer())
b25 = tf.Variable(tf.random_normal([1]))
STOI_hypothesis = tf.matmul(L24, W25) + b25
#########################Cost function and optimizer#########################
SE_var_list = [W11, W12, W13, W14, W15, b11, b12, b13, b14, b15]
cost = tf.reduce_mean(tf.square(STOI_target - STOI_hypothesis))
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost, var_list = SE_var_list)
saver = tf.train.Saver()
现在,我想使用一种方法来训练两个神经工作模型。 DNN1,这是我要训练的模型,DNN2 是已经训练好的模型。我尝试用tensorflow构建这两个模型的框架。但是,它有一条错误消息“尺寸必须相等,但为 2816 和 25600”。我觉得我不应该像传统的 tensorflow DNN 那样训练,所以请问我可以用什么样的方法来修改代码。
【问题讨论】: