Paddle.fluid之loader
程序员文章站
2022-04-01 13:05:17
paddle.batch(reader, batch_sizedef make_reader(txt_file, is_train = True): def reader(): with open(txt_file, 'r') as f: lines = f.readlines() f.close() if is_train: np.random.shuffle(lines) ....
self-defination reader
def make_reader(txt_file, is_train = True):
def reader():
with open(txt_file, 'r') as f:
lines = f.readlines()
f.close()
if is_train:
np.random.shuffle(lines)
# do somehting to balance the samples
for line in lines:
yield preprocess(line, is_train) # self-defination pre-processing
return paddle.reader.buffered(reader,size=256)
- for-loop style
db_test = make_reader(test_file, is_train=False)
for i, data in enumerate(db_test()):
# do something meaningful
- paddle.batch(reader, batch_size)
my_reader = make_reader(test_file, is_train=False)
test_reader = paddle.batch(my_reader, batch_size=bz) # iterator
# case-1
for idx, data in enumerate(test_reader()):
# type(data) = list, len(data) = batch_size
# case-2
test_py_reader = fluid.layers.py_reader(
capacity=256,
shapes=((-1, 3, 224, 224), (-1, 1)),
lod_levels=[0, 0],
dtypes=('float32', 'int64'),
use_double_buffer=True)
test_py_reader.decorate_paddle_reader(test_reader)
test_py_reader.start()
try:
while True:
test_exe.run(fetch_list=[test_loss.name])
except fluid.core.EOFException:
test_py_reader.reset()
fluid.io.PyReader
1
本文地址:https://blog.csdn.net/On_theway10/article/details/110290910
上一篇: 蜂蜜糖水怎么冲的?什么季节的蜂蜜最好?
下一篇: xlwing操作excel
推荐阅读
-
【学习笔记之CSS+DIV】CSS入门_html/css_WEB-ITnose
-
Python中处理字符串之endswith()方法的使用简介
-
ThinkPHP 之 自定义模型、连贯操作要点
-
java之Mybatis分页插件
-
Excel VBA之删除没有数据的行 使用CountA是否等于0进行判断
-
《乌合之众》读后感_20170824
-
Prototype使用指南之enumerable.js_prototype
-
JavaScript 定时器 SetTimeout之定时刷新窗口和关闭窗口(代码超简单)_javascript技巧
-
javascript dom操作之cloneNode文本节点克隆使用技巧_javascript技巧
-
玩转python爬虫之URLError异常处理