hanbt / learn_dl

Deep learning algorithms source code for beginners
Apache License 2.0
1.2k stars 988 forks source link

向量化编程错误之 ValueError: operands could not be broadcast together with shapes (10,) (10,300) #2

Closed supermanhuyu closed 7 years ago

supermanhuyu commented 7 years ago

你好,首先很感谢你提供的文章以及代码。 我在第三章神经网络用你提供的向量化编程中练习遇到如下错误

`ValueError Traceback (most recent call last)

in () 142 last_error_ratio = error_ratio 143 if __name__ == '__main__': --> 144 train_and_evaluate() in train_and_evaluate() 132 while True: 133 epoch += 1 --> 134 network.train(train_labels, train_data_set, 0.3, 1) 135 print '%s epoch %d finished' % (now(), epoch) 136 if epoch % 10 == 0: /home/superman/learn_dl/fc.py in train(self, labels, data_set, rate, epoch) 98 for d in range(len(data_set)): 99 self.train_one_sample(labels[d], --> 100 data_set[d], rate) 101 102 def train_one_sample(self, label, sample, rate): /home/superman/learn_dl/fc.py in train_one_sample(self, label, sample, rate) 102 def train_one_sample(self, label, sample, rate): 103 self.predict(sample) --> 104 self.calc_gradient(label) 105 self.update_weight(rate) 106 /home/superman/learn_dl/fc.py in calc_gradient(self, label) 108 delta = self.layers[-1].activator.backward( 109 self.layers[-1].output --> 110 ) * (label - self.layers[-1].output) 111 for layer in self.layers[::-1]: 112 layer.backward(delta) ValueError: operands could not be broadcast together with shapes (10,) (10,300) ` 在”神经网络实战--代码实现部分”,为了实现向量化编程练习。我吧 from bp import * 修改为 from fc import * ,于是出现上面的错误。好想有两个地方比较不一样就是 class network( ) 和 def train_data_set(): ,请问我要改怎么改才能实现呢? 谢谢
hanbt commented 7 years ago

你好,我上传了源码mnist.py,里面是使用fc的代码。运行代码需要在工作目录下包含MNIST数据集的四个文件: t10k-images-idx3-ubyte t10k-labels-idx1-ubyte train-images-idx3-ubyte train-labels-idx1-ubyte 然后执行python mnist.py即可。