def km3nnet(x):
    x = tf.reshape(x, shape=[-1, 13, 13, 18, 3])

    fc = cnn(x)

    output = tf.matmul(fc, weight([nodes["l5"], NUM_CLASSES
                                   ])) + bias(NUM_CLASSES)
    return output
def km3nnet(x):
    """ input: event tensor numpy shape num_minitimeslices, 18, 18, 13, 3
        output: label prediction shape 3 (one hot encoded)"""
    # loop over mini time slices
    nodes =   {"l1": 25,
               "l2": 25,
               "l3": 80,
               "l4": 40,
               "l5": 20} 
               
    weights = {"l1": weight([4, 4, 4, 3, nodes["l1"]]),
               "l2": weight([3, 3, 3, nodes["l1"], nodes["l2"]]),
               "l3": weight([11025, nodes["l3"]]),
               "l4": weight([nodes["l3"], nodes["l4"]])}

    biases =  {"l1": bias(nodes["l1"]),
               "l2": bias(nodes["l2"]),
               "l3": bias(nodes["l3"]),
               "l4": bias(nodes["l4"])}

    conv1 = tf.nn.relu(
        conv3d(x, weights["l1"]) + biases["l1"])

    conv2 = tf.nn.relu(
        conv3d(conv1, weights["l2"]) + biases["l2"])

    conv2 = maxpool3d(conv2)

    elements = np.prod(conv2._shape_as_list()[1:])

    fc = tf.reshape(conv2, [-1, elements])
    
    fc = tf.nn.relu(
        tf.matmul(fc, weights["l3"]) + biases["l3"])

    fc = tf.nn.relu(
        tf.matmul(fc, weights["l4"]) + biases["l4"])

    fc = tf.reshape(fc, [50, 1, 40])
    c = tf.unstack(fc, num_mini_timeslices, 0)
    
    lstm_layer = tf.contrib.rnn.BasicLSTMCell(nodes["l5"], forget_bias=1.)
    outputs, _ = tf.contrib.rnn.static_rnn(lstm_layer, c, dtype=tf.float32)
def km3nnet(x):
    """ input: event tensor numpy shape num_minitimeslices, 18, 18, 13, 3
        output: label prediction shape 3 (one hot encoded)"""
    # loop over mini time slices
    mini_timeslices = tf.unstack(x, num_mini_timeslices, 1)

    stacked_lstm = tf.contrib.rnn.MultiRNNCell([lstm_cell() for _ in range(2)])

    outputs, states = tf.contrib.rnn.static_rnn(stacked_lstm,
                                                mini_timeslices,
                                                dtype=tf.float32)
    output = tf.reshape(outputs[-1], [-1, 13 * 13 * 18 * 10])

    W = weight([13 * 13 * 18 * 10, 100])
    b = bias(100)
    z = tf.matmul(output, W) + b

    K = weight([100, NUM_CLASSES])
    k = bias(NUM_CLASSES)

    output = tf.matmul(z, K) + k
    return output
def km3nnet(x):
    """ input: event tensor numpy shape 400, 18, 18, 13, 3
        output: Energy, position, direction prediction in shape 7"""
    out_time_bin = []
    # loop over 400 time slices
    for i in range(x._shape_as_list()[1]):
        input_slice = x[:,i,:,:,:,:] 
        fc = cnn(input_slice)
        out_time_bin.append(fc)

    c = tf.concat(out_time_bin, 1)
    lstm_layer = tf.contrib.rnn.BasicLSTMCell(nodes["l5"], forget_bias=1)
    outputs, _ = tf.contrib.rnn.static_rnn(lstm_layer, [c], dtype=tf.float32)
    output = tf.matmul( outputs[-1], weight([nodes["l5"], NUM_CLASSES])) + bias(NUM_CLASSES)
    return output
