当前位置:网站首页>Tensorflow2.0 advanced learning - image (11)
Tensorflow2.0 advanced learning - image (11)
2022-06-10 12:26:00 【Hekai】
Convolution network
The standard picture size is the same , If it is not standard, it should be stretched to standard , Pay attention to the data size of input and output
Leading package
import tensorflow as tf
from tensorflow.keras import datasets, layers, models
import matplotlib.pyplot as plt
Data preparation
cifar10, Picture classification old friend .
(train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data()
# Normalize pixel values to be between 0 and 1
train_images, test_images = train_images / 255.0, test_images / 255.0
Look what it looks like
plt.figure(figsize=(10, 10))
for i in range(25):
plt.subplot(5, 5, i+1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(train_images[i])
# The CIFAR labels happen to be arrays,
# which is why you need the extra index
plt.xlabel(class_names[train_labels[i][0]])
plt.show()
Model preparation
model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.summary()
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10))
model.summary()
model.compile(optimizer='adam',
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
Run
history = model.fit(train_images, train_labels, epochs=10,
validation_data=(test_images, test_labels))
forecast
plt.plot(history.history['accuracy'], label='accuracy')
plt.plot(history.history['val_accuracy'], label = 'val_accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.ylim([0.5, 1])
plt.legend(loc='lower right')
plt.show()
test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=2)
print(test_acc)
边栏推荐
- 2022年浙江省赛
- Const Modified member function
- Unity3d 使用URP渲染管线实现AR阴影(阴影投射再透明地面)
- Stm32f407 learning notes (1) -exti interrupt event and NVIC register
- SLM4054独立线性锂电池充电器的芯片的学习
- 求k个字符串的公共子序列数
- 【严选】,真题解析
- UML类图
- Xijun data cooperates with Alibaba cloud to obtain Alibaba cloud product integration certification!
- STM32学习笔记(2)-USART(基础应用1)
猜你喜欢
随机推荐
Using Joern to process a large number of files and generate PDG is a slow solution
Zipoutputstream use
ShaderGraph——303摇曳的小草
JS judgment includes: includes
Const Modified member function
(六)类和对象,对象初始化和拷贝构造函数(3)
Learning of cc2642r Bluetooth MCU chip
Using SQLite3 database in embedded Linux
Surrender firehouse database access: Twitter is ready to meet Musk's requirements
Shadergraph - 301 bouncing ball
GIMP - 免费开源的图像处理软件,功能强大,被称为 Photoshop 的优秀替代品
大牛推荐,吊打面试官
js数组转json 、json转数组。数组转逗号隔开字符串、字符串转数组
【必备】,真题解析
eseses
C# 实现气泡窗体
C Introduction à la Bibliothèque des meilleures pratiques linguistiques (Partie 2)
js禁止复制页面内容
聊聊消息中间件(1),AMQP那些事儿
合集资料,必看








