next update
parent
571c5e03f4
commit
bea4c2a20c
|
@ -31,7 +31,6 @@ delta_L2 = np.ones((hid_size, out_size)) * 0.1
|
||||||
w0 = np.random.random((inp_size, hid_size)) - 0.5
|
w0 = np.random.random((inp_size, hid_size)) - 0.5
|
||||||
w1 = np.random.random((hid_size, out_size)) - 0.5
|
w1 = np.random.random((hid_size, out_size)) - 0.5
|
||||||
|
|
||||||
|
|
||||||
def multiply_learnrate(old, new):
|
def multiply_learnrate(old, new):
|
||||||
if old * new > 0:
|
if old * new > 0:
|
||||||
return 1.2
|
return 1.2
|
||||||
|
@ -61,9 +60,10 @@ for i in range(10000):
|
||||||
L1_error = np.matmul(L2_delta, w1.T)
|
L1_error = np.matmul(L2_delta, w1.T)
|
||||||
L1_delta = L1_error * deriv_sigmoid(L1)
|
L1_delta = L1_error * deriv_sigmoid(L1)
|
||||||
|
|
||||||
# Gradienten
|
# Gradienten berechnen
|
||||||
L2_grad_new = np.matmul(L1.T, L2_delta)
|
|
||||||
L1_grad_new = np.matmul(L0.T, L1_delta)
|
L1_grad_new = np.matmul(L0.T, L1_delta)
|
||||||
|
L2_grad_new = np.matmul(L1.T, L2_delta)
|
||||||
|
|
||||||
|
|
||||||
# Gewichte aktualisieren
|
# Gewichte aktualisieren
|
||||||
|
|
||||||
|
@ -72,10 +72,10 @@ for i in range(10000):
|
||||||
delta_L2 = np.clip(
|
delta_L2 = np.clip(
|
||||||
delta_L2 * v_multiply_learnrate(L2_grad_old, L2_grad_new), 0, 50)
|
delta_L2 * v_multiply_learnrate(L2_grad_old, L2_grad_new), 0, 50)
|
||||||
|
|
||||||
w1 -= np.sign(L2_grad_new) * delta_L2
|
|
||||||
w0 -= np.sign(L1_grad_new) * delta_L1
|
w0 -= np.sign(L1_grad_new) * delta_L1
|
||||||
|
w1 -= np.sign(L2_grad_new) * delta_L2
|
||||||
|
|
||||||
# Gradienten aktualisieren
|
# Gradienten aktualisieren bzw. kopieren
|
||||||
|
|
||||||
L1_grad_old = np.copy(L1_grad_new)
|
L1_grad_old = np.copy(L1_grad_new)
|
||||||
L2_grad_old = np.copy(L2_grad_new)
|
L2_grad_old = np.copy(L2_grad_new)
|
||||||
|
|
|
@ -36,7 +36,6 @@ def pool(image, stride=1, kernel_size=(2,2), transform=np.max, padding_size=(0,0
|
||||||
|
|
||||||
next = np.zeros((height, width))
|
next = np.zeros((height, width))
|
||||||
|
|
||||||
#'zero'|'mirror'
|
|
||||||
for i in range(height):
|
for i in range(height):
|
||||||
for j in range(width):
|
for j in range(width):
|
||||||
# Translate upper left corner into original image space
|
# Translate upper left corner into original image space
|
||||||
|
@ -45,7 +44,6 @@ def pool(image, stride=1, kernel_size=(2,2), transform=np.max, padding_size=(0,0
|
||||||
# Retrieve image window
|
# Retrieve image window
|
||||||
view = padded[y:y+kernel_size[0], x:x+kernel_size[1]]
|
view = padded[y:y+kernel_size[0], x:x+kernel_size[1]]
|
||||||
|
|
||||||
#print(view)
|
|
||||||
# Set pooled image value
|
# Set pooled image value
|
||||||
next[i][j] = transform(view)
|
next[i][j] = transform(view)
|
||||||
|
|
||||||
|
@ -60,10 +58,9 @@ weights = np.array([
|
||||||
])
|
])
|
||||||
|
|
||||||
new1 = pool(image, kernel_size=(5,5), padding_size=(2,2), transform=convolute(weights))
|
new1 = pool(image, kernel_size=(5,5), padding_size=(2,2), transform=convolute(weights))
|
||||||
new2 = pool(new1, stride=3, kernel_size=(30,30), transform=np.max)
|
|
||||||
|
|
||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
fig.canvas.manager.set_window_title("A Cat")
|
fig.canvas.manager.set_window_title("A Cat")
|
||||||
|
|
||||||
plt.imshow(new2, cmap="gray")
|
plt.imshow(new1, cmap="gray")
|
||||||
plt.show()
|
plt.show()
|
Loading…
Reference in New Issue