Skip to content

Commit ebc335b

Browse files
committed
final v
1 parent e6913b2 commit ebc335b

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

run_proj2.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from project2 import *
99

1010
def generateExample1():
11+
# Gets consistent weights in same manner as 2, 3 versions
1112
np.random.seed(20)
1213

1314
net_input = np.random.rand(5, 5)
@@ -113,9 +114,6 @@ def run_example1(option = 'keras'):
113114

114115
elif option == 'project':
115116

116-
#print(np.concatenate((l1k1.flatten(), l1b1)))
117-
#print(np.concatenate((l1k1.flatten(), l1b1)).shape)
118-
119117
# Add layers + initialize with weights
120118
cnn = NeuralNetwork(inputSize = (1, 5, 5), loss = 'square', lr = 100)
121119
cnn.addLayer(layer_type = 'Conv', kernel_size = 3, num_kernels = 1, \
@@ -138,12 +136,16 @@ def run_example1(option = 'keras'):
138136

139137
# Get weights:
140138
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])
143143

144144
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])
147149

148150

149151
def run_example2(option = 'keras'):
@@ -267,7 +269,6 @@ def run_example2(option = 'keras'):
267269
print(kernel2[-1])
268270

269271
kernel1_layer2 = cnn.network[1].kernels[0][0].w
270-
#kernel2_layer2 = cnn.network[1].kernels[1][0].w
271272
print('2nd convolutional layer weights:')
272273
print(kernel1_layer2[:-1].reshape(2, 3, 3))
273274
print('2nd convolutional layer bias:')

0 commit comments

Comments
 (0)