当前位置:网站首页>Tensorflow2.0进阶学习-图像 (十一)
Tensorflow2.0进阶学习-图像 (十一)
2022-06-10 12:15:00 【赫凯】
卷积网络
规范的图片尺寸都一样,不规范也要拉伸到规范,注意好输入输出的数据尺寸就好了
引包
import tensorflow as tf
from tensorflow.keras import datasets, layers, models
import matplotlib.pyplot as plt
数据准备
cifar10,图片分类老朋友了。
(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
看看长什么样子
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 = 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'])
跑起来
history = model.fit(train_images, train_labels, epochs=10,
validation_data=(test_images, test_labels))
预测
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)
边栏推荐
- Shadergraph - Crystal
- (10) Notes on null pointer accessing member function and this pointer
- ShaderGraph——302游动的龙
- Traversing object properties of unknown type
- How to insert PDF into ppt as vector graph
- Unity3d 使用URP渲染管线实现AR阴影(阴影投射再透明地面)
- 【云图说】每个成功的业务系统都离不开APIG的保驾护航
- 使用SoapUI工具生成发送短信接口代码
- Get enumeration values through reflection
- 【严选】,真题解析
猜你喜欢

js将时间戳转换成正常时间格式

IO文件流重复读取

Introduction: from the origin of etcd name to installation, deployment and usage posture

Ad-pcb schematic diagram learning (1)

大牛推荐,吊打面试官

Amateurs don't ask for help, drag and drop for 30 seconds to make the cover image

js全局计时器的案例
![[required] analysis of the real problem](/img/36/08c752763b8b89aa60feaa4339a689.png)
[required] analysis of the real problem

C语言最佳实践之库文件介绍(下)

Introduction to the library of C language best practices (Part 2)
随机推荐
In the era of digital economy, where should retail stores go
IO文件流重复读取
嵌入式Linux中使用SQLite3数据库
H5 pop up prompt layer - top, bottom, left and right center
(7) Deep and shallow copy
Living in the last era, etcd 3.0 is so simple to implement distributed locks!
ASP.NET 利用ImageMap控件设计导航栏
vs2010未定义的标识符 round
JS judgment includes: includes
mysql8.0安装
无代码五月大事件|微软低代码矩阵更新;多份行业报告发布...
Using SQLite3 database in embedded Linux
Dom4j parsing XML
JS converts timestamp to normal time format
Ad-pcb schematic diagram learning (1)
Introduction to the library of C language best practices (Part 2)
SQL Server AlwaysOn查看数据同步进度
ShaderGraph——303摇曳的小草
C# 实现气泡窗体
Unity3D开发MR实现模型遮挡与透明地面接收阴影