利用CNN处理CIFAR-10的测试精度没达到老师的要求,接下来试试Rsenet~想看完整CNN理论即建模优化过程的在这里:
Tensorflow之CNN实现CIFAR-10图像的分类python
不想看我啰嗦想直接下载代码的在这里:代码(数据有点大我没上传上去,没有数据的可以去上面那个文章里找)这里我就不赘述Resnet的原理了,直接开始实验~
数据准备
我们将数据准备过程放在load_data.py中:
import numpy as np
import os
import sys
import pickle
def load_batch(fpath, label_key='labels'):
with open(fpath, 'rb') as f:
if sys.version_info < (3,):
d = pickle.load(f)
else:
d = pickle.load(f, encoding='bytes')
# decode utf8
d_decoded = {
}
for k, v in d.items():
d_decoded[k.decode('utf8')] = v
d = d_decoded
data = d['data']
labels = d[label_key]
data = data.reshape(data.shape[0], 3, 32, 32)
return data, labels
def load_data():
# Returns Tuple of Numpy arrays: `(x_train, y_train), (x_test, y_test)`.
dirname = 'cifar-10-batches-py/'
path = './%s' % dirname
num_train_samples = 50000
x_train = np.empty((num_train_samples, 3, 32, 32), dtype='uint8')
y_train = np.empty((num_train_samples,), dtype='uint8')
for i in range(1, 6):
fpath = os.path.join(path, 'data_batch_' + str(i))
(x_train[(i - 1) * 10000: i * 10000, :, :, :],
y_train[(i - 1) * 10000: i * 10000]) = load_batch(fpath)
fpath = os.path.join(path, 'test_batch')
x_test, y_test = load_batch(fpath)
y_train = np.reshape(y_train, (len(y_train), 1))
y_test = np.reshape(y_test, (