net
新建netWork.py,添加以下代码
准备
|
LeNet
def LeNet(inputs): |
alex_net
def alex_net(_X, _weights, _biases, _dropout): |
cnn_1
def CNN_1(inputs): |
VGG16
|
vgg19
def VGG19(inputs): |
读取数据
加载数据
import pickle |
数据预处理
def pre_processing_data(x_train, y_train, x_test, y_test): |
数据准备
新建Read_date.pydef cifar10_data():
# 加载训练数据
cifar10_path = 'data'
# 一共是有5个batch的训练数据
x_train, y_train = load_cifar10_batch(cifar10_path, 1)
for n in range(2, 6):
features, labels = load_cifar10_batch(cifar10_path, n)
x_train = np.concatenate([x_train, features])
y_train = np.concatenate([y_train, labels])
# 加载测试数据
with open(cifar10_path + '/test_batch', mode='rb') as file:
batch = pickle.load(file, encoding='latin1')
x_test = batch['data'].reshape((len(batch['data']), 3, 32, 32)).transpose(0, 2, 3, 1)
y_test = batch['labels']
x_train, y_train, x_test, y_test = pre_processing_data(x_train, y_train, x_test, y_test)
return x_train, y_train, x_test, y_test
config
新建config.py;复制以下代码
初始化卷积神经网络参数
import tensorflow as tf |
定义placeholder
inputs = tf.placeholder(tf.float32, [None, 32, 32, 3], name='inputs') |
显示图片
|
存储网络参数(alexnet)
weights = { |