问题描述
我一直试图在 32 个小批量上实现损失。我的总数据集为 1024,我将数据分成 32 个不同的小批量。我试图从它的标签(1,69)中减去 minibatch 的每一行(1row x 69 列)。我在下面放了一小段代码。我收到有关未初始化变量的错误。我会很感激这个错误的可能解决方案
#This is the function that calculates the loss function
def _build_loss_function(self,label,mini batch):
error_i = tf.map_fn(lambda row: tf.square(label - row),mini batch)
square_difference = tf.reduce_sum(error_i,1)
self.loss = tf.reduce_mean(square_difference,name='loss')
self.loss = tf.cast(self.loss,tf.float32)
#this is the main file where the mini batch is calculated
data = np.random.random([1056,69])
agent = Agent.Control()
if __name__ == '__main__':
mini_batch_size = 32
num_epochs = 500
training_data_size = 1024
test_data_size = 32
# data set to train and test data sets
e_training_data = data[0:1024,:]
e_test_data = data[1024:,:]
with tf.Session() as sess:
init = tf.global_variables_initializer()
sess.run(init)
train_losses = []
test_losses = []
for i in range(num_epochs):
# randomize the expert_training data
np.random.shuffle(e_training_data)
e_frames_batches = np.split(e_training_data,int(training_data_size / mini_batch_size))
epoch_loss = 0
for mini_batch in e_frames_batches:
loss,predicted_angles,gradients,_ = agent.train(sess,mini_batch)
epoch_loss += loss
epoch_loss /= len(e_frames_batches)
test_loss = agent.predict_loss(e_test_data.astype('float32'))
train_losses.append(epoch_loss)
test_losses.append(test_loss)
print("\nEpoch: {},loss: {},test_loss: {} ".format(i,epoch_loss,test_loss))
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)