自定义reader不可调用
reader是一个生成器,每次生成一个batch数据,yield出来给pyreader,但是报错生成器不可调用,错误信息如下:
Traceback (most recent call last): File "xxx/python27-gcc482/lib/python2.7/threading.py", line 810, in __bootstrap_inner self.run() File "xxx/python27-gcc482/lib/python2.7/threading.py", line 763, in run self.__target(*self.__args, **self.__kwargs) File "xxx/python27-gcc482/lib/python2.7/site-packages/paddle/fluid/layers/io.py", line 563, in provider_thread for tensors in func(): TypeError: 'generator' object is not callable
reader代码: `def make_reader(filelist, batch_size, vocab, is_training, shuffle, **dataset_args): fl = open(filelist).readlines() fl = [line.strip() for line in fl if line.strip() != ''] if shuffle: random.shuffle(fl)
imgs_batch = []
text_batch = []
label_batch = []
identifier_batch = []
for file in fl:
with open(file) as fh:
for line in fh:
video, texts, identifiers = line.strip('\n').split('\t')
frames = json.loads(video)
text_list = texts.split('\001')
identifier_list = identifiers.split('\001')
num_text = len(text_list)
imgs = decode_video(frames,
mode=dataset_args['mode'],
seg_num=dataset_args['seg_num'],
short_size=dataset_args['short_size'],
target_size=dataset_args['crop_size'])
k = random.randint(num_text)
identifier = identifier_list[k]
text = text_list[k]
wordids = decode_text(text, vocab, max_words=dataset_args['max_words'])
text_batch.append(wordids)
label_batch.append(1) # unused
identifier_batch.append(identifier)
imgs_batch.append(imgs)
if len(imgs_batch) == batch_size:
#
imgs_out = np.array(imgs_batch).reshape([-1, dataset_args['seg_num'], 3, dataset_args['crop_size'], dataset_args['crop_size']]).astype("float32")
text_out = to_lodtensor(text_batch, self.place)
label_out = np.array(label_batch).reshape([-1, 1]).astype("int64")
identifier_out = np.array(identifier_batch).reshape([-1, 1]).astype("int64")
if dataset_args['data_mode'] == "point-wise":
batch_out = [imgs_out, text_out, label_out, identifier_out]
elif dataset_args['data_mode'] == "pair-wise":
index = np.arange(batch_size) + random.randint(1, batch_size)
index = index % batch_size
pos_text_out = text_out
neg_text_out = to_lodtensor(np.array(text_batch)[index].tolist(), self.place)
batch_out = [imgs_out, pos_text_out, neg_text_out, label_out, identifier_out]
yield batch_out
imgs_batch = []
text_batch = []
label_batch = []
identifier_batch = []
`
请检查下make_reader函数的返回值