当前位置:网站首页>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)
边栏推荐
- C语言最佳实践之库文件介绍(上)
- Shadergraph - 303 swaying grass
- Introduction to the library of C language best practices (Part 1)
- Web design and development, efficient web development
- Learning of cc2642r Bluetooth MCU chip
- Driver. JS - open source and independent interactive guidance tool library for web novices, powerful and highly customizable
- VDMA调试总结
- js点击按钮向左侧滑动效果
- AD-PCB原理图学习(1)
- 【移动机器人】轮式里程计原理
猜你喜欢

Surrender firehouse database access: Twitter is ready to meet Musk's requirements

Altium Designer重拾之学习资料推荐

Stm32f407 learning notes (1) -exti interrupt event and NVIC register

【必备】,真题解析

MAX3051的can芯片的学习

SQL Server AlwaysOn viewing data synchronization progress

(10) Notes on null pointer accessing member function and this pointer

Talk about message oriented middleware (1) and AMQP

使用Joern处理大量文件,生成PDG速度很慢的解决方法

好文分享|48小时敏捷开发攻略
随机推荐
无代码五月大事件|微软低代码矩阵更新;多份行业报告发布...
Shadergraph - 301 bouncing ball
How to insert PDF into ppt as vector graph
Building a trusted base for digital economy 𞓜 2022 trusted database summit will be held soon
Good article sharing | 48 hour agile development introduction
Yet Another Palindrome Partitioning
使用Joern处理大量文件,生成PDG速度很慢的解决方法
【严选】,真题解析
eseses
STM32F407学习笔记(1)-EXTI中断事件与NVIC寄存器
Unity3D开发MR实现模型遮挡与透明地面接收阴影
Using SQLite3 database in embedded Linux
(5) Class, object and class file splitting operation (2)
Web design and development, efficient web development
阿里云ECS服务器搭建Mysql数据库
C # balanced weight distribution
request获取请求服务器ip地址
0509-130 Symbol resolution failed for /oracle/app/oracle/12.2.0/db_1/lib/libons.so问题处理
Shadergraph - Crystal
ShaderGraph——水面