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

Method __init__

tools/data/ratio_sampler.py:12–118  ·  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 ima

(self,
                 data_source,
                 scales,
                 first_bs=512,
                 fix_bs=True,
                 divided_factor=[8, 16],
                 is_training=True,
                 max_ratio=10,
                 max_bs=1024,
                 seed=None)

Source from the content-addressed store, hash-verified

10class RatioSampler(Sampler):
11
12 def __init__(self,
13 data_source,
14 scales,
15 first_bs=512,
16 fix_bs=True,
17 divided_factor=[8, 16],
18 is_training=True,
19 max_ratio=10,
20 max_bs=1024,
21 seed=None):
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.max_ratio = max_ratio
41 self.max_bs = max_bs
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 base_elements = base_im_w * base_im_h * base_batch_size
53 self.base_elements = base_elements
54 self.base_batch_size = base_batch_size
55 self.base_im_h = base_im_h
56 self.base_im_w = base_im_w
57
58 # Get the GPU and node related information
59 num_replicas = torch.cuda.device_count() if torch.cuda.is_available(
60 ) else 1
61 # rank = dist.get_rank()
62 rank = (int(os.environ['LOCAL_RANK'])
63 if 'LOCAL_RANK' in os.environ else 0)
64 # self.rank = rank
65 # adjust the total samples to avoid batch dropping
66 num_samples_per_replica = int(
67 math.ceil(self.n_data_samples * 1.0 / num_replicas))
68
69 img_indices = [idx for idx in range(self.n_data_samples)]

Callers

nothing calls this directly

Calls 1

create_batchMethod · 0.95

Tested by

no test coverage detected