예제 #1
0
'''

config = Configs(models_dir='/models')

iters = 100

#model_name = 'retinaface_mnet025_v2'
model_name = 'retinaface_r50_v1'
input_shape = [1024, 768]

# 'plan' for TensorRT or 'onnx' for ONNX
backend = 'plan'

retina_backends = {'onnx': RetinaInferORT, 'plan': RetinaInferTRT}

model_dir, model_path = config.build_model_paths(model_name, backend)

retina_backend = retina_backends[backend](rec_name=model_path)

detector = FaceDetector(inference_backend=retina_backend)

detector.prepare(fix_image_size=(input_shape[1], input_shape[0]))

tt0 = time.time()
image = cv2.imread('test_images/Stallone.jpg.jpg', cv2.IMREAD_COLOR)
image = ImageData(image, input_shape)
image.resize_image(mode='pad')
tt1 = time.time()
print(f"Preparing image took: {tt1 - tt0}")

t0 = time.time()
예제 #2
0
    os.remove(intermediate_symbol)
    os.remove(intermediate_params)


if __name__ == '__main__':

    config = Configs(models_dir='/models')

    models_to_convert = [
        name for name in config.mxnet_models
        if config.in_official_package(name)
    ]
    custom_shape = (1, 3, 480, 640)

    for model in models_to_convert:
        print(f"Downloading model: {model}...")
        get_model_file(model, root=config.mxnet_models_dir)

    for model in models_to_convert:
        mxnet_symbol, mxnet_params = config.get_mxnet_model_paths(model)
        reshape = config.mxnet_models[model].get('reshape')
        shape = config.mxnet_models[model].get('shape', (1, 3, 112, 112))
        if custom_shape and reshape == True:
            shape = custom_shape
        output_onnx_dir, output_onnx_model = config.build_model_paths(
            model, "onnx")
        os.makedirs(output_onnx_dir, exist_ok=True)
        print(f'Converting "{model}" model to ONNX, shape {shape}...')
        convert_insight_model(mxnet_symbol, mxnet_params, output_onnx_model,
                              shape)
예제 #3
0
'''
ATTENTION!!! This script is for testing purposes only. Work in progress.
'''


def normalize(embedding):
    embedding_norm = norm(embedding)
    normed_embedding = embedding / embedding_norm
    return normed_embedding


config = Configs()

model_name = 'arcface_r100_v1'

engine = config.build_model_paths(model_name, 'plan')[1]
model_onnx = config.build_model_paths(model_name, 'onnx')[1]

model = InsightTRT(rec_name=engine)
#model = InsightTriton(rec_name=engine)
#model = InsightORT(rec_name=model_onnx)
model.prepare()

model_orig = model_zoo.get_model(model_name, root=config.mxnet_models_dir)
model_orig.prepare(-1)

im = cv2.imread('test_images/crop.jpg', cv2.IMREAD_COLOR)
iters = 100

t0 = time.time()
for i in range(iters):
if __name__ == '__main__':

    configs = Configs(models_dir='/models')
    #model_name = 'retinaface_r50_v1'
    model_name = 'retinaface_mnet025_v2'
    im_size = [1024, 768]  # W, H

    prepare_folders([
        configs.mxnet_models_dir, configs.onnx_models_dir,
        configs.trt_engines_dir
    ])

    mx_symbol, mx_params = configs.get_mxnet_model_paths(model_name)

    output_onnx_model_path, output_onnx = configs.build_model_paths(
        model_name, 'onnx')
    output_trt_engine_path, output_engine = configs.build_model_paths(
        model_name, 'plan')

    prepare_folders([output_onnx_model_path, output_trt_engine_path])

    prepare_retina_engine(mx_symbol,
                          mx_params,
                          output_onnx,
                          output_engine,
                          model_name,
                          configs.mxnet_models_dir,
                          shape=(1, 3, im_size[1], im_size[0]),
                          force=True)