Пример #5
0
def km3nnet(x):
    """ input: event tensor numpy shape num_minitimeslices, 18, 18, 13, 3
        output: label prediction shape 3 (one hot encoded)"""
    # loop over mini time slices
    mini_timeslices = tf.unstack(x, num_mini_timeslices, 1)
    out_time_bin = []
    for ts in mini_timeslices:
        out_time_bin.append(cnn(ts))
    c = tf.concat(out_time_bin, 1)
    c = tf.reshape(c, [-1, num_mini_timeslices, nodes["l4"]])
    c = tf.unstack(c, num_mini_timeslices, 1)
    lstm_layer = tf.contrib.rnn.BasicLSTMCell(nodes["l5"], forget_bias=1.)
    outputs, _ = tf.contrib.rnn.static_rnn(lstm_layer, c, dtype=tf.float32)
    output = tf.matmul(outputs[-1], weight([nodes["l5"], NUM_CLASSES])) + bias(NUM_CLASSES)

    return output 
Пример #6
0
def km3nnet(x):
    """ input: event tensor numpy shape num_minitimeslices, 18, 18, 13, 3
        output: label prediction shape 3 (one hot encoded)"""
    # loop over mini time slices

    mini_timeslices = tf.unstack(x, num_mini_timeslices, 1)

    out_time_bin = []
    for ts in mini_timeslices:
        out_time_bin.append(cnn(ts))

    stacked_lstm = tf.contrib.rnn.MultiRNNCell([lstm_cell() for _ in range(2)])

    outputs, states = tf.contrib.rnn.static_rnn(stacked_lstm, out_time_bin, dtype=tf.float32)
    fout = []
    for o in outputs:
        output = tf.reshape(o, [-1, 4 * 4 * 5 * 10 ])

        W = weight([4 * 4 * 5 * 10, NUM_CLASSES])
        b = bias(NUM_CLASSES)
        output = tf.matmul(output, W) + b
        fout.append(tf.nn.softmax(output))

    return output, fout
title = 'reconstruction'
EVT_TYPES = ['nueCC', 'anueCC', 'nueNC', 'anueNC', 'numuCC', 'anumuCC', 'nuK40', 'anuK40']
NUM_CLASSES = 7 # energie, x, y, z, dx, dy, dz

x = tf.placeholder(tf.float32, [None, 400, 13, 13, 18, 3], name="X_placeholder")
y = tf.placeholder(tf.float32, [None, NUM_CLASSES], name="Y_placeholder")
keep_prob = tf.placeholder(tf.float32)

nodes =   {"l1": 25,
           "l2": 35,
           "l3": 80,
           "l4": 40,
           "l5": 20} 
           
weights = {"l1": weight([4, 4, 4, 3, nodes["l1"]]),
           "l2": weight([3, 3, 3, nodes["l1"], nodes["l2"]]),
           "l3": weight([15435, nodes["l3"]]),
           "l4": weight([nodes["l3"], nodes["l4"]])}

biases =  {"l1": bias(nodes["l1"]),
           "l2": bias(nodes["l2"]),
           "l3": bias(nodes["l3"]),
           "l4": bias(nodes["l4"])}

