本文整理汇总了Python中maskrcnn_benchmark.data.samplers.GroupedBatchSampler方法的典型用法代码示例。如果您正苦于以下问题:Python samplers.GroupedBatchSampler方法的具体用法?Python samplers.GroupedBatchSampler怎么用?Python samplers.GroupedBatchSampler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类maskrcnn_benchmark.data.samplers
的用法示例。
在下文中一共展示了samplers.GroupedBatchSampler方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_respect_order
# 需要导入模块: from maskrcnn_benchmark.data import samplers [as 别名]
# 或者: from maskrcnn_benchmark.data.samplers import GroupedBatchSampler [as 别名]
def test_respect_order(self):
drop_uneven = False
dataset = [i for i in range(10)]
group_ids = [0, 0, 1, 0, 1, 1, 0, 1, 1, 0]
sampler = SequentialSampler(dataset)
expected = [
[[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]],
[[0, 1, 3], [2, 4, 5], [6, 9], [7, 8]],
[[0, 1, 3, 6], [2, 4, 5, 7], [8], [9]],
]
for idx, batch_size in enumerate([1, 3, 4]):
batch_sampler = GroupedBatchSampler(
sampler, group_ids, batch_size, drop_uneven
)
result = list(batch_sampler)
self.assertEqual(result, expected[idx])
示例2: test_len
# 需要导入模块: from maskrcnn_benchmark.data import samplers [as 别名]
# 或者: from maskrcnn_benchmark.data.samplers import GroupedBatchSampler [as 别名]
def test_len(self):
batch_size = 3
drop_uneven = True
dataset = [i for i in range(10)]
group_ids = [random.randint(0, 1) for _ in dataset]
sampler = RandomSampler(dataset)
batch_sampler = GroupedBatchSampler(sampler, group_ids, batch_size, drop_uneven)
result = list(batch_sampler)
self.assertEqual(len(result), len(batch_sampler))
self.assertEqual(len(result), len(batch_sampler))
batch_sampler = GroupedBatchSampler(sampler, group_ids, batch_size, drop_uneven)
batch_sampler_len = len(batch_sampler)
result = list(batch_sampler)
self.assertEqual(len(result), batch_sampler_len)
self.assertEqual(len(result), len(batch_sampler))
示例3: test_respect_order_simple
# 需要导入模块: from maskrcnn_benchmark.data import samplers [as 别名]
# 或者: from maskrcnn_benchmark.data.samplers import GroupedBatchSampler [as 别名]
def test_respect_order_simple(self):
drop_uneven = False
dataset = [i for i in range(40)]
group_ids = [i // 10 for i in dataset]
sampler = SequentialSampler(dataset)
for batch_size in [1, 3, 5, 6]:
batch_sampler = GroupedBatchSampler(
sampler, group_ids, batch_size, drop_uneven
)
result = list(batch_sampler)
merged_result = list(itertools.chain.from_iterable(result))
self.assertEqual(merged_result, dataset)
示例4: test_respect_order_drop_uneven
# 需要导入模块: from maskrcnn_benchmark.data import samplers [as 别名]
# 或者: from maskrcnn_benchmark.data.samplers import GroupedBatchSampler [as 别名]
def test_respect_order_drop_uneven(self):
batch_size = 3
drop_uneven = True
dataset = [i for i in range(10)]
group_ids = [0, 0, 1, 0, 1, 1, 0, 1, 1, 0]
sampler = SequentialSampler(dataset)
batch_sampler = GroupedBatchSampler(sampler, group_ids, batch_size, drop_uneven)
result = list(batch_sampler)
expected = [[0, 1, 3], [2, 4, 5]]
self.assertEqual(result, expected)
示例5: test_subset_sampler
# 需要导入模块: from maskrcnn_benchmark.data import samplers [as 别名]
# 或者: from maskrcnn_benchmark.data.samplers import GroupedBatchSampler [as 别名]
def test_subset_sampler(self):
batch_size = 3
drop_uneven = False
dataset = [i for i in range(10)]
group_ids = [0, 0, 1, 0, 1, 1, 0, 1, 1, 0]
sampler = SubsetSampler([0, 3, 5, 6, 7, 8])
batch_sampler = GroupedBatchSampler(sampler, group_ids, batch_size, drop_uneven)
result = list(batch_sampler)
expected = [[0, 3, 6], [5, 7, 8]]
self.assertEqual(result, expected)