Skip to content

Commit

Permalink
fix(demo): add warmup for wrong profiling result (#2339)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tpoisonooo committed Aug 16, 2023
1 parent b2c8703 commit a7e9be2
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 5 deletions.
6 changes: 4 additions & 2 deletions demo/csrc/cpp/classifier.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ int main(int argc, char* argv[]) {

// construct a classifier instance
mmdeploy::Classifier classifier(mmdeploy::Model{ARGS_model}, context);


// warmup
for (int i = 0; i < 20; ++i) {
classifier.Apply(img);
}

// apply the classifier; the result is an array-like class holding references to
// `mmdeploy_classification_t`, will be released automatically on destruction
Expand Down
5 changes: 5 additions & 0 deletions demo/csrc/cpp/detector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ int main(int argc, char* argv[]) {
// construct a detector instance
mmdeploy::Detector detector(mmdeploy::Model{ARGS_model}, context);

// warmup
for (int i = 0; i < 20; ++i) {
detector.Apply(img);
}

// apply the detector, the result is an array-like class holding references to
// `mmdeploy_detection_t`, will be released automatically on destruction
mmdeploy::Detector::Result dets = detector.Apply(img);
Expand Down
6 changes: 6 additions & 0 deletions demo/csrc/cpp/pose_detector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ int main(int argc, char *argv[]) {
context.Add(profiler);

PoseDetector detector{Model(model_path), context};

// warmup
for (int i = 0; i < 20; ++i) {
detector.Apply(img);
}

auto res = detector.Apply(img);

for (int i = 0; i < res[0].length; i++) {
Expand Down
5 changes: 5 additions & 0 deletions demo/csrc/cpp/restorer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ int main(int argc, char* argv[]) {
// construct a restorer instance
mmdeploy::Restorer restorer{mmdeploy::Model{ARGS_model}, context};

// warmup
for (int i = 0; i < 20; ++i) {
restorer.Apply(img);
}

// apply restorer to the image
mmdeploy::Restorer::Result result = restorer.Apply(img);

Expand Down
5 changes: 5 additions & 0 deletions demo/csrc/cpp/rotated_detector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ int main(int argc, char* argv[]) {
// construct a detector instance
mmdeploy::RotatedDetector detector(mmdeploy::Model{ARGS_model}, context);

// warmup
for (int i = 0; i < 20; ++i) {
detector.Apply(img);
}

// apply the detector, the result is an array-like class holding references to
// `mmdeploy_rotated_detection_t`, will be released automatically on destruction
mmdeploy::RotatedDetector::Result dets = detector.Apply(img);
Expand Down
5 changes: 5 additions & 0 deletions demo/csrc/cpp/segmentor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ int main(int argc, char* argv[]) {
context.Add(profiler);
mmdeploy::Segmentor segmentor{mmdeploy::Model{ARGS_model}, context};

// warmup
for (int i = 0; i < 20; ++i) {
segmentor.Apply(img);
}

// apply the detector, the result is an array-like class holding a reference to
// `mmdeploy_segmentation_t`, will be released automatically on destruction
mmdeploy::Segmentor::Result seg = segmentor.Apply(img);
Expand Down
6 changes: 3 additions & 3 deletions tools/scripts/build_ubuntu_x64_ncnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def install_pyncnn(dep_dir):
# git clone
if not os.path.exists('ncnn'):
os.system(
'git clone --depth 1 --branch 20230517 https://github.com/tencent/ncnn && cd ncnn' # noqa: E501
'git clone --depth 1 --branch 20230816 https://github.com/tencent/ncnn && cd ncnn' # noqa: E501
)

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

# install
os.chdir(ncnn_dir)
os.system('cd python && python -m pip install -e .')
os.system('cd python && python -m pip install -e . --user --no-cache-dir')
ncnn_cmake_dir = os.path.join(ncnn_dir, 'build', 'install', 'lib', 'cmake',
'ncnn')
assert (os.path.exists(ncnn_cmake_dir))
Expand Down Expand Up @@ -130,7 +130,7 @@ def install_mmdeploy(work_dir, dep_dir, ncnn_cmake_dir):
os.system(cmd)

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

0 comments on commit a7e9be2

Please sign in to comment.