def cnn(input_slice):
    """ input: event tensor numpy shape 1, 13, 13, 18, 3"""
    conv1 = tf.nn.relu(
        conv3d(input_slice, weights["l1"]) + biases["l1"])

    conv2 = tf.nn.relu(
from tf_help import conv3d, maxpool3d, weight, bias

title = 'three_classes_sum_tot'
EVT_TYPES = [
    'nueCC', 'anueCC', 'nueNC', 'anueNC', 'numuCC', 'anumuCC', 'nuK40',
    'anuK40'
]
NUM_CLASSES = 3

x = tf.placeholder(tf.float32, [None, 13, 13, 18, 3], name="X_placeholder")
y = tf.placeholder(tf.float32, [None, NUM_CLASSES], name="Y_placeholder")

nodes = {"l1": 25, "l2": 35, "l3": 80, "l4": 40, "l5": 20}

weights = {
    "l1": weight([4, 4, 4, 3, nodes["l1"]]),
    "l2": weight([3, 3, 3, nodes["l1"], nodes["l2"]]),
    "l3": weight([3, 3, 3, nodes["l2"], nodes["l3"]]),
    "l4": weight([7 * 7 * 9 * nodes["l3"], nodes["l4"]]),
    "l5": weight([nodes["l4"], nodes["l5"]])
}

biases = {
    "l1": bias(nodes["l1"]),
    "l2": bias(nodes["l2"]),
    "l3": bias(nodes["l3"]),
    "l4": bias(nodes["l4"]),
    "l5": bias(nodes["l5"])
}

Пример #9
0
from tf_help import conv3d, maxpool3d, weight, bias
from helper_functions import EVT_TYPES, NUM_CLASSES, PATH, NUM_TRAIN_EVENTS

title = 'test'
num_mini_timeslices = 50

x = tf.placeholder(tf.float32, [None, 13, 13, 18, 3], name="X_placeholder")
y = tf.placeholder(tf.float32, [None, NUM_CLASSES], name="Y_placeholder")
keep_prob = tf.placeholder(tf.float32)
learning_rate = tf.placeholder(tf.float32)

nodes = {"l1": 25, "l2": 25, "l3": 80, "l4": 40, "l5": 20}

weights = {
    "l1": weight([4, 4, 4, 3, nodes["l1"]]),
    "l2": weight([3, 3, 3, nodes["l1"], nodes["l2"]]),
    "l3": weight([11025, nodes["l3"]]),
    "l4": weight([nodes["l3"], nodes["l4"]])
}

biases = {
    "l1": bias(nodes["l1"]),
    "l2": bias(nodes["l2"]),
    "l3": bias(nodes["l3"]),
    "l4": bias(nodes["l4"])
}


def cnn(mini_timeslice):
    """ input: event tensor numpy shape 1, 13, 13, 18, 3"""
Пример #10
0
title = 'temporal_convLSTM'
num_mini_timeslices = 50

x = tf.placeholder(tf.float32, [None, num_mini_timeslices, 13, 13, 18, 3], name="X_placeholder")
y = tf.placeholder(tf.float32, [None, NUM_CLASSES], name="Y_placeholder")
keep_prob = tf.placeholder(tf.float32)
learning_rate = tf.placeholder(tf.float32)

nodes =   {"l1": 25,
           "l2": 25,
           "l3": 25,
           "l4": 1,
           "l5": 20} 
           
weights = {"l1": weight([4, 4, 4, 3, nodes["l1"]]),
           "l2": weight([3, 3, 3,    nodes["l1"], nodes["l2"]]),
           "l3": weight([3, 3, 3,    nodes["l2"], nodes["l3"]]),
           "l4": weight([2, 2, 2,    nodes["l3"], nodes["l4"]])}

biases =  {"l1": bias(nodes["l1"]),
           "l2": bias(nodes["l2"]),
           "l3": bias(nodes["l3"]),
           "l4": bias(nodes["l4"])}

def cnn(mini_timeslice):
    """ input: event tensor numpy shape 1, 13, 13, 18, 3"""
    conv1 = tf.nn.relu(
        conv3d(mini_timeslice, weights["l1"]) + biases["l1"])
    
    conv1 = tf.contrib.layers.batch_norm(conv1)
    fc = tf.reshape(conv2, [-1, elements])
    
    fc = tf.nn.relu(
        tf.matmul(fc, weights["l3"]) + biases["l3"])

    fc = tf.nn.relu(
        tf.matmul(fc, weights["l4"]) + biases["l4"])

    fc = tf.reshape(fc, [50, 1, 40])
    c = tf.unstack(fc, num_mini_timeslices, 0)
    
    lstm_layer = tf.contrib.rnn.BasicLSTMCell(nodes["l5"], forget_bias=1.)
    outputs, _ = tf.contrib.rnn.static_rnn(lstm_layer, c, dtype=tf.float32)

   output = tf.matmul(outputs[-1], weight([nodes["l5"], NUM_CLASSES])) + bias(NUM_CLASSES)
    
    return tf.reshape(output, [3])


class toy_gen:
    def __init__(self, title):
        self.title = title

    def __call__(self):
        while True:
            e, l = make_toy(50)
            yield e, l  
            

data_set = tf.data.Dataset.from_generator(