我想我可以实现一个非常小的Python程序来识别手写数字。你知道吗
1.我在一张纸上写字,拍照。你知道吗
2.使用Python阅读。你知道吗
3.将其转换为灰度和20*20
4.然后将其转换为1*400,并在开头添加一行,使其成为1*401
img1=Image.open('one.jpg').convert('L')
img1 = img1.resize((20,20))
a=np.reshape(input1,(1,400))
b=np.c_[np.ones(1),a]
作为Andrew ng在coursera课程的一部分,我得到了隐藏层的权重,因此通过使用只有一个隐藏层的神经网络,我可以通过做正向传播来预测数量。你知道吗
input_layer_size=20x20输入数字图像,即b1*401
25个隐藏单位,θ1=25*401,θ2=10*26
10个标签,从1到10,“0”映射到标签10
//I read the weights to python
weights = scipy.loadmat('ex3weights.mat',squeeze_me = True)
theta1 = weights['Theta1']
theta2 = weights['Theta2']
l1 = 1/(1+np.exp(-(np.dot(b,theta1.T))))
c = np.c_[np.ones(1),l1] //added 1 to make it 1*26
l2 = 1/(1+np.exp(-(np.dot(c,theta2.T))))
现在l2最大值的(位置+1)将是输出数。你知道吗
#Octave code:
a1=[ones(size(a,1),1),a];
z2=sigmoid(a1*Theta1');
a2=[ones(size(z2,1),1),z2];
a3=sigmoid(a2*Theta2');
[x,p ]= max(a3, [], 2);
p
//here p has the number
如果一切顺利的话,我应该从这段小代码中获得一些魔力,但是它在八度音阶中工作得很好,而不是在Python中。我将a保存在a.mat中,并将其加载到倍频程中,然后运行上面的代码,得到了答案。l2和p应该是一样的,对吧?你知道吗
我检查了所有的东西,这个代码来自http://iamtrask.github.io/2015/07/12/basic-python-network/ 我甚至用八度音阶尝试了他的11行神经网络,然后用Python和八度音阶得到了相同的输出。这应该行得通。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