K.set_image_data_format('channels_last') from subtlenet import config from subtlenet.generators.gen_singletons import make_coll, generate from paths import basedir ''' some global definitions ''' NEPOCH = 50 APOSTLE = 'v4_nopt' system('cp %s shallow_models/train_%s.py' % (argv[0], APOSTLE)) ''' instantiate data loaders ''' top = make_coll(basedir + '/PARTITION/Top_*_CATEGORY.npy') qcd = make_coll(basedir + '/PARTITION/QCD_*_CATEGORY.npy') data = [top, qcd] ''' first build the classifier! ''' # set up data classifier_train_gen = generate(data, partition='train', batch=1000) classifier_validation_gen = generate(data, partition='validate', batch=10000) classifier_test_gen = generate(data, partition='test', batch=10) test_i, test_o, test_w = next(classifier_test_gen) #print test_i inputs = Input(shape=(len(config.gen_default_variables), ), name='input')
from os import environ, system environ['KERAS_BACKEND'] = 'tensorflow' environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" environ["CUDA_VISIBLE_DEVICES"] = "" import numpy as np from keras.models import Model, load_model from subtlenet import config import akt_config # override defaults from subtlenet.generators.gen_singletons import make_coll from paths import basedir shallow = load_model('shallow_models/shallow_v4_shallow.h5') coll = make_coll(basedir + '/PARTITION/*_CATEGORY.npy') def predict_t(data): inputs = data['singletons'][:,[config.gen_singletons[x] for x in config.gen_default_variables]] if inputs.shape[0] > 0: if config.gen_default_mus is not None: mus = np.array(config.gen_default_mus) sigmas = np.array(config.gen_default_sigmas) inputs -= mus inputs /= sigmas r_shallow_t = shallow.predict(inputs)[:,config.n_truth-1] else: r_shallow_t = np.empty((0,1)) return r_shallow_t