Example #1
0
def profile(model_path, model_type):
    cfg = dk.load_config('config.py')
    model_path = os.path.expanduser(model_path)
    model = dk.utils.get_model_by_type(model_type, cfg)
    model.load(model_path)
    
    count, h, w, ch = 1, cfg.TARGET_H, cfg.TARGET_W, cfg.TARGET_D
    seq_len = 0

    if "rnn" in model_type or "3d" in model_type:
        seq_len = cfg.SEQUENCE_LENGTH

    #generate random array in the right shape
    img = np.random.rand(int(h), int(w), int(ch)).astype(np.uint8)

    if seq_len:
        img_arr = []
        for i in range(seq_len):
            img_arr.append(img)
        img_arr = np.array(img_arr)

    #make a timer obj
    timer = FPSTimer()

    try:
        while True:

            '''
            run forward pass on model
            '''
            if seq_len:
                model.run(img_arr)
            else:
                model.run(img)

            '''
            keep track of iterations and give feed back on iter/sec
            '''
            timer.on_frame()

    except KeyboardInterrupt:
        pass
Example #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--model',
                        help='File path of Tflite model.',
                        required=True)
    parser.add_argument('--image',
                        help='File path of the image to be recognized.',
                        required=True)
    args = parser.parse_args()
    # Initialize engine.
    engine = InferenceEngine(args.model)
    # Run inference.
    img = Image.open(args.image)
    result = engine.Inference(np.array(img))
    print("inference result", result)

    timer = FPSTimer()
    while True:
        engine.Inference(np.array(img))
        timer.on_frame()
Example #3
0
def profile(model_path, model_type):
    cfg = dk.load_config('config.py')
    model_path = os.path.expanduser(model_path)
    model = dk.utils.get_model_by_type(model_type, cfg)
    model.load(model_path)

    h, w, ch = cfg.TARGET_H, cfg.TARGET_W, cfg.TARGET_D

    # generate random array in the right shape in [0,1)
    img = np.random.randint(0, 255, size=(h, w, ch))

    # make a timer obj
    timer = FPSTimer()

    try:
        while True:
            # run inferencing
            model.run(img)
            # time
            timer.on_frame()

    except KeyboardInterrupt:
        pass
Example #4
0
in_model = os.path.expanduser(args['--model'])

# Load TFLite model and allocate tensors.
interpreter = tf.lite.Interpreter(model_path=in_model)
interpreter.allocate_tensors()

# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

# Test model on random input data.
input_shape = input_details[0]['shape']
input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)

interpreter.set_tensor(input_details[0]['index'], input_data)
interpreter.invoke()

#sample output
for tensor in output_details:
    output_data = interpreter.get_tensor(tensor['index'])
    print(output_data)

#run in a loop to test performance.
print("test performance: hit CTRL+C to break")
timer = FPSTimer()
while True:
    interpreter.set_tensor(input_details[0]['index'], input_data)
    interpreter.invoke()
    timer.on_frame()