9aa1aa24c0eaafb95f3a0a580de9df38e803e039,torchreid/samplers.py,RandomIdentitySampler,__iter__,#RandomIdentitySampler#,40
Before Change
self.length += num - num % self.num_instances
def __iter__(self):
list_container = []
for pid in self.pids:
idxs = copy.deepcopy(self.index_dic[pid])
if len(idxs) < self.num_instances:
idxs = np.random.choice(idxs, size=self.num_instances, replace=True)
random.shuffle(idxs)
batch_idxs = []
for idx in idxs:
batch_idxs.append(idx)
if len(batch_idxs) == self.num_instances:
list_container.append(batch_idxs)
batch_idxs = []
random.shuffle(list_container)
ret = []
for batch_idxs in list_container:
ret.extend(batch_idxs)
return iter(ret)
def __len__(self):
return self.length
After Change
self.length += num - num % self.num_instances
def __iter__(self):
batch_idxs_dict = defaultdict(list)
for pid in self.pids:
idxs = copy.deepcopy(self.index_dic[pid])
if len(idxs) < self.num_instances:
idxs = np.random.choice(idxs, size=self.num_instances, replace=True)
random.shuffle(idxs)
batch_idxs = []
for idx in idxs:
batch_idxs.append(idx)
if len(batch_idxs) == self.num_instances:
batch_idxs_dict[pid].append(batch_idxs)
batch_idxs = []
avai_pids = copy.deepcopy(self.pids)
final_idxs = []
while len(avai_pids) >= self.num_pids_per_batch:
selected_pids = random.sample(avai_pids, self.num_pids_per_batch)
for pid in selected_pids:
batch_idxs = batch_idxs_dict[pid].pop(0)
final_idxs.extend(batch_idxs)
if len(batch_idxs_dict[pid]) == 0:
avai_pids.remove(pid)
return iter(final_idxs)
def __len__(self):
return self.length
In pattern: SUPERPATTERN
Frequency: 4
Non-data size: 8
Instances
Project Name: KaiyangZhou/deep-person-reid
Commit Name: 9aa1aa24c0eaafb95f3a0a580de9df38e803e039
Time: 2018-08-16
Author: k.zhou@qmul.ac.uk
File Name: torchreid/samplers.py
Class Name: RandomIdentitySampler
Method Name: __iter__
Project Name: pfnet-research/chainer-chemistry
Commit Name: e2db5e6a3016d4df77312d8faf78cddb4d0bff5c
Time: 2019-01-29
Author: acc1ssnn9terias@gmail.com
File Name: examples/qm9/plot.py
Class Name:
Method Name: main
Project Name: pantsbuild/pants
Commit Name: 0b03c97748a27d26f5284ce1c88ed1b41316ede6
Time: 2016-11-17
Author: wangpeiyu@gmail.com
File Name: src/python/pants/backend/jvm/zinc/zinc_analysis_parser.py
Class Name: ZincAnalysisParser
Method Name: parse_deps
Project Name: pantsbuild/pants
Commit Name: a4a36ff66ac3deff1ea024f58e86e003ed83bb67
Time: 2015-04-11
Author: stuhood@gmail.com
File Name: src/python/pants/backend/jvm/tasks/jvm_compile/jvm_compile_global_strategy.py
Class Name: JvmCompileGlobalStrategy
Method Name: compute_classes_by_source