8
8
from project2 import *
9
9
10
10
def generateExample1 ():
11
+ # Gets consistent weights in same manner as 2, 3 versions
11
12
np .random .seed (20 )
12
13
13
14
net_input = np .random .rand (5 , 5 )
@@ -113,9 +114,6 @@ def run_example1(option = 'keras'):
113
114
114
115
elif option == 'project' :
115
116
116
- #print(np.concatenate((l1k1.flatten(), l1b1)))
117
- #print(np.concatenate((l1k1.flatten(), l1b1)).shape)
118
-
119
117
# Add layers + initialize with weights
120
118
cnn = NeuralNetwork (inputSize = (1 , 5 , 5 ), loss = 'square' , lr = 100 )
121
119
cnn .addLayer (layer_type = 'Conv' , kernel_size = 3 , num_kernels = 1 , \
@@ -138,12 +136,16 @@ def run_example1(option = 'keras'):
138
136
139
137
# Get weights:
140
138
kernel1 = cnn .network [0 ].kernels [0 ][0 ].w
141
- print ('Kernel 1 weights:' , kernel1 [:- 1 ])
142
- print ('Kernel 1 bias:' , kernel1 [- 1 ])
139
+ print ('1st convolutional layer, 1st kernel weights:' )
140
+ print (kernel1 [:- 1 ].reshape ((3 , 3 )))
141
+ print ('1st convolutional layer, 1st kernel bias:' )
142
+ print (kernel1 [- 1 ])
143
143
144
144
fc = cnn .network [- 1 ].neurons [0 ].w
145
- print ('FC 1 weights:' , fc [:- 1 ])
146
- print ('FC 1 bias:' , fc [- 1 ])
145
+ print ('fully connected layer weights:' )
146
+ print (fc [:- 1 ])
147
+ print ('fully connected layer bias:' )
148
+ print (fc [- 1 ])
147
149
148
150
149
151
def run_example2 (option = 'keras' ):
@@ -267,7 +269,6 @@ def run_example2(option = 'keras'):
267
269
print (kernel2 [- 1 ])
268
270
269
271
kernel1_layer2 = cnn .network [1 ].kernels [0 ][0 ].w
270
- #kernel2_layer2 = cnn.network[1].kernels[1][0].w
271
272
print ('2nd convolutional layer weights:' )
272
273
print (kernel1_layer2 [:- 1 ].reshape (2 , 3 , 3 ))
273
274
print ('2nd convolutional layer bias:' )
0 commit comments