Code Monkey home page Code Monkey logo

Comments (9)

ghoulich avatar ghoulich commented on August 17, 2024 2

反向传播是用下一层的误差项来推算本层的误差,从右至左逐层推算,所以
self.W_grad = np.dot(delta_array, self.input.T)
self.b_grad = delta_array
这两行代码没有问题,但是上一行代码
self.delta = self.activator.backward(self.input) * np.dot(self.W.T, delta_array)
我觉得是有问题的,本层的误差应该用本层的输出和下一层的误差来计算,但是这行代码却用本层的输入来计算,这个和公式-8是冲突的,我觉得正确的应该是
self.delta = self.activator.backward(self.output) * np.dot(self.W.T, delta_array)
还是得修改一下源码试试看!

from learn_dl.

FlyingCat-fa avatar FlyingCat-fa commented on August 17, 2024

你没搞懂全连接层的结构,此三层结构中只有两个全连接层。比如第一个全连接层l,连接输入层和隐藏层,则其输入是节点13的输出ai,i为13,输出是节点47的输出ai,i为47,权重为输入到隐藏层的连接权重,其误差项应为输入节点的误差项,该层下一层l+1的误差项应为该层(l层)输入乘以权重后的这个值的误差,也就是激活器的输入的误差

from learn_dl.

samchild avatar samchild commented on August 17, 2024

反向传播是用下一层的误差项来推算本层的误差,从右至左逐层推算,所以
self.W_grad = np.dot(delta_array, self.input.T)
self.b_grad = delta_array
这两行代码没有问题,但是上一行代码
self.delta = self.activator.backward(self.input) * np.dot(self.W.T, delta_array)
我觉得是有问题的,本层的误差应该用本层的输出和下一层的误差来计算,但是这行代码却用本层的输入来计算,这个和公式-8是冲突的,我觉得正确的应该是
self.delta = self.activator.backward(self.output) * np.dot(self.W.T, delta_array)
还是得修改一下源码试试看!

你的 self.delta = self.activator.backward(self.output) * np.dot(self.W.T, delta_array)这一句,还是没有使用下一层的权重呀?正确的是会不会是
self.delta = self.activator.backward(self.output) * np.dot(self.NextLayer.W.T, delta_array)(self.NextLayer.W这个只是示意下一层的权重) @hanbt @ghoulich

from learn_dl.

janlely avatar janlely commented on August 17, 2024

反向传播是用下一层的误差项来推算本层的误差,从右至左逐层推算,所以
self.W_grad = np.dot(delta_array, self.input.T)
self.b_grad = delta_array
这两行代码没有问题,但是上一行代码
self.delta = self.activator.backward(self.input) * np.dot(self.W.T, delta_array)
我觉得是有问题的,本层的误差应该用本层的输出和下一层的误差来计算,但是这行代码却用本层的输入来计算,这个和公式-8是冲突的,我觉得正确的应该是
self.delta = self.activator.backward(self.output) * np.dot(self.W.T, delta_array)
还是得修改一下源码试试看!

式4中a_j是节点j的输出值,是第一层的其中一个输出,实际就是第二层的其中一个输入,所以这块代码应该没问题,但这个网络用来训练mnist数据集好像不行,跑了两轮就直接退出了,错误率太高,不收敛。打印每次的梯度,发现值都很小(< 0.2)

from learn_dl.

dyustc avatar dyustc commented on August 17, 2024

反向传播是用下一层的误差项来推算本层的误差,从右至左逐层推算,所以
self.W_grad = np.dot(delta_array, self.input.T)
self.b_grad = delta_array
这两行代码没有问题,但是上一行代码
self.delta = self.activator.backward(self.input) * np.dot(self.W.T, delta_array)
我觉得是有问题的,本层的误差应该用本层的输出和下一层的误差来计算,但是这行代码却用本层的输入来计算,这个和公式-8是冲突的,我觉得正确的应该是
self.delta = self.activator.backward(self.output) * np.dot(self.W.T, delta_array)
还是得修改一下源码试试看!

赞同,应该改成self.output, 不过我改完之后,跑的mnist数据集会报错误, 出不了结果, 你改完结果是对的吗

from learn_dl.

ume-technology avatar ume-technology commented on August 17, 2024

最近我回头看反向传播的过程. 在全连接神经网络的反向传播的实现代码部分 (class NetWork): def calc_gradient(self, label): delta = self.layers[-1].activator.backward(self.layers[-1].output) * (label - self.layers[-1].output) for layer in self.layers[::-1]: layer.backward(delta) delta = layer.delta return delta.
结合文章, 我没有看明白求解梯度的这个第一行代码是在计算什么. 按照反向传播的起点来算, 应该是从损失函数开始算起, 但是这个求解梯度的方法并没有从损失值还是计算, 而是从输出层的神经元的激活结果开始算起, 这样子是正确的么? 如果正确, 还请帮我解释一下, 万分感谢各位的帮助. @FatCockHu, @samchild , @ghoulich

from learn_dl.

shironeko1337 avatar shironeko1337 commented on August 17, 2024

最近我回头看反向传播的过程. 在全连接神经网络的反向传播的实现代码部分 (class NetWork): def calc_gradient(self, label): delta = self.layers[-1].activator.backward(self.layers[-1].output) * (label - self.layers[-1].output) for layer in self.layers[::-1]: layer.backward(delta) delta = layer.delta return delta. 结合文章, 我没有看明白求解梯度的这个第一行代码是在计算什么. 按照反向传播的起点来算, 应该是从损失函数开始算起, 但是这个求解梯度的方法并没有从损失值还是计算, 而是从输出层的神经元的激活结果开始算起, 这样子是正确的么? 如果正确, 还请帮我解释一下, 万分感谢各位的帮助. @FatCockHu, @samchild , @ghoulich

损失函数的结果不需要计算,只需要计算损失函数对于最后输出的偏导,也就是 self.layers[-1].activator.backward(self.layers[-1].output) 这里

from learn_dl.

yepaoxixi avatar yepaoxixi commented on August 17, 2024

from learn_dl.

shironeko1337 avatar shironeko1337 commented on August 17, 2024

from learn_dl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.