MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / __init__

Method __init__

tools/data/multi_scale_sampler.py:10–121  ·  view source on GitHub ↗

multi scale samper Args: data_source(dataset) scales(list): several scales for image resolution first_bs(int): batch size for the first scale in scales divided_factor(list[w, h]): ImageNet models down-sample images by a factor, ensure

(
        self,
        data_source,
        scales,
        first_bs=128,
        fix_bs=True,
        divided_factor=[8, 16],
        is_training=True,
        ratio_wh=0.8,
        max_w=480.0,
        seed=None,
    )

Source from the content-addressed store, hash-verified

8class MultiScaleSampler(Sampler):
9
10 def __init__(
11 self,
12 data_source,
13 scales,
14 first_bs=128,
15 fix_bs=True,
16 divided_factor=[8, 16],
17 is_training=True,
18 ratio_wh=0.8,
19 max_w=480.0,
20 seed=None,
21 ):
22 """
23 multi scale samper
24 Args:
25 data_source(dataset)
26 scales(list): several scales for image resolution
27 first_bs(int): batch size for the first scale in scales
28 divided_factor(list[w, h]): ImageNet models down-sample images by a factor, ensure that width and height dimensions are multiples are multiple of devided_factor.
29 is_training(boolean): mode
30 """
31 # min. and max. spatial dimensions
32 self.data_source = data_source
33 self.data_idx_order_list = np.array(data_source.data_idx_order_list)
34 self.ds_width = data_source.ds_width
35 self.seed = data_source.seed
36 if self.ds_width:
37 self.wh_ratio = data_source.wh_ratio
38 self.wh_ratio_sort = data_source.wh_ratio_sort
39 self.n_data_samples = len(self.data_source)
40 self.ratio_wh = ratio_wh
41 self.max_w = max_w
42
43 if isinstance(scales[0], list):
44 width_dims = [i[0] for i in scales]
45 height_dims = [i[1] for i in scales]
46 elif isinstance(scales[0], int):
47 width_dims = scales
48 height_dims = scales
49 base_im_w = width_dims[0]
50 base_im_h = height_dims[0]
51 base_batch_size = first_bs
52
53 # Get the GPU and node related information
54 if dist.is_initialized():
55 num_replicas = dist.get_world_size()
56 rank = dist.get_rank()
57 else:
58 num_replicas = 1
59 rank = 0
60 # adjust the total samples to avoid batch dropping
61 num_samples_per_replica = int(self.n_data_samples * 1.0 / num_replicas)
62
63 img_indices = [idx for idx in range(self.n_data_samples)]
64
65 self.shuffle = False
66 if is_training:
67 # compute the spatial dimensions and corresponding batch size

Callers

nothing calls this directly

Calls 1

iterMethod · 0.95

Tested by

no test coverage detected