Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RBatchGenerator_NumPy.py File Reference

Detailed Description

View in nbviewer Open in SWAN

Example of getting batches of events from a ROOT dataset as Python generators of numpy arrays.

import ROOT
tree_name = "sig_tree"
file_name = "http://root.cern/files/Higgs_data.root"
batch_size = 128
chunk_size = 5_000
ds_train, ds_validation = ROOT.TMVA.Experimental.CreateNumPyGenerators(
tree_name,
file_name,
batch_size,
chunk_size,
validation_split=0.3,
shuffle=True,
)
# Loop through training set
for i, b in enumerate(ds_train):
print(f"Training batch {i} => {b.shape}")
# Loop through Validation set
for i, b in enumerate(ds_validation):
print(f"Validation batch {i} => {b.shape}")
Training batch 0 => (128, 29)
Training batch 1 => (128, 29)
Training batch 2 => (128, 29)
Training batch 3 => (128, 29)
Training batch 4 => (128, 29)
Training batch 5 => (128, 29)
Training batch 6 => (128, 29)
Training batch 7 => (128, 29)
Training batch 8 => (128, 29)
Training batch 9 => (128, 29)
Training batch 10 => (128, 29)
Training batch 11 => (128, 29)
Training batch 12 => (128, 29)
Training batch 13 => (128, 29)
Training batch 14 => (128, 29)
Training batch 15 => (128, 29)
Training batch 16 => (128, 29)
Training batch 17 => (128, 29)
Training batch 18 => (128, 29)
Training batch 19 => (128, 29)
Training batch 20 => (128, 29)
Training batch 21 => (128, 29)
Training batch 22 => (128, 29)
Training batch 23 => (128, 29)
Training batch 24 => (128, 29)
Training batch 25 => (128, 29)
Training batch 26 => (128, 29)
Training batch 27 => (128, 29)
Training batch 28 => (128, 29)
Training batch 29 => (128, 29)
Training batch 30 => (128, 29)
Training batch 31 => (128, 29)
Training batch 32 => (128, 29)
Training batch 33 => (128, 29)
Training batch 34 => (128, 29)
Training batch 35 => (128, 29)
Training batch 36 => (128, 29)
Training batch 37 => (128, 29)
Training batch 38 => (128, 29)
Training batch 39 => (128, 29)
Training batch 40 => (128, 29)
Training batch 41 => (128, 29)
Training batch 42 => (128, 29)
Training batch 43 => (128, 29)
Training batch 44 => (128, 29)
Training batch 45 => (128, 29)
Training batch 46 => (128, 29)
Training batch 47 => (128, 29)
Training batch 48 => (128, 29)
Training batch 49 => (128, 29)
Training batch 50 => (128, 29)
Training batch 51 => (128, 29)
Training batch 52 => (128, 29)
Training batch 53 => (128, 29)
Validation batch 0 => (128, 29)
Validation batch 1 => (128, 29)
Validation batch 2 => (128, 29)
Validation batch 3 => (128, 29)
Validation batch 4 => (128, 29)
Validation batch 5 => (128, 29)
Validation batch 6 => (128, 29)
Validation batch 7 => (128, 29)
Validation batch 8 => (128, 29)
Validation batch 9 => (128, 29)
Validation batch 10 => (128, 29)
Validation batch 11 => (128, 29)
Validation batch 12 => (128, 29)
Validation batch 13 => (128, 29)
Validation batch 14 => (128, 29)
Validation batch 15 => (128, 29)
Validation batch 16 => (128, 29)
Validation batch 17 => (128, 29)
Validation batch 18 => (128, 29)
Validation batch 19 => (128, 29)
Validation batch 20 => (128, 29)
Validation batch 21 => (128, 29)
Author
Dante Niewenhuis

Definition in file RBatchGenerator_NumPy.py.