diff options
author | Yuan Zhao | 2019-09-12 17:06:58 -0500 |
---|---|---|
committer | Yuan Zhao | 2019-09-13 10:32:28 -0500 |
commit | 24a0d91e74955eee8e08150a58993ad7f0b128f5 (patch) | |
tree | 03709bfd574be33061dbbb2515d90ee70ade9358 /examples | |
parent | 1417d91f33f5a31bdf887974ead1f992f9703b50 (diff) | |
download | tidl-api-24a0d91e74955eee8e08150a58993ad7f0b128f5.tar.gz tidl-api-24a0d91e74955eee8e08150a58993ad7f0b128f5.tar.xz tidl-api-24a0d91e74955eee8e08150a58993ad7f0b128f5.zip |
Fix classification example for tensorflow models
- Copy original image to show image before pre-processing, because
pre-processing will change BGR to RGB for tensorflow models
- Subtract 1 from output object class index, because tensorflow outputs
1001 bytes and uses index-0 for background. Regular imagenet labels
only have 1000 entries.
- Fix path to inceptionnet net and params binaries in the config file.
- MCT-1221
Diffstat (limited to 'examples')
-rw-r--r-- | examples/classification/main.cpp | 20 | ||||
-rw-r--r-- | examples/classification/readme.md | 6 | ||||
-rwxr-xr-x | examples/test/testvecs/config/infer/tidl_config_inceptionNetv1.txt | 4 | ||||
-rwxr-xr-x | examples/test/testvecs/config/infer/tidl_config_inceptionNetv1_lg2.txt | 4 | ||||
-rw-r--r-- | examples/test/testvecs/config/tidl_models/tidl_net_inceptionv1_224.bin (renamed from examples/test/testvecs/config/tidl_models/tidl_inception_v1_net.bin) | bin | 484384 -> 484384 bytes | |||
-rw-r--r-- | examples/test/testvecs/config/tidl_models/tidl_param_inceptionv1_224.bin (renamed from examples/test/testvecs/config/tidl_models/tidl_inception_v1_param.bin) | 0 |
6 files changed, 19 insertions, 15 deletions
diff --git a/examples/classification/main.cpp b/examples/classification/main.cpp index 25361f8..68c5f80 100644 --- a/examples/classification/main.cpp +++ b/examples/classification/main.cpp | |||
@@ -111,7 +111,8 @@ Rect rectCrop[NUM_ROI]; | |||
111 | // Report average FPS across a sliding window of 16 frames | 111 | // Report average FPS across a sliding window of 16 frames |
112 | AvgFPSWindow fps_window(16); | 112 | AvgFPSWindow fps_window(16); |
113 | 113 | ||
114 | static int tf_postprocess(uchar *in, int size, int roi_idx, int frame_idx, int f_id); | 114 | static int tf_postprocess(uchar *in, int out_size, int size, int roi_idx, |
115 | int frame_idx, int f_id); | ||
115 | static int ShowRegion(int roi_history[]); | 116 | static int ShowRegion(int roi_history[]); |
116 | // from most recent to oldest at top indices | 117 | // from most recent to oldest at top indices |
117 | static int selclass_history[MAX_NUM_ROI][3]; | 118 | static int selclass_history[MAX_NUM_ROI][3]; |
@@ -485,6 +486,7 @@ bool ReadFrame(ExecutionObjectPipeline* eop, const Configuration& c, | |||
485 | sprintf(tmp_string, "ROI[%02d]", frame_idx % NUM_ROI); | 486 | sprintf(tmp_string, "ROI[%02d]", frame_idx % NUM_ROI); |
486 | cv::imshow(tmp_string, r_image); | 487 | cv::imshow(tmp_string, r_image); |
487 | } | 488 | } |
489 | image.copyTo(show_image); | ||
488 | #endif | 490 | #endif |
489 | imgutil::PreprocessImage(r_image, eop->GetInputBufferPtr(), c); | 491 | imgutil::PreprocessImage(r_image, eop->GetInputBufferPtr(), c); |
490 | eop->SetFrameIndex(frame_idx); | 492 | eop->SetFrameIndex(frame_idx); |
@@ -495,10 +497,6 @@ bool ReadFrame(ExecutionObjectPipeline* eop, const Configuration& c, | |||
495 | writer << to_stream; | 497 | writer << to_stream; |
496 | #endif | 498 | #endif |
497 | 499 | ||
498 | #ifdef LIVE_DISPLAY | ||
499 | //waitKey(2); | ||
500 | image.copyTo(show_image); | ||
501 | #endif | ||
502 | return true; | 500 | return true; |
503 | } | 501 | } |
504 | } else { | 502 | } else { |
@@ -519,6 +517,7 @@ void DisplayFrame(const ExecutionObjectPipeline* eop, VideoWriter& writer, | |||
519 | int f_id = eop->GetFrameIndex(); | 517 | int f_id = eop->GetFrameIndex(); |
520 | int curr_roi = f_id % NUM_ROI; | 518 | int curr_roi = f_id % NUM_ROI; |
521 | int is_object = tf_postprocess((uchar*) eop->GetOutputBufferPtr(), | 519 | int is_object = tf_postprocess((uchar*) eop->GetOutputBufferPtr(), |
520 | eop->GetOutputBufferSizeInBytes(), | ||
522 | IMAGE_CLASSES_NUM, curr_roi, frame_idx, f_id); | 521 | IMAGE_CLASSES_NUM, curr_roi, frame_idx, f_id); |
523 | selclass_history[curr_roi][2] = selclass_history[curr_roi][1]; | 522 | selclass_history[curr_roi][2] = selclass_history[curr_roi][1]; |
524 | selclass_history[curr_roi][1] = selclass_history[curr_roi][0]; | 523 | selclass_history[curr_roi][1] = selclass_history[curr_roi][0]; |
@@ -691,12 +690,17 @@ bool tf_expected_id(int id) | |||
691 | return false; | 690 | return false; |
692 | } | 691 | } |
693 | 692 | ||
694 | int tf_postprocess(uchar *in, int size, int roi_idx, int frame_idx, int f_id) | 693 | int tf_postprocess(uchar *in, int out_size, int size, int roi_idx, |
694 | int frame_idx, int f_id) | ||
695 | { | 695 | { |
696 | //prob_i = exp(TIDL_Lib_output_i) / sum(exp(TIDL_Lib_output)) | 696 | //prob_i = exp(TIDL_Lib_output_i) / sum(exp(TIDL_Lib_output)) |
697 | // sort and get k largest values and corresponding indices | 697 | // sort and get k largest values and corresponding indices |
698 | const int k = TOP_CANDIDATES; | 698 | const int k = TOP_CANDIDATES; |
699 | int rpt_id = -1; | 699 | int rpt_id = -1; |
700 | // Tensorflow trained network outputs 1001 probabilities, | ||
701 | // with 0-index being background, thus we need to subtract 1 when | ||
702 | // reporting classified object from 1000 categories | ||
703 | int background_offset = out_size == 1001 ? 1 : 0; | ||
700 | 704 | ||
701 | typedef std::pair<uchar, int> val_index; | 705 | typedef std::pair<uchar, int> val_index; |
702 | auto cmp = [](val_index &left, val_index &right) { return left.first > right.first; }; | 706 | auto cmp = [](val_index &left, val_index &right) { return left.first > right.first; }; |
@@ -725,13 +729,13 @@ int tf_postprocess(uchar *in, int size, int roi_idx, int frame_idx, int f_id) | |||
725 | 729 | ||
726 | for (int i = 0; i < k; i++) | 730 | for (int i = 0; i < k; i++) |
727 | { | 731 | { |
728 | int id = sorted[i].second; | 732 | int id = sorted[i].second - background_offset; |
729 | 733 | ||
730 | if (tf_expected_id(id)) | 734 | if (tf_expected_id(id)) |
731 | { | 735 | { |
732 | std::cout << "Frame:" << frame_idx << "," << f_id << " ROI[" << roi_idx << "]: rank=" | 736 | std::cout << "Frame:" << frame_idx << "," << f_id << " ROI[" << roi_idx << "]: rank=" |
733 | << k-i << ", outval=" << (float)sorted[i].first / 255 << ", " | 737 | << k-i << ", outval=" << (float)sorted[i].first / 255 << ", " |
734 | << labels_classes[sorted[i].second] << std::endl; | 738 | << labels_classes[id] << std::endl; |
735 | rpt_id = id; | 739 | rpt_id = id; |
736 | } | 740 | } |
737 | } | 741 | } |
diff --git a/examples/classification/readme.md b/examples/classification/readme.md index 565807a..047a922 100644 --- a/examples/classification/readme.md +++ b/examples/classification/readme.md | |||
@@ -3,8 +3,8 @@ | |||
3 | # 1. Live camera input, using 2xEVE and 2xDSP cores, based on model with single layers group | 3 | # 1. Live camera input, using 2xEVE and 2xDSP cores, based on model with single layers group |
4 | ./tidl_classification -g 1 -d 2 -e 2 -l ./imagenet.txt -s ./classlist.txt -i 1 -c ./stream_config_j11_v2.txt | 4 | ./tidl_classification -g 1 -d 2 -e 2 -l ./imagenet.txt -s ./classlist.txt -i 1 -c ./stream_config_j11_v2.txt |
5 | # 2. Use video clip as input stream, using 2xEVE and 2xDSP cores, based on model with single layers group | 5 | # 2. Use video clip as input stream, using 2xEVE and 2xDSP cores, based on model with single layers group |
6 | ./tidl_classification -g 1 -d 2 -e 2 -l ./imagenet.txt -s ./classlist.txt -i ./clips/test50.mp4 -c ./stream_config_j11_v2.txt | 6 | ./tidl_classification -g 1 -d 2 -e 2 -l ./imagenet.txt -s ./classlist.txt -i ./clips/test10.mp4 -c ./stream_config_j11_v2.txt |
7 | # 3. Use video clip as input stream, using 2xEVE and 1xDSP cores, based on model with two layers group (1st layers group running on EVE, 2nd layers group on DSP) | 7 | # 3. Use video clip as input stream, using 2xEVE and 1xDSP cores, based on model with two layers group (1st layers group running on EVE, 2nd layers group on DSP) |
8 | ./tidl_classification -g 2 -d 1 -e 2 -l ./imagenet.txt -s ./classlist.txt -i ./clips/test50.mp4 -c ./stream_config_j11_v2.txt | 8 | ./tidl_classification -g 2 -d 1 -e 2 -l ./imagenet.txt -s ./classlist.txt -i ./clips/test10.mp4 -c ./stream_config_j11_v2.txt |
9 | # 4. Use video clip as input stream, using no EVEs and 2xDSP cores, based on model with single layers group | 9 | # 4. Use video clip as input stream, using no EVEs and 2xDSP cores, based on model with single layers group |
10 | ./tidl_classification -g 1 -d 2 -e 0 -l ./imagenet.txt -s ./classlist.txt -i ./clips/test50.mp4 -c ./stream_config_j11_v2.txt | 10 | ./tidl_classification -g 1 -d 2 -e 0 -l ./imagenet.txt -s ./classlist.txt -i ./clips/test10.mp4 -c ./stream_config_j11_v2.txt |
diff --git a/examples/test/testvecs/config/infer/tidl_config_inceptionNetv1.txt b/examples/test/testvecs/config/infer/tidl_config_inceptionNetv1.txt index 934cff6..6ba34d4 100755 --- a/examples/test/testvecs/config/infer/tidl_config_inceptionNetv1.txt +++ b/examples/test/testvecs/config/infer/tidl_config_inceptionNetv1.txt | |||
@@ -2,8 +2,8 @@ numFrames = 1 | |||
2 | preProcType = 2 | 2 | preProcType = 2 |
3 | inData = ../test/testvecs/input/preproc_2_224x224.y | 3 | inData = ../test/testvecs/input/preproc_2_224x224.y |
4 | outData = "stats_tool_out.bin" | 4 | outData = "stats_tool_out.bin" |
5 | netBinFile = ../test/testvecs/config/tidl_models/tidl_inception_v1_net.bin | 5 | netBinFile = ../test/testvecs/config/tidl_models/tidl_net_inceptionv1_224.bin |
6 | paramsBinFile = ../test/testvecs/config/tidl_models/tidl_inception_v1_param.bin | 6 | paramsBinFile = ../test/testvecs/config/tidl_models/tidl_param_inceptionv1_224.bin |
7 | inWidth = 224 | 7 | inWidth = 224 |
8 | inHeight = 224 | 8 | inHeight = 224 |
9 | inNumChannels = 3 | 9 | inNumChannels = 3 |
diff --git a/examples/test/testvecs/config/infer/tidl_config_inceptionNetv1_lg2.txt b/examples/test/testvecs/config/infer/tidl_config_inceptionNetv1_lg2.txt index b41294b..f2fb97f 100755 --- a/examples/test/testvecs/config/infer/tidl_config_inceptionNetv1_lg2.txt +++ b/examples/test/testvecs/config/infer/tidl_config_inceptionNetv1_lg2.txt | |||
@@ -2,8 +2,8 @@ numFrames = 1 | |||
2 | preProcType = 2 | 2 | preProcType = 2 |
3 | inData = ../test/testvecs/input/preproc_2_224x224.y | 3 | inData = ../test/testvecs/input/preproc_2_224x224.y |
4 | outData = "stats_tool_out.bin" | 4 | outData = "stats_tool_out.bin" |
5 | netBinFile = ../test/testvecs/config/tidl_models/tidl_inception_v1_net.bin | 5 | netBinFile = ../test/testvecs/config/tidl_models/tidl_net_inceptionv1_224.bin |
6 | paramsBinFile = ../test/testvecs/config/tidl_models/tidl_inception_v1_param.bin | 6 | paramsBinFile = ../test/testvecs/config/tidl_models/tidl_param_inceptionv1_224.bin |
7 | inWidth = 224 | 7 | inWidth = 224 |
8 | inHeight = 224 | 8 | inHeight = 224 |
9 | inNumChannels = 3 | 9 | inNumChannels = 3 |
diff --git a/examples/test/testvecs/config/tidl_models/tidl_inception_v1_net.bin b/examples/test/testvecs/config/tidl_models/tidl_net_inceptionv1_224.bin index 96dc888..96dc888 100644 --- a/examples/test/testvecs/config/tidl_models/tidl_inception_v1_net.bin +++ b/examples/test/testvecs/config/tidl_models/tidl_net_inceptionv1_224.bin | |||
Binary files differ | |||
diff --git a/examples/test/testvecs/config/tidl_models/tidl_inception_v1_param.bin b/examples/test/testvecs/config/tidl_models/tidl_param_inceptionv1_224.bin index 5f395de..5f395de 100644 --- a/examples/test/testvecs/config/tidl_models/tidl_inception_v1_param.bin +++ b/examples/test/testvecs/config/tidl_models/tidl_param_inceptionv1_224.bin | |||