Skip to content

Commit

Permalink
update ci script
Browse files Browse the repository at this point in the history
  • Loading branch information
BUG1989 committed Jul 10, 2021
1 parent a50a002 commit 6e7f689
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 95 deletions.
5 changes: 5 additions & 0 deletions tests/models/test_model_classification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ int main(int argc, char* argv[])
std::vector<float> reference_data(output_size);
FILE *fp;
fp = fopen(reference_file.c_str(), "rb");
if (!fp)
{
fprintf(stderr, "read reference %s failed!\n",reference_file.c_str());
return -1;
}
if (fread(reference_data.data(), sizeof(float), output_size, fp) == 0)
{
fprintf(stderr, "read reference data file failed!\n");
Expand Down
78 changes: 16 additions & 62 deletions tests/models/test_model_yolov3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int float_mismatch(float* current, float* reference, int size)
for(int i=0;i<size;i++)
{
float tmp = fabs(current[i]) - fabs(reference[i]);
if(fabs(tmp) > 0.0001)
if(fabs(tmp) > 0.001)
{
fprintf(stderr, "test failed, index:%d, a:%f, b:%f\n", i, current[i], reference[i]);
return -1;
Expand All @@ -49,61 +49,23 @@ int float_mismatch(float* current, float* reference, int size)
return 0;
}

void show_usage()
{
fprintf(
stderr,
"[Usage]: [-h]\n [-m model_file] [-r repeat_count] [-t thread_count] \n");
}

int main(int argc, char* argv[])
{
const char* model_file ="./models/yolov3.tmfile";
std::string model_file = "./models/yolov3.tmfile";
std::string model_name = "yolov3";
int img_h = 416;
int img_w = 416;
int img_c = 3;
const float mean[3] = {0, 0, 0};
const float scale[3] = {0.003921, 0.003921, 0.003921};

int repeat_count = 1;
int num_thread = 1;

int res;
while ((res = getopt(argc, argv, "m:i:r:t:h:")) != -1)
{
switch (res)
{
case 'm':
model_file = optarg;
break;
case 'r':
repeat_count = std::strtoul(optarg, nullptr, 10);
break;
case 't':
num_thread = std::strtoul(optarg, nullptr, 10);
break;
case 'h':
show_usage();
return 0;
default:
break;
}
}
std::string model_name="yolov3";
/* check files */
if (nullptr == model_file)
{
fprintf(stderr, "Error: Tengine model yolov3.tmfile not specified!\n");
show_usage();
return -1;
}

if (!check_file_exist(model_file))
if (!check_file_exist(model_file.c_str()));
return -1;

/* set runtime options */
struct options opt;
opt.num_thread = num_thread;
opt.num_thread = 1;
opt.cluster = TENGINE_CLUSTER_ALL;
opt.precision = TENGINE_MODE_FP32;
opt.affinity = 0;
Expand All @@ -117,7 +79,7 @@ int main(int argc, char* argv[])
fprintf(stderr, "tengine-lite library version: %s\n", get_tengine_version());

/* create graph, load tengine model xxx.tmfile */
graph_t graph = create_graph(nullptr, "tengine", model_file);
graph_t graph = create_graph(nullptr, "tengine", model_file.c_str());
if (graph == nullptr)
{
fprintf(stderr, "Create graph failed.\n");
Expand Down Expand Up @@ -167,25 +129,15 @@ int main(int argc, char* argv[])
fclose(fp);

/* run graph */
double min_time = DBL_MAX;
double max_time = DBL_MIN;
double total_time = 0.;
for (int i = 0; i < repeat_count; i++)
double start = get_current_time();
if (run_graph(graph, 1) < 0)
{
double start = get_current_time();
if (run_graph(graph, 1) < 0)
{
fprintf(stderr, "Run graph failed\n");
return -1;
}
double end = get_current_time();
double cur = end - start;
total_time += cur;
min_time = std::min(min_time, cur);
max_time = std::max(max_time, cur);
fprintf(stderr, "Run graph failed\n");
return -1;
}
fprintf(stderr, "Repeat %d times, thread %d, avg time %.2f ms, max_time %.2f ms, min_time %.2f ms\n", repeat_count, num_thread,
total_time/repeat_count, max_time, min_time);
double end = get_current_time();

fprintf(stderr, "Inference time %.2f ms\n", end - start);
fprintf(stderr, "--------------------------------------\n");

tensor_t p8_output = get_graph_output_tensor(graph, 2, 0);
Expand Down Expand Up @@ -231,10 +183,12 @@ int main(int argc, char* argv[])
int ret2 = float_mismatch(p16_data, reference_data2.data(), output_size2);
int ret3 = float_mismatch(p32_data, reference_data3.data(), output_size3);

/* postprocess */
int ret = (ret1 | ret2 | ret3);

/* release tengine */
postrun_graph(graph);
destroy_graph(graph);
release_tengine();

return ret;
}
38 changes: 25 additions & 13 deletions tests/test.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
#!/bin/bash -

./tests/test_model_classification -m squeezenet -i images/cat.jpg -g 227,227 -w 104.007,116.669,122.679 -s 1,1,1
./tests/test_model_classification -m mobilenet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017
./tests/test_model_classification -m mobilenet_v2 -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017
./tests/test_model_classification -m googlenet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 1,1,1
./tests/test_model_classification -m inception_v3 -i images/cat.jpg -g 395,395 -w 104.007,116.669,122.679 -s 0.0078,0.0078,0.0078
./tests/test_model_classification -m inception_v4 -i images/cat.jpg -g 299,299 -w 104.007,116.669,122.679 -s 0.007843,0.007843,0.007843
./tests/test_model_classification -m resnet50 -i images/bike.jpg -g 224,224 -w 104.007,116.669,122.679 -s 1,1,1
./tests/test_model_classification -m mnasnet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017
./tests/test_model_classification -m shufflenet_1xg3 -i images/cat.jpg -g 224,224 -w 103.940,116.780,123.680 -s 0.017,0.017,0.017
./tests/test_model_classification -m shufflenet_v2 -i images/cat.jpg -g 224,224 -w 103.940,116.780,123.680 -s 0.00392156,0.00392156,0.00392156

# detection
./tests/test_model_yolov3
set -ex

test_models=(
"./tests/test_model_classification -m squeezenet -i images/cat.jpg -g 227,227 -w 104.007,116.669,122.679 -s 1,1,1"
"./tests/test_model_classification -m mobilenet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017"
"./tests/test_model_classification -m mobilenet_v2 -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017"
"./tests/test_model_classification -m googlenet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 1,1,1"
"./tests/test_model_classification -m inception_v3 -i images/cat.jpg -g 395,395 -w 104.007,116.669,122.679 -s 0.0078,0.0078,0.0078"
"./tests/test_model_classification -m inception_v4 -i images/cat.jpg -g 299,299 -w 104.007,116.669,122.679 -s 0.007843,0.007843,0.007843"
"./tests/test_model_classification -m resnet50 -i images/bike.jpg -g 224,224 -w 104.007,116.669,122.679 -s 1,1,1"
"./tests/test_model_classification -m mnasnet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017"
"./tests/test_model_classification -m shufflenet_1xg3 -i images/cat.jpg -g 224,224 -w 103.940,116.780,123.680 -s 0.017,0.017,0.017"
"./tests/test_model_classification -m shufflenet_v2 -i images/cat.jpg -g 224,224 -w 103.940,116.780,123.680 -s 0.00392156,0.00392156,0.00392156"
"./tests/test_model_yolov3"
)

for (( i = 0 ; i < ${#test_models[@]} ; i++ ))
do
echo ${test_models[$i]} | xargs -i sh -c "{}"

if [ "$?" != 0 ]; then
echo "failed"
exit 1
fi
done
33 changes: 23 additions & 10 deletions tests/test_arm32.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
#!/bin/bash -

qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m squeezenet -i images/cat.jpg -g 227,227 -w 104.007,116.669,122.679 -s 1,1,1
qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m mobilenet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017
qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m mobilenet_v2 -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017
qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m googlenet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 1,1,1
qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m inception_v3 -i images/cat.jpg -g 395,395 -w 104.007,116.669,122.679 -s 0.0078,0.0078,0.0078
qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m inception_v4 -i images/cat.jpg -g 299,299 -w 104.007,116.669,122.679 -s 0.007843,0.007843,0.007843
qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m resnet50 -i images/bike.jpg -g 224,224 -w 104.007,116.669,122.679 -s 1,1,1
qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m mnasnet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017
qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m shufflenet_1xg3 -i images/cat.jpg -g 224,224 -w 103.940,116.780,123.680 -s 0.017,0.017,0.017
qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m shufflenet_v2 -i images/cat.jpg -g 224,224 -w 103.940,116.780,123.680 -s 0.00392156,0.00392156,0.00392156
test_models=(
"qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m squeezenet -i images/cat.jpg -g 227,227 -w 104.007,116.669,122.679 -s 1,1,1"
"qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m mobilenet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017"
"qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m mobilenet_v2 -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017"
"qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m googlenet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 1,1,1"
"qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m inception_v3 -i images/cat.jpg -g 395,395 -w 104.007,116.669,122.679 -s 0.0078,0.0078,0.0078"
"qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m inception_v4 -i images/cat.jpg -g 299,299 -w 104.007,116.669,122.679 -s 0.007843,0.007843,0.007843"
"qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m resnet50 -i images/bike.jpg -g 224,224 -w 104.007,116.669,122.679 -s 1,1,1"
"qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m mnasnet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017"
"qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m shufflenet_1xg3 -i images/cat.jpg -g 224,224 -w 103.940,116.780,123.680 -s 0.017,0.017,0.017"
"qemu-arm -L /usr/arm-linux-gnueabi ./tests/test_model_classification -m shufflenet_v2 -i images/cat.jpg -g 224,224 -w 103.940,116.780,123.680 -s 0.00392156,0.00392156,0.00392156"
)

for (( i = 0 ; i < ${#test_models[@]} ; i++ ))
do
echo ${test_models[$i]}
echo ${test_models[$i]} | xargs -i sh -c "{}"

if [ "$?" != 0 ]; then
echo "failed"
exit 1
fi
done
35 changes: 25 additions & 10 deletions tests/test_arm64.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
#!/bin/bash -

qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m squeezenet -i images/cat.jpg -g 227,227 -w 104.007,116.669,122.679 -s 1,1,1
qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m mobilenet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017
qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m mobilenet_v2 -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017
qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m googlenet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 1,1,1
qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m inception_v3 -i images/cat.jpg -g 395,395 -w 104.007,116.669,122.679 -s 0.0078,0.0078,0.0078
qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m inception_v4 -i images/cat.jpg -g 299,299 -w 104.007,116.669,122.679 -s 0.007843,0.007843,0.007843
qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m resnet50 -i images/bike.jpg -g 224,224 -w 104.007,116.669,122.679 -s 1,1,1
qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m mnasnet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017
qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m shufflenet_1xg3 -i images/cat.jpg -g 224,224 -w 103.940,116.780,123.680 -s 0.017,0.017,0.017
qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m shufflenet_v2 -i images/cat.jpg -g 224,224 -w 103.940,116.780,123.680 -s 0.00392156,0.00392156,0.00392156
set -x

test_models=(
"qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m squeezenet -i images/cat.jpg -g 227,227 -w 104.007,116.669,122.679 -s 1,1,1"
"qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m mobilenet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017"
"qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m mobilenet_v2 -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017"
"qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m googlenet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 1,1,1"
"qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m inception_v3 -i images/cat.jpg -g 395,395 -w 104.007,116.669,122.679 -s 0.0078,0.0078,0.0078"
"qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m inception_v4 -i images/cat.jpg -g 299,299 -w 104.007,116.669,122.679 -s 0.007843,0.007843,0.007843"
"qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m resnet50 -i images/bike.jpg -g 224,224 -w 104.007,116.669,122.679 -s 1,1,1"
"qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m mnasnet -i images/cat.jpg -g 224,224 -w 104.007,116.669,122.679 -s 0.017,0.017,0.017"
"qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m shufflenet_1xg3 -i images/cat.jpg -g 224,224 -w 103.940,116.780,123.680 -s 0.017,0.017,0.017"
"qemu-aarch64 -L /usr/aarch64-linux-gnu ./tests/test_model_classification -m shufflenet_v2 -i images/cat.jpg -g 224,224 -w 103.940,116.780,123.680 -s 0.00392156,0.00392156,0.00392156"
)

for (( i = 0 ; i < ${#test_models[@]} ; i++ ))
do
echo ${test_models[$i]}
echo ${test_models[$i]} | xargs -i sh -c "{}"

if [ "$?" != 0 ]; then
echo "failed"
exit 1
fi
done

0 comments on commit 6e7f689

Please sign in to comment.