MCPcopy Create free account
hub / github.com/TPCD/DCCL / __iter__

Method __iter__

project_utils/sampler.py:132–156  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

130 return self.num_samples * self.num_instances
131
132 def __iter__(self):
133 indices = torch.randperm(len(self.pids)).tolist()
134 ret = []
135
136 for kid in indices:
137 i = random.choice(self.pid_index[self.pids[kid]])
138 # _, i_pid, i_cam = self.data_source[i]
139 # _, i_pid, i_cam
140 ret.append(i)
141
142 pid_i = self.index_pid[i]
143 index = self.pid_index[pid_i]
144
145 select_indexes = No_index(index, i)
146 if not select_indexes:
147 continue
148 if len(select_indexes) >= self.num_instances:
149 ind_indexes = np.random.choice(select_indexes, size=self.num_instances-1, replace=False)
150 else:
151 ind_indexes = np.random.choice(select_indexes, size=self.num_instances-1, replace=True)
152
153 for kk in ind_indexes:
154 ret.append(index[kk])
155
156 return iter(ret)

Callers

nothing calls this directly

Calls 1

No_indexFunction · 0.85

Tested by

no test coverage detected