Machine learning 卷积函数的前向传播误差

Machine learning 卷积函数的前向传播误差,machine-learning,deep-learning,computer-vision,Machine Learning,Deep Learning,Computer Vision,这是我想要的代码 (m, n_H_prev, n_W_prev, n_C_prev) = A_prev.shape (f, f, n_C_prev, n_C) = W.shape # Retrieve information from "hparameters" (≈2 lines) stride = hparameters["stride"] pad = hparameters["pad"] n_H = int((n_H_

这是我想要的代码

(m, n_H_prev, n_W_prev, n_C_prev) = A_prev.shape 

(f, f, n_C_prev, n_C) = W.shape 

# Retrieve information from "hparameters" (≈2 lines)
stride = hparameters["stride"]
pad =  hparameters["pad"]

n_H = int((n_H_prev - f + 2 * pad) / stride)
n_W = int((n_W_prev - f + 2 * pad) / stride)

# Initialize the output volume Z with zeros. (≈1 line)
Z = np.zeros((m, n_H, n_W, n_C))

# Create A_prev_pad by padding A_prev
A_prev_pad = zero_pad(A_prev, pad)

for i in range(m):               # loop over the batch of training examples
    a_prev_pad = A_prev_pad[i]               # Select ith training example's padded activation
    for h in range(n_H):           # loop over vertical axis of the output volume
        vert_start = h * stride
        vert_end = vert_start + f
        
        for w in range(n_W):       # loop over horizontal axis of the output volume
            horiz_start = w * stride
            horiz_end = horiz_start + f
            
            for c in range(n_C):   # loop over channels (= #filters) of the output volume
                                    

                a_slice_prev = a_prev_pad[vert_start:vert_end, horiz_start:horiz_end, :]
                

                weights = W[:,:,:,c]
                biases = b[:,:,:,c]
                Z[i, h, w, c] = conv_single_step(a_slice_prev,weights, biases)
它给了我一个错误:-

---> 10 print("Z[0,2,1] =\n", Z[0, 2, 1])
     11 print("cache_conv[0][1][2][3] =\n", cache_conv[0][1][2][3])
     12 

IndexError: index 2 is out of bounds for axis 1 with size 2