<file_sep>from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation, Flatten
from keras.layers.convolutional import Convolution2D, MaxPooling2D
from keras.layers.normalization import BatchNormalization
from keras.applications.vgg16 import VGG16
from keras.applications.inception_v3 import InceptionV3
from keras.applications.resnet50 import ResNet50
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input
import numpy as np
import h5py
from keras.models import load_model


def create_model(model):
    print("Loading Keras model from a h5 file.")
    model_folder = "keras_frozen/"
    if model == "alexnet":
        return load_model(model_folder + "keras_alexnet.h5", compile=False)
    elif model == "vgg":
        return load_model(model_folder + "keras_vgg.h5", compile=False)
    elif model == "inception":
        return load_model(model_folder + "keras_inception.h5", compile=False)
    elif model == "resnet":
        return load_model(model_folder + "keras_resnet.h5", compile=False)
    else:
        raise RuntimeError("No such model exists: " + str(model))


def create_model_old(model):
    if model == "alexnet":
        return create_model_alex()
    elif model == "vgg":
        return create_model_vgg16()
    elif model == "inception":
        return create_model_inception_v3()
    elif model == "resnet":
        return create_model_resnet50()
    else:
        raise RuntimeError("No such model exists: " + str(model))


# AlexNet with batch normalization in Keras
# input image is 224x224

def create_model_alex():
    model = Sequential()

    # FEATURES
    model.add(Convolution2D(filters=64, kernel_size=11, strides=(4, 4),
                            padding="same", input_shape=(224, 224, 3)))
    model.add(Activation('relu'))
    model.add(MaxPooling2D(pool_size=(3, 3), strides=2))

    model.add(Convolution2D(filters=192, kernel_size=5, padding="same"))
    model.add(Activation('relu'))
    model.add(MaxPooling2D(pool_size=(3, 3), strides=2))

    model.add(Convolution2D(filters=384, kernel_size=3, padding="same"))
    model.add(Activation('relu'))

    model.add(Convolution2D(filters=256, kernel_size=3, padding="same"))
    model.add(Activation('relu'))

    model.add(Convolution2D(filters=256, kernel_size=3, padding="same"))
    model.add(Activation('relu'))

    model.add(MaxPooling2D(pool_size=(3, 3), strides=2))

    # CLASSIFIER
    model.add(Flatten())

    # model.add(Dropout(0.5))
    model.add(Dense(4096, kernel_initializer="normal", use_bias=True))
    model.add(Activation('relu'))

    # model.add(Dropout(0.5))
    model.add(Dense(4096, kernel_initializer="normal", use_bias=True))
    model.add(Activation('relu'))

    model.add(Dense(1000, kernel_initializer="normal", use_bias=True))
    # model.add(Activation('softmax'))

    print(model.summary())

    return model


def create_model_vgg16():
    model = VGG16(weights='imagenet', include_top=True)
    print(model.summary())
    return model


def create_model_resnet50():
    model = ResNet50(weights='imagenet', include_top=True)
    print(model.summary())
    return model


def create_model_inception_v3():
    model = InceptionV3(weights='imagenet', include_top=True)
    print(model.summary())
    return model
<file_sep>#!/bin/bash
# Basic range in for loop
for value in $(seq 1 10)
do
echo $value
python throughput.py --framework keras --num_batches 10000 --batch_size $value --model alexnet
done
echo All done
<file_sep>#!/bin/bash
# Basic range in for loop
for value in $(seq 1 10); do
  for frameworkName in keras torch; do
    for convNet in resnet vgg inception; do
      python throughput.py --framework $frameworkName --num_batches 10000 --batch_size $value --model $convNet
    done
  done
done
for value in $(seq 7 10); do
  for frameworkName in tf; do
    for convNet in resnet vgg inception; do
      python throughput.py --framework $frameworkName --num_batches 10000 --batch_size $value --model $convNet
    done
  done
done
echo All done
<file_sep>import tensorflow as tf
import _thread as thread
import rpyc
from concurrent.futures import ThreadPoolExecutor
from rpyc.utils.server import ThreadedServer
import queue
import time
from torch.autograd import Variable
from skimage import io
import argparse
import random
import os
from utils import round_ms,get_image_size
import cProfile, pstats, io as io2
from numpy import prod
import numpy as np

BATCH_SIZE = 4
BATCH_TIMEOUT = 0.1
FRAMEWORK = ""
MODEL = "alexnet"

tpe_in = ThreadPoolExecutor(max_workers=8)
#tpe_out = tpe
tpe_out = ThreadPoolExecutor(max_workers=None)

image_queue = queue.Queue()
time_q = queue.Queue()

total_latency = 0.0
count_lat = 0 
total_done = 0

total_classification_time = 0
classification_batches = 0

global classify, t1
graph = None

def generate_dummy_images(fw, batch_size, image_size):
    if fw in {"torch", "pytorch"}:
        images = np.random.randint(256, size=(batch_size, 3, image_size, image_size)) / 255.
    elif fw in {"tensorflow", "tf", "keras"}:
        images = np.random.randint(256, size=(batch_size, image_size, image_size, 3)) / 255.
    else:
        raise RuntimeError("Mock images not defined for framework: " + str(fw))

    print("Images shape", images.shape)
    return images.astype(np.float32)


def prepare_keras(model):
    print("Preparing Keras")
    import models_keras
    global net, graph

    net = models_keras.create_model(model)
    # net.save('keras_alex2.h5')
    # print("Saved")

    graph = tf.get_default_graph()

    # Easiest way to make the model build and compute the prediction function
    net.predict(np.random.randint(0, 256, size=(1, 224, 224, 3), dtype=np.uint8))
    # net.build()
    # net.model._make_predict_function()


def keras_classify(imgs):
    global graph
    with graph.as_default():
        imgs = np.stack(imgs, axis=0)
        # try:
        res = net.predict(imgs)
        # except Exception as e:
        #     print(e)
        # print(res)
        output = res.argmax(axis=1)
        # print(output)
        return output


def prepare_torch(model):
    global torch
    global torchvision
    import torch
    import torchvision
    print("Preparing Torch")
    global net

    model_file = "torch_frozen/torch_" + str(model) + ".out"

    net = torch.load(model_file)
    # if model == "alexnet":
    #     from torch_models.torch_alexnet import alexnet
    #     net = alexnet(pretrained=True)  # works
    # elif model == "vgg":
    #     from torch_models.torch_vgg import vgg16
    #     net = vgg16(pretrained=True)  # works
    # elif model == "inception":
    #     from torch_models.torch_inception import inception_v3
    #     net = inception_v3(pretrained=True)  # 299 x 299 x 3
    # elif model == "resnet":
    #     from torch_models.torch_resnet import resnet50
    #     net = resnet50(pretrained=True)  # works
    net.cuda()
    print(net)
    image_size = get_image_size(model)
    # Generate one dummy img.
    images = generate_dummy_images("torch", 1, image_size)
    net.forward(Variable(torch.from_numpy(images)).cuda())


def torch_classify(imgs):
    transform = torchvision.transforms.ToTensor()
    img_data = list(map(lambda x: Variable(transform(x)).cuda(), imgs))

    # print(img_data)
    # print("Batch", batch)
    batch = torch.stack(img_data)

    try:
        output = net.forward(batch)
    except Exception as e:
        print("Torch_classify failed, err: " + str(e))

    # print("Output", output)
    max_val, max_index = torch.max(output, 1)
    output = max_index.cpu().data.numpy()

    return output


def load_frozen_tensorflow_graph(model):
    model_file = "tf_frozen/"

    if model == "alexnet":
        # model_file += "tf_alexnetOP.pb"
        model_file += "tf_alex.pb"
    elif model == "vgg":
        model_file += "tf_vgg.pb"
    elif model == "inception":
        model_file += "tf_inception.pb"
    elif model == "resnet":
        model_file += "tf_resnet.pb"
    print("TF model file", model_file)

    with tf.gfile.GFile(model_file, "rb") as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
    with tf.Graph().as_default() as graph:
        tf.import_graph_def(graph_def, name="main")
    return graph


def prepare_tf(model):
    print("Preparing TensorFlow")
    from alexnet_tf import alexnet_inference

    global fnames, enq_op, prob, main_sess, images_placeholder, g, g_input, g_output

    g = load_frozen_tensorflow_graph(model)

    #for op in g.get_operations():
    #    print(op.name, op.type)

    input_tensor_name = g.get_operations()[0].name + ":0"
    output_tensor_name = g.get_operations()[-1].name + ":0"
    print(input_tensor_name, "<->", output_tensor_name)

    with g.as_default():
        g_input = g.get_tensor_by_name(input_tensor_name)
        g_output = g.get_tensor_by_name(output_tensor_name)

        # g_input = tf.placeholder(tf.uint8, shape=(None, 224, 224, 3))
        #
        # img_batch_float = tf.cast(g_input, tf.float32)
        # img_batch_float = tf.map_fn(tf.image.per_image_standardization, img_batch_float)
        # img_batch_float = tf.map_fn(lambda frame: tf.clip_by_value(frame, -1.0, 1.0), img_batch_float)
        # g_output, __ = alexnet_inference(img_batch_float)


        # image_batch = tf.stack(images)
        # print(image_batch) #/image_batch.dtype)

        # prob, __ = vgg_16(img_batch_float)
        # print(main_sess.run(prob))
        init_global = tf.global_variables_initializer()

    main_sess = tf.Session(graph=g)
    main_sess.run(init_global)

    image_size = get_image_size(model)
    dummy_images = generate_dummy_images("tf", BATCH_SIZE, image_size)
    main_sess.run(g_output, feed_dict={g_input: dummy_images})


def tf_classify(imgs):
    global g, g_input, g_output
    # img_data = np.empty(shape=(len(imgs), 224, 224, 3))
    # for i, img in enumerate(imgs):
    #     print(img)
    # img_data[i] = img

    imgs = np.stack(imgs, axis=0)

    result = main_sess.run(g_output, feed_dict={g_input: imgs})
    # print(result)
    return result.argmax(axis=1)


def mock_classify(raw_images):
    def get_random_num(raw_img):
        return random.randint(0, 1000)

    return list(map(get_random_num, raw_images))


class MyService(rpyc.Service):
    def __init__(self, conn):
        super().__init__(conn)
        print("MASTER INIT")

    def on_connect(self):
        print("Executive connected", thread.get_ident())

    def on_disconnect(self):
        global total_latency, count_lat
        print("Executive has disconnected...")
        print("count_lat=", count_lat)
        print("Avg latency server side (ms)", round_ms(total_latency / count_lat))

    def exposed_RemoteCallbackTest(self, raw_img, callback):
        img = np.fromstring(raw_img, dtype=np.uint8)
        elems = int(img.shape[0])
        dim = int((elems / 3) ** 0.5)
        img = img.reshape(dim, dim, 3)
        image_queue.put((img, callback))
        t = time.time()
        # print("GOT", round_ms(t) % 10000)
        time_q.put(t)


def parse_arguments():
    global BATCH_SIZE, FRAMEWORK, BATCH_TIMEOUT, MODEL
    parser = argparse.ArgumentParser()
    parser.add_argument("-b", "--batch_size", help="batch_size", type=int)
    parser.add_argument("-t", "--timeout", help="timeout for batch", type=float)
    parser.add_argument("-f", "--framework", help="framework")
    parser.add_argument("-m", "--model", help="convnet model")

    args = parser.parse_args()
    if args.batch_size is not None:
        BATCH_SIZE = args.batch_size

    if args.framework is not None:
        FRAMEWORK = args.framework

    if args.timeout is not None:
        BATCH_TIMEOUT = args.timeout

    if args.model is not None:
        if args.model.startswith("vgg"):
            MODEL = "vgg"
        elif args.model.startswith("incep"):
            MODEL = "inception"
        elif args.model.startswith("res"):
            MODEL = "resnet"
        else:
            MODEL = "alexnet"

    print("Model:", MODEL)
    print("Batch sizes:", BATCH_SIZE)
    print("Batch timeout:", BATCH_TIMEOUT)


def run_job_batcher():
    batch_size = BATCH_SIZE
    last_batch_time = None

    # TODO - now first batch always full
    while True:
        if image_queue.qsize() >= batch_size:
            last_batch_time = time.time()
            process_and_return(batch_size)
        elif image_queue.qsize() and last_batch_time and (time.time() - last_batch_time) >= BATCH_TIMEOUT:
            last_batch_time = time.time()
            print("Timed out")
            process_and_return(image_queue.qsize())
        else:
            time.sleep(0)


def process_and_return(batch_size):
    global total_classification_time, classification_batches

    inputs = [None] * batch_size
    callbacks = [None] * batch_size
    for i in range(batch_size):
        inputs[i], callbacks[i] = image_queue.get()

    classify_start = time.time()

    # pr.enable()
    # THE CLASSIFICATION
    try:
        outputs = classify(inputs)
    except Exception as e:
        print("Classification error:", e)
    # pr.disable()

    classify_time = time.time() - classify_start
    total_classification_time += classify_time
    classification_batches += 1

    if not classification_batches % 20:
        print("batch=" + str(batch_size) +
              ", took (ms) " + str(round_ms(classify_time)) +
              ", avg (ms) " + str(round_ms(total_classification_time / classification_batches)))

    # s = io2.StringIO()
    # ps = pstats.Stats(pr, stream=s).sort_stats("cumulative")
    # ps.print_stats()
    # print(s.getvalue())

    for i in range(batch_size):
        #send_response(callbacks[i], outputs[i])
        tpe_out.submit(send_response, callbacks[i],outputs[i])


def send_response(callback, result):
    global total_latency, count_lat, total_done
    curr_latency = time.time() - time_q.get()

    total_done += 1
    if total_done > 50:
        count_lat += 1
        total_latency += curr_latency
    #print("S",end="")
    callback(result)

def prepare_framework():
    global classify
    if FRAMEWORK == "tf" or FRAMEWORK == "tensorflow":
        prepare_tf(MODEL)
        classify = tf_classify
        print("Using TensorFlow")
    elif FRAMEWORK == "torch" or FRAMEWORK == "pytorch":
        prepare_torch(MODEL)
        classify = torch_classify
        print("Using PyTorch")
    elif FRAMEWORK == "keras":
        prepare_keras(MODEL)
        classify = keras_classify
        print("Using Keras")
    else:
        classify = mock_classify
        print("using MOCK framework")


if __name__ == '__main__':
    pr = cProfile.Profile()

    parse_arguments()
    prepare_framework()

    my_service = ThreadedServer(MyService, port=1200,
                                protocol_config={"allow_public_attrs": True})
    print("Waiting for a connection...")
    tpe_in.submit(run_job_batcher)
    my_service.start()
<file_sep>
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

#from memory_profiler import profile
import argparse
import cProfile
import io as io2
import math
import pstats
import sys
import time
from datetime import datetime

import numpy as np
import tensorflow as tf
import torch
from keras import backend as K
from six.moves import xrange
from tensorflow.python.client import timeline
from torch.autograd import Variable
from utils import get_image_size, round_ms

FLAGS = None
g = None
run_metadata = tf.RunMetadata()
options = None
prep_start = 0


def prepare_torch(model):
    print("Preparing Torch")
    global net

    model_file = "torch_frozen/torch_" + str(model) + ".out"

    net = torch.load(model_file)
    if torch.cuda.is_available():
        net.cuda()
    # torch.set_num_threads(4)
    # print(net)


def torch_classify(imgs, opts=None, run_md=None):
    batch = Variable(torch.from_numpy(imgs), requires_grad=False)
    if torch.cuda.is_available():
        r = net.forward(batch.cuda())
        r.cpu()
    else:
        net.forward(batch)


def prepare_keras(model):
    print("Preparing Keras")
    import models_keras
    global net, graph

    net = models_keras.create_model(model)
    net.summary()

    graph = tf.get_default_graph()
    keras_session = K.get_session()

    # old_run = keras_session.run
    # print("old_run", old_run)
    # print("K.sess 1", keras_session)
    #
    # def new_run(*args, **kwargs):
    #     # print("X", self)
    #     print("NewRunning", *args)
    #     old_run(*args, **kwargs)

    # keras_session.run = new_run


def keras_classify(imgs, opts=None, run_md=None):
    global graph
    with graph.as_default():
        net.predict(imgs)


def prepare_tf(model):
    print("Preparing TensorFlow")
    global main_sess, images_placeholder, g, g_input, g_output

    g = load_frozen_tensorflow_graph(model)

    input_tensor_name = g.get_operations()[0].name + ":0"
    if model in {"alexnet"}:
        output_tensor_name = "dense_3/BiasAdd:0"
    else:
        output_tensor_name = g.get_operations()[-1].name + ":0"

    print("I:", input_tensor_name)
    print("O:", output_tensor_name)

    with g.as_default():
        g_input = g.get_tensor_by_name(input_tensor_name)
        g_output = g.get_tensor_by_name(output_tensor_name)

        init_global = tf.global_variables_initializer()

    config = tf.ConfigProto()

    # Not relevant for non-GPU
    # config.gpu_options.allocator_type = 'BFC'

    main_sess = tf.Session(graph=g, config=config)
    main_sess.run(init_global)


def load_frozen_tensorflow_graph(model):
    global main_sess, g
    # saver = tf.train.import_meta_graph('./tmp/model.ckpt-55695.meta')
    # saver.restore(session, './tmp/model.ckpt-55695')

    model_file = "./tf_frozen/" if model in {"alexnet"} else "tf_frozen/"

    if model == "alexnet":
        model_file += "tf_alexnet.ckpt"

        with tf.Graph().as_default() as g, tf.Session() as sess:
            saver = tf.train.import_meta_graph(model_file + ".meta")
            saver.restore(sess, model_file)
        print("TF model file", model_file)
    else:
        if model == "vgg":
            model_file += "tf_vgg.pb"
        elif model == "inception":
            model_file += "tf_inception.pb"
        elif model == "resnet":
            model_file += "tf_resnet.pb"
        print("TF model file", model_file)

        with tf.gfile.GFile(model_file, "rb") as f:
            graph_def = tf.GraphDef()
            graph_def.ParseFromString(f.read())

        with tf.Graph().as_default() as g:
            tf.import_graph_def(graph_def, name="main")
    return g


