當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。