我有一些ipython笔记本和另一个在此笔记本中使用的辅助python文件“ init_utils.py”。 我得到以下回溯:
ValueError Traceback (most recent
call last)
<ipython-input-42-baebd5bdcbf9> in <module>
----> 1 parameters = model(train_X, train_Y, initialization =
"random")
2
3 print("On the train set:")
4 predictions_train = predict(train_X, train_Y, parameters)
5 print("On the test set:")
<ipython-input-41-dc37f4190760> in model(X, Y, learning_rate,
num_iterations, print_cost, initialization)
34 # Forward propagation: LINEAR -> RELU -> LINEAR ->
RELU -> LINEAR -> SIGMOID.
35 print("W2 =",parameters['W2'])
---> 36 a3, cache = forward_propagation(X, parameters)
37
38 # Loss
~/Documents/practice/courses/Deep-Learning-Coursera/Improving Deep
Neural Networks Hyperparameter tuning, Regularization and
Optimization/init_utils.py in forward_propagation(X, parameters)
62 z1 = np.dot(W1, X) + b1
63 a1 = relu(z1)
---> 64 z2 = np.dot(W2, a1) + b2
65 a2 = relu(z2)
66 z3 = np.dot(W3, a2) + b3
ValueError: shapes (10,2) and (10,300) not aligned: 2 (dim 1) !=
10 (dim 0)
我试图打印W1矩阵,这是它的样子
W2 = [[ 0.74505627 1.97611078]
[-1.24412333 -0.62641691]
[-0.80376609 -2.41908317]
[-0.92379202 -1.02387576]
[ 1.12397796 -0.13191423]
[-1.62328545 0.64667545]
[-0.35627076 -1.74314104]
[-0.59664964 -0.58859438]
[-0.8738823 0.02971382]
[-2.24825777 -0.26776186]]
由于错误,我无法打印a1矩阵
我在这里仅共享相关代码
parameters = model(train_X, train_Y, initialization = "random")
def model(X, Y, learning_rate=0.01, num_iterations=15000, print_cost=True, initialization="he"):
.
.
.
a3, cache = forward_propagation(X, parameters)
.
.
def forward_propagation(X, parameters):
.
.
.
W2 = parameters["W2"]
z1 = np.dot(W1, X) + b1
a1 = relu(z1)
z2 = np.dot(W2, a1) + b2
a2 = relu(z2)
z3 = np.dot(W3, a2) + b3
a3 = sigmoid(z3)
.
.
.
我无法调试它。谢谢