diff --git a/research/cv/pointnet/README.md b/research/cv/pointnet/README.md index a3d6a858151cd330263c1c34a52e9e1e69a3894c..72ceafec9b9c075556a3c2ebec6378b05c7702c9 100644 --- a/research/cv/pointnet/README.md +++ b/research/cv/pointnet/README.md @@ -90,6 +90,7 @@ bash scripts/run_standalone_eval.sh '/home/pointnet/shapenetcore_partanno_segmen │ ├── run_distribute_gpu.sh # launch distributed training with gpu platform (8p) │ ├── run_standalone_eval_ascend.sh # launch evaluating with ascend platform (1p) │ ├── run_standalone_eval_gpu.sh # launch evaluating with gpu platform (1p) + │ ├── run_standalone_eval_onnx_gpu.sh # launch evaluating onnx with gpu platform (1p) │ ├── run_infer_310.sh # run 310 infer │ ├── run_standalone_train_ascend.sh # launch standalone training with ascend platform (1p) │ └── run_standalone_train_gpu.sh # launch standalone training with gpu platform (1p) @@ -101,6 +102,7 @@ bash scripts/run_standalone_eval.sh '/home/pointnet/shapenetcore_partanno_segmen │ ├── network.py # network definition │ └── preprocess.py # data preprocessing for training ├── eval.py # eval net + ├── eval_onnx.py # eval onnx ├── postprocess.py # 310 postprocess ├── preprocess.py # 310 preprocess ├── README.md @@ -145,15 +147,6 @@ bash scripts/run_distribution_ascend.sh [RANK_TABLE_FILE] ./ckpts ../shapenetcor ``` -- running on CPU - -```shell -# Run stand-alone training for CPU -python ./train.py --data_url=[DATA_URL] --device_target="CPU" --train_url=[TRAIN_URL] -# example: -python ./train.py --data_url=../shapenetcore_partanno_segmentation_benchmark_v0 --device_target="CPU" --train_url=./ckpts -``` - - running on GPU ```shell @@ -202,7 +195,7 @@ Before running the command below, please check the checkpoint path used for eval # Evaluate on ascend bash scripts/run_standalone_eval_ascend.sh [DATA_PATH] [MODEL_PATH] [DEVICE_ID] # example: -bash scripts/run_standalone_eval_ascend.sh shapenetcore_partanno_segmentation_benchmark_v0 pointnet.ckpt 0 +bash scripts/run_standalone_eval_ascend.sh shapenetcore_partanno_segmentation_benchmark_v0 pointnet.ckpt 1 ``` You can view the results through the file "log_standalone_eval_ascend". The accuracy of the test dataset will be as follows: @@ -212,38 +205,39 @@ You can view the results through the file "log_standalone_eval_ascend". The accu 'mIOU for class Chair: 0.869' ``` -- running on CPU +- running on GPU ```shell -# Evaluate on CPU -python ./eval.py --data_url=[DATA_URL] --device_target="CPU" --train_url=[TRAIN_URL] + # Evaluate on GPU +bash scripts/run_standalone_eval_gpu.sh [DATA_PATH] [MODEL_PATH] [DEVICE_ID] # example: -python ./eval.py --data_url=../shapenetcore_partanno_segmentation_benchmark_v0 --device_target="CPU" --train_url=./ckpts - +bash scripts/run_standalone_eval_gpu.sh shapenetcore_partanno_segmentation_benchmark_v0 pointnet.ckpt 1 ``` -You can view the results through the file "log_standalone_eval_cpu". The accuracy of the test dataset will be as follows : +You can view the results through the file "log_standalone_eval_gpu". The accuracy of the test dataset will be as follows: ```bash -# grep "mIOU " log_standalone_eval_cpu +# grep "mIOU " log_standalone_eval_gpu 'mIOU for class Chair: 0.869' ``` +## ONNX Evaluation + - running on GPU -```shell + ```shell # Evaluate on GPU -bash scripts/run_standalone_eval_gpu.sh [DATA_PATH] [MODEL_PATH] [DEVICE_ID] -# example: -bash scripts/run_standalone_eval_gpu.sh shapenetcore_partanno_segmentation_benchmark_v0 pointnet.ckpt 0 -``` + bash scripts/run_standalone_eval_onnx_gpu.sh [DATA_PATH] [MODEL_PATH] [DEVICE_ID] + # example + bash scripts/run_standalone_eval_onnx_gpu.sh dataset/shapenetcore_partanno_segmentation_benchmark_v0 mindir/pointnet.onnx 1 + ``` -You can view the results through the file "log_standalone_eval_gpu". The accuracy of the test dataset will be as follows: + You can view the results through the file "log_standalone_eval_onnx_gpu". The accuracy of the test dataset will be as follows: -```bash -# grep "mIOU " log_standalone_eval_gpu -'mIOU for class Chair: 0.869' -``` + ```bash + # grep "mIOU " log_standalone_eval_onnx_gpu + 'mIOU for class Chair: 0.869' + ``` # [310 Inference Process](#310-infer-process) @@ -282,7 +276,7 @@ Here, DVPP should be 'N'! ## Training Performance | Parameters | Ascend | GPU(V100(PCIE)) | -| -------------------------- |---------------------------------------------------|---------------------------------------------| +| -------------------------- | ------------------------------------------------- | ------------------------------------------- | | Model Version | PointNet | PointNet | | Resource | Ascend 910; CPU 24cores; Memory 256G; OS Euler2.8 | NVIDIA RTX Titan-24G | | uploaded Date | 11/30/2021 (month/day/year) | 4/19/2022 (month/day/year) | @@ -299,17 +293,17 @@ Here, DVPP should be 'N'! ## Inference Performance -| Parameters | Ascend | GPU(V100(PCIE)) | -| ------------------- |---------------------------------------------------|---------------------------| -| Model Version | PointNet | PointNet | -| Resource | Ascend 910; CPU 24cores; Memory 256G; OS Euler2.8 | NVIDIA RTX Titan-24G | -| Uploaded Date | 11/30/2021 (month/day/year) | 4/19/2022 (month/day/year) | -| MindSpore Version | 1.3.0 | 1.3.0 1.5.0 1.6.0 | -| Dataset | A subset of ShapeNet | A subset of ShapeNet | -| Batch_size | 64 | 64 | -| Outputs | probability | probability | -| mIOU | 86.3% (1p) | 86.3% (1p) | -| Total time | 1 min | 1 min | +| Parameters | Ascend | GPU(V100(PCIE)) | +| ----------------- | ------------------------------------------------- | -------------------------- | +| Model Version | PointNet | PointNet | +| Resource | Ascend 910; CPU 24cores; Memory 256G; OS Euler2.8 | NVIDIA RTX Titan-24G | +| Uploaded Date | 11/30/2021 (month/day/year) | 4/19/2022 (month/day/year) | +| MindSpore Version | 1.3.0 | 1.3.0 1.5.0 1.6.0 | +| Dataset | A subset of ShapeNet | A subset of ShapeNet | +| Batch_size | 64 | 64 | +| Outputs | probability | probability | +| mIOU | 86.3% (1p) | 86.3% (1p) | +| Total time | 1 min | 1 min | # [Description of Random Situation](#contents) @@ -317,4 +311,4 @@ We use random seed in train.py # [ModelZoo Homepage](#contents) -Please check the official [homepage](https://gitee.com/mindspore/models). +Please check the official [homepage](https://gitee.com/mindspore/models). \ No newline at end of file diff --git a/research/cv/pointnet/eval_onnx.py b/research/cv/pointnet/eval_onnx.py new file mode 100644 index 0000000000000000000000000000000000000000..9ded5f98ca7ca8491d374efba7cc1c68ca093b6c --- /dev/null +++ b/research/cv/pointnet/eval_onnx.py @@ -0,0 +1,97 @@ +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +"""Run evaluation for a model exported to ONNX""" +from __future__ import print_function +import argparse +import numpy as np +import onnxruntime as ort +from mindspore import Tensor +import mindspore.dataset as ds +import mindspore.ops as ops +from src.dataset import ShapeNetDataset +from tqdm import tqdm + +parser = argparse.ArgumentParser(description='MindSpore Pointnet Segmentation') +parser.add_argument('--batchSize', type=int, default=1, help='input batch size') +parser.add_argument('--nepoch', type=int, default=100, help='number of epochs to train for') +parser.add_argument('--device_id', type=int, default=0, help='device id') +parser.add_argument('--device_target', default='GPU', help='device id') +parser.add_argument('--data_path', type=str, default='./dataset/shapenetcore_partanno_segmentation_benchmark_v0', + help="dataset path") +parser.add_argument('--onnx_path', type=str, default='./mindir/pointnet.onnx', help="onnx path") +parser.add_argument('--class_choice', type=str, default='Chair', help="class_choice") +parser.add_argument('--feature_transform', action='store_true', help="use feature transform") +parser.add_argument('--enable_modelarts', default=False, help="use feature transform") + +args = parser.parse_args() + +def run_eval(): + if args.device_target == 'GPU': + providers = ['CUDAExecutionProvider'] + elif args.device_target in ('CPU', 'Ascend'): + providers = ['CPUExecutionProvider'] + else: + raise ValueError(f"Unsupported device_target '{device_target}'. Expected one of: 'CPU', 'GPU', 'Ascend'") + session = ort.InferenceSession(args.onnx_path, providers=providers) + input_name = session.get_inputs()[0].name + local_data_url = args.data_path + dataset_generator = ShapeNetDataset( + root=local_data_url, + classification=False, + class_choice=[args.class_choice]) + test_dataset_generator = ShapeNetDataset( + root=local_data_url, + classification=False, + class_choice=[args.class_choice], + split='test', + data_augmentation=False) + + test_dataloader = ds.GeneratorDataset(test_dataset_generator, ["point", "label"], shuffle=True) + test_dataset = test_dataloader.batch(args.batchSize) + num_classes = dataset_generator.num_seg_classes + + print('batchSize', test_dataset.get_batch_size()) + print('shapes2', test_dataset.output_shapes()) + print('test_dataset_size', test_dataset.get_dataset_size()) + + shape_ious = [] + for _, data in tqdm(enumerate(test_dataset.create_dict_iterator(), 0)): + points, target = data['point'], data['label'] + points = Tensor(points).asnumpy() + pred = session.run(None, {input_name: points}) + pred_choice = ops.ArgMaxWithValue(axis=3)(Tensor(pred))[0] + pred_np = pred_choice.asnumpy() + target_np = target.asnumpy() - 1 + + for shape_idx in range(target_np.shape[0]): + parts = range(num_classes) + part_ious = [] + for part in parts: + I = np.sum(np.logical_and((pred_np[shape_idx] == part), target_np[shape_idx] == part).reshape( + (target_np[shape_idx] == part).shape[0], 1)) + U = np.sum(np.logical_or((pred_np[shape_idx] == part), target_np[shape_idx] == part).reshape( + (target_np[shape_idx] == part).shape[0], 1)) + if U == 0: + iou = 1 + else: + iou = I / float(U) + part_ious.append(iou) + shape_ious.append(np.mean(part_ious)) + print(np.mean(part_ious)) + + print("mIOU for class {}: {}".format(args.class_choice, np.mean(shape_ious))) + +if __name__ == '__main__': + run_eval() diff --git a/research/cv/pointnet/scripts/run_standalone_eval_onnx_gpu.sh b/research/cv/pointnet/scripts/run_standalone_eval_onnx_gpu.sh new file mode 100644 index 0000000000000000000000000000000000000000..aeb57ad4e5a4b3fc5cc87607d7a94dce5362823e --- /dev/null +++ b/research/cv/pointnet/scripts/run_standalone_eval_onnx_gpu.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# Copyright 2022 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +if [ $# -ne 3 ] +then + echo "Usage: bash scripts/run_standalone_eval_onnx_gpu.sh [DATA_PATH] [ONNX_PATH] [DEVICE_ID]" +exit 1 +fi +DATA_PATH=$1 +ONNX_PATH=$2 +DEVICE_ID=$3 +get_real_path(){ + if [ "${1:0:1}" == "/" ]; then + echo "$1" + else + echo "$(realpath -m $PWD/$1)" + fi +} + +PATH1=$(get_real_path $1) +echo $PATH1 +PATH2=$(get_real_path $2) +echo $PATH2 +if [ $# == 3 ]; then + DEVICE_ID=$3 +fi + + +export RANK_SIZE=1 + +echo "======start training======" + +export CUDA_VISIBLE_DEVICES=$DEVICE_ID +nohup python ./eval_onnx.py \ + --data_path=$DATA_PATH \ + --device_target="GPU" \ + --onnx_path=$ONNX_PATH >log_standalone_eval_onnx_gpu 2>&1 &