Skip to content

Commit a7e9be2

Browse files
authored
fix(demo): add warmup for wrong profiling result (#2339)
* fix(demo): add warmup for wrong profiling result * style(demo/csrc): format cpp code * fix(demo): compile error * Update build_ubuntu_x64_ncnn.py * Update build_ubuntu_x64_ncnn.py
1 parent b2c8703 commit a7e9be2

File tree

7 files changed

+33
-5
lines changed

7 files changed

+33
-5
lines changed

demo/csrc/cpp/classifier.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ int main(int argc, char* argv[]) {
2828

2929
// construct a classifier instance
3030
mmdeploy::Classifier classifier(mmdeploy::Model{ARGS_model}, context);
31-
32-
31+
// warmup
32+
for (int i = 0; i < 20; ++i) {
33+
classifier.Apply(img);
34+
}
3335

3436
// apply the classifier; the result is an array-like class holding references to
3537
// `mmdeploy_classification_t`, will be released automatically on destruction

demo/csrc/cpp/detector.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ int main(int argc, char* argv[]) {
2929
// construct a detector instance
3030
mmdeploy::Detector detector(mmdeploy::Model{ARGS_model}, context);
3131

32+
// warmup
33+
for (int i = 0; i < 20; ++i) {
34+
detector.Apply(img);
35+
}
36+
3237
// apply the detector, the result is an array-like class holding references to
3338
// `mmdeploy_detection_t`, will be released automatically on destruction
3439
mmdeploy::Detector::Result dets = detector.Apply(img);

demo/csrc/cpp/pose_detector.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ int main(int argc, char *argv[]) {
2727
context.Add(profiler);
2828

2929
PoseDetector detector{Model(model_path), context};
30+
31+
// warmup
32+
for (int i = 0; i < 20; ++i) {
33+
detector.Apply(img);
34+
}
35+
3036
auto res = detector.Apply(img);
3137

3238
for (int i = 0; i < res[0].length; i++) {

demo/csrc/cpp/restorer.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ int main(int argc, char* argv[]) {
3030
// construct a restorer instance
3131
mmdeploy::Restorer restorer{mmdeploy::Model{ARGS_model}, context};
3232

33+
// warmup
34+
for (int i = 0; i < 20; ++i) {
35+
restorer.Apply(img);
36+
}
37+
3338
// apply restorer to the image
3439
mmdeploy::Restorer::Result result = restorer.Apply(img);
3540

demo/csrc/cpp/rotated_detector.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ int main(int argc, char* argv[]) {
3030
// construct a detector instance
3131
mmdeploy::RotatedDetector detector(mmdeploy::Model{ARGS_model}, context);
3232

33+
// warmup
34+
for (int i = 0; i < 20; ++i) {
35+
detector.Apply(img);
36+
}
37+
3338
// apply the detector, the result is an array-like class holding references to
3439
// `mmdeploy_rotated_detection_t`, will be released automatically on destruction
3540
mmdeploy::RotatedDetector::Result dets = detector.Apply(img);

demo/csrc/cpp/segmentor.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ int main(int argc, char* argv[]) {
3333
context.Add(profiler);
3434
mmdeploy::Segmentor segmentor{mmdeploy::Model{ARGS_model}, context};
3535

36+
// warmup
37+
for (int i = 0; i < 20; ++i) {
38+
segmentor.Apply(img);
39+
}
40+
3641
// apply the detector, the result is an array-like class holding a reference to
3742
// `mmdeploy_segmentation_t`, will be released automatically on destruction
3843
mmdeploy::Segmentor::Result seg = segmentor.Apply(img);

tools/scripts/build_ubuntu_x64_ncnn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def install_pyncnn(dep_dir):
6060
# git clone
6161
if not os.path.exists('ncnn'):
6262
os.system(
63-
'git clone --depth 1 --branch 20230517 https://github.com/tencent/ncnn && cd ncnn' # noqa: E501
63+
'git clone --depth 1 --branch 20230816 https://github.com/tencent/ncnn && cd ncnn' # noqa: E501
6464
)
6565

6666
ncnn_dir = os.path.join(dep_dir, 'ncnn')
@@ -90,7 +90,7 @@ def install_pyncnn(dep_dir):
9090

9191
# install
9292
os.chdir(ncnn_dir)
93-
os.system('cd python && python -m pip install -e .')
93+
os.system('cd python && python -m pip install -e . --user --no-cache-dir')
9494
ncnn_cmake_dir = os.path.join(ncnn_dir, 'build', 'install', 'lib', 'cmake',
9595
'ncnn')
9696
assert (os.path.exists(ncnn_cmake_dir))
@@ -130,7 +130,7 @@ def install_mmdeploy(work_dir, dep_dir, ncnn_cmake_dir):
130130
os.system(cmd)
131131

132132
os.system('cd build && make -j {} && make install'.format(g_jobs))
133-
os.system('python3 -m pip install -v -e .')
133+
os.system('python3 -m pip install -v -e . --user --no-cache-dir')
134134
os.system(""" echo 'export PATH={}:$PATH' >> ~/mmdeploy.env """.format(
135135
os.path.join(work_dir, 'mmdeploy', 'backend', 'ncnn')))
136136
try:

0 commit comments

Comments
 (0)