Esempio n. 1
0
    def set_prerequisites(self, params):
        try:
            Logger.info(ObjectDetectionService.LOG_TAG, params)
            self.url_root = params.get("url_root")
            self.user_id = params.get("user_id")
            self.app_name = params.get("app_name")
            self.path_to_image = os.path.join(ObjectDetectionService.CWD_PATH, 'storage', self.user_id,
                                              self.app_name)
            self.path_to_upload_original = os.path.join(self.path_to_image, config["storage"]["upload_dir"],
                                                        config["storage"]["original_dir"])
            self.path_to_upload_thumbnail = os.path.join(self.path_to_image, config["storage"]["upload_dir"],
                                                         config["storage"]["thumbnail_dir"])
            self.path_to_output = os.path.join(self.path_to_image, config["storage"]["output_dir"])

            if not os.path.isdir(self.path_to_image):
                mkdir_p(self.path_to_image)

            if not os.path.isdir(self.path_to_upload_original):
                mkdir_p(self.path_to_upload_original)

            if not os.path.isdir(self.path_to_upload_thumbnail):
                mkdir_p(self.path_to_upload_thumbnail)

            if not os.path.isdir(self.path_to_output):
                mkdir_p(self.path_to_output)
        except Exception as e:
            ApiResponse.set_msg(1, "Internal server error")
            Logger.error(ObjectDetectionService.LOG_TAG, "Exception: {error}".format(error=str(e)))
            return ApiResponse.get(config["api"]["base_code_object_detection"])
        ll = tf.math.abs(tf.math.log(model.calculate_loss(inputs, pois)))
        ll = tf.reduce_mean(ll)
    if i % 10 == 0: print("Epoch ", i, ll)
    grad = tape.gradient(ll, model.trainable_weights)
    optimizer.apply_gradients(zip(grad, model.trainable_weights))

# _________________________________________________________________ ||
# Saving
# _________________________________________________________________ ||
model.save(saved_model_path)

# _________________________________________________________________ ||
# Draw validation contour
# _________________________________________________________________ ||
plot_dir = os.path.join(saved_model_path, "plot")
mkdir_p(plot_dir)
plotBins = [
    rate_low + ibin * (rate_high - rate_low) / nPlotBin
    for ibin in range(nPlotBin + 1)
]
for i in range(nDraw):
    plt.clf()
    x, hists, pois = generator.generate(1, (sample_size, ))

    inputs = model(hists)
    ll = np.array([
        model.calculate_loss(inputs, tf.constant([[b]], dtype=np.float32))[0]
        for b in plotBins
    ])

    plt.title(label='rate: ' + str(pois[0].numpy()))
cfg = read_from_file_python2(sys.argv[1])
# ______________________________________________________________________ ||
input_file_pattern = os.path.join(cfg.param_dict.out_delphes_dir, "*.root")
job_name = cfg.param_dict.litetree_job_name
out_dir = cfg.param_dict.out_litetree_dir

cmssw_dir = cfg.param_dict.cmssw_dir
delphes_dir = cfg.param_dict.delphes_dir

script_name = "LiteTreeProducer.C"

# ______________________________________________________________________ ||
input_file_list = [f for f in glob.glob(input_file_pattern)]
input_file_list.sort()
n_file = len(input_file_list)
mkdir_p(out_dir)
for ijob, f in enumerate(input_file_list):
    each_job_name = job_name + "_" + str(ijob)
    out_file_name = os.path.basename(f)
    commands = "\n".join([
        "cd " + cmssw_dir,
        "eval `scramv1 runtime -sh`",
        "cd " + delphes_dir,
        "root -b -q \'" + script_name +
        "(\"{inputFile}\",\"{outputFile}\")\'".format(
            inputFile=f, outputFile=os.path.join(out_dir, out_file_name)),
    ], )
    script_file_name = os.path.join(out_dir, each_job_name + ".cfg")
    worker = SLURMWorker()
    worker.make_sbatch_script(
        script_file_name,
Esempio n. 4
0
import os, sys
from distutils.dir_util import copy_tree
import numpy as np
import subprocess

from utils.ObjDict import read_from_file_python2
from utils.mkdir_p import mkdir_p

cfg = read_from_file_python2(sys.argv[1])
for key in cfg.param_dict:
    exec(key + " = cfg.param_dict." + key)

mkdir_p(out_mg_dir)
for _ in range(n_dir):

    n = np.random.rand()
    param = param_low + n * (param_high - param_low)
    seed = np.random.randint(seed_low, seed_high)

    out_dir = os.path.join(out_mg_dir, "_".join([str(param), str(seed)]) + "/")

    print("Copying directory as param, seed " + str(param), str(seed))

    copy_tree(template_dir, out_dir)
    subprocess.call([
        "sed", "-i", "-e", 's/' + param_name + '/' + str(param) + '/g',
        os.path.join(out_dir, "Cards/param_card.dat")
    ])
    subprocess.call([
        "sed", "-i", "-e", 's/' + seed_name + '/' + str(seed) + '/g',
        os.path.join(out_dir, "Cards/run_card.dat")