0
ReLU 활성화 함수를 사용하여 다음 입력 숫자를 인쇄하려고합니다. 네트워크를 여러 번 훈련했지만 출력을 0으로 받았습니다.ReLU 신경망은 0을 반환합니다.
다음은 구현하려는 코드입니다. 아무도 내가 뭘 잘못하고 있다고 말할 수 있습니까? 이와 중량 increamenting 출력이 조정 값을 감소시킴으로써 0 그냥 증분 중량 내가 출력을 가지고 매우 때
import numpy as np,random
class NeuralNetwork():
def _init_(self):
random.seed(1)
self.weights = 0.5
def relu(self,x):
for i in range(0,len(x)):
if x[i]>0:
pass
else:
x[i]=0
return x
def relu_derv(self,x):
for i in range(0,len(x)):
if x[i]>0:
x[i]=1
else:
x[i]=0
return x
def train(self,input ,output,iterations):
for i in xrange(iterations):
out = self.think(input)
error = output-out
adjustments = np.dot(input.T,error*self.relu_derv(out))
self.weights += adjustments
def think(self,input):
return self.relu(np.dot(input,self.weights))
if _name_=="__main__":
neural= NeuralNetwork()
print "before train weights"
print neural.weights
input = np.array([1,2,3,4,5,6,7,8,9])
output = np.array([2,3,4,5,6,7,8,9,10]).T
print input
neural.train(input,output,100000)
print "after train weights"
print neural.weights
print "neural"
a=[13,15]
print neural.think(a)
'self.weights'는 스칼라입니다. 그러므로'np.dot'는 스칼라를 wll로 반환합니다. 런타임 오류가 발생하지 않고 어떻게'relu' 내부에서'len'을 호출 할 수 있습니까? – Omni
스칼라와 벡터의 내적은 벡터입니다. 벡터의 모든 요소에 스칼라를 곱하면됩니다. input = np.array ([1,2,3,4,5,6,7,8,9]) print np.dot (input, 2) 2 * 입력 인쇄 –