使用numpy实现一个前向传播的神经网络(不带反向传导功能,未实现)

代码:

import numpy as np
import matplotlib.pyplot as plt

class Net():
    def __init__(self):
        self.w = np.random.randn(784, 10)
        self.b = np.random.randn(10)
        
    def forward(self, x):
        x = x.reshape(-1, 784)
        y = x @ self.w + self.b

        # relu
        return np.where(y>0, y, 0)
        # nn.relu(nn.Lineaer(784, 10))(X)

image = np.random.randn(28, 28)
print(image)
print(image.shape)

plt.imshow(image, cmap='gray')
plt.imsave("image_1015.png", image, cmap='gray')

net = Net()
y_hat = net.forward(image)


随机生成的图片:


image_1015



posted on 2025-10-28 11:36  Angry_Panda  阅读(1)  评论(0)    收藏  举报

导航