如何在使用 recordio 数据时区分 train 和 test 数据?
Created by: joodo
根据 文档 中描述,写了以下测试程序(已精简):
import paddle
import paddle.fluid as fluid
USE_CUDA = True
IMAGE_RESIZE_SIZE = 128
BATCH_SIZE = 32
PASS_NUM = 100
# Layers
def network(is_test):
data_shape = [-1, 3, IMAGE_RESIZE_SIZE, IMAGE_RESIZE_SIZE]
if not is_test:
file_obj = fluid.layers.open_files(
filenames=['train.recordio'],
shapes=[data_shape, [-1, 1]],
lod_levels=[0, 0],
dtypes=['float32', 'float32'],
pass_num=PASS_NUM,
)
file_obj = fluid.layers.shuffle(file_obj, buffer_size=8192)
else:
file_obj = fluid.layers.open_files(
filenames=['test.recordio'],
shapes=[data_shape, [-1, 1]],
lod_levels=[0, 0],
dtypes=['float32', 'float32'],
)
file_obj = fluid.layers.batch(file_obj, batch_size=BATCH_SIZE)
file_obj = fluid.layers.double_buffer(file_obj)
image_layer, label_layer = fluid.layers.read_file(file_obj)
return label_layer
# Train program
with fluid.unique_name.guard():
train_label_layer = network(is_test=False)
# Test program
test_program = fluid.Program()
with fluid.unique_name.guard():
with fluid.program_guard(test_program, fluid.Program()):
test_label_layer = network(is_test=True)
# Executor
place = fluid.CUDAPlace(0) if USE_CUDA else fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
# Train
while True:
test_label, = exe.run(program=test_program, fetch_list=[test_label_layer])
print(test_label) # 应该打印测试数据的 label
raw_input()
结果运行时,打印的是训练数据,也就是 train.recordio 中的数据,请问是什么原因?谢谢