赞
踩
1.直接下载:http://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
2.将下载下来的文件放到~/.keras/datasets/ 目录下,然后将文件名改名为cifar-10-batches-py.tar.gz ,再次运行代码的时候,则会先检查本地是否存在,存在则使用本地的该数据集,不会再进行下载。
32 x 32 | 32 filter, Size:3 x 3 | rate: 0.2 | 32 filter, Size:3 x 3 | rate: 0.2 | Size: (2 x 2) | 512个神经元+Relu激活 | rate: 0.5 | 10个神经元+softmax激活 | |
---|---|---|---|---|---|---|---|---|---|
输入层 | 卷积层① | Dropout层① | 卷积层② | Dropout层② | (最大)池化层 | Flatten 层 | 全连接层 | Dropout层 | 输出层 |
from keras.datasets import cifar10 import numpy as np from keras.models import Sequential from keras.layers import Dense from keras.layers import Dropout from keras.layers import Flatten from keras.layers.convolutional import Conv2D from keras.layers.convolutional import MaxPooling2D from keras.optimizers import SGD from keras.constraints import maxnorm from keras.utils import np_utils from keras import backend backend.set_image_data_format('channels_first') # 设定随机数种子 seed = 7 np.random.seed(seed) # 导入数据 (x_train, y_train), (x_validation, y_validation) = cifar10.load_data() x_train = x_train.astype('float32') x_validation = x_validation.astype('float32') x_train = x_train/255.0 x_validation = x_validation/255.0 # 进行one-hot编码 y_train = np_utils.to_categorical(y_train) y_validation = np_utils.to_categorical(y_validation) num_classes = y_train.shape[1] # 定义模型创建函数 def create_model(epochs=25): model = Sequential() model.add(Conv2D(32, (3, 3), input_shape=(3, 32, 32), padding='same', activation='relu', kernel_constraint=maxnorm(3))) model.add(Dropout(0.2)) model.add(Conv2D(32, (3, 3), activation
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。