当前位置:网站首页>Classification of cifar100 data set based on convolutional neural network
Classification of cifar100 data set based on convolutional neural network
2022-04-23 17:53:00 【Stephen_ Tao】
List of articles
CIFAR100 Data set introduction
CIFAR100 The dataset has 100 Categories , Each category contains 600 A picture , And each category has 500 Training pictures and 100 Test pictures .CIFAR100 Data sets 100 The three categories are divided into 20 A superclass . Each image has a " fine " label ( The class it belongs to ) And a " Rough " label ( The superclass it belongs to ).
Code implementation
Reading data sets
# Import dataset
from tensorflow.python.keras.datasets import cifar100
class CNNMnist(object):
def __init__(self):
# Reading data sets
(self.train,self.train_label),(self.test,self.test_label) = cifar100.load_data()
# Normalize the data set
self.train = self.train.reshape(-1,32,32,3) / 255.0
self.test = self.test.reshape(-1,32,32,3) / 255.0
Build a network model
- Convolution layer :32 individual 5*5 Convolution kernel , The step size is set to 1, The activation function uses relu
- Pooling layer : The pool size is 2, The step size is set to 2
- Convolution layer :64 individual 5*5 Convolution kernel , The step size is set to 1, The activation function uses relu
- Pooling layer : The pool size is 2, The step size is set to 2
- Fully connected layer : Set up 1024 Neurons , The activation function is relu
- Fully connected layer : Set up 100 Neurons , The activation function is softmax
# Import necessary packages
from tensorflow.python.keras import layers,losses,optimizers
from tensorflow.python.keras.models import Sequential
import tensorflow as tf
class CNNMnist(object):
model = Sequential([
layers.Conv2D(32,kernel_size=5,strides=1,padding='same',data_format='channels_last',activation=tf.nn.relu),
layers.MaxPool2D(pool_size=2,strides=2,padding='same'),
layers.Conv2D(64,kernel_size=5,strides=1,padding='same',data_format='channels_last',activation=tf.nn.relu),
layers.MaxPool2D(pool_size=2,strides=2,padding='same'),
layers.Flatten(),
layers.Dense(1024,activation=tf.nn.relu),
layers.Dense(100,activation=tf.nn.softmax)
])
Network model compilation
class CNNMnist(object):
def compile(self):
CNNMnist.model.compile(optimizer=optimizers.adam_v2.Adam(),
loss=losses.sparse_categorical_crossentropy,
metrics=['accuracy'])
return None
model training
class CNNMnist(object):
def fit(self):
CNNMnist.model.fit(self.train,self.train_label,epochs=1,batch_size=32)
return None
Model to evaluate
class CNNMnist(object):
def evaluate(self):
train_loss,train_acc = CNNMnist.model.evaluate(self.train,self.train_label)
test_loss,test_acc = CNNMnist.model.evaluate(self.test,self.test_label)
print("train_loss:",train_loss)
print("train_acc:",train_acc)
print("test_loss:",test_loss)
print("test_acc:",test_acc)
return None
The model runs
if __name__ == '__main__':
cnn = CNNMnist()
cnn.compile()
cnn.fit()
cnn.evaluate()
Model running results
1563/1563 [==============================] - 199s 126ms/step - loss: 3.5098 - accuracy: 0.1748
1563/1563 [==============================] - 56s 35ms/step - loss: 2.8101 - accuracy: 0.3094
313/313 [==============================] - 11s 33ms/step - loss: 2.9732 - accuracy: 0.2672
train_loss: 2.81014084815979
train_acc: 0.3094399869441986
test_loss: 2.9731905460357666
test_acc: 0.2671999931335449
You can see from the results , The accuracy obtained is still relatively low . Because the loss of convolutional neural networks does not decline as fast as fully connected neural networks , And the above code only iterates once . However, compared with fully connected neural networks, convolutional neural networks , Reduced training parameters , It can reduce the requirements for computing power and performance of equipment , Therefore, in pattern recognition 、 Object detection has a wide range of applications .
summary
This paper focuses on how to build a convolutional neural network model , No necessary improvements have been made to the model .
notes : The code resource of this article comes from the dark horse programmer course
版权声明
本文为[Stephen_ Tao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230548468570.html
边栏推荐
- Examination question bank and online simulation examination of the third batch (main person in charge) of special operation certificate of safety officer a certificate in Guangdong Province in 2022
- Amount input box, used for recharge and withdrawal
- 2022年茶艺师(初级)考试模拟100题及模拟考试
- 1217_使用SCons生成目标文件
- 386. 字典序排数(中等)-迭代-全排列
- Use of list - addition, deletion, modification and query
- Future usage details
- 102. Sequence traversal of binary tree
- 2022制冷与空调设备运行操作判断题及答案
- JS parsing and execution process
猜你喜欢
MySQL advanced index [classification, performance analysis, use, design principles]
Applet learning notes (I)
2022年流动式起重机司机国家题库模拟考试平台操作
Kubernetes 服务发现 监控Endpoints
Flask项目的部署详解
极致体验,揭晓抖音背后的音视频技术
Halo open source project learning (II): entity classes and data tables
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
Halo 开源项目学习(二):实体类与数据表
QTableWidget使用讲解
随机推荐
Go的Gin框架学习
958. Complete binary tree test
ES6
2022制冷与空调设备运行操作判断题及答案
纳米技术+AI赋能蛋白质组学|珞米生命科技完成近千万美元融资
394. String decoding - auxiliary stack
Add animation to the picture under V-for timing
Click Cancel to return to the previous page and modify the parameter value of the previous page, let pages = getcurrentpages() let prevpage = pages [pages. Length - 2] / / the data of the previous pag
EasymodbusTCP之clientexample解析
Submit local warehouse and synchronize code cloud warehouse
JS implementation private attribute
Theory and practice of laser slam in dark blue College - Chapter 2 (odometer calibration)
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
2022 Jiangxi Photovoltaic Exhibition, China distributed Photovoltaic Exhibition, Nanchang solar energy utilization Exhibition
QT modification UI does not take effect
102. Sequence traversal of binary tree
2021 Great Wall Cup WP
1217_ Generating target files using scons
C1小笔记【任务训练篇一】
Go语言JSON包使用