Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 1 addition & 31 deletions tutorials/machine_learning/TMVA_CNN_Classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,18 @@
## The difference between signal and background is in the gaussian width.
## The width for the background gaussian is slightly larger than the signal width by few % values

import ROOT

import os
import importlib.util

Check failure on line 28 in tutorials/machine_learning/TMVA_CNN_Classification.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

tutorials/machine_learning/TMVA_CNN_Classification.py:25:1: I001 Import block is un-sorted or un-formatted

useKerasCNN = False

if ROOT.gSystem.GetFromPipe("root-config --has-tmva-pymva") == "yes":
useKerasCNN = True

opt = [1, 1, 1, 1, 1]
useTMVACNN = opt[0] if len(opt) > 0 else False
useKerasCNN = opt[1] if len(opt) > 1 else useKerasCNN
useKerasCNN = opt[1] if len(opt) > 1 else False
useTMVADNN = opt[2] if len(opt) > 2 else False
useTMVABDT = opt[3] if len(opt) > 3 else False
usePyTorchCNN = opt[4] if len(opt) > 4 else False

if useKerasCNN:
try:
import tensorflow
except:
ROOT.Warning("TMVA_CNN_Classification", "Skip using Keras since tensorflow cannot be imported")
useKerasCNN = False

# PyTorch has to be imported before ROOT to avoid crashes because of clashing
# std::regexp symbols that are exported by cppyy.
# See also: https://github.com/wlav/cppyy/issues/227
torch_spec = importlib.util.find_spec("torch")
if torch_spec is None:
usePyTorchCNN = False
print("TMVA_CNN_Classificaton","Skip using PyTorch since torch is not installed")
else:
try:
import torch
except:
ROOT.Warning("TMVA_CNN_Classification", "Skip using PyTorch since it cannot be imported")
usePyTorchCNN = False


import ROOT


TMVA = ROOT.TMVA
TFile = ROOT.TFile

Expand Down Expand Up @@ -120,7 +90,7 @@
h2.FillRandom(f2, nRndmEvts)

for k in range(nh):
for l in range(nw):

Check failure on line 93 in tutorials/machine_learning/TMVA_CNN_Classification.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E741)

tutorials/machine_learning/TMVA_CNN_Classification.py:93:17: E741 Ambiguous variable name: `l`
m = k * nw + l
# add some noise in each bin
x1[m] = h1.GetBinContent(k + 1, l + 1) + ROOT.gRandom.Gaus(0, pixelNoise)
Expand All @@ -147,7 +117,7 @@
useTMVACNN = False
useTMVADNN = False

if not "tmva-pymva" in ROOT.gROOT.GetConfigFeatures():

Check failure on line 120 in tutorials/machine_learning/TMVA_CNN_Classification.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E713)

tutorials/machine_learning/TMVA_CNN_Classification.py:120:8: E713 Test for membership should be `not in`
useKerasCNN = False
usePyTorchCNN = False
else:
Expand Down Expand Up @@ -475,13 +445,13 @@
ROOT.Info("TMVA_CNN_Classification", "Building convolutional keras model")
# create python script which can be executed
# create 2 conv2d layer + maxpool + dense
import tensorflow

Check failure on line 448 in tutorials/machine_learning/TMVA_CNN_Classification.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

tutorials/machine_learning/TMVA_CNN_Classification.py:448:12: F401 `tensorflow` imported but unused
from tensorflow.keras.models import Sequential
from tensorflow.keras.optimizers import Adam

# from keras.initializers import TruncatedNormal
# from keras import initializations
from tensorflow.keras.layers import Input, Dense, Dropout, Flatten, Conv2D, MaxPooling2D, Reshape

Check failure on line 454 in tutorials/machine_learning/TMVA_CNN_Classification.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

tutorials/machine_learning/TMVA_CNN_Classification.py:454:55: F401 `tensorflow.keras.layers.Dropout` imported but unused

Check failure on line 454 in tutorials/machine_learning/TMVA_CNN_Classification.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

tutorials/machine_learning/TMVA_CNN_Classification.py:454:41: F401 `tensorflow.keras.layers.Input` imported but unused

Check failure on line 454 in tutorials/machine_learning/TMVA_CNN_Classification.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

tutorials/machine_learning/TMVA_CNN_Classification.py:448:5: I001 Import block is un-sorted or un-formatted

# from keras.callbacks import ReduceLROnPlateau
model = Sequential()
Expand Down
Loading