我正在尝试实现一个神经网络,将图像分类为两个离散类别之一.但问题是,它目前总是为任何输入预测为0,我不确定为什么.
这是我的特征提取方法:
def extract(file):
# Resize and subtract mean pixel
img = cv2.resize(cv2.imread(file), (224, 224)).astype(np.float32)
img[:, :, 0] -= 103.939
img[:, :, 1] -= 116.779
img[:, :, 2] -= 123.68
# Normalize features
img = (img.flatten() - np.mean(img)) / np.std(img)
return np.array([img])
Run Code Online (Sandbox Code Playgroud)
这是我的梯度下降程序:
def fit(x, y, t1, t2):
"""Training routine"""
ils = x.shape[1] if len(x.shape) > 1 else 1
labels = len(set(y))
if t1 is None or t2 is None:
t1 = randweights(ils, 10)
t2 = randweights(10, labels)
params = …Run Code Online (Sandbox Code Playgroud) numpy neural-network python-3.x gradient-descent deep-learning