Skip to content

Instantly share code, notes, and snippets.

View shi510's full-sized avatar
🤣

Im Sunghoon shi510

🤣
  • SI Analytics
  • Daejeon, South Korea
View GitHub Profile
@shi510
shi510 / ohem_generator.py
Last active January 29, 2023 20:29
Tensorflow 2.0 Online Hard Example Mining (OHEM)
class HardExampleMiner(tf.keras.utils.Sequence):
def __init__(self, model, x, y, batch_size, map_fn=None, ratio=0.8):
self.x = np.array(x, dtype=np.float32)
self.y = np.array(y, dtype=np.float32)
self.batch_size = batch_size
self.model = model
self.ratio = ratio
self.num_of_batch = int(math.floor((len(self.x) / self.batch_size)))
self.hard_idxs = np.arange(self.num_of_batch * self.batch_size)