Skip to content

Commit f99147c

Browse files
committed
added conv example
1 parent a61d5ae commit f99147c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

example_conv.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from network import Network
2+
from fc_layer import FCLayer
3+
from conv_layer import ConvLayer
4+
from activation_layer import ActivationLayer
5+
from losses import *
6+
from activations import *
7+
import numpy as np
8+
9+
# training data
10+
x_train = [np.random.rand(10,10,1)];
11+
y_train = [np.random.rand(4,4,2)];
12+
13+
# network
14+
net = Network();
15+
net.add(ConvLayer((10,10,1), (3,3), 1));
16+
net.add(ActivationLayer((8,8,1), tanh, tanh_prime));
17+
net.add(ConvLayer((8,8,1), (3,3), 1));
18+
net.add(ActivationLayer((6,6,1), tanh, tanh_prime));
19+
net.add(ConvLayer((6,6,1), (3,3), 2));
20+
net.add(ActivationLayer((4,4,2), tanh, tanh_prime));
21+
22+
# train
23+
net.use(mse, mse_prime);
24+
net.fit(x_train, y_train, epochs=1000, learning_rate=0.3);
25+
26+
# test
27+
out = net.predict(x_train);
28+
print("predicted = ", out);
29+
print("expected = ", y_train);

0 commit comments

Comments
 (0)