forked from PaddlePaddle/Paddle2ONNX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request PaddlePaddle#86 from wangye707/wy_vgg
添加vgg11模型
- Loading branch information
Showing
4 changed files
with
217 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
197 changes: 197 additions & 0 deletions
197
inference/python_api_test/test_class_model/test_vgg11.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
# -*- coding: utf-8 -*- | ||
# encoding=utf-8 vi:ts=4:sw=4:expandtab:ft=python | ||
""" | ||
test vgg11 model | ||
""" | ||
|
||
import os | ||
import sys | ||
import logging | ||
import tarfile | ||
import six | ||
import wget | ||
import pytest | ||
import numpy as np | ||
|
||
# pylint: disable=wrong-import-position | ||
sys.path.append("..") | ||
from test_case import InferenceTest | ||
|
||
# pylint: enable=wrong-import-position | ||
|
||
|
||
def check_model_exist(): | ||
""" | ||
check model exist | ||
""" | ||
vgg11_url = "https://paddle-qa.bj.bcebos.com/inference_model/2.1/class/vgg11.tgz" | ||
if not os.path.exists("./vgg11/inference.pdiparams"): | ||
wget.download(vgg11_url, out="./") | ||
tar = tarfile.open("vgg11.tgz") | ||
tar.extractall() | ||
tar.close() | ||
|
||
|
||
@pytest.mark.p0 | ||
@pytest.mark.config_init_combined_model | ||
def test_config(): | ||
""" | ||
test combined model config | ||
""" | ||
check_model_exist() | ||
test_suite = InferenceTest() | ||
test_suite.load_config(model_file="./vgg11/inference.pdmodel", params_file="./vgg11/inference.pdiparams") | ||
test_suite.config_test() | ||
|
||
|
||
@pytest.mark.p0 | ||
@pytest.mark.config_disablegpu_memory | ||
def test_disable_gpu(): | ||
""" | ||
test no gpu resources occupied after disable gpu | ||
""" | ||
check_model_exist() | ||
test_suite = InferenceTest() | ||
test_suite.load_config(model_file="./vgg11/inference.pdmodel", params_file="./vgg11/inference.pdiparams") | ||
batch_size = 1 | ||
fake_input = np.random.randn(batch_size, 3, 224, 224).astype("float32") | ||
print(fake_input.shape) | ||
input_data_dict = {"x": fake_input} | ||
test_suite.disable_gpu_test(input_data_dict) | ||
|
||
|
||
@pytest.mark.p1 | ||
@pytest.mark.trt_fp32_more_bz_precision | ||
def test_trtfp32_more_bz(): | ||
""" | ||
compared trt fp32 batch_size=1-10 vgg11 outputs with true val | ||
""" | ||
check_model_exist() | ||
|
||
file_path = "./vgg11" | ||
images_size = 224 | ||
batch_size_pool = [1, 10] | ||
for batch_size in batch_size_pool: | ||
test_suite = InferenceTest() | ||
test_suite.load_config(model_file="./vgg11/inference.pdmodel", params_file="./vgg11/inference.pdiparams") | ||
images_list, npy_list = test_suite.get_images_npy(file_path, images_size) | ||
fake_input = np.array(images_list[0:batch_size]).astype("float32") | ||
input_data_dict = {"x": fake_input} | ||
output_data_dict = test_suite.get_truth_val(input_data_dict, device="gpu") | ||
|
||
del test_suite # destroy class to save memory | ||
|
||
test_suite2 = InferenceTest() | ||
test_suite2.load_config(model_file="./vgg11/inference.pdmodel", params_file="./vgg11/inference.pdiparams") | ||
test_suite2.trt_fp32_more_bz_test(input_data_dict, output_data_dict) | ||
|
||
del test_suite2 # destroy class to save memory | ||
|
||
|
||
@pytest.mark.p1 | ||
@pytest.mark.trt_fp32_multi_thread_bz1_precision | ||
def test_trtfp32_bz1_multi_thread(): | ||
""" | ||
compared trt fp32 batch_size=1 vgg11 multi_thread outputs with true val | ||
""" | ||
check_model_exist() | ||
|
||
file_path = "./vgg11" | ||
images_size = 224 | ||
batch_size = 1 | ||
test_suite = InferenceTest() | ||
test_suite.load_config(model_file="./vgg11/inference.pdmodel", params_file="./vgg11/inference.pdiparams") | ||
images_list, npy_list = test_suite.get_images_npy(file_path, images_size) | ||
fake_input = np.array(images_list[0:batch_size]).astype("float32") | ||
input_data_dict = {"x": fake_input} | ||
output_data_dict = test_suite.get_truth_val(input_data_dict, device="gpu") | ||
|
||
del test_suite # destroy class to save memory | ||
|
||
test_suite2 = InferenceTest() | ||
test_suite2.load_config(model_file="./vgg11/inference.pdmodel", params_file="./vgg11/inference.pdiparams") | ||
test_suite2.trt_fp32_bz1_multi_thread_test(input_data_dict, output_data_dict) | ||
|
||
del test_suite2 # destroy class to save memory | ||
|
||
|
||
@pytest.mark.p1 | ||
@pytest.mark.trt_fp16_more_bz_precision | ||
def test_trtfp16_more_bz(): | ||
""" | ||
compared trt fp16 batch_size=1-10 vgg11 outputs with true val | ||
""" | ||
check_model_exist() | ||
|
||
file_path = "./vgg11" | ||
images_size = 224 | ||
batch_size_pool = [1, 10] | ||
for batch_size in batch_size_pool: | ||
test_suite = InferenceTest() | ||
test_suite.load_config(model_file="./vgg11/inference.pdmodel", params_file="./vgg11/inference.pdiparams") | ||
images_list, npy_list = test_suite.get_images_npy(file_path, images_size) | ||
fake_input = np.array(images_list[0:batch_size]).astype("float32") | ||
input_data_dict = {"x": fake_input} | ||
output_data_dict = test_suite.get_truth_val(input_data_dict, device="gpu") | ||
|
||
del test_suite # destroy class to save memory | ||
|
||
test_suite2 = InferenceTest() | ||
test_suite2.load_config(model_file="./vgg11/inference.pdmodel", params_file="./vgg11/inference.pdiparams") | ||
test_suite2.trt_fp16_more_bz_test(input_data_dict, output_data_dict, repeat=1, delta=1e-3, gpu_mem=3000) | ||
|
||
del test_suite2 # destroy class to save memory | ||
|
||
|
||
@pytest.mark.p1 | ||
@pytest.mark.trt_fp16_multi_thread_bz1_precision | ||
def test_trtfp16_bz1_multi_thread(): | ||
""" | ||
compared trt fp16 batch_size=1 vgg11 multi_thread outputs with true val | ||
""" | ||
check_model_exist() | ||
|
||
file_path = "./vgg11" | ||
images_size = 224 | ||
batch_size = 1 | ||
test_suite = InferenceTest() | ||
test_suite.load_config(model_file="./vgg11/inference.pdmodel", params_file="./vgg11/inference.pdiparams") | ||
images_list, npy_list = test_suite.get_images_npy(file_path, images_size) | ||
fake_input = np.array(images_list[0:batch_size]).astype("float32") | ||
input_data_dict = {"x": fake_input} | ||
output_data_dict = test_suite.get_truth_val(input_data_dict, device="gpu") | ||
|
||
del test_suite # destroy class to save memory | ||
|
||
test_suite2 = InferenceTest() | ||
test_suite2.load_config(model_file="./vgg11/inference.pdmodel", params_file="./vgg11/inference.pdiparams") | ||
test_suite2.trt_fp16_bz1_multi_thread_test(input_data_dict, output_data_dict, gpu_mem=3000) | ||
|
||
del test_suite2 # destroy class to save memory | ||
|
||
|
||
@pytest.mark.p1 | ||
@pytest.mark.mkldnn_bz1_precision | ||
def test_mkldnn(): | ||
""" | ||
compared mkldnn vgg11 outputs with true val | ||
""" | ||
check_model_exist() | ||
|
||
file_path = "./vgg11" | ||
images_size = 224 | ||
batch_size = 1 | ||
test_suite = InferenceTest() | ||
test_suite.load_config(model_file="./vgg11/inference.pdmodel", params_file="./vgg11/inference.pdiparams") | ||
images_list, npy_list = test_suite.get_images_npy(file_path, images_size) | ||
fake_input = np.array(images_list[0:batch_size]).astype("float32") | ||
input_data_dict = {"x": fake_input} | ||
output_data_dict = test_suite.get_truth_val(input_data_dict, device="gpu") | ||
|
||
del test_suite # destroy class to save memory | ||
|
||
test_suite2 = InferenceTest() | ||
test_suite2.load_config(model_file="./vgg11/inference.pdmodel", params_file="./vgg11/inference.pdiparams") | ||
test_suite2.mkldnn_test(input_data_dict, output_data_dict) | ||
|
||
del test_suite2 # destroy class to save memory |