构建真实世界的卷积神经网络:CIFAR - 10 模型优化与实现
1. 加载和准备 CIFAR - 10 图像数据
CIFAR - 10 数据集包含 50000 张训练图像,以 Python Pickle 格式存储。为了更好地训练卷积神经网络(CNN),我们需要对数据进行加载、清理和预处理。
1.1 数据加载和清理步骤
- 加载 Pickle 格式的数据到 Python 字典。
- 清理数据,包括将图像转换为灰度图以减少学习参数的数量,裁剪图像以减少背景噪声,并对图像进行归一化处理。
以下是实现这些功能的代码:
import pickle
import numpy as np
def unpickle(file):
fo = open(file, 'rb')
dict = pickle.load(fo, encoding='latin1')
fo.close()
return dict
def clean(data):
imgs = data.reshape(data.shape[0], 3, 32, 32)
grayscale_imgs = imgs.mean(1)
cropped_imgs = grayscale_imgs[:, 4:28, 4:28]
img_data = cropped_imgs.reshape(imgs.shape[0], -1)
img_size = np.shape(img_data)[1]
means = np.mea
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



