forked from huawei/mindspore2022
fix bug ctpn eval.py and modify openpose train param
This commit is contained in:
parent
2ba987d64f
commit
51721e130f
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
"""Evaluation for CTPN"""
|
||||
import os
|
||||
from mindspore import context
|
||||
from mindspore.train.serialization import load_checkpoint, load_param_into_net
|
||||
from mindspore.common import set_seed
|
||||
from src.ctpn import CTPN
|
||||
|
|
@ -22,12 +23,13 @@ from src.dataset import create_ctpn_dataset
|
|||
from src.eval_utils import eval_for_ctpn
|
||||
from src.model_utils.config import config
|
||||
from src.model_utils.moxing_adapter import moxing_wrapper
|
||||
from src.model_utils.device_adapter import get_device_id
|
||||
|
||||
|
||||
set_seed(1)
|
||||
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE, device_target=config.device_target, device_id=get_device_id)
|
||||
context.set_context(mode=context.GRAPH_MODE, device_target=config.device_target, device_id=get_device_id())
|
||||
|
||||
|
||||
def modelarts_pre_process():
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ In the currently provided training script, the coco2017 data set is used as an e
|
|||
Run python gen_ignore_mask.py
|
||||
|
||||
````python
|
||||
python gen_ignore_mask.py --train_ann ../dataset/annotations/person_keypoints_train2017.json --val_ann ../dataset/annotations/person_keypoints_val2017.json --train_dir train2017 --val_dir val2017
|
||||
python gen_ignore_mask.py --train_ann ../dataset/annotations/person_keypoints_train2017.json --val_ann ../dataset/annotations/person_keypoints_val2017.json --train_dir ../dataset/train2017 --val_dir ../dataset/val2017
|
||||
````
|
||||
|
||||
- The dataset folder is generated in the root directory and contains the following files:
|
||||
|
|
@ -90,10 +90,10 @@ After installing MindSpore via the official website, you can start training and
|
|||
|
||||
```python
|
||||
# run training example
|
||||
python train.py --imgpath_train ./train2017 --jsonpath_train ./person_keypoints_train2017.json --maskpath_train ./ignore_mask_train2017 > train.log 2>&1 &
|
||||
python train.py --imgpath_train ./train2017 --jsonpath_train ./person_keypoints_train2017.json --maskpath_train ./ignore_mask_train2017 --vgg_path ./vgg19-0-97_5004.ckpt > train.log 2>&1 &
|
||||
|
||||
# run distributed training example
|
||||
bash run_distribute_train.sh [RANK_TABLE_FILE] [IMGPATH_TRAIN] [JSONPATH_TRAIN] [MASKPATH_TRAIN]
|
||||
bash run_distribute_train.sh [RANK_TABLE_FILE] [IMGPATH_TRAIN] [JSONPATH_TRAIN] [MASKPATH_TRAIN] [VGG_PATH]
|
||||
|
||||
# run evaluation example
|
||||
python eval.py --model_path path_to_eval_model.ckpt --imgpath_val ./dataset/val2017 --ann ./dataset/annotations/person_keypoints_val2017.json > eval.log 2>&1 &
|
||||
|
|
@ -165,7 +165,7 @@ For more configuration details, please refer the script `default_config.yaml`.
|
|||
- running on Ascend
|
||||
|
||||
```python
|
||||
python train.py --imgpath_train ./train2017 --jsonpath_train ./person_keypoints_train2017.json --maskpath_train ./ignore_mask_train2017 > train.log 2>&1 &
|
||||
python train.py --imgpath_train ./train2017 --jsonpath_train ./person_keypoints_train2017.json --maskpath_train ./ignore_mask_train2017 --vgg_path ./vgg19-0-97_5004.ckpt > train.log 2>&1 &
|
||||
```
|
||||
|
||||
The python command above will run in the background, you can view the results through the file `train.log`.
|
||||
|
|
|
|||
|
|
@ -10,8 +10,14 @@ output_path: "/cache/train"
|
|||
load_path: "/cache/checkpoint_path"
|
||||
device_target: "Ascend"
|
||||
enable_profiling: False
|
||||
checkpoint_path: "./checkpoint/"
|
||||
checkpoint_file: "./checkpoint/.ckpt"
|
||||
|
||||
# ======================================================================================
|
||||
# create ignore mask options
|
||||
train_dir: ""
|
||||
val_dir: ""
|
||||
train_ann: ""
|
||||
val_ann: ""
|
||||
vis: False
|
||||
|
||||
# ======================================================================================
|
||||
# Training options
|
||||
|
|
@ -144,9 +150,12 @@ export_batch_size: "batch size"
|
|||
file_name: "output file name"
|
||||
file_format: "file format choices[AIR, MINDIR, ONNX]"
|
||||
ckpt_file: "Checkpoint file path."
|
||||
train_dir: "train data dir"
|
||||
train_ann: "train annotations json"
|
||||
model_path: "path of testing model"
|
||||
imgpath_val: "path of testing imgs"
|
||||
ann: "path of annotations"
|
||||
output_img_path: "path of testing imgs"
|
||||
vis: "visualize annotations and ignore masks"
|
||||
val_ann: "val annotations json"
|
||||
train_ann: "train annotations json"
|
||||
train_dir: "name of train dir"
|
||||
val_dir: "name of val dir"
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
if [ $# != 4 ]
|
||||
if [ $# != 5 ]
|
||||
then
|
||||
echo "Usage: sh scripts/run_distribute_train.sh [RANK_TABLE_FILE] [IAMGEPATH_TRAIN] [JSONPATH_TRAIN] [MASKPATH_TRAIN]"
|
||||
echo "Usage: sh scripts/run_distribute_train.sh [RANK_TABLE_FILE] [IAMGEPATH_TRAIN] [JSONPATH_TRAIN] [MASKPATH_TRAIN] [VGG_PATH]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
|
@ -56,6 +56,7 @@ do
|
|||
python train.py \
|
||||
--imgpath_train=$2 \
|
||||
--jsonpath_train=$3 \
|
||||
--maskpath_train=$4 > log.txt 2>&1 &
|
||||
--maskpath_train=$4 \
|
||||
--vgg_path=$5 > log.txt 2>&1 &
|
||||
cd ..
|
||||
done
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ exit 1
|
|||
fi
|
||||
|
||||
export DEVICE_ID=0
|
||||
export DEVICE_NUM=1
|
||||
export RANK_SIZE=1
|
||||
export RANK_ID=0
|
||||
python eval.py \
|
||||
--model_path=$1 \
|
||||
|
|
|
|||
|
|
@ -14,14 +14,14 @@
|
|||
# limitations under the License.
|
||||
# ============================================================================
|
||||
|
||||
if [ $# != 3 ]
|
||||
if [ $# != 4 ]
|
||||
then
|
||||
echo "Usage: sh scripts/run_standalone_train.sh [IAMGEPATH_TRAIN] [JSONPATH_TRAIN] [MASKPATH_TRAIN]"
|
||||
echo "Usage: sh scripts/run_standalone_train.sh [IAMGEPATH_TRAIN] [JSONPATH_TRAIN] [MASKPATH_TRAIN] [VGG_PATH]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export DEVICE_ID=0
|
||||
export DEVICE_NUM=1
|
||||
export RANK_SIZE=1
|
||||
export RANK_ID=0
|
||||
rm -rf train
|
||||
mkdir train
|
||||
|
|
@ -29,5 +29,6 @@ cp -r ./src ./train
|
|||
cp -r ./scripts ./train
|
||||
cp ./*.py ./train
|
||||
cp ./*yaml ./train
|
||||
cd ./train
|
||||
python train.py --imgpath_train=$1 --jsonpath_train=$2 --maskpath_train=$3 > train.log 2>&1 &
|
||||
cd ./train || exit
|
||||
python train.py --imgpath_train=$1 --jsonpath_train=$2 --maskpath_train=$3 --vgg_path=$4 > train.log 2>&1 &
|
||||
cd ..
|
||||
|
|
|
|||
|
|
@ -13,13 +13,12 @@
|
|||
# limitations under the License.
|
||||
# ============================================================================
|
||||
import os
|
||||
import argparse
|
||||
import cv2
|
||||
import numpy as np
|
||||
from tqdm import tqdm
|
||||
from pycocotools.coco import COCO as ReadJson
|
||||
from model_utils.config import config
|
||||
|
||||
from config import params
|
||||
|
||||
class DataLoader():
|
||||
def __init__(self, train_, dir_name, mode_='train'):
|
||||
|
|
@ -42,7 +41,7 @@ class DataLoader():
|
|||
intxn = mask_all_1 & mask
|
||||
mask_miss_1 = np.bitwise_or(mask_miss_1.astype(int), np.subtract(mask, intxn, dtype=np.int32))
|
||||
mask_all_1 = np.bitwise_or(mask_all_1.astype(int), mask.astype(int))
|
||||
elif ann['num_keypoints'] < params['min_keypoints'] or ann['area'] <= params['min_area']:
|
||||
elif ann['num_keypoints'] < config.min_keypoints or ann['area'] <= config.min_area:
|
||||
mask_all_1 = np.bitwise_or(mask_all_1.astype(int), mask.astype(int))
|
||||
mask_miss_1 = np.bitwise_or(mask_miss_1.astype(int), mask.astype(int))
|
||||
else:
|
||||
|
|
@ -90,25 +89,18 @@ class DataLoader():
|
|||
anno_ids = self.train.getAnnIds(imgIds=[img_id_])
|
||||
annotations_ = self.train.loadAnns(anno_ids)
|
||||
|
||||
img_file = os.path.join(params['data_dir'], self.dir_name, self.train.loadImgs([img_id_])[0]['file_name'])
|
||||
img_file = os.path.join(self.dir_name, self.train.loadImgs([img_id_])[0]['file_name'])
|
||||
image_ = cv2.imread(img_file)
|
||||
return image_, annotations_, img_id_
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--vis', action='store_true', help='visualize annotations and ignore masks')
|
||||
parser.add_argument('--train_ann', type=str, help='train annotations json')
|
||||
parser.add_argument('--val_ann', type=str, help='val annotations json')
|
||||
parser.add_argument('--train_dir', type=str, help='name of train dir')
|
||||
parser.add_argument('--val_dir', type=str, help='name of val dir')
|
||||
args = parser.parse_args()
|
||||
path_list = [args.train_ann, args.val_ann, args.train_dir, args.val_dir]
|
||||
path_list = [config.train_ann, config.val_ann, config.train_dir, config.val_dir]
|
||||
for index, mode in enumerate(['train', 'val']):
|
||||
train = ReadJson(path_list[index])
|
||||
data_loader = DataLoader(train, path_list[index+2], mode_=mode)
|
||||
|
||||
save_dir = os.path.join(params['data_dir'], 'ignore_mask_{}'.format(mode))
|
||||
save_dir = os.path.join(os.path.dirname(path_list[index+2]), 'ignore_mask_{}'.format(mode))
|
||||
if not os.path.exists(save_dir):
|
||||
os.makedirs(save_dir)
|
||||
|
||||
|
|
@ -116,7 +108,7 @@ if __name__ == '__main__':
|
|||
img, annotations, img_id = data_loader.get_img_annotation(ind=i)
|
||||
mask_all, mask_miss = data_loader.gen_masks(img, annotations)
|
||||
|
||||
if args.vis:
|
||||
if config.vis:
|
||||
ann_img = data_loader.draw_masks_and_keypoints(img, annotations)
|
||||
msk_img = data_loader.dwaw_gen_masks(img, mask_miss)
|
||||
cv2.imshow('image', np.hstack((ann_img, msk_img)))
|
||||
|
|
@ -126,7 +118,7 @@ if __name__ == '__main__':
|
|||
elif k == ord('s'):
|
||||
cv2.imwrite('aaa.png', np.hstack((ann_img, msk_img)))
|
||||
|
||||
if np.any(mask_miss) and not args.vis:
|
||||
if np.any(mask_miss) and not config.vis:
|
||||
mask_miss = mask_miss.astype(np.uint8) * 255
|
||||
save_path = os.path.join(save_dir, '{:012d}.png'.format(img_id))
|
||||
cv2.imwrite(save_path, mask_miss)
|
||||
|
|
|
|||
Loading…
Reference in New Issue