-
Notifications
You must be signed in to change notification settings - Fork 0
/
convolutional_model_example.py
44 lines (38 loc) · 1.19 KB
/
convolutional_model_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import numpy as np
from muskie.models import *
from muskie.layers import *
from muskie.data import *
from muskie.activation_functions import *
from muskie.processing import *
from muskie.optimizers import *
from muskie.loss_functions import *
from muskie.datasets import *
if __name__ == "__main__":
data = create_image_dataset("images/fish_images", (100, 50))
data.display_data(3,3)
model = ClassificationModel([
Conv2D(3, kernel_size=3),
Tanh(),
PrintShape(),
Flatten(),
Dense(3),
Tanh(),
Dense(1)
])
model.summary()
x1 = model.forward(np.reshape([0,0], (2,1)))
x2 = model.forward(np.reshape([0,1], (2,1)))
x3 = model.forward(np.reshape([1,0], (2,1)))
x4 = model.forward(np.reshape([1,1], (2,1)))
train(model=model, data=data, epochs=10000, optimizer=SGD(lr=0.1), loss=MSE())
print("BEFORE TRAINING:")
print(x1)
print(x2)
print(x3)
print(x4)
print("")
print("AFTER TRAINING:")
print(model.forward(np.reshape([0,0], (2,1))))
print(model.forward(np.reshape([0,1], (2,1))))
print(model.forward(np.reshape([1,0], (2,1))))
print(model.forward(np.reshape([1,1], (2,1))))