Skip to content

Commit 9d927e1

Browse files
authored
[lint] use pre-commit to auto check and lint (#183)
* [lint] use pre-commit to auto check and lint * [lint] auto format all by pre-commit, including c++, python * [lint] cpplint==1.6.1 * [lint] remove sphinx
1 parent 8a908ad commit 9d927e1

37 files changed

+437
-358
lines changed

.github/workflows/doc.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ jobs:
88
steps:
99
- uses: actions/checkout@v1
1010

11-
# install sphinx related package and build sphinx files
12-
- uses: ammaraskar/sphinx-action@master
13-
with:
14-
docs-folder: "docs/"
15-
pre-build-command: "pip install sphinx-markdown-tables nbsphinx jinja2 recommonmark sphinx_rtd_theme"
16-
17-
1811
# add .nojekyll to notice Pages use the _* dirs
1912
- name: copy the generated site
2013
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Setup Python
3636
uses: actions/setup-python@v1
3737
with:
38-
python-version: 3.x
38+
python-version: 3.9
3939
architecture: x64
4040
- name: Fetch Wenet
4141
uses: actions/checkout@v1
@@ -80,7 +80,7 @@ jobs:
8080
- name: Run cpplint
8181
run: |
8282
set -eux
83-
pip install cpplint
83+
pip install cpplint==1.6.1
8484
cpplint --version
8585
cpplint --recursive .
8686
if [ $? != 0 ]; then exit 1; fi

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.5.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- repo: https://github.com/pre-commit/mirrors-yapf
7+
rev: 'v0.32.0'
8+
hooks:
9+
- id: yapf
10+
- repo: https://github.com/pycqa/flake8
11+
rev: '3.8.2'
12+
hooks:
13+
- id: flake8
14+
- repo: https://github.com/pre-commit/mirrors-clang-format
15+
rev: 'v17.0.6'
16+
hooks:
17+
- id: clang-format
18+
args: ['--style=file']
19+
exclude: 'runtime/android/app/src/.*\.(json|java|js|m|mm|proto)'
20+
- repo: https://github.com/cpplint/cpplint
21+
rev: '1.6.1'
22+
hooks:
23+
- id: cpplint

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pip install torch torchaudio
4545

4646
``` sh
4747
pip install -r requirements.txt
48+
pre-commit install # for clean and tidy code
4849
```
4950

5051
## Dataset

docs/conf.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
# import sys
1515
# sys.path.insert(0, os.path.abspath('.'))
1616

17-
1817
# -- Project information -----------------------------------------------------
1918

2019
project = 'Wenet'
2120
copyright = '2020, wenet-team'
2221
author = 'wenet-team'
2322

24-
2523
# -- General configuration ---------------------------------------------------
2624

2725
# Add any Sphinx extension module names here, as strings. They can be
@@ -43,7 +41,6 @@
4341
# Add any paths that contain templates here, relative to this directory.
4442
templates_path = ['_templates']
4543

46-
4744
# The suffix(es) of source filenames.
4845
# You can specify multiple suffix as a list of string:
4946
source_suffix = {
@@ -57,7 +54,6 @@
5754
# This pattern also affects html_static_path and html_extra_path.
5855
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
5956

60-
6157
# -- Options for HTML output -------------------------------------------------
6258

6359
# The theme to use for HTML and HTML Help pages. See the documentation for

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ pyflakes==2.2.0
1515
lmdb
1616
scipy
1717
tqdm
18+
pre-commit==3.5.0

runtime/android/app/src/main/cpp/wekws.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,18 @@ void set_input_finished() {
8282
// }
8383

8484
void start_spot() {
85-
std::vector<std::vector<float>> feats;
86-
feature_pipeline->Read(80, &feats);
87-
std::vector<std::vector<float>> prob;
88-
spotter->Forward(feats, &prob);
89-
float max_prob = 0.0;
90-
for (int t = 0; t < prob.size(); t++) {
91-
for (int j = 0; j < prob[t].size(); j++) {
92-
max_prob = std::max(prob[t][j], max_prob);
93-
}
85+
std::vector<std::vector<float>> feats;
86+
feature_pipeline->Read(80, &feats);
87+
std::vector<std::vector<float>> prob;
88+
spotter->Forward(feats, &prob);
89+
float max_prob = 0.0;
90+
for (int t = 0; t < prob.size(); t++) {
91+
for (int j = 0; j < prob[t].size(); j++) {
92+
max_prob = std::max(prob[t][j], max_prob);
9493
}
95-
result = std::to_string(offset) + " prob: " + std::to_string(max_prob);
96-
offset += prob.size();
94+
}
95+
result = std::to_string(offset) + " prob: " + std::to_string(max_prob);
96+
offset += prob.size();
9797
}
9898

9999
jstring get_result(JNIEnv* env, jobject) {

runtime/core/bin/kws_main.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
1615
#include <iostream>
1716
#include <string>
1817

runtime/core/frontend/feature_pipeline.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include <vector>
2222

2323
#include "frontend/fbank.h"
24-
#include "utils/log.h"
2524
#include "utils/blocking_queue.h"
25+
#include "utils/log.h"
2626

2727
namespace wenet {
2828

runtime/core/kws/keyword_spotting.cc

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
1615
#include "kws/keyword_spotting.h"
1716

1817
#include <iostream>
@@ -35,30 +34,27 @@ KeywordSpotting::KeywordSpotting(const std::string& model_path) {
3534
out_names_ = {"output", "r_cache"};
3635
auto metadata = session_->GetModelMetadata();
3736
Ort::AllocatorWithDefaultOptions allocator;
38-
cache_dim_ = std::stoi(metadata.LookupCustomMetadataMap("cache_dim",
39-
allocator));
40-
cache_len_ = std::stoi(metadata.LookupCustomMetadataMap("cache_len",
41-
allocator));
37+
cache_dim_ =
38+
std::stoi(metadata.LookupCustomMetadataMap("cache_dim", allocator));
39+
cache_len_ =
40+
std::stoi(metadata.LookupCustomMetadataMap("cache_len", allocator));
4241
std::cout << "Kws Model Info:" << std::endl
4342
<< "\tcache_dim: " << cache_dim_ << std::endl
4443
<< "\tcache_len: " << cache_len_ << std::endl;
4544
Reset();
4645
}
4746

48-
4947
void KeywordSpotting::Reset() {
5048
Ort::MemoryInfo memory_info =
51-
Ort::MemoryInfo::CreateCpu(OrtDeviceAllocator, OrtMemTypeCPU);
49+
Ort::MemoryInfo::CreateCpu(OrtDeviceAllocator, OrtMemTypeCPU);
5250
cache_.resize(cache_dim_ * cache_len_, 0.0);
5351
const int64_t cache_shape[] = {1, cache_dim_, cache_len_};
54-
cache_ort_ = Ort::Value::CreateTensor<float>(
55-
memory_info, cache_.data(), cache_.size(), cache_shape, 3);
52+
cache_ort_ = Ort::Value::CreateTensor<float>(memory_info, cache_.data(),
53+
cache_.size(), cache_shape, 3);
5654
}
5755

58-
59-
void KeywordSpotting::Forward(
60-
const std::vector<std::vector<float>>& feats,
61-
std::vector<std::vector<float>>* prob) {
56+
void KeywordSpotting::Forward(const std::vector<std::vector<float>>& feats,
57+
std::vector<std::vector<float>>* prob) {
6258
prob->clear();
6359
if (feats.size() == 0) return;
6460
Ort::MemoryInfo memory_info =
@@ -78,9 +74,9 @@ void KeywordSpotting::Forward(
7874
inputs.emplace_back(std::move(feats_ort));
7975
inputs.emplace_back(std::move(cache_ort_));
8076
// ort_outputs.size() == 2
81-
std::vector<Ort::Value> ort_outputs = session_->Run(
82-
Ort::RunOptions{nullptr}, in_names_.data(), inputs.data(),
83-
inputs.size(), out_names_.data(), out_names_.size());
77+
std::vector<Ort::Value> ort_outputs =
78+
session_->Run(Ort::RunOptions{nullptr}, in_names_.data(), inputs.data(),
79+
inputs.size(), out_names_.data(), out_names_.size());
8480

8581
// 3. Update cache
8682
cache_ort_ = std::move(ort_outputs[1]);
@@ -92,9 +88,9 @@ void KeywordSpotting::Forward(
9288
int output_dim = type_info.GetShape()[2];
9389
prob->resize(num_outputs);
9490
for (int i = 0; i < num_outputs; i++) {
95-
(*prob)[i].resize(output_dim);
96-
memcpy((*prob)[i].data(), data + i * output_dim,
97-
sizeof(float) * output_dim);
91+
(*prob)[i].resize(output_dim);
92+
memcpy((*prob)[i].data(), data + i * output_dim,
93+
sizeof(float) * output_dim);
9894
}
9995
}
10096

0 commit comments

Comments
 (0)