def tf_classify(imgs, opts=None, run_md=None):
    main_sess.run(g_output, options=opts, run_metadata=run_md, feed_dict={g_input: imgs})


def time_run(info_string, imgs, fw, model):
    global run_inference, run_metadata, prep_start
    """Run the computation and print timing stats.

    Args:
      session: the TensorFlow session to run the computation under.
      target: the target Tensor that is passed to the session's run() function.
      info_string: a string summarizing this run, to be printed with the stats.

    Returns:
      None
    """
    num_steps_burn_in = 25
    total_duration = 0.0
    total_duration_squared = 0.0

    durs = []

    for i in xrange(FLAGS.num_batches + num_steps_burn_in):
        start_time = time.time()
        run_inference(imgs)
        duration = time.time() - start_time

        if i >= num_steps_burn_in:
            if not i % 50:
                print('%s: step %d, duration = %.3f' %
                      (datetime.now(), i - num_steps_burn_in, duration))
            total_duration += duration
            total_duration_squared += duration * duration
            durs.append(duration)

        if i == 0:
            print(datetime.now(), "Classified first batch, time since start (ms): ",
                  int(round_ms(time.time() - prep_start)))

    mn = total_duration / FLAGS.num_batches
    vr = total_duration_squared / FLAGS.num_batches - mn * mn
    sd = math.sqrt(vr)
    
    batches_per_second = 1.0 / mn
    images_per_second = batches_per_second * FLAGS.batch_size
    #durs 
    durs50 = np.percentile(durs,50)
    durs75 = np.percentile(durs,75)
    durs90 = np.percentile(durs,90)
    durs99 = np.percentile(durs,99)
    print('%s: %s across %d steps (WALL TIME), %.4f +/- %.4f sec / batch' %
          (datetime.now(), info_string, FLAGS.num_batches, mn, sd))
    print('%s: PERCENTILES - 50: %.4f, 75: %.4f, 90: %.4f sec/batch' %
          (datetime.now(), durs50, durs75, durs90)) 
    print('%s: 99LAT - %.4f s/batch, THROUGHPUT (IPS) - %.3f' % (datetime.now(), durs99, images_per_second))
    
    result_file = ("tp_logs/" + str(fw) + "_" + str(model) + "_b" + str(FLAGS.batch_size) + "_num" + 
                  str(FLAGS.num_batches) + "_" + datetime.now().strftime("%m%d_%H%M%S") + ".out")
    with open(result_file, "w") as f:
        f.write("Framework\t" + str(fw) + "\n")
        f.write("Model____\t" + str(model) + "\n")
        f.write("Bsize____\t" + str(FLAGS.batch_size) + "\n")
        f.write("TP (Img/s)\t%.2f\n" % (images_per_second))
        f.write("99pct LAT\t%.4f\n" % (durs99))
        f.write("90pct LAT\t%.4f\n" % (durs90))
        f.write("\n75pct LAT\t%.4f\n" % (durs75))
        f.write("50pct LAT\t%.4f\n "% (durs50))

def generate_dummy_images(fw, batch_size, image_size):
    if fw in {"torch", "pytorch"}:
        images = np.random.randint(256, size=(batch_size, 3, image_size, image_size)) / 255.
    elif fw in {"tensorflow", "tf", "keras"}:
        images = np.random.randint(256, size=(batch_size, image_size, image_size, 3)) / 255.
    else:
        raise RuntimeError("Mock images not defined for framework: " + str(fw))

    print("Images shape", images.shape)
    return images.astype(np.float32)


def run_benchmark(fw, model):
    global g
    if fw in {"keras"}:
        g = g or tf.get_default_graph()

    image_size = get_image_size(model)
    # Generate some dummy images.
    images = generate_dummy_images(fw, FLAGS.batch_size, image_size)

    info_string = str(fw) + ", " + str(model) + ", batch_size " + str(FLAGS.batch_size) + " |"
    time_run(info_string, images, fw, model)


def prepare_benchmark(fw, model):
    global run_inference

    print("Params: ", fw, "running", model)

    if fw in {"tensorflow", "tf"}:
        prepare_tf(model)
        run_inference = tf_classify
    elif fw in {"pytorch", "torch"}:
        prepare_torch(model)
        run_inference = torch_classify
    elif fw in {"keras"}:
        prepare_keras(model)
        run_inference = keras_classify
    else:
        raise RuntimeError("No framework with this name")


def main(_):
    pr = cProfile.Profile()

    global prep_start
    model = FLAGS.model.lower()
    framework = FLAGS.framework.lower()

    prep_start = time.time()
    # pr.enable()
    prepare_benchmark(framework, model)
    # pr.disable()
    run_benchmark(framework, model)


def get_argument_parser():
    global parser
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--batch_size',
        type=int,
        default=1,
        help='Batch size.'
    )
    parser.add_argument(
        '--num_batches',
        type=int,
        default=1000,
        help='Number of batches to run.'
    )
    parser.add_argument(
        '--framework',
        type=str,
        default="tensorflow",
        help='Framework to use'
    )
    parser.add_argument(
        '--model',
        type=str,
        default="alexnet",
        help='ConvNet model to use'
    )
    return parser


if __name__ == '__main__':
    parser = get_argument_parser()
    FLAGS, unparsed = parser.parse_known_args()
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
<file_sep>import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F

__weights_dict = dict()

def load_weights(weight_file):
    if weight_file == None:
        return

    try:
        weights_dict = np.load(weight_file).item()
    except:
        weights_dict = np.load(weight_file, encoding='bytes').item()

    return weights_dict

