From f6859c46a4859a419f73512d03776729c054b81f Mon Sep 17 00:00:00 2001 From: Bobholamovic Date: Tue, 28 Nov 2023 14:45:13 +0800 Subject: [PATCH] Fix bugs --- requirements.txt | 2 +- tests/check_coverage.sh | 6 ++++-- tests/deploy/test_predictor.py | 13 +++++++------ tests/run_fast_tests.sh | 2 +- tests/run_tipc_lite.sh | 2 +- tests/tools/run_coco_tools.py | 14 +++++++------- tests/tools/run_extract_ms_patches.py | 3 ++- tests/tools/run_generate_file_lists.py | 4 +++- tests/tools/run_match.py | 3 ++- tests/tools/run_oif.py | 4 +++- tests/tools/run_pca.py | 3 ++- tests/tools/run_split.py | 3 ++- 12 files changed, 35 insertions(+), 24 deletions(-) diff --git a/requirements.txt b/requirements.txt index d8ec8021..ca07db55 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ opencv-contrib-python <= 4.3.0.28 openpyxl # paddlepaddle >= 2.5.0 # paddlepaddle-gpu >= 2.5.0 -paddleslim +paddleslim @ git+https://github.com/PaddlePaddle/PaddleSlim.git@release/2.5 pandas protobuf >= 3.1.0 pycocotools diff --git a/tests/check_coverage.sh b/tests/check_coverage.sh index 02586d70..9ac36540 100644 --- a/tests/check_coverage.sh +++ b/tests/check_coverage.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash -coverage run --source paddlers --omit=../paddlers/models/* -m unittest discover -v +bash download_test_data.sh + +coverage run --source paddlers --omit='*/paddlers/models/*' -m unittest discover -v coverage report -coverage html -d coverage_html \ No newline at end of file +coverage html -d coverage_html diff --git a/tests/deploy/test_predictor.py b/tests/deploy/test_predictor.py index 07090b54..eaed54d9 100644 --- a/tests/deploy/test_predictor.py +++ b/tests/deploy/test_predictor.py @@ -13,6 +13,7 @@ # limitations under the License. import os.path as osp +import sys import tempfile import unittest.mock as mock @@ -54,7 +55,7 @@ def _test_predictor_impl(self): optimizer.state_dict.return_value = {'foo': 'bar'} trainer.optimizer = optimizer trainer.save_model(dynamic_model_dir) - export_cmd = f"python export_model.py --model_dir {dynamic_model_dir} --save_dir {static_model_dir} " + export_cmd = f"{sys.executable} export_model.py --model_dir {dynamic_model_dir} --save_dir {static_model_dir} " if trainer_name in self.TRAINER_NAME_TO_EXPORT_OPTS: export_cmd += self.TRAINER_NAME_TO_EXPORT_OPTS[ trainer_name] @@ -126,7 +127,7 @@ def check_predictor(self, predictor, trainer): t2_path = "data/ssmt/optical_t2.bmp" single_input = (t1_path, t2_path) num_inputs = 2 - transforms = [pdrs.transforms.Normalize()] + transforms = pdrs.transforms.Compose([pdrs.transforms.Normalize()]) # Expected failure with self.assertRaises(ValueError): @@ -191,7 +192,7 @@ class TestClasPredictor(TestPredictor): def check_predictor(self, predictor, trainer): single_input = "data/ssst/optical.bmp" num_inputs = 2 - transforms = [pdrs.transforms.Normalize()] + transforms = pdrs.transforms.Compose([pdrs.transforms.Normalize()]) labels = list(range(2)) trainer.labels = labels predictor._model.labels = labels @@ -257,7 +258,7 @@ def check_predictor(self, predictor, trainer): # given that the network is (partially?) randomly initialized. single_input = "data/ssst/optical.bmp" num_inputs = 2 - transforms = [pdrs.transforms.Normalize()] + transforms = pdrs.transforms.Compose([pdrs.transforms.Normalize()]) labels = list(range(80)) trainer.labels = labels predictor._model.labels = labels @@ -319,7 +320,7 @@ def check_predictor(self, predictor, trainer): # because the output is of uint8 type. single_input = "data/ssst/optical.bmp" num_inputs = 2 - transforms = [pdrs.transforms.Normalize()] + transforms = pdrs.transforms.Compose([pdrs.transforms.Normalize()]) # Single input (file path) input_ = single_input @@ -371,7 +372,7 @@ class TestSegPredictor(TestPredictor): def check_predictor(self, predictor, trainer): single_input = "data/ssst/optical.bmp" num_inputs = 2 - transforms = [pdrs.transforms.Normalize()] + transforms = pdrs.transforms.Compose([pdrs.transforms.Normalize()]) # Single input (file path) input_ = single_input diff --git a/tests/run_fast_tests.sh b/tests/run_fast_tests.sh index fac43985..9732d7b4 100644 --- a/tests/run_fast_tests.sh +++ b/tests/run_fast_tests.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash bash download_test_data.sh -python -m unittest -v fast_tests \ No newline at end of file +python -m unittest -v fast_tests diff --git a/tests/run_tipc_lite.sh b/tests/run_tipc_lite.sh index 50a8f9f2..bd8a3096 100644 --- a/tests/run_tipc_lite.sh +++ b/tests/run_tipc_lite.sh @@ -10,4 +10,4 @@ for config in $(ls test_tipc/configs/*/*/train_infer_python.txt); do if grep -q 'failed' "test_tipc/output/${task}/${model}/lite_train_lite_infer/results_python.log"; then exit 1 fi -done \ No newline at end of file +done diff --git a/tests/tools/run_coco_tools.py b/tests/tools/run_coco_tools.py index 072035d1..b0873663 100644 --- a/tests/tools/run_coco_tools.py +++ b/tests/tools/run_coco_tools.py @@ -12,26 +12,26 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tempfile +import sys from testing_utils import run_script if __name__ == '__main__': run_script( - f"python coco_tools/json_info_show.py --json_path ../tests/data/instances_val2017.json", + f"{sys.executable} coco_tools/json_info_show.py --json_path ../tests/data/instances_val2017.json", wd="../tools") run_script( - f"python coco_tools/json_image2json.py --image_dir ../tests/data/img_test --json_train_path ../tests/data/instances_train2017.json --result_path ../tests/data/test.json", + f"{sys.executable} coco_tools/json_image2json.py --image_dir ../tests/data/img_test --json_train_path ../tests/data/instances_train2017.json --result_path ../tests/data/test.json", wd="../tools") run_script( - f"python coco_tools/json_merge.py --json1_path ../tests/data/instances_train2017.json --json2_path ../tests/data/instances_train2017.json --save_path ../tests/data/instances_trainval2017.json", + f"{sys.executable} coco_tools/json_merge.py --json1_path ../tests/data/instances_train2017.json --json2_path ../tests/data/instances_train2017.json --save_path ../tests/data/instances_trainval2017.json", wd="../tools") run_script( - f"python coco_tools/json_split.py --json_all_path ../tests/data/instances_train2017.json --json_train_path ../tests/data/instances_train2017_1.json --json_val_path ../tests/data/instances_train2017_2.json", + f"{sys.executable} coco_tools/json_split.py --json_all_path ../tests/data/instances_train2017.json --json_train_path ../tests/data/instances_train2017_1.json --json_val_path ../tests/data/instances_train2017_2.json", wd="../tools") run_script( - f"python coco_tools/json_image_sta.py --json_path ../tests/data/instances_train2017.json --csv_path ../tests/data/instances_val2017_images.csv --pic_shape_path ../tests/data/images_shape.png --pic_shape_rate_path ../tests/data/shape_rate.png", + f"{sys.executable} coco_tools/json_image_sta.py --json_path ../tests/data/instances_train2017.json --csv_path ../tests/data/instances_val2017_images.csv --pic_shape_path ../tests/data/images_shape.png --pic_shape_rate_path ../tests/data/shape_rate.png", wd="../tools") run_script( - f"python coco_tools/json_anno_sta.py --json_path ../tests/data/instances_train2017.json --csv_path ../tests/data/instances_val2017_annos.csv --pic_shape_path ../tests/data/images_shape.png --pic_shape_rate_path ../tests/data/shape_rate.png --pic_pos_path ../tests/data/pos.png --pic_pos_end_path ../tests/data/pos_end.png --pic_cat_path ../tests/data/cat.png --pic_obj_num_path ../tests/data/obj_num.png", + f"{sys.executable} coco_tools/json_anno_sta.py --json_path ../tests/data/instances_train2017.json --csv_path ../tests/data/instances_val2017_annos.csv --pic_shape_path ../tests/data/images_shape.png --pic_shape_rate_path ../tests/data/shape_rate.png --pic_pos_path ../tests/data/pos.png --pic_pos_end_path ../tests/data/pos_end.png --pic_cat_path ../tests/data/cat.png --pic_obj_num_path ../tests/data/obj_num.png", wd="../tools") diff --git a/tests/tools/run_extract_ms_patches.py b/tests/tools/run_extract_ms_patches.py index b389f1a8..c6af931d 100644 --- a/tests/tools/run_extract_ms_patches.py +++ b/tests/tools/run_extract_ms_patches.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys import tempfile from testing_utils import run_script @@ -19,5 +20,5 @@ if __name__ == '__main__': with tempfile.TemporaryDirectory() as td: run_script( - f"python extract_ms_patches.py --image_paths ../tests/data/ssst/multispectral.tif --mask_path ../tests/data/ssst/multiclass_gt2.png --min_patch_size 32 --save_dir {td}", + f"{sys.executable} extract_ms_patches.py --image_paths ../tests/data/ssst/multispectral.tif --mask_path ../tests/data/ssst/multiclass_gt2.png --min_patch_size 32 --save_dir {td}", wd="../tools") diff --git a/tests/tools/run_generate_file_lists.py b/tests/tools/run_generate_file_lists.py index 85078d0f..6aba56fe 100644 --- a/tests/tools/run_generate_file_lists.py +++ b/tests/tools/run_generate_file_lists.py @@ -12,9 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys + from testing_utils import run_script if __name__ == '__main__': run_script( - f"python generate_file_lists.py --data_dir ../tests/data/levircd_crop --save_dir ../tests/data/levircd_crop --subsets train val test --subdirs A B label --glob_pattern '*' --store_abs_path", + f"{sys.executable} generate_file_lists.py --data_dir ../tests/data/levircd_crop --save_dir ../tests/data/levircd_crop --subsets train val test --subdirs A B label --glob_pattern '*' --store_abs_path", wd="../tools") diff --git a/tests/tools/run_match.py b/tests/tools/run_match.py index 8a3729d0..2e6d59e2 100644 --- a/tests/tools/run_match.py +++ b/tests/tools/run_match.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys import tempfile from testing_utils import run_script @@ -19,5 +20,5 @@ if __name__ == '__main__': with tempfile.TemporaryDirectory() as td: run_script( - f"python match.py --image1_path ../tests/data/ssmt/multispectral_t1.tif --image2_path ../tests/data/ssmt/multispectral_t1.tif --save_path {td}/out.tiff", + f"{sys.executable} match.py --image1_path ../tests/data/ssmt/multispectral_t1.tif --image2_path ../tests/data/ssmt/multispectral_t1.tif --save_path {td}/out.tiff", wd="../tools") diff --git a/tests/tools/run_oif.py b/tests/tools/run_oif.py index d837ae44..3de3592e 100644 --- a/tests/tools/run_oif.py +++ b/tests/tools/run_oif.py @@ -12,9 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys + from testing_utils import run_script if __name__ == '__main__': run_script( - f"python oif.py --image_path ../tests/data/ssst/multispectral.tif", + f"{sys.executable} oif.py --image_path ../tests/data/ssst/multispectral.tif", wd="../tools") diff --git a/tests/tools/run_pca.py b/tests/tools/run_pca.py index 233f7f16..90c5ef44 100644 --- a/tests/tools/run_pca.py +++ b/tests/tools/run_pca.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys import tempfile from testing_utils import run_script @@ -19,5 +20,5 @@ if __name__ == '__main__': with tempfile.TemporaryDirectory() as td: run_script( - f"python pca.py --image_path ../tests/data/ssst/multispectral.tif --save_dir {td} --dim 5", + f"{sys.executable} pca.py --image_path ../tests/data/ssst/multispectral.tif --save_dir {td} --dim 5", wd="../tools") diff --git a/tests/tools/run_split.py b/tests/tools/run_split.py index d5a43dc8..72a0c1c5 100644 --- a/tests/tools/run_split.py +++ b/tests/tools/run_split.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys import tempfile from testing_utils import CpuCommonTest, run_script @@ -19,5 +20,5 @@ if __name__ == '__main__': with tempfile.TemporaryDirectory() as td: run_script( - f"python split.py --image_path ../tests/data/ssst/multispectral.tif --mask_path ../tests/data/ssst/multiclass_gt2.png --block_size 128 --save_dir {td}", + f"{sys.executable} split.py --image_path ../tests/data/ssst/multispectral.tif --mask_path ../tests/data/ssst/multiclass_gt2.png --block_size 128 --save_dir {td}", wd="../tools")