当前位置: 首页>>代码示例>>Python>>正文


Python samplers.GroupedBatchSampler方法代码示例

本文整理汇总了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]) 
开发者ID:Res2Net,项目名称:Res2Net-maskrcnn,代码行数:20,代码来源:test_data_samplers.py

示例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)) 
开发者ID:Res2Net,项目名称:Res2Net-maskrcnn,代码行数:19,代码来源:test_data_samplers.py

示例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) 
开发者ID:Res2Net,项目名称:Res2Net-maskrcnn,代码行数:14,代码来源:test_data_samplers.py

示例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) 
开发者ID:Res2Net,项目名称:Res2Net-maskrcnn,代码行数:14,代码来源:test_data_samplers.py

示例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) 
开发者ID:Res2Net,项目名称:Res2Net-maskrcnn,代码行数:14,代码来源:test_data_samplers.py


注:本文中的maskrcnn_benchmark.data.samplers.GroupedBatchSampler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。