class KitModel(nn.Module):


    def __init__(self, weight_file):
        super(KitModel, self).__init__()
        global __weights_dict
        __weights_dict = load_weights(weight_file)

        self.block1_conv1 = self.__conv(2, name='block1_conv1', in_channels=3, out_channels=64, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.block1_conv2 = self.__conv(2, name='block1_conv2', in_channels=64, out_channels=64, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.block2_conv1 = self.__conv(2, name='block2_conv1', in_channels=64, out_channels=128, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.block2_conv2 = self.__conv(2, name='block2_conv2', in_channels=128, out_channels=128, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.block3_conv1 = self.__conv(2, name='block3_conv1', in_channels=128, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.block3_conv2 = self.__conv(2, name='block3_conv2', in_channels=256, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.block3_conv3 = self.__conv(2, name='block3_conv3', in_channels=256, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.block4_conv1 = self.__conv(2, name='block4_conv1', in_channels=256, out_channels=512, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.block4_conv2 = self.__conv(2, name='block4_conv2', in_channels=512, out_channels=512, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.block4_conv3 = self.__conv(2, name='block4_conv3', in_channels=512, out_channels=512, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.block5_conv1 = self.__conv(2, name='block5_conv1', in_channels=512, out_channels=512, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.block5_conv2 = self.__conv(2, name='block5_conv2', in_channels=512, out_channels=512, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.block5_conv3 = self.__conv(2, name='block5_conv3', in_channels=512, out_channels=512, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.fc1 = self.__dense(name = 'fc1', in_features = 25088, out_features = 4096, bias = True)
        self.fc2 = self.__dense(name = 'fc2', in_features = 4096, out_features = 4096, bias = True)
        self.predictions = self.__dense(name = 'predictions', in_features = 4096, out_features = 1000, bias = True)

    def forward(self, x):
        block1_conv1_pad = F.pad(x, (1, 1, 1, 1))
        block1_conv1    = self.block1_conv1(block1_conv1_pad)
        block1_conv1_activation = F.relu(block1_conv1, inplace=True)
        block1_conv2_pad = F.pad(block1_conv1_activation, (1, 1, 1, 1))
        block1_conv2    = self.block1_conv2(block1_conv2_pad)
        block1_conv2_activation = F.relu(block1_conv2, inplace=True)
        block1_pool     = F.max_pool2d(block1_conv2_activation, kernel_size=(2, 2), stride=(2, 2))
        block2_conv1_pad = F.pad(block1_pool, (1, 1, 1, 1))
        block2_conv1    = self.block2_conv1(block2_conv1_pad)
        block2_conv1_activation = F.relu(block2_conv1, inplace=True)
        block2_conv2_pad = F.pad(block2_conv1_activation, (1, 1, 1, 1))
        block2_conv2    = self.block2_conv2(block2_conv2_pad)
        block2_conv2_activation = F.relu(block2_conv2, inplace=True)
        block2_pool     = F.max_pool2d(block2_conv2_activation, kernel_size=(2, 2), stride=(2, 2))
        block3_conv1_pad = F.pad(block2_pool, (1, 1, 1, 1))
        block3_conv1    = self.block3_conv1(block3_conv1_pad)
        block3_conv1_activation = F.relu(block3_conv1, inplace=True)
        block3_conv2_pad = F.pad(block3_conv1_activation, (1, 1, 1, 1))
        block3_conv2    = self.block3_conv2(block3_conv2_pad)
        block3_conv2_activation = F.relu(block3_conv2, inplace=True)
        block3_conv3_pad = F.pad(block3_conv2_activation, (1, 1, 1, 1))
        block3_conv3    = self.block3_conv3(block3_conv3_pad)
        block3_conv3_activation = F.relu(block3_conv3, inplace=True)
        block3_pool     = F.max_pool2d(block3_conv3_activation, kernel_size=(2, 2), stride=(2, 2))
        block4_conv1_pad = F.pad(block3_pool, (1, 1, 1, 1))
        block4_conv1    = self.block4_conv1(block4_conv1_pad)
        block4_conv1_activation = F.relu(block4_conv1, inplace=True)
        block4_conv2_pad = F.pad(block4_conv1_activation, (1, 1, 1, 1))
        block4_conv2    = self.block4_conv2(block4_conv2_pad)
        block4_conv2_activation = F.relu(block4_conv2, inplace=True)
        block4_conv3_pad = F.pad(block4_conv2_activation, (1, 1, 1, 1))
        block4_conv3    = self.block4_conv3(block4_conv3_pad)
        block4_conv3_activation = F.relu(block4_conv3, inplace=True)
        block4_pool     = F.max_pool2d(block4_conv3_activation, kernel_size=(2, 2), stride=(2, 2))
        block5_conv1_pad = F.pad(block4_pool, (1, 1, 1, 1))
        block5_conv1    = self.block5_conv1(block5_conv1_pad)
        block5_conv1_activation = F.relu(block5_conv1, inplace=True)
        block5_conv2_pad = F.pad(block5_conv1_activation, (1, 1, 1, 1))
        block5_conv2    = self.block5_conv2(block5_conv2_pad)
        block5_conv2_activation = F.relu(block5_conv2, inplace=True)
        block5_conv3_pad = F.pad(block5_conv2_activation, (1, 1, 1, 1))
        block5_conv3    = self.block5_conv3(block5_conv3_pad)
        block5_conv3_activation = F.relu(block5_conv3, inplace=True)
        block5_pool     = F.max_pool2d(block5_conv3_activation, kernel_size=(2, 2), stride=(2, 2))
        flatten         = block5_pool.view(block5_pool.size(0), -1)
        fc1             = self.fc1(flatten)
        fc1_activation  = F.relu(fc1, inplace=True)
        fc2             = self.fc2(fc1_activation)
        fc2_activation  = F.relu(fc2, inplace=True)
        predictions     = self.predictions(fc2_activation)
        predictions_activation = F.softmax(predictions,dim=1)
        return predictions_activation


    @staticmethod
    def __conv(dim, name, **kwargs):
        if   dim == 1:  layer = nn.Conv1d(**kwargs)
        elif dim == 2:  layer = nn.Conv2d(**kwargs)
        elif dim == 3:  layer = nn.Conv3d(**kwargs)
        else:           raise NotImplementedError()

        layer.state_dict()['weight'].copy_(torch.from_numpy(__weights_dict[name]['weights']))
        if 'bias' in __weights_dict[name]:
            layer.state_dict()['bias'].copy_(torch.from_numpy(__weights_dict[name]['bias']))
        return layer

    @staticmethod
    def __dense(name, **kwargs):
        layer = nn.Linear(**kwargs)
        layer.state_dict()['weight'].copy_(torch.from_numpy(__weights_dict[name]['weights']))
        if 'bias' in __weights_dict[name]:
            layer.state_dict()['bias'].copy_(torch.from_numpy(__weights_dict[name]['bias']))
        return layer
<file_sep>import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import tensorrt as trt
from tensorrt.parsers import uffparser

import pycuda.driver as cuda
import pycuda.autoinit
import numpy as np
from random import randint # generate a random test case
from PIL import Image
import time #import system tools
import os

import uff

OUTPUT_NAMES = ["predictions/Softmax"]
PB_DIR =  "../tf_frozen/"
uff_model = uff.from_tensorflow_frozen_model(PB_DIR + "tf_inception.pb", OUTPUT_NAMES)
G_LOGGER = trt.infer.ConsoleLogger(trt.infer.LogSeverity.ERROR)

parser = uffparser.create_uff_parser()
parser.register_input("input_1", (3,299,299), 0)
parser.register_output(OUTPUT_NAMES[0])

engine = trt.utils.uff_to_trt_engine(G_LOGGER, uff_model, parser, 1, 1 << 20)
parser.destroy()

img = np.random.randint(256, size=(3, 299, 299)) / 255.
img = img.astype(np.float32)

label = 123

runtime = trt.infer.create_infer_runtime(G_LOGGER)
context = engine.create_execution_context()

output = np.empty(1000, dtype = np.float32)

d_input = cuda.mem_alloc(1 * img.size * img.dtype.itemsize)
d_output = cuda.mem_alloc(1 * output.size * output.dtype.itemsize)

bindings = [int(d_input), int(d_output)]
stream = cuda.Stream()


#transfer input data to device
cuda.memcpy_htod_async(d_input, img, stream)
#execute model
context.enqueue(1, bindings, stream.handle, None)
#transfer predictions back
cuda.memcpy_dtoh_async(output, d_output, stream)
#syncronize threads
stream.synchronize()

print("Test Case: " + str(label))
print ("Prediction: " + str(np.argmax(output)))

def infer():
    #transfer input data to device
    cuda.memcpy_htod_async(d_input, img, stream)
    #execute model
    context.enqueue(1, bindings, stream.handle, None)
    #transfer predictions back
    cuda.memcpy_dtoh_async(output, d_output, stream)
    #syncronize threads
    stream.synchronize()

RUNS = 1000
total_run_time = 0

for i in range(1000):
    img = np.random.randint(256, size=(3, 299, 299)) / 255.
    img = img.astype(np.float32)
    start = time.time()
    infer()
    end = time.time()

    run_time = end-start
    total_run_time += run_time
    print("Test vs Pred: " + str(label) + " " + str(np.argmax(output)))
    print("Ran for: " + str(1000 * (end-start)) + " ms")
print("Done.")
print("Avg: " + str(1000 * (total_run_time / RUNS)) + " ms")
<file_sep>import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import tensorrt as trt
from tensorrt.parsers import uffparser

import pycuda.driver as cuda
import pycuda.autoinit
import numpy as np
# from PIL import Image
import time #import system tools
import os

import uff

PB_DIR = "../tf_frozen/"

OUTPUT_NAMES = ["activation_8/Softmax"]
BATCH_SIZE = 6

uff_model = uff.from_tensorflow_frozen_model(PB_DIR + "tf_alex.pb", OUTPUT_NAMES)
G_LOGGER = trt.infer.ConsoleLogger(trt.infer.LogSeverity.ERROR)

parser = uffparser.create_uff_parser()
parser.register_input("conv2d_1_input", (3,224,224),0)
parser.register_output(OUTPUT_NAMES[0])

engine = trt.utils.uff_to_trt_engine(G_LOGGER, uff_model, parser, BATCH_SIZE, 0) # 1 << 20

#engine = trt.utils.load_engine(G_LOGGER, "./alex.engine")
#parser.destroy()

img = np.random.randint(256, size=(BATCH_SIZE, 3, 224, 224)) / 255.
img = img.astype(np.float32)

label = 123

runtime = trt.infer.create_infer_runtime(G_LOGGER)
context = engine.create_execution_context()

output = np.empty((BATCH_SIZE, 1000), dtype = np.float32)

d_input = cuda.mem_alloc(BATCH_SIZE * img.size * img.dtype.itemsize)
d_output = cuda.mem_alloc(BATCH_SIZE * output.size * output.dtype.itemsize)

bindings = [int(d_input), int(d_output)]
stream = cuda.Stream()

def infer():
    #transfer input data to device
    cuda.memcpy_htod_async(d_input, img, stream)
    #execute model
    context.enqueue(BATCH_SIZE, bindings, stream.handle, None)
    #transfer predictions back
    cuda.memcpy_dtoh_async(output, d_output, stream)
    #syncronize threads
    stream.synchronize()

for i in range(1000):
    img = np.random.randint(256, size=(BATCH_SIZE, 3, 224, 224)) / 255.
    img = img.astype(np.float32)
    start = time.time()
    infer()
    end = time.time()
    print("Test vs Pred: " + str(label) + " " +str(np.argmax(output, axis=1)) + " " + str(np.max(output, axis=1)))
    print("Ran for: " + str(1000 * (end-start)) + " ms")
<file_sep>import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F

__weights_dict = dict()

def load_weights(weight_file):
    if weight_file == None:
        return

    try:
        weights_dict = np.load(weight_file).item()
    except:
        weights_dict = np.load(weight_file, encoding='bytes').item()

    return weights_dict

class KitModel(nn.Module):

    
    def __init__(self, weight_file):
        super(KitModel, self).__init__()
        global __weights_dict
        __weights_dict = load_weights(weight_file)

        self.conv2d_1 = self.__conv(2, name='conv2d_1', in_channels=3, out_channels=64, kernel_size=(11, 11), stride=(4, 4), groups=1, bias=True)
        self.conv2d_2 = self.__conv(2, name='conv2d_2', in_channels=64, out_channels=192, kernel_size=(5, 5), stride=(1, 1), groups=1, bias=True)
        self.conv2d_3 = self.__conv(2, name='conv2d_3', in_channels=192, out_channels=384, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.conv2d_4 = self.__conv(2, name='conv2d_4', in_channels=384, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.conv2d_5 = self.__conv(2, name='conv2d_5', in_channels=256, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.dense_1 = self.__dense(name = 'dense_1', in_features = 9216, out_features = 4096, bias = True)
        self.dense_2 = self.__dense(name = 'dense_2', in_features = 4096, out_features = 4096, bias = True)
        self.dense_3 = self.__dense(name = 'dense_3', in_features = 4096, out_features = 1000, bias = True)

    def forward(self, x):
        conv2d_1_pad    = F.pad(x, (3, 4, 3, 4))
        conv2d_1        = self.conv2d_1(conv2d_1_pad)
        activation_1    = F.relu(conv2d_1)
        max_pooling2d_1 = F.max_pool2d(activation_1, kernel_size=(3, 3), stride=(2, 2))
        conv2d_2_pad    = F.pad(max_pooling2d_1, (2, 2, 2, 2))
        conv2d_2        = self.conv2d_2(conv2d_2_pad)
        activation_2    = F.relu(conv2d_2)
        max_pooling2d_2 = F.max_pool2d(activation_2, kernel_size=(3, 3), stride=(2, 2))
        conv2d_3_pad    = F.pad(max_pooling2d_2, (1, 1, 1, 1))
        conv2d_3        = self.conv2d_3(conv2d_3_pad)
        activation_3    = F.relu(conv2d_3)
        conv2d_4_pad    = F.pad(activation_3, (1, 1, 1, 1))
        conv2d_4        = self.conv2d_4(conv2d_4_pad)
        activation_4    = F.relu(conv2d_4)
        conv2d_5_pad    = F.pad(activation_4, (1, 1, 1, 1))
        conv2d_5        = self.conv2d_5(conv2d_5_pad)
        activation_5    = F.relu(conv2d_5)
        max_pooling2d_3 = F.max_pool2d(activation_5, kernel_size=(3, 3), stride=(2, 2))
        flatten_1       = max_pooling2d_3.view(max_pooling2d_3.size(0), -1)
        dense_1         = self.dense_1(flatten_1)
        activation_6    = F.relu(dense_1)
        dense_2         = self.dense_2(activation_6)
        activation_7    = F.relu(dense_2)
        dense_3         = self.dense_3(activation_7)
        return dense_3


    @staticmethod
    def __dense(name, **kwargs):
        layer = nn.Linear(**kwargs)
        layer.state_dict()['weight'].copy_(torch.from_numpy(__weights_dict[name]['weights']))
        if 'bias' in __weights_dict[name]:
            layer.state_dict()['bias'].copy_(torch.from_numpy(__weights_dict[name]['bias']))
        return layer

    @staticmethod
    def __conv(dim, name, **kwargs):
        if   dim == 1:  layer = nn.Conv1d(**kwargs)
        elif dim == 2:  layer = nn.Conv2d(**kwargs)
        elif dim == 3:  layer = nn.Conv3d(**kwargs)
        else:           raise NotImplementedError()

        layer.state_dict()['weight'].copy_(torch.from_numpy(__weights_dict[name]['weights']))
        if 'bias' in __weights_dict[name]:
            layer.state_dict()['bias'].copy_(torch.from_numpy(__weights_dict[name]['bias']))
        return layer
<file_sep>import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F

__weights_dict = dict()

def load_weights(weight_file):
    if weight_file == None:
        return

    try:
        weights_dict = np.load(weight_file).item()
    except:
        weights_dict = np.load(weight_file, encoding='bytes').item()

    return weights_dict

class KitModel(nn.Module):

    
    def __init__(self, weight_file):
        super(KitModel, self).__init__()
        global __weights_dict
        __weights_dict = load_weights(weight_file)

        self.conv2d_1 = self.__conv(2, name='conv2d_1', in_channels=3, out_channels=32, kernel_size=(3, 3), stride=(2, 2), groups=1, bias=False)
        self.batch_normalization_1 = self.__batch_normalization(2, 'batch_normalization_1', num_features = 32, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_2 = self.__conv(2, name='conv2d_2', in_channels=32, out_channels=32, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_2 = self.__batch_normalization(2, 'batch_normalization_2', num_features = 32, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_3 = self.__conv(2, name='conv2d_3', in_channels=32, out_channels=64, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_3 = self.__batch_normalization(2, 'batch_normalization_3', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_4 = self.__conv(2, name='conv2d_4', in_channels=64, out_channels=80, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_4 = self.__batch_normalization(2, 'batch_normalization_4', num_features = 80, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_5 = self.__conv(2, name='conv2d_5', in_channels=80, out_channels=192, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_5 = self.__batch_normalization(2, 'batch_normalization_5', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_9 = self.__conv(2, name='conv2d_9', in_channels=192, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_7 = self.__conv(2, name='conv2d_7', in_channels=192, out_channels=48, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_6 = self.__conv(2, name='conv2d_6', in_channels=192, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_9 = self.__batch_normalization(2, 'batch_normalization_9', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_7 = self.__batch_normalization(2, 'batch_normalization_7', num_features = 48, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_12 = self.__conv(2, name='conv2d_12', in_channels=192, out_channels=32, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_6 = self.__batch_normalization(2, 'batch_normalization_6', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_12 = self.__batch_normalization(2, 'batch_normalization_12', num_features = 32, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_10 = self.__conv(2, name='conv2d_10', in_channels=64, out_channels=96, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False)
        self.conv2d_8 = self.__conv(2, name='conv2d_8', in_channels=48, out_channels=64, kernel_size=(5, 5), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_10 = self.__batch_normalization(2, 'batch_normalization_10', num_features = 96, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_8 = self.__batch_normalization(2, 'batch_normalization_8', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_11 = self.__conv(2, name='conv2d_11', in_channels=96, out_channels=96, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_11 = self.__batch_normalization(2, 'batch_normalization_11', num_features = 96, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_16 = self.__conv(2, name='conv2d_16', in_channels=256, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_14 = self.__conv(2, name='conv2d_14', in_channels=256, out_channels=48, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_13 = self.__conv(2, name='conv2d_13', in_channels=256, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_16 = self.__batch_normalization(2, 'batch_normalization_16', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_14 = self.__batch_normalization(2, 'batch_normalization_14', num_features = 48, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_19 = self.__conv(2, name='conv2d_19', in_channels=256, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_13 = self.__batch_normalization(2, 'batch_normalization_13', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_19 = self.__batch_normalization(2, 'batch_normalization_19', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_17 = self.__conv(2, name='conv2d_17', in_channels=64, out_channels=96, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False)
        self.conv2d_15 = self.__conv(2, name='conv2d_15', in_channels=48, out_channels=64, kernel_size=(5, 5), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_17 = self.__batch_normalization(2, 'batch_normalization_17', num_features = 96, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_15 = self.__batch_normalization(2, 'batch_normalization_15', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_18 = self.__conv(2, name='conv2d_18', in_channels=96, out_channels=96, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_18 = self.__batch_normalization(2, 'batch_normalization_18', num_features = 96, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_23 = self.__conv(2, name='conv2d_23', in_channels=288, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_21 = self.__conv(2, name='conv2d_21', in_channels=288, out_channels=48, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_20 = self.__conv(2, name='conv2d_20', in_channels=288, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_23 = self.__batch_normalization(2, 'batch_normalization_23', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_21 = self.__batch_normalization(2, 'batch_normalization_21', num_features = 48, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_26 = self.__conv(2, name='conv2d_26', in_channels=288, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_20 = self.__batch_normalization(2, 'batch_normalization_20', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_26 = self.__batch_normalization(2, 'batch_normalization_26', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_24 = self.__conv(2, name='conv2d_24', in_channels=64, out_channels=96, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False)
        self.conv2d_22 = self.__conv(2, name='conv2d_22', in_channels=48, out_channels=64, kernel_size=(5, 5), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_24 = self.__batch_normalization(2, 'batch_normalization_24', num_features = 96, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_22 = self.__batch_normalization(2, 'batch_normalization_22', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_25 = self.__conv(2, name='conv2d_25', in_channels=96, out_channels=96, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_25 = self.__batch_normalization(2, 'batch_normalization_25', num_features = 96, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_28 = self.__conv(2, name='conv2d_28', in_channels=288, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_27 = self.__conv(2, name='conv2d_27', in_channels=288, out_channels=384, kernel_size=(3, 3), stride=(2, 2), groups=1, bias=False)
        self.batch_normalization_28 = self.__batch_normalization(2, 'batch_normalization_28', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_27 = self.__batch_normalization(2, 'batch_normalization_27', num_features = 384, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_29 = self.__conv(2, name='conv2d_29', in_channels=64, out_channels=96, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_29 = self.__batch_normalization(2, 'batch_normalization_29', num_features = 96, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_30 = self.__conv(2, name='conv2d_30', in_channels=96, out_channels=96, kernel_size=(3, 3), stride=(2, 2), groups=1, bias=False)
        self.batch_normalization_30 = self.__batch_normalization(2, 'batch_normalization_30', num_features = 96, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_35 = self.__conv(2, name='conv2d_35', in_channels=768, out_channels=128, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_32 = self.__conv(2, name='conv2d_32', in_channels=768, out_channels=128, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_31 = self.__conv(2, name='conv2d_31', in_channels=768, out_channels=192, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_35 = self.__batch_normalization(2, 'batch_normalization_35', num_features = 128, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_32 = self.__batch_normalization(2, 'batch_normalization_32', num_features = 128, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_40 = self.__conv(2, name='conv2d_40', in_channels=768, out_channels=192, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_31 = self.__batch_normalization(2, 'batch_normalization_31', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_40 = self.__batch_normalization(2, 'batch_normalization_40', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_36 = self.__conv(2, name='conv2d_36', in_channels=128, out_channels=128, kernel_size=(7, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_33 = self.__conv(2, name='conv2d_33', in_channels=128, out_channels=128, kernel_size=(1, 7), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_36 = self.__batch_normalization(2, 'batch_normalization_36', num_features = 128, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_33 = self.__batch_normalization(2, 'batch_normalization_33', num_features = 128, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_37 = self.__conv(2, name='conv2d_37', in_channels=128, out_channels=128, kernel_size=(1, 7), stride=(1, 1), groups=1, bias=False)
        self.conv2d_34 = self.__conv(2, name='conv2d_34', in_channels=128, out_channels=192, kernel_size=(7, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_37 = self.__batch_normalization(2, 'batch_normalization_37', num_features = 128, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_34 = self.__batch_normalization(2, 'batch_normalization_34', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_38 = self.__conv(2, name='conv2d_38', in_channels=128, out_channels=128, kernel_size=(7, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_38 = self.__batch_normalization(2, 'batch_normalization_38', num_features = 128, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_39 = self.__conv(2, name='conv2d_39', in_channels=128, out_channels=192, kernel_size=(1, 7), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_39 = self.__batch_normalization(2, 'batch_normalization_39', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_45 = self.__conv(2, name='conv2d_45', in_channels=768, out_channels=160, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_42 = self.__conv(2, name='conv2d_42', in_channels=768, out_channels=160, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_41 = self.__conv(2, name='conv2d_41', in_channels=768, out_channels=192, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_45 = self.__batch_normalization(2, 'batch_normalization_45', num_features = 160, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_42 = self.__batch_normalization(2, 'batch_normalization_42', num_features = 160, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_50 = self.__conv(2, name='conv2d_50', in_channels=768, out_channels=192, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_41 = self.__batch_normalization(2, 'batch_normalization_41', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_50 = self.__batch_normalization(2, 'batch_normalization_50', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_46 = self.__conv(2, name='conv2d_46', in_channels=160, out_channels=160, kernel_size=(7, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_43 = self.__conv(2, name='conv2d_43', in_channels=160, out_channels=160, kernel_size=(1, 7), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_46 = self.__batch_normalization(2, 'batch_normalization_46', num_features = 160, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_43 = self.__batch_normalization(2, 'batch_normalization_43', num_features = 160, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_47 = self.__conv(2, name='conv2d_47', in_channels=160, out_channels=160, kernel_size=(1, 7), stride=(1, 1), groups=1, bias=False)
        self.conv2d_44 = self.__conv(2, name='conv2d_44', in_channels=160, out_channels=192, kernel_size=(7, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_47 = self.__batch_normalization(2, 'batch_normalization_47', num_features = 160, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_44 = self.__batch_normalization(2, 'batch_normalization_44', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_48 = self.__conv(2, name='conv2d_48', in_channels=160, out_channels=160, kernel_size=(7, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_48 = self.__batch_normalization(2, 'batch_normalization_48', num_features = 160, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_49 = self.__conv(2, name='conv2d_49', in_channels=160, out_channels=192, kernel_size=(1, 7), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_49 = self.__batch_normalization(2, 'batch_normalization_49', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_55 = self.__conv(2, name='conv2d_55', in_channels=768, out_channels=160, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_52 = self.__conv(2, name='conv2d_52', in_channels=768, out_channels=160, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_51 = self.__conv(2, name='conv2d_51', in_channels=768, out_channels=192, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_55 = self.__batch_normalization(2, 'batch_normalization_55', num_features = 160, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_52 = self.__batch_normalization(2, 'batch_normalization_52', num_features = 160, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_60 = self.__conv(2, name='conv2d_60', in_channels=768, out_channels=192, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_51 = self.__batch_normalization(2, 'batch_normalization_51', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_60 = self.__batch_normalization(2, 'batch_normalization_60', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_56 = self.__conv(2, name='conv2d_56', in_channels=160, out_channels=160, kernel_size=(7, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_53 = self.__conv(2, name='conv2d_53', in_channels=160, out_channels=160, kernel_size=(1, 7), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_56 = self.__batch_normalization(2, 'batch_normalization_56', num_features = 160, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_53 = self.__batch_normalization(2, 'batch_normalization_53', num_features = 160, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_57 = self.__conv(2, name='conv2d_57', in_channels=160, out_channels=160, kernel_size=(1, 7), stride=(1, 1), groups=1, bias=False)
        self.conv2d_54 = self.__conv(2, name='conv2d_54', in_channels=160, out_channels=192, kernel_size=(7, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_57 = self.__batch_normalization(2, 'batch_normalization_57', num_features = 160, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_54 = self.__batch_normalization(2, 'batch_normalization_54', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_58 = self.__conv(2, name='conv2d_58', in_channels=160, out_channels=160, kernel_size=(7, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_58 = self.__batch_normalization(2, 'batch_normalization_58', num_features = 160, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_59 = self.__conv(2, name='conv2d_59', in_channels=160, out_channels=192, kernel_size=(1, 7), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_59 = self.__batch_normalization(2, 'batch_normalization_59', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_65 = self.__conv(2, name='conv2d_65', in_channels=768, out_channels=192, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_62 = self.__conv(2, name='conv2d_62', in_channels=768, out_channels=192, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_61 = self.__conv(2, name='conv2d_61', in_channels=768, out_channels=192, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_65 = self.__batch_normalization(2, 'batch_normalization_65', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_62 = self.__batch_normalization(2, 'batch_normalization_62', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_70 = self.__conv(2, name='conv2d_70', in_channels=768, out_channels=192, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_61 = self.__batch_normalization(2, 'batch_normalization_61', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_70 = self.__batch_normalization(2, 'batch_normalization_70', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_66 = self.__conv(2, name='conv2d_66', in_channels=192, out_channels=192, kernel_size=(7, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_63 = self.__conv(2, name='conv2d_63', in_channels=192, out_channels=192, kernel_size=(1, 7), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_66 = self.__batch_normalization(2, 'batch_normalization_66', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_63 = self.__batch_normalization(2, 'batch_normalization_63', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_67 = self.__conv(2, name='conv2d_67', in_channels=192, out_channels=192, kernel_size=(1, 7), stride=(1, 1), groups=1, bias=False)
        self.conv2d_64 = self.__conv(2, name='conv2d_64', in_channels=192, out_channels=192, kernel_size=(7, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_67 = self.__batch_normalization(2, 'batch_normalization_67', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_64 = self.__batch_normalization(2, 'batch_normalization_64', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_68 = self.__conv(2, name='conv2d_68', in_channels=192, out_channels=192, kernel_size=(7, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_68 = self.__batch_normalization(2, 'batch_normalization_68', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_69 = self.__conv(2, name='conv2d_69', in_channels=192, out_channels=192, kernel_size=(1, 7), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_69 = self.__batch_normalization(2, 'batch_normalization_69', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_73 = self.__conv(2, name='conv2d_73', in_channels=768, out_channels=192, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_71 = self.__conv(2, name='conv2d_71', in_channels=768, out_channels=192, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_73 = self.__batch_normalization(2, 'batch_normalization_73', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_71 = self.__batch_normalization(2, 'batch_normalization_71', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_74 = self.__conv(2, name='conv2d_74', in_channels=192, out_channels=192, kernel_size=(1, 7), stride=(1, 1), groups=1, bias=False)
        self.conv2d_72 = self.__conv(2, name='conv2d_72', in_channels=192, out_channels=320, kernel_size=(3, 3), stride=(2, 2), groups=1, bias=False)
        self.batch_normalization_74 = self.__batch_normalization(2, 'batch_normalization_74', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_72 = self.__batch_normalization(2, 'batch_normalization_72', num_features = 320, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_75 = self.__conv(2, name='conv2d_75', in_channels=192, out_channels=192, kernel_size=(7, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_75 = self.__batch_normalization(2, 'batch_normalization_75', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_76 = self.__conv(2, name='conv2d_76', in_channels=192, out_channels=192, kernel_size=(3, 3), stride=(2, 2), groups=1, bias=False)
        self.batch_normalization_76 = self.__batch_normalization(2, 'batch_normalization_76', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_81 = self.__conv(2, name='conv2d_81', in_channels=1280, out_channels=448, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_78 = self.__conv(2, name='conv2d_78', in_channels=1280, out_channels=384, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_77 = self.__conv(2, name='conv2d_77', in_channels=1280, out_channels=320, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_81 = self.__batch_normalization(2, 'batch_normalization_81', num_features = 448, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_78 = self.__batch_normalization(2, 'batch_normalization_78', num_features = 384, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_85 = self.__conv(2, name='conv2d_85', in_channels=1280, out_channels=192, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_77 = self.__batch_normalization(2, 'batch_normalization_77', num_features = 320, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_85 = self.__batch_normalization(2, 'batch_normalization_85', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_82 = self.__conv(2, name='conv2d_82', in_channels=448, out_channels=384, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False)
        self.conv2d_79 = self.__conv(2, name='conv2d_79', in_channels=384, out_channels=384, kernel_size=(1, 3), stride=(1, 1), groups=1, bias=False)
        self.conv2d_80 = self.__conv(2, name='conv2d_80', in_channels=384, out_channels=384, kernel_size=(3, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_82 = self.__batch_normalization(2, 'batch_normalization_82', num_features = 384, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_79 = self.__batch_normalization(2, 'batch_normalization_79', num_features = 384, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_80 = self.__batch_normalization(2, 'batch_normalization_80', num_features = 384, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_83 = self.__conv(2, name='conv2d_83', in_channels=384, out_channels=384, kernel_size=(1, 3), stride=(1, 1), groups=1, bias=False)
        self.conv2d_84 = self.__conv(2, name='conv2d_84', in_channels=384, out_channels=384, kernel_size=(3, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_83 = self.__batch_normalization(2, 'batch_normalization_83', num_features = 384, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_84 = self.__batch_normalization(2, 'batch_normalization_84', num_features = 384, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_90 = self.__conv(2, name='conv2d_90', in_channels=2048, out_channels=448, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_87 = self.__conv(2, name='conv2d_87', in_channels=2048, out_channels=384, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.conv2d_86 = self.__conv(2, name='conv2d_86', in_channels=2048, out_channels=320, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_90 = self.__batch_normalization(2, 'batch_normalization_90', num_features = 448, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_87 = self.__batch_normalization(2, 'batch_normalization_87', num_features = 384, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_94 = self.__conv(2, name='conv2d_94', in_channels=2048, out_channels=192, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_86 = self.__batch_normalization(2, 'batch_normalization_86', num_features = 320, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_94 = self.__batch_normalization(2, 'batch_normalization_94', num_features = 192, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_91 = self.__conv(2, name='conv2d_91', in_channels=448, out_channels=384, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=False)
        self.conv2d_88 = self.__conv(2, name='conv2d_88', in_channels=384, out_channels=384, kernel_size=(1, 3), stride=(1, 1), groups=1, bias=False)
        self.conv2d_89 = self.__conv(2, name='conv2d_89', in_channels=384, out_channels=384, kernel_size=(3, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_91 = self.__batch_normalization(2, 'batch_normalization_91', num_features = 384, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_88 = self.__batch_normalization(2, 'batch_normalization_88', num_features = 384, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_89 = self.__batch_normalization(2, 'batch_normalization_89', num_features = 384, eps = 0.0010000000474974513, momentum = 0.0)
        self.conv2d_92 = self.__conv(2, name='conv2d_92', in_channels=384, out_channels=384, kernel_size=(1, 3), stride=(1, 1), groups=1, bias=False)
        self.conv2d_93 = self.__conv(2, name='conv2d_93', in_channels=384, out_channels=384, kernel_size=(3, 1), stride=(1, 1), groups=1, bias=False)
        self.batch_normalization_92 = self.__batch_normalization(2, 'batch_normalization_92', num_features = 384, eps = 0.0010000000474974513, momentum = 0.0)
        self.batch_normalization_93 = self.__batch_normalization(2, 'batch_normalization_93', num_features = 384, eps = 0.0010000000474974513, momentum = 0.0)
        self.predictions = self.__dense(name = 'predictions', in_features = 2048, out_features = 1000, bias = True)

    def forward(self, x):
        conv2d_1        = self.conv2d_1(x)
        batch_normalization_1 = self.batch_normalization_1(conv2d_1)
        activation_1    = F.relu(batch_normalization_1)
        conv2d_2        = self.conv2d_2(activation_1)
        batch_normalization_2 = self.batch_normalization_2(conv2d_2)
        activation_2    = F.relu(batch_normalization_2)
        conv2d_3_pad    = F.pad(activation_2, (1, 1, 1, 1))
        conv2d_3        = self.conv2d_3(conv2d_3_pad)
        batch_normalization_3 = self.batch_normalization_3(conv2d_3)
        activation_3    = F.relu(batch_normalization_3)
        max_pooling2d_1 = F.max_pool2d(activation_3, kernel_size=(3, 3), stride=(2, 2))
        conv2d_4        = self.conv2d_4(max_pooling2d_1)
        batch_normalization_4 = self.batch_normalization_4(conv2d_4)
        activation_4    = F.relu(batch_normalization_4)
        conv2d_5        = self.conv2d_5(activation_4)
        batch_normalization_5 = self.batch_normalization_5(conv2d_5)
        activation_5    = F.relu(batch_normalization_5)
        max_pooling2d_2 = F.max_pool2d(activation_5, kernel_size=(3, 3), stride=(2, 2))
        conv2d_9        = self.conv2d_9(max_pooling2d_2)
        conv2d_7        = self.conv2d_7(max_pooling2d_2)
        average_pooling2d_1_pad = F.pad(max_pooling2d_2, (1, 1, 1, 1))
        average_pooling2d_1 = F.avg_pool2d(average_pooling2d_1_pad, kernel_size=(3, 3), stride=(1, 1))
        conv2d_6        = self.conv2d_6(max_pooling2d_2)
        batch_normalization_9 = self.batch_normalization_9(conv2d_9)
        batch_normalization_7 = self.batch_normalization_7(conv2d_7)
        conv2d_12       = self.conv2d_12(average_pooling2d_1)
        batch_normalization_6 = self.batch_normalization_6(conv2d_6)
        activation_9    = F.relu(batch_normalization_9)
        activation_7    = F.relu(batch_normalization_7)
        batch_normalization_12 = self.batch_normalization_12(conv2d_12)
        activation_6    = F.relu(batch_normalization_6)
        conv2d_10_pad   = F.pad(activation_9, (1, 1, 1, 1))
        conv2d_10       = self.conv2d_10(conv2d_10_pad)
        conv2d_8_pad    = F.pad(activation_7, (2, 2, 2, 2))
        conv2d_8        = self.conv2d_8(conv2d_8_pad)
        activation_12   = F.relu(batch_normalization_12)
        batch_normalization_10 = self.batch_normalization_10(conv2d_10)
        batch_normalization_8 = self.batch_normalization_8(conv2d_8)
        activation_10   = F.relu(batch_normalization_10)
        activation_8    = F.relu(batch_normalization_8)
        conv2d_11_pad   = F.pad(activation_10, (1, 1, 1, 1))
        conv2d_11       = self.conv2d_11(conv2d_11_pad)
        batch_normalization_11 = self.batch_normalization_11(conv2d_11)
        activation_11   = F.relu(batch_normalization_11)
        mixed0          = torch.cat((activation_6, activation_8, activation_11, activation_12), 1)
        conv2d_16       = self.conv2d_16(mixed0)
        conv2d_14       = self.conv2d_14(mixed0)
        average_pooling2d_2_pad = F.pad(mixed0, (1, 1, 1, 1))
        average_pooling2d_2 = F.avg_pool2d(average_pooling2d_2_pad, kernel_size=(3, 3), stride=(1, 1))
        conv2d_13       = self.conv2d_13(mixed0)
        batch_normalization_16 = self.batch_normalization_16(conv2d_16)
        batch_normalization_14 = self.batch_normalization_14(conv2d_14)
        conv2d_19       = self.conv2d_19(average_pooling2d_2)
        batch_normalization_13 = self.batch_normalization_13(conv2d_13)
        activation_16   = F.relu(batch_normalization_16)
        activation_14   = F.relu(batch_normalization_14)
        batch_normalization_19 = self.batch_normalization_19(conv2d_19)
        activation_13   = F.relu(batch_normalization_13)
        conv2d_17_pad   = F.pad(activation_16, (1, 1, 1, 1))
        conv2d_17       = self.conv2d_17(conv2d_17_pad)
        conv2d_15_pad   = F.pad(activation_14, (2, 2, 2, 2))
        conv2d_15       = self.conv2d_15(conv2d_15_pad)
        activation_19   = F.relu(batch_normalization_19)
        batch_normalization_17 = self.batch_normalization_17(conv2d_17)
        batch_normalization_15 = self.batch_normalization_15(conv2d_15)
        activation_17   = F.relu(batch_normalization_17)
        activation_15   = F.relu(batch_normalization_15)
        conv2d_18_pad   = F.pad(activation_17, (1, 1, 1, 1))
        conv2d_18       = self.conv2d_18(conv2d_18_pad)
        batch_normalization_18 = self.batch_normalization_18(conv2d_18)
        activation_18   = F.relu(batch_normalization_18)
        mixed1          = torch.cat((activation_13, activation_15, activation_18, activation_19), 1)
        conv2d_23       = self.conv2d_23(mixed1)
        conv2d_21       = self.conv2d_21(mixed1)
        average_pooling2d_3_pad = F.pad(mixed1, (1, 1, 1, 1))
        average_pooling2d_3 = F.avg_pool2d(average_pooling2d_3_pad, kernel_size=(3, 3), stride=(1, 1))
        conv2d_20       = self.conv2d_20(mixed1)
        batch_normalization_23 = self.batch_normalization_23(conv2d_23)
        batch_normalization_21 = self.batch_normalization_21(conv2d_21)
        conv2d_26       = self.conv2d_26(average_pooling2d_3)
        batch_normalization_20 = self.batch_normalization_20(conv2d_20)
        activation_23   = F.relu(batch_normalization_23)
        activation_21   = F.relu(batch_normalization_21)
        batch_normalization_26 = self.batch_normalization_26(conv2d_26)
        activation_20   = F.relu(batch_normalization_20)
        conv2d_24_pad   = F.pad(activation_23, (1, 1, 1, 1))
        conv2d_24       = self.conv2d_24(conv2d_24_pad)
        conv2d_22_pad   = F.pad(activation_21, (2, 2, 2, 2))
        conv2d_22       = self.conv2d_22(conv2d_22_pad)
        activation_26   = F.relu(batch_normalization_26)
        batch_normalization_24 = self.batch_normalization_24(conv2d_24)
        batch_normalization_22 = self.batch_normalization_22(conv2d_22)
        activation_24   = F.relu(batch_normalization_24)
        activation_22   = F.relu(batch_normalization_22)
        conv2d_25_pad   = F.pad(activation_24, (1, 1, 1, 1))
        conv2d_25       = self.conv2d_25(conv2d_25_pad)
        batch_normalization_25 = self.batch_normalization_25(conv2d_25)
        activation_25   = F.relu(batch_normalization_25)
        mixed2          = torch.cat((activation_20, activation_22, activation_25, activation_26), 1)
        conv2d_28       = self.conv2d_28(mixed2)
        conv2d_27       = self.conv2d_27(mixed2)
        max_pooling2d_3 = F.max_pool2d(mixed2, kernel_size=(3, 3), stride=(2, 2))
        batch_normalization_28 = self.batch_normalization_28(conv2d_28)
        batch_normalization_27 = self.batch_normalization_27(conv2d_27)
        activation_28   = F.relu(batch_normalization_28)
        activation_27   = F.relu(batch_normalization_27)
        conv2d_29_pad   = F.pad(activation_28, (1, 1, 1, 1))
        conv2d_29       = self.conv2d_29(conv2d_29_pad)
        batch_normalization_29 = self.batch_normalization_29(conv2d_29)
        activation_29   = F.relu(batch_normalization_29)
        conv2d_30       = self.conv2d_30(activation_29)
        batch_normalization_30 = self.batch_normalization_30(conv2d_30)
        activation_30   = F.relu(batch_normalization_30)
        mixed3          = torch.cat((activation_27, activation_30, max_pooling2d_3), 1)
        conv2d_35       = self.conv2d_35(mixed3)
        conv2d_32       = self.conv2d_32(mixed3)
        average_pooling2d_4_pad = F.pad(mixed3, (1, 1, 1, 1))
        average_pooling2d_4 = F.avg_pool2d(average_pooling2d_4_pad, kernel_size=(3, 3), stride=(1, 1))
        conv2d_31       = self.conv2d_31(mixed3)
        batch_normalization_35 = self.batch_normalization_35(conv2d_35)
        batch_normalization_32 = self.batch_normalization_32(conv2d_32)
        conv2d_40       = self.conv2d_40(average_pooling2d_4)
        batch_normalization_31 = self.batch_normalization_31(conv2d_31)
        activation_35   = F.relu(batch_normalization_35)
        activation_32   = F.relu(batch_normalization_32)
        batch_normalization_40 = self.batch_normalization_40(conv2d_40)
        activation_31   = F.relu(batch_normalization_31)
        conv2d_36_pad   = F.pad(activation_35, (0, 0, 3, 3))
        conv2d_36       = self.conv2d_36(conv2d_36_pad)
        conv2d_33_pad   = F.pad(activation_32, (3, 3, 0, 0))
        conv2d_33       = self.conv2d_33(conv2d_33_pad)
        activation_40   = F.relu(batch_normalization_40)
        batch_normalization_36 = self.batch_normalization_36(conv2d_36)
        batch_normalization_33 = self.batch_normalization_33(conv2d_33)
        activation_36   = F.relu(batch_normalization_36)
        activation_33   = F.relu(batch_normalization_33)
        conv2d_37_pad   = F.pad(activation_36, (3, 3, 0, 0))
        conv2d_37       = self.conv2d_37(conv2d_37_pad)
        conv2d_34_pad   = F.pad(activation_33, (0, 0, 3, 3))
        conv2d_34       = self.conv2d_34(conv2d_34_pad)
        batch_normalization_37 = self.batch_normalization_37(conv2d_37)
        batch_normalization_34 = self.batch_normalization_34(conv2d_34)
        activation_37   = F.relu(batch_normalization_37)
        activation_34   = F.relu(batch_normalization_34)
        conv2d_38_pad   = F.pad(activation_37, (0, 0, 3, 3))
        conv2d_38       = self.conv2d_38(conv2d_38_pad)
        batch_normalization_38 = self.batch_normalization_38(conv2d_38)
        activation_38   = F.relu(batch_normalization_38)
        conv2d_39_pad   = F.pad(activation_38, (3, 3, 0, 0))
        conv2d_39       = self.conv2d_39(conv2d_39_pad)
        batch_normalization_39 = self.batch_normalization_39(conv2d_39)
        activation_39   = F.relu(batch_normalization_39)
        mixed4          = torch.cat((activation_31, activation_34, activation_39, activation_40), 1)
        conv2d_45       = self.conv2d_45(mixed4)
        conv2d_42       = self.conv2d_42(mixed4)
        average_pooling2d_5_pad = F.pad(mixed4, (1, 1, 1, 1))
        average_pooling2d_5 = F.avg_pool2d(average_pooling2d_5_pad, kernel_size=(3, 3), stride=(1, 1))
        conv2d_41       = self.conv2d_41(mixed4)
        batch_normalization_45 = self.batch_normalization_45(conv2d_45)
        batch_normalization_42 = self.batch_normalization_42(conv2d_42)
        conv2d_50       = self.conv2d_50(average_pooling2d_5)
        batch_normalization_41 = self.batch_normalization_41(conv2d_41)
        activation_45   = F.relu(batch_normalization_45)
        activation_42   = F.relu(batch_normalization_42)
        batch_normalization_50 = self.batch_normalization_50(conv2d_50)
        activation_41   = F.relu(batch_normalization_41)
        conv2d_46_pad   = F.pad(activation_45, (0, 0, 3, 3))
        conv2d_46       = self.conv2d_46(conv2d_46_pad)
        conv2d_43_pad   = F.pad(activation_42, (3, 3, 0, 0))
        conv2d_43       = self.conv2d_43(conv2d_43_pad)
        activation_50   = F.relu(batch_normalization_50)
        batch_normalization_46 = self.batch_normalization_46(conv2d_46)
        batch_normalization_43 = self.batch_normalization_43(conv2d_43)
        activation_46   = F.relu(batch_normalization_46)
        activation_43   = F.relu(batch_normalization_43)
        conv2d_47_pad   = F.pad(activation_46, (3, 3, 0, 0))
        conv2d_47       = self.conv2d_47(conv2d_47_pad)
        conv2d_44_pad   = F.pad(activation_43, (0, 0, 3, 3))
        conv2d_44       = self.conv2d_44(conv2d_44_pad)
        batch_normalization_47 = self.batch_normalization_47(conv2d_47)
        batch_normalization_44 = self.batch_normalization_44(conv2d_44)
        activation_47   = F.relu(batch_normalization_47)
        activation_44   = F.relu(batch_normalization_44)
        conv2d_48_pad   = F.pad(activation_47, (0, 0, 3, 3))
        conv2d_48       = self.conv2d_48(conv2d_48_pad)
        batch_normalization_48 = self.batch_normalization_48(conv2d_48)
        activation_48   = F.relu(batch_normalization_48)
        conv2d_49_pad   = F.pad(activation_48, (3, 3, 0, 0))
        conv2d_49       = self.conv2d_49(conv2d_49_pad)
        batch_normalization_49 = self.batch_normalization_49(conv2d_49)
        activation_49   = F.relu(batch_normalization_49)
        mixed5          = torch.cat((activation_41, activation_44, activation_49, activation_50), 1)
        conv2d_55       = self.conv2d_55(mixed5)
        conv2d_52       = self.conv2d_52(mixed5)
        average_pooling2d_6_pad = F.pad(mixed5, (1, 1, 1, 1))
        average_pooling2d_6 = F.avg_pool2d(average_pooling2d_6_pad, kernel_size=(3, 3), stride=(1, 1))
        conv2d_51       = self.conv2d_51(mixed5)
        batch_normalization_55 = self.batch_normalization_55(conv2d_55)
        batch_normalization_52 = self.batch_normalization_52(conv2d_52)
        conv2d_60       = self.conv2d_60(average_pooling2d_6)
        batch_normalization_51 = self.batch_normalization_51(conv2d_51)
        activation_55   = F.relu(batch_normalization_55)
        activation_52   = F.relu(batch_normalization_52)
        batch_normalization_60 = self.batch_normalization_60(conv2d_60)
        activation_51   = F.relu(batch_normalization_51)
        conv2d_56_pad   = F.pad(activation_55, (0, 0, 3, 3))
        conv2d_56       = self.conv2d_56(conv2d_56_pad)
        conv2d_53_pad   = F.pad(activation_52, (3, 3, 0, 0))
        conv2d_53       = self.conv2d_53(conv2d_53_pad)
        activation_60   = F.relu(batch_normalization_60)
        batch_normalization_56 = self.batch_normalization_56(conv2d_56)
        batch_normalization_53 = self.batch_normalization_53(conv2d_53)
        activation_56   = F.relu(batch_normalization_56)
        activation_53   = F.relu(batch_normalization_53)
        conv2d_57_pad   = F.pad(activation_56, (3, 3, 0, 0))
        conv2d_57       = self.conv2d_57(conv2d_57_pad)
        conv2d_54_pad   = F.pad(activation_53, (0, 0, 3, 3))
        conv2d_54       = self.conv2d_54(conv2d_54_pad)
        batch_normalization_57 = self.batch_normalization_57(conv2d_57)
        batch_normalization_54 = self.batch_normalization_54(conv2d_54)
        activation_57   = F.relu(batch_normalization_57)
        activation_54   = F.relu(batch_normalization_54)
        conv2d_58_pad   = F.pad(activation_57, (0, 0, 3, 3))
        conv2d_58       = self.conv2d_58(conv2d_58_pad)
        batch_normalization_58 = self.batch_normalization_58(conv2d_58)
        activation_58   = F.relu(batch_normalization_58)
        conv2d_59_pad   = F.pad(activation_58, (3, 3, 0, 0))
        conv2d_59       = self.conv2d_59(conv2d_59_pad)
        batch_normalization_59 = self.batch_normalization_59(conv2d_59)
        activation_59   = F.relu(batch_normalization_59)
        mixed6          = torch.cat((activation_51, activation_54, activation_59, activation_60), 1)
        conv2d_65       = self.conv2d_65(mixed6)
        conv2d_62       = self.conv2d_62(mixed6)
        average_pooling2d_7_pad = F.pad(mixed6, (1, 1, 1, 1))
        average_pooling2d_7 = F.avg_pool2d(average_pooling2d_7_pad, kernel_size=(3, 3), stride=(1, 1))
        conv2d_61       = self.conv2d_61(mixed6)
        batch_normalization_65 = self.batch_normalization_65(conv2d_65)
        batch_normalization_62 = self.batch_normalization_62(conv2d_62)
        conv2d_70       = self.conv2d_70(average_pooling2d_7)
        batch_normalization_61 = self.batch_normalization_61(conv2d_61)
        activation_65   = F.relu(batch_normalization_65)
        activation_62   = F.relu(batch_normalization_62)
        batch_normalization_70 = self.batch_normalization_70(conv2d_70)
        activation_61   = F.relu(batch_normalization_61)
        conv2d_66_pad   = F.pad(activation_65, (0, 0, 3, 3))
        conv2d_66       = self.conv2d_66(conv2d_66_pad)
        conv2d_63_pad   = F.pad(activation_62, (3, 3, 0, 0))
        conv2d_63       = self.conv2d_63(conv2d_63_pad)
        activation_70   = F.relu(batch_normalization_70)
        batch_normalization_66 = self.batch_normalization_66(conv2d_66)
        batch_normalization_63 = self.batch_normalization_63(conv2d_63)
        activation_66   = F.relu(batch_normalization_66)
        activation_63   = F.relu(batch_normalization_63)
        conv2d_67_pad   = F.pad(activation_66, (3, 3, 0, 0))
        conv2d_67       = self.conv2d_67(conv2d_67_pad)
        conv2d_64_pad   = F.pad(activation_63, (0, 0, 3, 3))
        conv2d_64       = self.conv2d_64(conv2d_64_pad)
        batch_normalization_67 = self.batch_normalization_67(conv2d_67)
        batch_normalization_64 = self.batch_normalization_64(conv2d_64)
        activation_67   = F.relu(batch_normalization_67)
        activation_64   = F.relu(batch_normalization_64)
        conv2d_68_pad   = F.pad(activation_67, (0, 0, 3, 3))
        conv2d_68       = self.conv2d_68(conv2d_68_pad)
        batch_normalization_68 = self.batch_normalization_68(conv2d_68)
        activation_68   = F.relu(batch_normalization_68)
        conv2d_69_pad   = F.pad(activation_68, (3, 3, 0, 0))
        conv2d_69       = self.conv2d_69(conv2d_69_pad)
        batch_normalization_69 = self.batch_normalization_69(conv2d_69)
        activation_69   = F.relu(batch_normalization_69)
        mixed7          = torch.cat((activation_61, activation_64, activation_69, activation_70), 1)
        conv2d_73       = self.conv2d_73(mixed7)
        conv2d_71       = self.conv2d_71(mixed7)
        max_pooling2d_4 = F.max_pool2d(mixed7, kernel_size=(3, 3), stride=(2, 2))
        batch_normalization_73 = self.batch_normalization_73(conv2d_73)
        batch_normalization_71 = self.batch_normalization_71(conv2d_71)
        activation_73   = F.relu(batch_normalization_73)
        activation_71   = F.relu(batch_normalization_71)
        conv2d_74_pad   = F.pad(activation_73, (3, 3, 0, 0))
        conv2d_74       = self.conv2d_74(conv2d_74_pad)
        conv2d_72       = self.conv2d_72(activation_71)
        batch_normalization_74 = self.batch_normalization_74(conv2d_74)
        batch_normalization_72 = self.batch_normalization_72(conv2d_72)
        activation_74   = F.relu(batch_normalization_74)
        activation_72   = F.relu(batch_normalization_72)
        conv2d_75_pad   = F.pad(activation_74, (0, 0, 3, 3))
        conv2d_75       = self.conv2d_75(conv2d_75_pad)
        batch_normalization_75 = self.batch_normalization_75(conv2d_75)
        activation_75   = F.relu(batch_normalization_75)
        conv2d_76       = self.conv2d_76(activation_75)
        batch_normalization_76 = self.batch_normalization_76(conv2d_76)
        activation_76   = F.relu(batch_normalization_76)
        mixed8          = torch.cat((activation_72, activation_76, max_pooling2d_4), 1)
        conv2d_81       = self.conv2d_81(mixed8)
        conv2d_78       = self.conv2d_78(mixed8)
        average_pooling2d_8_pad = F.pad(mixed8, (1, 1, 1, 1))
        average_pooling2d_8 = F.avg_pool2d(average_pooling2d_8_pad, kernel_size=(3, 3), stride=(1, 1))
        conv2d_77       = self.conv2d_77(mixed8)
        batch_normalization_81 = self.batch_normalization_81(conv2d_81)
        batch_normalization_78 = self.batch_normalization_78(conv2d_78)
        conv2d_85       = self.conv2d_85(average_pooling2d_8)
        batch_normalization_77 = self.batch_normalization_77(conv2d_77)
        activation_81   = F.relu(batch_normalization_81)
        activation_78   = F.relu(batch_normalization_78)
        batch_normalization_85 = self.batch_normalization_85(conv2d_85)
        activation_77   = F.relu(batch_normalization_77)
        conv2d_82_pad   = F.pad(activation_81, (1, 1, 1, 1))
        conv2d_82       = self.conv2d_82(conv2d_82_pad)
        conv2d_79_pad   = F.pad(activation_78, (1, 1, 0, 0))
        conv2d_79       = self.conv2d_79(conv2d_79_pad)
        conv2d_80_pad   = F.pad(activation_78, (0, 0, 1, 1))
        conv2d_80       = self.conv2d_80(conv2d_80_pad)
        activation_85   = F.relu(batch_normalization_85)
        batch_normalization_82 = self.batch_normalization_82(conv2d_82)
        batch_normalization_79 = self.batch_normalization_79(conv2d_79)
        batch_normalization_80 = self.batch_normalization_80(conv2d_80)
        activation_82   = F.relu(batch_normalization_82)
        activation_79   = F.relu(batch_normalization_79)
        activation_80   = F.relu(batch_normalization_80)
        conv2d_83_pad   = F.pad(activation_82, (1, 1, 0, 0))
        conv2d_83       = self.conv2d_83(conv2d_83_pad)
        conv2d_84_pad   = F.pad(activation_82, (0, 0, 1, 1))
        conv2d_84       = self.conv2d_84(conv2d_84_pad)
        mixed9_0        = torch.cat((activation_79, activation_80), 1)
        batch_normalization_83 = self.batch_normalization_83(conv2d_83)
        batch_normalization_84 = self.batch_normalization_84(conv2d_84)
        activation_83   = F.relu(batch_normalization_83)
        activation_84   = F.relu(batch_normalization_84)
        concatenate_1   = torch.cat((activation_83, activation_84), 1)
        mixed9          = torch.cat((activation_77, mixed9_0, concatenate_1, activation_85), 1)
        conv2d_90       = self.conv2d_90(mixed9)
        conv2d_87       = self.conv2d_87(mixed9)
        average_pooling2d_9_pad = F.pad(mixed9, (1, 1, 1, 1))
        average_pooling2d_9 = F.avg_pool2d(average_pooling2d_9_pad, kernel_size=(3, 3), stride=(1, 1))
        conv2d_86       = self.conv2d_86(mixed9)
        batch_normalization_90 = self.batch_normalization_90(conv2d_90)
        batch_normalization_87 = self.batch_normalization_87(conv2d_87)
        conv2d_94       = self.conv2d_94(average_pooling2d_9)
        batch_normalization_86 = self.batch_normalization_86(conv2d_86)
        activation_90   = F.relu(batch_normalization_90)
        activation_87   = F.relu(batch_normalization_87)
        batch_normalization_94 = self.batch_normalization_94(conv2d_94)
        activation_86   = F.relu(batch_normalization_86)
        conv2d_91_pad   = F.pad(activation_90, (1, 1, 1, 1))
        conv2d_91       = self.conv2d_91(conv2d_91_pad)
        conv2d_88_pad   = F.pad(activation_87, (1, 1, 0, 0))
        conv2d_88       = self.conv2d_88(conv2d_88_pad)
        conv2d_89_pad   = F.pad(activation_87, (0, 0, 1, 1))
        conv2d_89       = self.conv2d_89(conv2d_89_pad)
        activation_94   = F.relu(batch_normalization_94)
        batch_normalization_91 = self.batch_normalization_91(conv2d_91)
        batch_normalization_88 = self.batch_normalization_88(conv2d_88)
        batch_normalization_89 = self.batch_normalization_89(conv2d_89)
        activation_91   = F.relu(batch_normalization_91)
        activation_88   = F.relu(batch_normalization_88)
        activation_89   = F.relu(batch_normalization_89)
        conv2d_92_pad   = F.pad(activation_91, (1, 1, 0, 0))
        conv2d_92       = self.conv2d_92(conv2d_92_pad)
        conv2d_93_pad   = F.pad(activation_91, (0, 0, 1, 1))
        conv2d_93       = self.conv2d_93(conv2d_93_pad)
        mixed9_1        = torch.cat((activation_88, activation_89), 1)
        batch_normalization_92 = self.batch_normalization_92(conv2d_92)
        batch_normalization_93 = self.batch_normalization_93(conv2d_93)
        activation_92   = F.relu(batch_normalization_92)
        activation_93   = F.relu(batch_normalization_93)
        concatenate_2   = torch.cat((activation_92, activation_93), 1)
        mixed10         = torch.cat((activation_86, mixed9_1, concatenate_2, activation_94), 1)
        avg_pool        = F.avg_pool2d(input = mixed10, kernel_size = mixed10.size()[2:])
        avg_pool_flatten = avg_pool.view(avg_pool.size(0), -1)
        predictions     = self.predictions(avg_pool_flatten)
        predictions_activation = F.softmax(predictions)
        return predictions_activation


    @staticmethod
    def __dense(name, **kwargs):
        layer = nn.Linear(**kwargs)
        layer.state_dict()['weight'].copy_(torch.from_numpy(__weights_dict[name]['weights']))
        if 'bias' in __weights_dict[name]:
            layer.state_dict()['bias'].copy_(torch.from_numpy(__weights_dict[name]['bias']))
        return layer

    @staticmethod
    def __conv(dim, name, **kwargs):
        if   dim == 1:  layer = nn.Conv1d(**kwargs)
        elif dim == 2:  layer = nn.Conv2d(**kwargs)
        elif dim == 3:  layer = nn.Conv3d(**kwargs)
        else:           raise NotImplementedError()

        layer.state_dict()['weight'].copy_(torch.from_numpy(__weights_dict[name]['weights']))
        if 'bias' in __weights_dict[name]:
            layer.state_dict()['bias'].copy_(torch.from_numpy(__weights_dict[name]['bias']))
        return layer

    @staticmethod
    def __batch_normalization(dim, name, **kwargs):
        if   dim == 1:  layer = nn.BatchNorm1d(**kwargs)
        elif dim == 2:  layer = nn.BatchNorm2d(**kwargs)
        elif dim == 3:  layer = nn.BatchNorm3d(**kwargs)
        else:           raise NotImplementedError()

        if 'scale' in __weights_dict[name]:
            layer.state_dict()['weight'].copy_(torch.from_numpy(__weights_dict[name]['scale']))
        else:
            layer.weight.data.fill_(1)

        if 'bias' in __weights_dict[name]:
            layer.state_dict()['bias'].copy_(torch.from_numpy(__weights_dict[name]['bias']))
        else:
            layer.bias.data.fill_(0)

        layer.state_dict()['running_mean'].copy_(torch.from_numpy(__weights_dict[name]['mean']))
        layer.state_dict()['running_var'].copy_(torch.from_numpy(__weights_dict[name]['var']))
        return layer
<file_sep>import tensorflow as tf
from numpy import prod


def print_activations(t):
    print(t.op.name, ' ', t.get_shape().as_list())


def alexnet_inference(images):
    """Build the AlexNet model.

    Args:
      images: Images Tensor

    Returns:
      pool5: the last Tensor in the convolutional component of AlexNet.
      parameters: a list of Tensors corresponding to the weights and biases of the
          AlexNet model.
    """
    parameters = []
    # conv1
    with tf.name_scope('conv1') as scope:
        kernel = tf.Variable(tf.truncated_normal([11, 11, 3, 64], dtype=tf.float32,
                                                 stddev=1e-1), name='weights')
        conv = tf.nn.conv2d(images, kernel, [1, 4, 4, 1], padding='SAME')
        biases = tf.Variable(tf.constant(0.0, shape=[64], dtype=tf.float32),
                             trainable=True, name='biases')
        bias = tf.nn.bias_add(conv, biases)
        conv1 = tf.nn.relu(bias, name=scope)
        print_activations(conv1)
        parameters += [kernel, biases]

    # lrn1
    lrn1 = conv1
    # with tf.name_scope('lrn1') as scope:
    # lrn1 = tf.nn.local_response_normalization(conv1,
    #                                           alpha=1e-4,
    #                                           beta=0.75,
    #                                           depth_radius=2,
    #                                           bias=2.0)

    # pool1
    pool1 = tf.nn.max_pool(lrn1,
                           ksize=[1, 3, 3, 1],
                           strides=[1, 2, 2, 1],
                           padding='VALID',
                           name='pool1')
    print_activations(pool1)

    # conv2
    with tf.name_scope('conv2') as scope:
        kernel = tf.Variable(tf.truncated_normal([5, 5, 64, 192], dtype=tf.float32,
                                                 stddev=1e-1), name='weights')
        conv = tf.nn.conv2d(pool1, kernel, [1, 1, 1, 1], padding='SAME')
        biases = tf.Variable(tf.constant(0.0, shape=[192], dtype=tf.float32),
                             trainable=True, name='biases')
        bias = tf.nn.bias_add(conv, biases)
        conv2 = tf.nn.relu(bias, name=scope)
        parameters += [kernel, biases]
    print_activations(conv2)

    # lrn2
    lrn2 = conv2
    # with tf.name_scope('lrn2') as scope:
    #     lrn2 = tf.nn.local_response_normalization(conv2,
    #                                               alpha=1e-4,
    #                                               beta=0.75,
    #                                               depth_radius=2,
    #                                               bias=2.0)

    # pool2
    pool2 = tf.nn.max_pool(lrn2,
                           ksize=[1, 3, 3, 1],
                           strides=[1, 2, 2, 1],
                           padding='VALID',
                           name='pool2')
    print_activations(pool2)

    # conv3
    with tf.name_scope('conv3') as scope:
        kernel = tf.Variable(tf.truncated_normal([3, 3, 192, 384],
                                                 dtype=tf.float32,
                                                 stddev=1e-1), name='weights')
        conv = tf.nn.conv2d(pool2, kernel, [1, 1, 1, 1], padding='SAME')
        biases = tf.Variable(tf.constant(0.0, shape=[384], dtype=tf.float32),
                             trainable=True, name='biases')
        bias = tf.nn.bias_add(conv, biases)
        conv3 = tf.nn.relu(bias, name=scope)
        parameters += [kernel, biases]
        print_activations(conv3)

    # conv4
    with tf.name_scope('conv4') as scope:
        kernel = tf.Variable(tf.truncated_normal([3, 3, 384, 256],
                                                 dtype=tf.float32,
                                                 stddev=1e-1), name='weights')
        conv = tf.nn.conv2d(conv3, kernel, [1, 1, 1, 1], padding='SAME')
        biases = tf.Variable(tf.constant(0.0, shape=[256], dtype=tf.float32),
                             trainable=True, name='biases')
        bias = tf.nn.bias_add(conv, biases)
        conv4 = tf.nn.relu(bias, name=scope)
        parameters += [kernel, biases]
        print_activations(conv4)

    # conv5
    with tf.name_scope('conv5') as scope:
        kernel = tf.Variable(tf.truncated_normal([3, 3, 256, 256],
                                                 dtype=tf.float32,
                                                 stddev=1e-1), name='weights')
        conv = tf.nn.conv2d(conv4, kernel, [1, 1, 1, 1], padding='SAME')
        biases = tf.Variable(tf.constant(0.0, shape=[256], dtype=tf.float32),
                             trainable=True, name='biases')
        bias = tf.nn.bias_add(conv, biases)
        conv5 = tf.nn.relu(bias, name=scope)
        parameters += [kernel, biases]
        print_activations(conv5)

    # pool5
    pool5 = tf.nn.max_pool(conv5,
                           ksize=[1, 3, 3, 1],
                           strides=[1, 2, 2, 1],
                           padding='VALID',
                           name='pool5')
    print_activations(pool5)

    maxpool5 = pool5

    # fc6
    # fc(4096, name='fc6')
    # fc6W = tf.Variable(net_data["fc6"][0])
    # fc6b = tf.Variable(net_data["fc6"][1])
    # print(tf.reshape(maxpool5, [-1, int(prod(maxpool5.get_shape()[1:]))])) #1, 9216
    with tf.name_scope('fcc6') as scope:
        fc6W = tf.Variable(tf.random_normal([9216, 4096],
                                            mean=0,
                                            stddev=1.0,
                                            dtype=tf.float32,
                                            name='fc6_weights'))

        fc6b = tf.Variable(tf.constant(0.0, shape=[4096], dtype=tf.float32,
                                       name='fc6_biases'))

        fc6 = tf.nn.relu_layer(tf.reshape(maxpool5, [-1, int(prod(maxpool5.get_shape()[1:]))]), fc6W, fc6b)
        print_activations(fc6)


        # fc7
        # fc(4096, name='fc7')
    with tf.name_scope('fcc7') as scope:
        fc7W = tf.Variable(tf.random_normal([4096, 4096], mean=0, stddev=1.0, dtype=tf.float32, name='fc7_weights'))
        fc7b = tf.Variable(tf.constant(0.0, shape=[4096], dtype=tf.float32, name='fc7_biases'))

        fc7 = tf.nn.relu_layer(fc6, fc7W, fc7b)

        print_activations(fc7)

        # fc8
        # fc(1000, relu=False, name='fc8')
    with tf.name_scope('fcc7') as scope:
        fc8W = tf.Variable(tf.random_normal([4096, 1000], mean=0, stddev=1.0, dtype=tf.float32, name='fc8_weights'))
        fc8b = tf.Variable(tf.constant(0.0, shape=[1000], dtype=tf.float32, name='fc8_biases'))
        fc8 = tf.nn.xw_plus_b(fc7, fc8W, fc8b)
        print_activations(fc8)

    # return fc8, parameters

    prob = tf.nn.softmax(fc8)
    return prob, parameters
<file_sep>import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import tensorrt as trt
from tensorrt.parsers import uffparser

import pycuda.driver as cuda
import pycuda.autoinit
import numpy as np
from random import randint # generate a random test case
from PIL import Image
import time #import system tools
import os

import uff

OUTPUT_NAMES = ["predictions/Softmax"]

uff_model = uff.from_tensorflow_frozen_model("tf_vgg.pb", OUTPUT_NAMES)
G_LOGGER = trt.infer.ConsoleLogger(trt.infer.LogSeverity.ERROR)

parser = uffparser.create_uff_parser()
parser.register_input("input_1", (3,224,224), 0)
parser.register_output(OUTPUT_NAMES[0])

engine = trt.utils.uff_to_trt_engine(G_LOGGER, uff_model, parser, 1, 1 << 20)
parser.destroy()

img = np.random.randint(256, size=(3, 224, 224)) / 255.
img = img.astype(np.float32)

label = 123

runtime = trt.infer.create_infer_runtime(G_LOGGER)
context = engine.create_execution_context()

output = np.empty(1000, dtype = np.float32)

d_input = cuda.mem_alloc(1 * img.size * img.dtype.itemsize)
d_output = cuda.mem_alloc(1 * output.size * output.dtype.itemsize)

bindings = [int(d_input), int(d_output)]
stream = cuda.Stream()


#transfer input data to device
cuda.memcpy_htod_async(d_input, img, stream)
#execute model
context.enqueue(1, bindings, stream.handle, None)
#transfer predictions back
cuda.memcpy_dtoh_async(output, d_output, stream)
#syncronize threads
stream.synchronize()

print("Test Case: " + str(label))
print ("Prediction: " + str(np.argmax(output)))

trt.utils.write_engine_to_file("./tf_mnist.engine", engine.serialize())

<file_sep>def round_ms(seconds):
    return round(1000 * seconds, 3)


def get_image_size(model):
    if model in {"alexnet", "resnet", "vgg"}:
        image_size = 224
    elif model in {"inception"}:
        image_size = 299
    else:
        raise RuntimeError("Image size not defined for model: " + str(model))

    return image_size<file_sep>import rpyc
import glob
import time
import argparse
from skimage import io
import random
import numpy as np

from utils import round_ms
from concurrent.futures import ThreadPoolExecutor
import cProfile, pstats, io as io2


tpe = ThreadPoolExecutor(max_workers=None)
#print(tpe)
tpe_out = ThreadPoolExecutor(max_workers=15)

TOTAL_SENT = 500
TIME_BETWEEN_REQUESTS = 0.02

total_latency = 0.0
TOTAL_RECEIVED = 0
IMG_SIZE = None
moving_latency_average = 0.0
first_packet_time = None
last_packet_time = None
ALPHA = 0.925  # moving average


def callback_func_higher(i, start_time):
    def cb_func(x):
        # print("Got answer", time.time())
        global total_latency, count_latency, TOTAL_RECEIVED, ALPHA, moving_latency_average
        latency = time.time() - start_time

        moving_latency_average = ALPHA * moving_latency_average + (1 - ALPHA) * latency
        if not i % 100:
            print("GOT " + str(i) + " c: " + str(x) +
                  " LAT: " + str(round_ms(latency)) +
                  " Moving LAT avg:" + str(round_ms(moving_latency_average)))
        total_latency += latency
        TOTAL_RECEIVED += 1

    return cb_func


def report_stats():
    global last_packet_time, first_packet_time
    print("COUNT:", TOTAL_RECEIVED)
    time_to_send_all = last_packet_time - first_packet_time
    time_to_send_one = time_to_send_all / TOTAL_RECEIVED
    packets_sent_per_second = 1 / time_to_send_one
    print("TOTAL time taken to send (ms):", round_ms(time_to_send_all))
    print("Packets sent per sec", packets_sent_per_second)
    print("AVG latency (ms):", round_ms(total_latency / TOTAL_RECEIVED))


def parse_arguments():
    global TOTAL_SENT, TIME_BETWEEN_REQUESTS, IMG_SIZE
    parser = argparse.ArgumentParser()
    parser.add_argument("--requests", help="num of total requests", type=int)
    parser.add_argument("--time", help="time between each request", type=float)
    parser.add_argument("--size", help="size of img (pix)", type=int)
    args = parser.parse_args()
    if args.requests is not None:
        TOTAL_SENT = args.requests

    if args.time is not None:
        TIME_BETWEEN_REQUESTS = args.time

    if args.size is not None:
        IMG_SIZE = args.size

    print("Sending", TOTAL_SENT, "requests")
    print("Sleeping", TIME_BETWEEN_REQUESTS, "between each")
    time.sleep(0.1)


def main():
    global first_packet_time, last_packet_time
    parse_arguments()
    host = "localhost"
    port = 1200
    conn = rpyc.connect(host, port)
    rpyc.BgServingThread.SLEEP_INTERVAL = 0
    rpyc.BgServingThread(conn)
    #tpe.submit(rpyc.BgServingThread, conn)

    filenames = glob.glob("/Users/justas/PycharmProjects/ugproject/img/*.jpg")  # assuming gif
    random.shuffle(filenames)

    t1 = time.time()
    first_packet_time = time.time()
    for i in range(TOTAL_SENT):
        t2 = time.time()
        #if not ((i + 1) % 50):
        #    print("SENT", i, t2 - t1)
        t1 = t2

        if IMG_SIZE is not None:
            img_numpy = np.random.randint(256, size=(IMG_SIZE, IMG_SIZE, 3), dtype=np.uint8)
            # print(img_numpy.shape)
        else:
            file_name = filenames[i]
            img_numpy = io.imread(file_name)
            # print(img_numpy)

        raw_data = img_numpy.tobytes()

        tpe_out.submit(send_img, conn, i, raw_data)
        time.sleep(TIME_BETWEEN_REQUESTS)

    while TOTAL_RECEIVED < TOTAL_SENT:
        time.sleep(0.01)
    report_stats()


def send_img(conn, i, raw_data):
    conn.root.RemoteCallbackTest(raw_data, callback_func_higher(i, start_time=time.time()), )
    if not i % 50:
        print("SENT\t" +  str(i) + " " + str(time.time()))
    # print("Sent img", time.time())
    # pr.enable()

    if i == 0:
        global first_packet_time
        first_packet_time = time.time()
    if i == (TOTAL_SENT - 1):
        global last_packet_time
        last_packet_time = time.time()

        # pr.disable()

    # s = io2.StringIO()
    # sortby = 'cumulative'
    # ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
    # ps.print_stats()
    # print(s.getvalue())


if __name__ == '__main__':
    pr = cProfile.Profile()
    main()
<file_sep>import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import tensorrt as trt
from tensorrt.parsers import uffparser

import pycuda.driver as cuda
import pycuda.autoinit
import numpy as np
from random import randint # generate a random test case
from PIL import Image
import time #import system tools
import os

import uff

OUTPUT_NAMES = ["fc1000/Softmax"]

BATCH_SIZE = 2
PB_DIR = "../tf_frozen/"
uff_model = uff.from_tensorflow_frozen_model(PB_DIR + "tf_resnet.pb", OUTPUT_NAMES)
G_LOGGER = trt.infer.ConsoleLogger(trt.infer.LogSeverity.ERROR)

parser = uffparser.create_uff_parser()
parser.register_input("input_1", (3,224,224), 0)
parser.register_output(OUTPUT_NAMES[0])

engine = trt.utils.uff_to_trt_engine(G_LOGGER, uff_model, parser, BATCH_SIZE, 0) #1 << 20) #, datatype=trt.infer.DataType.HALF)
parser.destroy()

img = np.random.randint(256, size=(3, 224, 224)) / 255.
img = img.astype(np.float32)

label = 123

runtime = trt.infer.create_infer_runtime(G_LOGGER)
context = engine.create_execution_context()

output = np.empty((BATCH_SIZE,1000), dtype = np.float32)

d_input = cuda.mem_alloc(BATCH_SIZE * img.size * img.dtype.itemsize)
d_output = cuda.mem_alloc(BATCH_SIZE * output.size * output.dtype.itemsize)

bindings = [int(d_input), int(d_output)]
stream = cuda.Stream()

def infer(img_input):
    global output
    #transfer input data to device
    cuda.memcpy_htod_async(d_input, img_input, stream)
    #execute model
    context.enqueue(BATCH_SIZE, bindings, stream.handle, None)
    #transfer predictions back
    cuda.memcpy_dtoh_async(output, d_output, stream)
    #syncronize threads
    stream.synchronize()

total_run_time = 0.0
RUNS = 1000

for i in range(RUNS):
    img = np.random.randint(256, size=(BATCH_SIZE, 3, 224, 224)) / 255.
    img = img.astype(np.float32)
    start = time.time()
    infer(img)
    end = time.time() 
    print("Ran for: " + str(1000 * (end-start)) + " ms\t\t" + "test v prod " + str(label) + " " + str(np.argmax(output, axis=1)))
    total_run_time += (end-start)
print("Done.")
print("AVG: " + str(1000 * (total_run_time / RUNS))) 
<file_sep>from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf
import argparse
import cProfile, pstats, io as io2

from datetime import datetime
import math
import sys
import time

import gc
import numpy as np
from torch.autograd import Variable
import torch
from tensorflow.python.client import timeline

from six.moves import xrange

import torchvision
from memory_profiler import profile

from keras import backend as K

from utils import get_image_size, round_ms

FLAGS = None
g = None
run_metadata = tf.RunMetadata()
options = None
prep_start = 0


def prepare_torch(model):
    print("Preparing Torch")
    global net

    model_file = "torch_frozen/torch_" + str(model) + ".out"

    net = torch.load(model_file)
    net.cuda()
    # torch.set_num_threads(4)
    print(net)


def torch_classify(imgs, opts=None, run_md=None):
    batch = Variable(torch.from_numpy(imgs))
    r = net.forward(batch.cuda())
    r.cpu()


# #@profile
def prepare_keras(model):
    print("Preparing Keras")
    import models_keras
    global net, graph

    net = models_keras.create_model(model)

    graph = tf.get_default_graph()
    keras_session = K.get_session()

    # if FLAGS.trace:
    # run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
    # net.compile(loss='MSE', optimizer='Adam', options=run_options, run_metadata=run_metadata)

    # old_run = keras_session.run
    # print("old_run", old_run)
    # print("K.sess 1", keras_session)
    #
    # def new_run(*args, **kwargs):
    #     # print("X", self)
    #     print("NewRunning", *args)
    #     old_run(*args, **kwargs)

    # keras_session.run = new_run


# #@profile
def keras_classify(imgs, opts=None, run_md=None):
    global graph
    with graph.as_default():
        net.predict(imgs)


def prepare_tf(model):
    print("Preparing TensorFlow")
    global main_sess, images_placeholder, g, g_input, g_output

    g = load_frozen_tensorflow_graph(model)

    input_tensor_name = g.get_operations()[0].name + ":0"
    output_tensor_name = g.get_operations()[-1].name + ":0"

    with g.as_default():
        g_input = g.get_tensor_by_name(input_tensor_name)
        g_output = g.get_tensor_by_name(output_tensor_name)

        init_global = tf.global_variables_initializer()

    config = tf.ConfigProto()

    # Not relevant for non-GPU
    # config.gpu_options.allocator_type = 'BFC'

    main_sess = tf.Session(graph=g, config=config)
    main_sess.run(init_global)


def load_frozen_tensorflow_graph(model):
    model_file = "tf_frozen/"

    if model == "alexnet":
        model_file += "tf_alex.pb"
    elif model == "vgg":
        model_file += "tf_vgg.pb"
    elif model == "inception":
        model_file += "tf_inception.pb"
    elif model == "resnet":
        model_file += "tf_resnet.pb"
    print("TF model file", model_file)

    with tf.gfile.GFile(model_file, "rb") as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
    with tf.Graph().as_default() as graph:
        tf.import_graph_def(graph_def, name="main")
    return graph


# #@profile
def tf_classify(imgs, opts=None, run_md=None):
    main_sess.run(g_output, options=opts, run_metadata=run_md, feed_dict={g_input: imgs})


def time_run(info_string, imgs, fw, model):
    global run_inference, run_metadata, prep_start
    """Run the computation and print timing stats.

    Args:
      session: the TensorFlow session to run the computation under.
      target: the target Tensor that is passed to the session's run() function.
      info_string: a string summarizing this run, to be printed with the stats.

    Returns:
      None
    """
    num_steps_burn_in = 10
    total_duration = 0.0
    total_duration_squared = 0.0

    total_process_duration = 0.0
    total_process_duration_squared = 0.0

    file_name = 'tf_traces/batch_' + str(fw) + "_" + str(model) + str(FLAGS.batch_size) + '.json'
    torch_chrome_file_name = 'torch_traces/batch_' + str(fw) + "_" + str(model) + str(FLAGS.batch_size) + '.json'
    dump_profiler_file_name = 'profiler_traces/' + str(fw) + "_" + str(model) + str(FLAGS.batch_size) + '.pstats'

    pr = cProfile.Profile()

    output_trace = FLAGS.trace
    print("Output trace: " + str(output_trace))

    for i in xrange(FLAGS.num_batches + num_steps_burn_in):

        # options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE) if output_trace else None
        # run_metadata = tf.RunMetadata()

        start_p_time = time.process_time()
        start_time = time.time()

        if output_trace:
            if fw in {"torch", "pytorch"}:
                with torch.autograd.profiler.profile() as torch_prof:
                    run_inference(imgs)
                # print(torch_prof.key_averages())
                torch_prof.export_chrome_trace(torch_chrome_file_name)

            else:
                if i >= num_steps_burn_in:
                    pr.enable()

                # run_inference(imgs, opts=options, run_md=run_metadata)
                run_inference(imgs)  # , opts=options, run_md=run_metadata)

                if i >= num_steps_burn_in:
                    pr.disable()
        else:
            run_inference(imgs)

        duration = time.time() - start_time
        p_duration = time.process_time() - start_p_time

        if output_trace:
            fetched_timeline = timeline.Timeline(run_metadata.step_stats)
            chrome_trace = fetched_timeline.generate_chrome_trace_format(show_dataflow=True, show_memory=False)

            with open(file_name, 'w') as f:
                f.write(chrome_trace)

        if i >= num_steps_burn_in:
            if not i % 10:
                print('%s: step %d, duration = %.3f' %
                      (datetime.now(), i - num_steps_burn_in, duration))
            total_duration += duration
            total_duration_squared += duration * duration
            total_process_duration += p_duration
            total_process_duration_squared += p_duration * p_duration

            # if i == 0:
            #     print(datetime.now(), "Classified first batch, time since start (ms): ",
            #           int(round_ms(time.time() - prep_start)))

    if output_trace:
        s = io2.StringIO()
        ps = pstats.Stats(pr, stream=s).sort_stats("cumulative")
        ps.dump_stats(dump_profiler_file_name)
        # ps.print_stats()

    mn = total_duration / FLAGS.num_batches
    vr = total_duration_squared / FLAGS.num_batches - mn * mn
    sd = math.sqrt(vr)

    mean_process = total_process_duration / FLAGS.num_batches
    var_process = total_process_duration_squared / FLAGS.num_batches - mean_process * mean_process
    sd_process = math.sqrt(var_process)

    print('%s: %s across %d steps (WALL TIME), %.3f +/- %.3f sec / batch' %
          (datetime.now(), info_string, FLAGS.num_batches, mn, sd))
    print('%s: PROCESS_TIME: %.3f +/- %.3f sec / batch' %
          (datetime.now(), mean_process, sd_process))


def generate_dummy_images(fw, batch_size, image_size):
    if fw in {"torch", "pytorch"}:
        images = np.random.randint(256, size=(batch_size, 3, image_size, image_size)) / 255.
    elif fw in {"tensorflow", "tf", "keras"}:
        images = np.random.randint(256, size=(batch_size, image_size, image_size, 3)) / 255.
    else:
        raise RuntimeError("Mock images not defined for framework: " + str(fw))

    print("Images shape", images.shape)
    return images.astype(np.float32)


def run_benchmark(fw, model):
    global g
    if fw in {"keras"}:
        g = g or tf.get_default_graph()

    image_size = get_image_size(model)
    # Generate some dummy images.
    images = generate_dummy_images(fw, FLAGS.batch_size, image_size)

    info_string = str(fw) + ", " + str(model) + ", batch_size " + str(FLAGS.batch_size) + " |"
    time_run(info_string, images, fw, model)


# #@profile
def prepare_benchmark(fw, model):
    global run_inference

    print("Params: ", fw, "running", model)

    if fw in {"tensorflow", "tf"}:
        prepare_tf(model)
        run_inference = tf_classify
    elif fw in {"pytorch", "torch"}:
        prepare_torch(model)
        run_inference = torch_classify
    elif fw in {"keras"}:
        prepare_keras(model)
        run_inference = keras_classify
    else:
        raise RuntimeError("No framework with this name")


# @profile
def main(_):
    # pr = cProfile.Profile()

    global prep_start
    model = FLAGS.model.lower()
    framework = FLAGS.framework.lower()

    # prep_start = time.time()
    # pr.enable()

    prepare_benchmark(framework, model)

    # pr.disable()

    # s = io2.StringIO()
    # ps = pstats.Stats(pr, stream=s).sort_stats("cumulative")
    # prep_pstats = str(framework) + "_" + str(model) + "_prep.pstats"
    # ps.dump_stats(prep_pstats)
    # prep_end = time.time()

    # print("PREP_TIME (ms)", int(round_ms(prep_end - prep_start)))
    run_benchmark(framework, model)


def get_argument_parser():
    global parser
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--batch_size',
        type=int,
        default=1,
        help='Batch size.'
    )
    parser.add_argument(
        '--num_batches',
        type=int,
        default=20,
        help='Number of batches to run.'
    )
    parser.add_argument(
        '--framework',
        type=str,
        default="tensorflow",
        help='Framework to use'
    )
    parser.add_argument(
        '--model',
        type=str,
        default="alexnet",
        help='ConvNet model to use'
    )
    parser.add_argument(
        '--trace',
        type=bool,
        default=False,
        help='trace'
    )
    return parser


if __name__ == '__main__':
    parser = get_argument_parser()
    FLAGS, unparsed = parser.parse_known_args()
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
<file_sep>import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
import tensorrt as trt
from tensorrt.parsers import uffparser

import pycuda.driver as cuda
import pycuda.autoinit
import numpy as np
from random import randint # generate a random test case
from PIL import Image
import time #import system tools
import os

import uff

OUTPUT_NAMES = ["predictions/Softmax"]
BATCH_SIZE = 1
PB_DIR = "../tf_frozen/"
uff_model = uff.from_tensorflow_frozen_model(PB_DIR + "tf_vgg.pb", OUTPUT_NAMES)
G_LOGGER = trt.infer.ConsoleLogger(trt.infer.LogSeverity.ERROR)

parser = uffparser.create_uff_parser()
parser.register_input("input_1", (3,224,224), 0)
parser.register_output(OUTPUT_NAMES[0])

engine = trt.utils.uff_to_trt_engine(G_LOGGER, uff_model, parser, BATCH_SIZE, 1 << 20)

#engine = trt.utils.load_engine(G_LOGGER, "./vgg.engine")
#parser.destroy()

img = np.random.randint(256, size=(3, 224, 224)) / 255.
img = img.astype(np.float32)

label = 123

runtime = trt.infer.create_infer_runtime(G_LOGGER)
context = engine.create_execution_context()

output = np.empty(1000, dtype = np.float32)

d_input = cuda.mem_alloc(BATCH_SIZE * img.size * img.dtype.itemsize)
d_output = cuda.mem_alloc(BATCH_SIZE * output.size * output.dtype.itemsize)

bindings = [int(d_input), int(d_output)]
stream = cuda.Stream()

def infer():
    global img
    #transfer input data to device
    cuda.memcpy_htod_async(d_input, img, stream)
    #execute model
    context.enqueue(BATCH_SIZE, bindings, stream.handle, None)
    #transfer predictions back
    cuda.memcpy_dtoh_async(output, d_output, stream)
    #syncronize threads
    stream.synchronize()
for i in range(1000):
    img = np.random.randint(256, size=(3, 224, 224)) / 255.
    img = img.astype(np.float32)
    start = time.time()
    infer()
    end = time.time()
    print("Test vs Pred: " + str(label) + " " + str(np.argmax(output)))
    print("Ran for: " + str(1000 * (end-start)) + " ms")
<file_sep>python benchmark.py --batch_size 2 --num_batches 1 --framework keras --model inception<file_sep>'''
HelloWorld example using TensorFlow library.

Author: <NAME>
Project: https://github.com/aymericdamien/TensorFlow-Examples/
'''

from __future__ import print_function

import tensorflow as tf
import numpy as np


def load_frozen_graph():
    with tf.gfile.GFile("tf_vgg.pb", "rb") as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
    with tf.Graph().as_default() as graph:
        tf.import_graph_def(graph_def, name="main")
    return graph

# Simple hello world using TensorFlow

# Create a Constant op
# The op is added as a node to the default graph.
#
# The value returned by the constructor represents the output
# of the Constant op.
hello = tf.constant('Hello, TensorFlow!')

# Start tf session
g = load_frozen_graph()
sess = tf.Session(graph=g)


# Run the op
for op in g.as_graph_def().node:
    print(op.name)

# for op in g.get_operations():
#     print(op.name)

x = g.get_tensor_by_name('main/input_1:0')
y = g.get_tensor_by_name('main/output_node0:0')


for i in range(10):
    print("BEFORE")
    y_out = sess.run(y, feed_dict={x: np.random.randint(225, size=(5,224,224,3))})
    print(y_out.argmax(axis=1))
    # print(sess.run(y))
    print("AFTER")
<file_sep>import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F

__weights_dict = dict()

def load_weights(weight_file):
    if weight_file == None:
        return

    try:
        weights_dict = np.load(weight_file).item()
    except:
        weights_dict = np.load(weight_file, encoding='bytes').item()

    return weights_dict

class KitModel(nn.Module):

    
    def __init__(self, weight_file):
        super(KitModel, self).__init__()
        global __weights_dict
        __weights_dict = load_weights(weight_file)

        self.conv1 = self.__conv(2, name='conv1', in_channels=3, out_channels=64, kernel_size=(7, 7), stride=(2, 2), groups=1, bias=True)
        self.bn_conv1 = self.__batch_normalization(2, 'bn_conv1', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.res2a_branch2a = self.__conv(2, name='res2a_branch2a', in_channels=64, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.res2a_branch1 = self.__conv(2, name='res2a_branch1', in_channels=64, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn2a_branch2a = self.__batch_normalization(2, 'bn2a_branch2a', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.bn2a_branch1 = self.__batch_normalization(2, 'bn2a_branch1', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.res2a_branch2b = self.__conv(2, name='res2a_branch2b', in_channels=64, out_channels=64, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn2a_branch2b = self.__batch_normalization(2, 'bn2a_branch2b', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.res2a_branch2c = self.__conv(2, name='res2a_branch2c', in_channels=64, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn2a_branch2c = self.__batch_normalization(2, 'bn2a_branch2c', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.res2b_branch2a = self.__conv(2, name='res2b_branch2a', in_channels=256, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn2b_branch2a = self.__batch_normalization(2, 'bn2b_branch2a', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.res2b_branch2b = self.__conv(2, name='res2b_branch2b', in_channels=64, out_channels=64, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn2b_branch2b = self.__batch_normalization(2, 'bn2b_branch2b', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.res2b_branch2c = self.__conv(2, name='res2b_branch2c', in_channels=64, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn2b_branch2c = self.__batch_normalization(2, 'bn2b_branch2c', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.res2c_branch2a = self.__conv(2, name='res2c_branch2a', in_channels=256, out_channels=64, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn2c_branch2a = self.__batch_normalization(2, 'bn2c_branch2a', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.res2c_branch2b = self.__conv(2, name='res2c_branch2b', in_channels=64, out_channels=64, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn2c_branch2b = self.__batch_normalization(2, 'bn2c_branch2b', num_features = 64, eps = 0.0010000000474974513, momentum = 0.0)
        self.res2c_branch2c = self.__conv(2, name='res2c_branch2c', in_channels=64, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn2c_branch2c = self.__batch_normalization(2, 'bn2c_branch2c', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.res3a_branch2a = self.__conv(2, name='res3a_branch2a', in_channels=256, out_channels=128, kernel_size=(1, 1), stride=(2, 2), groups=1, bias=True)
        self.res3a_branch1 = self.__conv(2, name='res3a_branch1', in_channels=256, out_channels=512, kernel_size=(1, 1), stride=(2, 2), groups=1, bias=True)
        self.bn3a_branch2a = self.__batch_normalization(2, 'bn3a_branch2a', num_features = 128, eps = 0.0010000000474974513, momentum = 0.0)
        self.bn3a_branch1 = self.__batch_normalization(2, 'bn3a_branch1', num_features = 512, eps = 0.0010000000474974513, momentum = 0.0)
        self.res3a_branch2b = self.__conv(2, name='res3a_branch2b', in_channels=128, out_channels=128, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn3a_branch2b = self.__batch_normalization(2, 'bn3a_branch2b', num_features = 128, eps = 0.0010000000474974513, momentum = 0.0)
        self.res3a_branch2c = self.__conv(2, name='res3a_branch2c', in_channels=128, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn3a_branch2c = self.__batch_normalization(2, 'bn3a_branch2c', num_features = 512, eps = 0.0010000000474974513, momentum = 0.0)
        self.res3b_branch2a = self.__conv(2, name='res3b_branch2a', in_channels=512, out_channels=128, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn3b_branch2a = self.__batch_normalization(2, 'bn3b_branch2a', num_features = 128, eps = 0.0010000000474974513, momentum = 0.0)
        self.res3b_branch2b = self.__conv(2, name='res3b_branch2b', in_channels=128, out_channels=128, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn3b_branch2b = self.__batch_normalization(2, 'bn3b_branch2b', num_features = 128, eps = 0.0010000000474974513, momentum = 0.0)
        self.res3b_branch2c = self.__conv(2, name='res3b_branch2c', in_channels=128, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn3b_branch2c = self.__batch_normalization(2, 'bn3b_branch2c', num_features = 512, eps = 0.0010000000474974513, momentum = 0.0)
        self.res3c_branch2a = self.__conv(2, name='res3c_branch2a', in_channels=512, out_channels=128, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn3c_branch2a = self.__batch_normalization(2, 'bn3c_branch2a', num_features = 128, eps = 0.0010000000474974513, momentum = 0.0)
        self.res3c_branch2b = self.__conv(2, name='res3c_branch2b', in_channels=128, out_channels=128, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn3c_branch2b = self.__batch_normalization(2, 'bn3c_branch2b', num_features = 128, eps = 0.0010000000474974513, momentum = 0.0)
        self.res3c_branch2c = self.__conv(2, name='res3c_branch2c', in_channels=128, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn3c_branch2c = self.__batch_normalization(2, 'bn3c_branch2c', num_features = 512, eps = 0.0010000000474974513, momentum = 0.0)
        self.res3d_branch2a = self.__conv(2, name='res3d_branch2a', in_channels=512, out_channels=128, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn3d_branch2a = self.__batch_normalization(2, 'bn3d_branch2a', num_features = 128, eps = 0.0010000000474974513, momentum = 0.0)
        self.res3d_branch2b = self.__conv(2, name='res3d_branch2b', in_channels=128, out_channels=128, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn3d_branch2b = self.__batch_normalization(2, 'bn3d_branch2b', num_features = 128, eps = 0.0010000000474974513, momentum = 0.0)
        self.res3d_branch2c = self.__conv(2, name='res3d_branch2c', in_channels=128, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn3d_branch2c = self.__batch_normalization(2, 'bn3d_branch2c', num_features = 512, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4a_branch2a = self.__conv(2, name='res4a_branch2a', in_channels=512, out_channels=256, kernel_size=(1, 1), stride=(2, 2), groups=1, bias=True)
        self.res4a_branch1 = self.__conv(2, name='res4a_branch1', in_channels=512, out_channels=1024, kernel_size=(1, 1), stride=(2, 2), groups=1, bias=True)
        self.bn4a_branch2a = self.__batch_normalization(2, 'bn4a_branch2a', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.bn4a_branch1 = self.__batch_normalization(2, 'bn4a_branch1', num_features = 1024, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4a_branch2b = self.__conv(2, name='res4a_branch2b', in_channels=256, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn4a_branch2b = self.__batch_normalization(2, 'bn4a_branch2b', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4a_branch2c = self.__conv(2, name='res4a_branch2c', in_channels=256, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn4a_branch2c = self.__batch_normalization(2, 'bn4a_branch2c', num_features = 1024, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4b_branch2a = self.__conv(2, name='res4b_branch2a', in_channels=1024, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn4b_branch2a = self.__batch_normalization(2, 'bn4b_branch2a', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4b_branch2b = self.__conv(2, name='res4b_branch2b', in_channels=256, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn4b_branch2b = self.__batch_normalization(2, 'bn4b_branch2b', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4b_branch2c = self.__conv(2, name='res4b_branch2c', in_channels=256, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn4b_branch2c = self.__batch_normalization(2, 'bn4b_branch2c', num_features = 1024, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4c_branch2a = self.__conv(2, name='res4c_branch2a', in_channels=1024, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn4c_branch2a = self.__batch_normalization(2, 'bn4c_branch2a', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4c_branch2b = self.__conv(2, name='res4c_branch2b', in_channels=256, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn4c_branch2b = self.__batch_normalization(2, 'bn4c_branch2b', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4c_branch2c = self.__conv(2, name='res4c_branch2c', in_channels=256, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn4c_branch2c = self.__batch_normalization(2, 'bn4c_branch2c', num_features = 1024, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4d_branch2a = self.__conv(2, name='res4d_branch2a', in_channels=1024, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn4d_branch2a = self.__batch_normalization(2, 'bn4d_branch2a', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4d_branch2b = self.__conv(2, name='res4d_branch2b', in_channels=256, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn4d_branch2b = self.__batch_normalization(2, 'bn4d_branch2b', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4d_branch2c = self.__conv(2, name='res4d_branch2c', in_channels=256, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn4d_branch2c = self.__batch_normalization(2, 'bn4d_branch2c', num_features = 1024, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4e_branch2a = self.__conv(2, name='res4e_branch2a', in_channels=1024, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn4e_branch2a = self.__batch_normalization(2, 'bn4e_branch2a', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4e_branch2b = self.__conv(2, name='res4e_branch2b', in_channels=256, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn4e_branch2b = self.__batch_normalization(2, 'bn4e_branch2b', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4e_branch2c = self.__conv(2, name='res4e_branch2c', in_channels=256, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn4e_branch2c = self.__batch_normalization(2, 'bn4e_branch2c', num_features = 1024, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4f_branch2a = self.__conv(2, name='res4f_branch2a', in_channels=1024, out_channels=256, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn4f_branch2a = self.__batch_normalization(2, 'bn4f_branch2a', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4f_branch2b = self.__conv(2, name='res4f_branch2b', in_channels=256, out_channels=256, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn4f_branch2b = self.__batch_normalization(2, 'bn4f_branch2b', num_features = 256, eps = 0.0010000000474974513, momentum = 0.0)
        self.res4f_branch2c = self.__conv(2, name='res4f_branch2c', in_channels=256, out_channels=1024, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn4f_branch2c = self.__batch_normalization(2, 'bn4f_branch2c', num_features = 1024, eps = 0.0010000000474974513, momentum = 0.0)
        self.res5a_branch2a = self.__conv(2, name='res5a_branch2a', in_channels=1024, out_channels=512, kernel_size=(1, 1), stride=(2, 2), groups=1, bias=True)
        self.res5a_branch1 = self.__conv(2, name='res5a_branch1', in_channels=1024, out_channels=2048, kernel_size=(1, 1), stride=(2, 2), groups=1, bias=True)
        self.bn5a_branch2a = self.__batch_normalization(2, 'bn5a_branch2a', num_features = 512, eps = 0.0010000000474974513, momentum = 0.0)
        self.bn5a_branch1 = self.__batch_normalization(2, 'bn5a_branch1', num_features = 2048, eps = 0.0010000000474974513, momentum = 0.0)
        self.res5a_branch2b = self.__conv(2, name='res5a_branch2b', in_channels=512, out_channels=512, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn5a_branch2b = self.__batch_normalization(2, 'bn5a_branch2b', num_features = 512, eps = 0.0010000000474974513, momentum = 0.0)
        self.res5a_branch2c = self.__conv(2, name='res5a_branch2c', in_channels=512, out_channels=2048, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn5a_branch2c = self.__batch_normalization(2, 'bn5a_branch2c', num_features = 2048, eps = 0.0010000000474974513, momentum = 0.0)
        self.res5b_branch2a = self.__conv(2, name='res5b_branch2a', in_channels=2048, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn5b_branch2a = self.__batch_normalization(2, 'bn5b_branch2a', num_features = 512, eps = 0.0010000000474974513, momentum = 0.0)
        self.res5b_branch2b = self.__conv(2, name='res5b_branch2b', in_channels=512, out_channels=512, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn5b_branch2b = self.__batch_normalization(2, 'bn5b_branch2b', num_features = 512, eps = 0.0010000000474974513, momentum = 0.0)
        self.res5b_branch2c = self.__conv(2, name='res5b_branch2c', in_channels=512, out_channels=2048, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn5b_branch2c = self.__batch_normalization(2, 'bn5b_branch2c', num_features = 2048, eps = 0.0010000000474974513, momentum = 0.0)
        self.res5c_branch2a = self.__conv(2, name='res5c_branch2a', in_channels=2048, out_channels=512, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn5c_branch2a = self.__batch_normalization(2, 'bn5c_branch2a', num_features = 512, eps = 0.0010000000474974513, momentum = 0.0)
        self.res5c_branch2b = self.__conv(2, name='res5c_branch2b', in_channels=512, out_channels=512, kernel_size=(3, 3), stride=(1, 1), groups=1, bias=True)
        self.bn5c_branch2b = self.__batch_normalization(2, 'bn5c_branch2b', num_features = 512, eps = 0.0010000000474974513, momentum = 0.0)
        self.res5c_branch2c = self.__conv(2, name='res5c_branch2c', in_channels=512, out_channels=2048, kernel_size=(1, 1), stride=(1, 1), groups=1, bias=True)
        self.bn5c_branch2c = self.__batch_normalization(2, 'bn5c_branch2c', num_features = 2048, eps = 0.0010000000474974513, momentum = 0.0)
        self.fc1000 = self.__dense(name = 'fc1000', in_features = 2048, out_features = 1000, bias = True)

    def forward(self, x):
        conv1_pad       = F.pad(x, (2, 3, 2, 3))
        conv1           = self.conv1(conv1_pad)
        bn_conv1        = self.bn_conv1(conv1)
        activation_1    = F.relu(bn_conv1)
        max_pooling2d_1 = F.max_pool2d(activation_1, kernel_size=(3, 3), stride=(2, 2))
        res2a_branch2a  = self.res2a_branch2a(max_pooling2d_1)
        res2a_branch1   = self.res2a_branch1(max_pooling2d_1)
        bn2a_branch2a   = self.bn2a_branch2a(res2a_branch2a)
        bn2a_branch1    = self.bn2a_branch1(res2a_branch1)
        activation_2    = F.relu(bn2a_branch2a)
        res2a_branch2b_pad = F.pad(activation_2, (1, 1, 1, 1))
        res2a_branch2b  = self.res2a_branch2b(res2a_branch2b_pad)
        bn2a_branch2b   = self.bn2a_branch2b(res2a_branch2b)
        activation_3    = F.relu(bn2a_branch2b)
        res2a_branch2c  = self.res2a_branch2c(activation_3)
        bn2a_branch2c   = self.bn2a_branch2c(res2a_branch2c)
        add_1           = bn2a_branch2c+ bn2a_branch1
        activation_4    = F.relu(add_1)
        res2b_branch2a  = self.res2b_branch2a(activation_4)
        bn2b_branch2a   = self.bn2b_branch2a(res2b_branch2a)
        activation_5    = F.relu(bn2b_branch2a)
        res2b_branch2b_pad = F.pad(activation_5, (1, 1, 1, 1))
        res2b_branch2b  = self.res2b_branch2b(res2b_branch2b_pad)
        bn2b_branch2b   = self.bn2b_branch2b(res2b_branch2b)
        activation_6    = F.relu(bn2b_branch2b)
        res2b_branch2c  = self.res2b_branch2c(activation_6)
        bn2b_branch2c   = self.bn2b_branch2c(res2b_branch2c)
        add_2           = bn2b_branch2c+ activation_4
        activation_7    = F.relu(add_2)
        res2c_branch2a  = self.res2c_branch2a(activation_7)
        bn2c_branch2a   = self.bn2c_branch2a(res2c_branch2a)
        activation_8    = F.relu(bn2c_branch2a)
        res2c_branch2b_pad = F.pad(activation_8, (1, 1, 1, 1))
        res2c_branch2b  = self.res2c_branch2b(res2c_branch2b_pad)
        bn2c_branch2b   = self.bn2c_branch2b(res2c_branch2b)
        activation_9    = F.relu(bn2c_branch2b)
        res2c_branch2c  = self.res2c_branch2c(activation_9)
        bn2c_branch2c   = self.bn2c_branch2c(res2c_branch2c)
        add_3           = bn2c_branch2c+ activation_7
        activation_10   = F.relu(add_3)
        res3a_branch2a  = self.res3a_branch2a(activation_10)
        res3a_branch1   = self.res3a_branch1(activation_10)
        bn3a_branch2a   = self.bn3a_branch2a(res3a_branch2a)
        bn3a_branch1    = self.bn3a_branch1(res3a_branch1)
        activation_11   = F.relu(bn3a_branch2a)
        res3a_branch2b_pad = F.pad(activation_11, (1, 1, 1, 1))
        res3a_branch2b  = self.res3a_branch2b(res3a_branch2b_pad)
        bn3a_branch2b   = self.bn3a_branch2b(res3a_branch2b)
        activation_12   = F.relu(bn3a_branch2b)
        res3a_branch2c  = self.res3a_branch2c(activation_12)
        bn3a_branch2c   = self.bn3a_branch2c(res3a_branch2c)
        add_4           = bn3a_branch2c+ bn3a_branch1
        activation_13   = F.relu(add_4)
        res3b_branch2a  = self.res3b_branch2a(activation_13)
        bn3b_branch2a   = self.bn3b_branch2a(res3b_branch2a)
        activation_14   = F.relu(bn3b_branch2a)
        res3b_branch2b_pad = F.pad(activation_14, (1, 1, 1, 1))
        res3b_branch2b  = self.res3b_branch2b(res3b_branch2b_pad)
        bn3b_branch2b   = self.bn3b_branch2b(res3b_branch2b)
        activation_15   = F.relu(bn3b_branch2b)
        res3b_branch2c  = self.res3b_branch2c(activation_15)
        bn3b_branch2c   = self.bn3b_branch2c(res3b_branch2c)
        add_5           = bn3b_branch2c+ activation_13
        activation_16   = F.relu(add_5)
        res3c_branch2a  = self.res3c_branch2a(activation_16)
        bn3c_branch2a   = self.bn3c_branch2a(res3c_branch2a)
        activation_17   = F.relu(bn3c_branch2a)
        res3c_branch2b_pad = F.pad(activation_17, (1, 1, 1, 1))
        res3c_branch2b  = self.res3c_branch2b(res3c_branch2b_pad)
        bn3c_branch2b   = self.bn3c_branch2b(res3c_branch2b)
        activation_18   = F.relu(bn3c_branch2b)
        res3c_branch2c  = self.res3c_branch2c(activation_18)
        bn3c_branch2c   = self.bn3c_branch2c(res3c_branch2c)
        add_6           = bn3c_branch2c+ activation_16
        activation_19   = F.relu(add_6)
        res3d_branch2a  = self.res3d_branch2a(activation_19)
        bn3d_branch2a   = self.bn3d_branch2a(res3d_branch2a)
        activation_20   = F.relu(bn3d_branch2a)
        res3d_branch2b_pad = F.pad(activation_20, (1, 1, 1, 1))
        res3d_branch2b  = self.res3d_branch2b(res3d_branch2b_pad)
        bn3d_branch2b   = self.bn3d_branch2b(res3d_branch2b)
        activation_21   = F.relu(bn3d_branch2b)
        res3d_branch2c  = self.res3d_branch2c(activation_21)
        bn3d_branch2c   = self.bn3d_branch2c(res3d_branch2c)
        add_7           = bn3d_branch2c+ activation_19
        activation_22   = F.relu(add_7)
        res4a_branch2a  = self.res4a_branch2a(activation_22)
        res4a_branch1   = self.res4a_branch1(activation_22)
        bn4a_branch2a   = self.bn4a_branch2a(res4a_branch2a)
        bn4a_branch1    = self.bn4a_branch1(res4a_branch1)
        activation_23   = F.relu(bn4a_branch2a)
        res4a_branch2b_pad = F.pad(activation_23, (1, 1, 1, 1))
        res4a_branch2b  = self.res4a_branch2b(res4a_branch2b_pad)
        bn4a_branch2b   = self.bn4a_branch2b(res4a_branch2b)
        activation_24   = F.relu(bn4a_branch2b)
        res4a_branch2c  = self.res4a_branch2c(activation_24)
        bn4a_branch2c   = self.bn4a_branch2c(res4a_branch2c)
        add_8           = bn4a_branch2c+ bn4a_branch1
        activation_25   = F.relu(add_8)
        res4b_branch2a  = self.res4b_branch2a(activation_25)
        bn4b_branch2a   = self.bn4b_branch2a(res4b_branch2a)
        activation_26   = F.relu(bn4b_branch2a)
        res4b_branch2b_pad = F.pad(activation_26, (1, 1, 1, 1))
        res4b_branch2b  = self.res4b_branch2b(res4b_branch2b_pad)
        bn4b_branch2b   = self.bn4b_branch2b(res4b_branch2b)
        activation_27   = F.relu(bn4b_branch2b)
        res4b_branch2c  = self.res4b_branch2c(activation_27)
        bn4b_branch2c   = self.bn4b_branch2c(res4b_branch2c)
        add_9           = bn4b_branch2c+ activation_25
        activation_28   = F.relu(add_9)
        res4c_branch2a  = self.res4c_branch2a(activation_28)
        bn4c_branch2a   = self.bn4c_branch2a(res4c_branch2a)
        activation_29   = F.relu(bn4c_branch2a)
        res4c_branch2b_pad = F.pad(activation_29, (1, 1, 1, 1))
        res4c_branch2b  = self.res4c_branch2b(res4c_branch2b_pad)
        bn4c_branch2b   = self.bn4c_branch2b(res4c_branch2b)
        activation_30   = F.relu(bn4c_branch2b)
        res4c_branch2c  = self.res4c_branch2c(activation_30)
        bn4c_branch2c   = self.bn4c_branch2c(res4c_branch2c)
        add_10          = bn4c_branch2c+ activation_28
        activation_31   = F.relu(add_10)
        res4d_branch2a  = self.res4d_branch2a(activation_31)
        bn4d_branch2a   = self.bn4d_branch2a(res4d_branch2a)
        activation_32   = F.relu(bn4d_branch2a)
        res4d_branch2b_pad = F.pad(activation_32, (1, 1, 1, 1))
        res4d_branch2b  = self.res4d_branch2b(res4d_branch2b_pad)
        bn4d_branch2b   = self.bn4d_branch2b(res4d_branch2b)
        activation_33   = F.relu(bn4d_branch2b)
        res4d_branch2c  = self.res4d_branch2c(activation_33)
        bn4d_branch2c   = self.bn4d_branch2c(res4d_branch2c)
        add_11          = bn4d_branch2c+ activation_31
        activation_34   = F.relu(add_11)
        res4e_branch2a  = self.res4e_branch2a(activation_34)
        bn4e_branch2a   = self.bn4e_branch2a(res4e_branch2a)
        activation_35   = F.relu(bn4e_branch2a)
        res4e_branch2b_pad = F.pad(activation_35, (1, 1, 1, 1))
        res4e_branch2b  = self.res4e_branch2b(res4e_branch2b_pad)
        bn4e_branch2b   = self.bn4e_branch2b(res4e_branch2b)
        activation_36   = F.relu(bn4e_branch2b)
        res4e_branch2c  = self.res4e_branch2c(activation_36)
        bn4e_branch2c   = self.bn4e_branch2c(res4e_branch2c)
        add_12          = bn4e_branch2c+ activation_34
        activation_37   = F.relu(add_12)
        res4f_branch2a  = self.res4f_branch2a(activation_37)
        bn4f_branch2a   = self.bn4f_branch2a(res4f_branch2a)
        activation_38   = F.relu(bn4f_branch2a)
        res4f_branch2b_pad = F.pad(activation_38, (1, 1, 1, 1))
        res4f_branch2b  = self.res4f_branch2b(res4f_branch2b_pad)
        bn4f_branch2b   = self.bn4f_branch2b(res4f_branch2b)
        activation_39   = F.relu(bn4f_branch2b)
        res4f_branch2c  = self.res4f_branch2c(activation_39)
        bn4f_branch2c   = self.bn4f_branch2c(res4f_branch2c)
        add_13          = bn4f_branch2c+ activation_37
        activation_40   = F.relu(add_13)
        res5a_branch2a  = self.res5a_branch2a(activation_40)
        res5a_branch1   = self.res5a_branch1(activation_40)
        bn5a_branch2a   = self.bn5a_branch2a(res5a_branch2a)
        bn5a_branch1    = self.bn5a_branch1(res5a_branch1)
        activation_41   = F.relu(bn5a_branch2a)
        res5a_branch2b_pad = F.pad(activation_41, (1, 1, 1, 1))
        res5a_branch2b  = self.res5a_branch2b(res5a_branch2b_pad)
        bn5a_branch2b   = self.bn5a_branch2b(res5a_branch2b)
        activation_42   = F.relu(bn5a_branch2b)
        res5a_branch2c  = self.res5a_branch2c(activation_42)
        bn5a_branch2c   = self.bn5a_branch2c(res5a_branch2c)
        add_14          = bn5a_branch2c+ bn5a_branch1
        activation_43   = F.relu(add_14)
        res5b_branch2a  = self.res5b_branch2a(activation_43)
        bn5b_branch2a   = self.bn5b_branch2a(res5b_branch2a)
        activation_44   = F.relu(bn5b_branch2a)
        res5b_branch2b_pad = F.pad(activation_44, (1, 1, 1, 1))
        res5b_branch2b  = self.res5b_branch2b(res5b_branch2b_pad)
        bn5b_branch2b   = self.bn5b_branch2b(res5b_branch2b)
        activation_45   = F.relu(bn5b_branch2b)
        res5b_branch2c  = self.res5b_branch2c(activation_45)
        bn5b_branch2c   = self.bn5b_branch2c(res5b_branch2c)
        add_15          = bn5b_branch2c+ activation_43
        activation_46   = F.relu(add_15)
        res5c_branch2a  = self.res5c_branch2a(activation_46)
        bn5c_branch2a   = self.bn5c_branch2a(res5c_branch2a)
        activation_47   = F.relu(bn5c_branch2a)
        res5c_branch2b_pad = F.pad(activation_47, (1, 1, 1, 1))
        res5c_branch2b  = self.res5c_branch2b(res5c_branch2b_pad)
        bn5c_branch2b   = self.bn5c_branch2b(res5c_branch2b)
        activation_48   = F.relu(bn5c_branch2b)
        res5c_branch2c  = self.res5c_branch2c(activation_48)
        bn5c_branch2c   = self.bn5c_branch2c(res5c_branch2c)
        add_16          = bn5c_branch2c+ activation_46
        activation_49   = F.relu(add_16)
        avg_pool        = F.avg_pool2d(activation_49, kernel_size=(7, 7), stride=(7, 7))
        flatten_1       = avg_pool.view(avg_pool.size(0), -1)
        fc1000          = self.fc1000(flatten_1)
        fc1000_activation = F.softmax(fc1000)
        return fc1000_activation


    @staticmethod
    def __conv(dim, name, **kwargs):
        if   dim == 1:  layer = nn.Conv1d(**kwargs)
        elif dim == 2:  layer = nn.Conv2d(**kwargs)
        elif dim == 3:  layer = nn.Conv3d(**kwargs)
        else:           raise NotImplementedError()

        layer.state_dict()['weight'].copy_(torch.from_numpy(__weights_dict[name]['weights']))
        if 'bias' in __weights_dict[name]:
            layer.state_dict()['bias'].copy_(torch.from_numpy(__weights_dict[name]['bias']))
        return layer

    @staticmethod
    def __batch_normalization(dim, name, **kwargs):
        if   dim == 1:  layer = nn.BatchNorm1d(**kwargs)
        elif dim == 2:  layer = nn.BatchNorm2d(**kwargs)
        elif dim == 3:  layer = nn.BatchNorm3d(**kwargs)
        else:           raise NotImplementedError()

        if 'scale' in __weights_dict[name]:
            layer.state_dict()['weight'].copy_(torch.from_numpy(__weights_dict[name]['scale']))
        else:
            layer.weight.data.fill_(1)

        if 'bias' in __weights_dict[name]:
            layer.state_dict()['bias'].copy_(torch.from_numpy(__weights_dict[name]['bias']))
        else:
            layer.bias.data.fill_(0)

        layer.state_dict()['running_mean'].copy_(torch.from_numpy(__weights_dict[name]['mean']))
        layer.state_dict()['running_var'].copy_(torch.from_numpy(__weights_dict[name]['var']))
        return layer

    @staticmethod
    def __dense(name, **kwargs):
        layer = nn.Linear(**kwargs)
        layer.state_dict()['weight'].copy_(torch.from_numpy(__weights_dict[name]['weights']))
        if 'bias' in __weights_dict[name]:
            layer.state_dict()['bias'].copy_(torch.from_numpy(__weights_dict[name]['bias']))
        return layer
