当前位置:网站首页>Two ways of tensorflow2 training data sets
Two ways of tensorflow2 training data sets
2022-06-12 17:31:00 【Laoyoutiao 666】
Mode one :
def pre_process(x, y):
x = 2. * tf.cast(x, dtype=tf.float32) / 255. - 1.
y = tf.cast(y, dtype=tf.int32)
return x, y
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.cifar100.load_data()
x_train, y_train = pre_process(x_train, y_train)
x_test, y_test = pre_process(x_test, y_test)
print(x_train.shape, y_train.shape)
history = net.fit(x_train, y_train,
batch_size=512,
epochs=100,
validation_split=0.2)
test_scores = net.evaluate(x_test, y_test, verbose=2)Training mode II :
def pre_process(x, y):
# [0,255] => [-1,1] ,[-1,1] It may be the most suitable range for neural network calculation
x = 2. * tf.cast(x, dtype=tf.float32) / 255. - 1
y = tf.squeeze(y) # Remove from the tensor shape a value of 1 Dimensions .
y = tf.cast(y, dtype=tf.int32)
y = tf.one_hot(y, depth=10)
return x, y
batch_size = 128
(x, y), (x_val, y_val) = datasets.cifar10.load_data()
print('datasets:', x.shape, y.shape, x.min(), y.min())
train_db = tf.data.Dataset.from_tensor_slices((x, y))
train_db = train_db.map(pre_process).shuffle(1000).batch(batch_size)
test_db = tf.data.Dataset.from_tensor_slices((x_val, y_val))
test_db = test_db.map(pre_process).shuffle(1000).batch(batch_size)
sample = next(iter(train_db))
print('batch:', sample[0].shape, sample[1].shape)
network = MyNetwork() # MYNetwork yes Keras.Model A subclass of
network.compile(
optimizer=optimizers.Adam(learning_rate=1e-3),
loss=tf.losses.CategoricalCrossentropy(from_logits=True),
metrics=['accuracy']
)
network.fit(train_db, epochs=50, validation_data=test_db, validation_freq=1)
network.evaluate(test_db)
network.save_weights('./ckpt/cifar10_weights.ckpt') # b Save the model to a disk file Reference link :
1. Li Mu great God 《 Hands on deep learning 》TensorFlow Realization ,GitHub link :https://github.com/TrickyGo/Dive-into-DL-TensorFlow2.0, Refer to CNN5.9GoogleNet Part of the code
2 Long Liangqu . Deep learning and TensorFlow Introduction of actual combat , project GitHub link :https://github.com/dragen1860/Deep-Learning-with-TensorFlow-book, From which Lesson40--CIFAR And VGG actual combat
边栏推荐
- Sizepolicy policy in layout management
- Notes on user experience elements: user centered product design
- R language uses the sum function of epidisplay package to calculate the descriptive statistical summary information of the specified variables in dataframe under different grouped variables and visual
- 布局管理中的sizePolicy的策略问题
- Hangzhou AI developer meetup registration opens!
- R语言使用epiDisplay包的tabpct函数生成二维列联表并使用马赛克图可视化列联表(二维列联表、边际频数、以及按行、按列的比例)、自定义设置ylab参数设置Y轴的轴标签文本(y axis)
- Enterprise internal online training system source code
- 分辨率与行场同步信号的关系 场消隐
- (4) Golang operator
- Selenium element positioning
猜你喜欢

Yyds dry goods inventory leetcode question set 911 - 920

How to use the official documents of pytorch and torchvision

Download PHP source code of leaf sharing station

A variety of Qt development methods, which do you choose?

内核中断整体流程图

多种Qt的开发方式,你选择哪种?

5、Embedding

office应用程序无法正常启动0xc0000142

迄今微软不同时期发布的SQL Server各版本之间的大致区别,供参考查阅

快速入门scrapy爬虫框架
随机推荐
Risc-v ide mounriver studio v1.60 update point introduction
Tcp/ip family structure and protocol of tcp/ip series overview
(8) Goto keyword
To understand Devops, you must read these ten books!
(7) Loop statement for
Enterprise internal online training system source code
如何查看、修改和删除SSH
Analysis of CA certificate with high value
R language uses the sum function of epidisplay package to calculate the descriptive statistical summary information of the specified variables in dataframe under different grouped variables and visual
两位新晋Committer的“升级攻略”
Introduction of one object one code tracing system
(3) Golang - data type
Is it cost-effective to apply for Huagui sweet home term life insurance? What are the advantages of this product?
R语言使用plot函数可视化数据散点图,使用font.axis参数指定坐标轴刻度标签的字体类型为斜体字体(italic)
qemu+gdb小节
R语言使用epiDisplay包的tableStack函数基于分组变量生成统计分析表(包含描述性统计分析、假设检验、不同数据使用不同的统计量和假设检验方法)、自定义配置是否显示统计检验内容
快速入门scrapy爬虫框架
Tidb Hackathon 2021 - pcloud: conduct icloud pcloud team interview on the database
R语言使用pdf函数将可视化图像结果保存到pdf文件中、使用pdf函数打开图像设备、使用dev.off函数关闭图像设备、自定义width参数和height参数指定图像的宽度和高度
[BSP video tutorial] stm32h7 video tutorial Issue 8: the last issue of the MDK theme, the new generation of debugging technologies event recorder and RTT, and using stm32cubemx to generate project tem