SaulLu commited on
Commit
d97c5ae
1 Parent(s): 6bdfd1f

use a new random generator

Browse files
Files changed (1) hide show
  1. Caltech-101.py +3 -8
Caltech-101.py CHANGED
@@ -259,10 +259,7 @@ class Caltech101(datasets.GeneratorBasedBuilder):
259
 
260
  is_train_split = split == "train"
261
 
262
- # Sets random seed so the random partitioning of files is the same when
263
- # called for the train and test splits.
264
- numpy_original_state = np.random.get_state()
265
- np.random.seed(1234)
266
 
267
  for class_dir in img_dir.iterdir():
268
  class_name = class_dir.name
@@ -277,10 +274,10 @@ class Caltech101(datasets.GeneratorBasedBuilder):
277
  raise ValueError(
278
  f"Fewer than {_TRAIN_POINTS_PER_CLASS} ({len(index_codes)}) points in class {class_dir.name}"
279
  )
280
-
281
- train_indices = np.random.choice(
282
  index_codes, _TRAIN_POINTS_PER_CLASS, replace=False
283
  )
 
284
  test_indices = set(index_codes).difference(train_indices)
285
 
286
  indices_to_emit = train_indices if is_train_split else test_indices
@@ -315,5 +312,3 @@ class Caltech101(datasets.GeneratorBasedBuilder):
315
  "box_coord": data["box_coord"],
316
  }
317
  yield f"{class_dir.name.lower()}/{f'image_{indice}.jpg'}", record
318
- # Resets the seeds to their previous states.
319
- np.random.set_state(numpy_original_state)
 
259
 
260
  is_train_split = split == "train"
261
 
262
+ rng = np.random.default_rng(1234)
 
 
 
263
 
264
  for class_dir in img_dir.iterdir():
265
  class_name = class_dir.name
 
274
  raise ValueError(
275
  f"Fewer than {_TRAIN_POINTS_PER_CLASS} ({len(index_codes)}) points in class {class_dir.name}"
276
  )
277
+ train_indices = rng.choice(
 
278
  index_codes, _TRAIN_POINTS_PER_CLASS, replace=False
279
  )
280
+
281
  test_indices = set(index_codes).difference(train_indices)
282
 
283
  indices_to_emit = train_indices if is_train_split else test_indices
 
312
  "box_coord": data["box_coord"],
313
  }
314
  yield f"{class_dir.name.lower()}/{f'image_{indice}.jpg'}", record