本文整理汇总了Python中multiprocessing.Queue.append方法的典型用法代码示例。如果您正苦于以下问题:Python Queue.append方法的具体用法?Python Queue.append怎么用?Python Queue.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.Queue
的用法示例。
在下文中一共展示了Queue.append方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QueueDataSet
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import append [as 别名]
class QueueDataSet(DataSet):
def __init__(self, base, batch_size, config, ntrain=None, ntest=None, n=1):
if ntrain is None:
ntrain = n
if ntest is None:
ntest = n
self._means = base._means
self._stds = base._stds
self._batch_size = batch_size
self._num_classes = base.num_classes()
self._processes = []
self._queue_train = None
self._queue_test = None
self._train_size = base.size(train=True)
if ntrain != 0:
cnt_train = self._train_size // batch_size
if self._train_size % batch_size != 0:
cnt_train += 1
if ntrain == "all":
ntr = cnt_train
else:
ntr = ntrain
print("QueueDataSet: starting %d processes for generating training data." % ntr)
if ntr == 1:
self._queue_train = Queue((cnt_train + 1) * 2)
self._processes.append(Process(target=run_process, args=(self._queue_train, base, batch_size, config.clone_extend(train=True, filter=lambda _: True))))
else:
self._queue_train = []
for i in range(ntr):
q = Queue((cnt_train // ntr) * 2)
self._processes.append(Process(target=run_process, args=(q, base, batch_size, config.clone_extend(train=True, filter=lambda x, vi=i: x % ntr == vi))))
self._queue_train.append(q)
q = Queue((cnt_train + 1) * 2)
self._processes.append(Process(target=run_process_aggr, args=(self._queue_train[:], q)))
self._queue_train.append(q)
self._test_size = base.size(train=False)
if ntest != 0:
cnt_test = self._test_size // batch_size
if self._test_size % batch_size != 0:
cnt_test += 1
if ntest == "all":
ntst = cnt_test
else:
ntst = ntest
print("QueueDataSet: starting %d processes for generating test data." % ntst)
if ntst == 1:
self._queue_test = Queue((cnt_test + 1) * 2)
self._processes.append(Process(target=run_process, args=(self._queue_test, base, batch_size, config.clone_extend(train=False, filter=lambda _: True))))
else:
self._queue_test = []
for i in range(ntst):
q = Queue((cnt_test // ntst) * 2)
self._processes.append(Process(target=run_process, args=(q, base, batch_size, config.clone_extend(train=False, filter=lambda x, vi=i: x % ntst == vi))))
self._queue_test.append(q)
q = Queue((cnt_test + 1) * 2)
self._processes.append(Process(target=run_process_aggr, args=(self._queue_test[:], q)))
self._queue_test.append(q)
self._closed = False
import atexit
atexit.register(self.close)
for p in self._processes:
p.start()
def num_classes(self):
return self._num_classes
def size(self, train=True):
if train:
return self._train_size
else:
return self._test_size
def iter(self, batch_size, config):
assert batch_size == self._batch_size
if config.train:
q = self._queue_train
else:
q = self._queue_test
if q is None:
return
if type(q) is list:
q = q[-1]
while True:
obj = q.get()
#.........这里部分代码省略.........