有一个代码段。运行该程序会出现以下错误
epoch, step, d_train_feed_dict, g_train_feed_dict = inf_data_gen.next()
AttributeError: 'generator' object has no attribute 'next'
相应的代码段如下所示。它背后的原因是什么?你知道吗
inf_data_gen = self.inf_get_next_batch(config)
def inf_get_next_batch(self, config):
"""Loop through batches for infinite epoches.
"""
if config.dataset == 'mnist':
num_batches = min(len(self.data_X), config.train_size) // config.batch_size
else:
self.data = glob(os.path.join("./data", config.dataset, self.input_fname_pattern))
num_batches = min(len(self.data), config.train_size) // config.batch_size
epoch = 0
while True:
epoch += 1
for (step, d_train_feed_dict, g_train_feed_dict) in \
self.get_next_batch_one_epoch(num_batches, config):
yield epoch, step, d_train_feed_dict, g_train_feed_dict
您需要使用:
而不是:
python3去掉了
.next()
,将其重命名为.__next__()
,但最好使用next(generator)
。你知道吗试试这个:
看这个:there's no next() function in a yield generator in python 3
在python3中,需要使用
next()
而不是.next()
。你知道吗Dillon Davis建议:您也可以使用
.__next__()
,尽管.next()
更好。你知道吗相关问题 更多 >
编程相关推荐