提交 7a178866 编写于 作者: S syyxsxx

change cfg_dir to cfg_file

上级 d1866a90
......@@ -22,7 +22,7 @@
#include "include/paddlex/paddlex.h"
DEFINE_string(model_dir, "", "Path of inference model");
DEFINE_string(cfg_dir, "", "Path of PaddelX model yml file");
DEFINE_string(cfg_file, "", "Path of PaddelX model yml file");
DEFINE_string(device, "CPU", "Device name");
DEFINE_string(image, "", "Path of test image file");
DEFINE_string(image_list, "", "Path of test image list file");
......@@ -35,8 +35,8 @@ int main(int argc, char** argv) {
std::cerr << "--model_dir need to be defined" << std::endl;
return -1;
}
if (FLAGS_cfg_dir == "") {
std::cerr << "--cfg_dir need to be defined" << std::endl;
if (FLAGS_cfg_file == "") {
std::cerr << "--cfg_file need to be defined" << std::endl;
return -1;
}
if (FLAGS_image == "" & FLAGS_image_list == "") {
......@@ -46,7 +46,7 @@ int main(int argc, char** argv) {
// 加载模型
PaddleX::Model model;
model.Init(FLAGS_model_dir, FLAGS_cfg_dir, FLAGS_device);
model.Init(FLAGS_model_dir, FLAGS_cfg_file, FLAGS_device);
// 进行预测
if (FLAGS_image_list != "") {
......
......@@ -29,7 +29,7 @@
using namespace std::chrono; // NOLINT
DEFINE_string(model_dir, "", "Path of openvino model xml file");
DEFINE_string(cfg_dir, "", "Path of PaddleX model yaml file");
DEFINE_string(cfg_file, "", "Path of PaddleX model yaml file");
DEFINE_string(image, "", "Path of test image file");
DEFINE_string(image_list, "", "Path of test image list file");
DEFINE_string(device, "CPU", "Device name");
......@@ -45,8 +45,8 @@ int main(int argc, char** argv) {
std::cerr << "--model_dir need to be defined" << std::endl;
return -1;
}
if (FLAGS_cfg_dir == "") {
std::cerr << "--cfg_dir need to be defined" << std::endl;
if (FLAGS_cfg_file == "") {
std::cerr << "--cfg_file need to be defined" << std::endl;
return -1;
}
if (FLAGS_image == "" & FLAGS_image_list == "") {
......@@ -56,7 +56,7 @@ int main(int argc, char** argv) {
//
PaddleX::Model model;
model.Init(FLAGS_model_dir, FLAGS_cfg_dir, FLAGS_device);
model.Init(FLAGS_model_dir, FLAGS_cfg_file, FLAGS_device);
int imgs = 1;
auto colormap = PaddleX::GenerateColorMap(model.labels.size());
......
......@@ -25,7 +25,7 @@
DEFINE_string(model_dir, "", "Path of openvino model xml file");
DEFINE_string(cfg_dir, "", "Path of PaddleX model yaml file");
DEFINE_string(cfg_file, "", "Path of PaddleX model yaml file");
DEFINE_string(image, "", "Path of test image file");
DEFINE_string(image_list, "", "Path of test image list file");
DEFINE_string(device, "CPU", "Device name");
......@@ -39,8 +39,8 @@ int main(int argc, char** argv) {
std::cerr << "--model_dir need to be defined" << std::endl;
return -1;
}
if (FLAGS_cfg_dir == "") {
std::cerr << "--cfg_dir need to be defined" << std::endl;
if (FLAGS_cfg_file == "") {
std::cerr << "--cfg_file need to be defined" << std::endl;
return -1;
}
if (FLAGS_image == "" & FLAGS_image_list == "") {
......@@ -51,7 +51,7 @@ int main(int argc, char** argv) {
//
std::cout << "init start" << std::endl;
PaddleX::Model model;
model.Init(FLAGS_model_dir, FLAGS_cfg_dir, FLAGS_device);
model.Init(FLAGS_model_dir, FLAGS_cfg_file, FLAGS_device);
std::cout << "init done" << std::endl;
int imgs = 1;
auto colormap = PaddleX::GenerateColorMap(model.labels.size());
......
......@@ -39,13 +39,13 @@ namespace PaddleX {
class Model {
public:
void Init(const std::string& model_dir,
const std::string& cfg_dir,
const std::string& cfg_file,
std::string device) {
create_predictor(model_dir, cfg_dir, device);
create_predictor(model_dir, cfg_file, device);
}
void create_predictor(const std::string& model_dir,
const std::string& cfg_dir,
const std::string& cfg_file,
std::string device);
bool load_config(const std::string& model_dir);
......
......@@ -34,28 +34,18 @@ def arg_parser():
help="Specify the target device to infer on:[CPU, GPU, FPGA, HDDL, MYRIAD,HETERO]"
"Default value is CPU")
parser.add_argument(
"--img",
"-i",
type=str,
default=None,
help="path to an image files")
"--img", "-i", type=str, default=None, help="path to an image files")
parser.add_argument(
"--img_list",
"-l",
type=str,
default=None,
help="Path to a imglist")
"--img_list", "-l", type=str, default=None, help="Path to a imglist")
parser.add_argument(
"--cfg_dir",
"--cfg_file",
"-c",
type=str,
default=None,
help="Path to PaddelX model yml file")
return parser
......@@ -63,16 +53,16 @@ def main():
parser = arg_parser()
args = parser.parse_args()
model_xml = args.model_dir
model_yaml = args.cfg_dir
model_yaml = args.cfg_file
#model init
if("CPU" not in args.device):
predictor = deploy.Predictor(model_xml,model_yaml,args.device)
if ("CPU" not in args.device):
predictor = deploy.Predictor(model_xml, model_yaml, args.device)
else:
predictor = deploy.Predictor(model_xml,model_yaml)
predictor = deploy.Predictor(model_xml, model_yaml)
#predict
if(args.img_list != None):
if (args.img_list != None):
f = open(args.img_list)
lines = f.readlines()
for im_path in lines:
......@@ -83,5 +73,6 @@ def main():
im_path = args.img
predictor.predict(im_path)
if __name__ == "__main__":
main()
......@@ -20,7 +20,7 @@
namespace PaddleX {
void Model::create_predictor(const std::string& model_dir,
const std::string& cfg_dir,
const std::string& cfg_file,
std::string device) {
InferenceEngine::Core ie;
network_ = ie.ReadNetwork(
......@@ -49,11 +49,11 @@ void Model::create_predictor(const std::string& model_dir,
} else {
executable_network_ = ie.LoadNetwork(network_, device);
}
load_config(cfg_dir);
load_config(cfg_file);
}
bool Model::load_config(const std::string& cfg_dir) {
YAML::Node config = YAML::LoadFile(cfg_dir);
bool Model::load_config(const std::string& cfg_file) {
YAML::Node config = YAML::LoadFile(cfg_file);
type = config["_Attributes"]["model_type"].as<std::string>();
name = config["Model"].as<std::string>();
bool to_rgb = true;
......
......@@ -22,7 +22,7 @@
#include "include/paddlex/paddlex.h"
DEFINE_string(model_dir, "", "Path of inference model");
DEFINE_string(cfg_dir, "", "Path of PaddelX model yml file");
DEFINE_string(cfg_file, "", "Path of PaddelX model yml file");
DEFINE_string(image, "", "Path of test image file");
DEFINE_string(image_list, "", "Path of test image list file");
DEFINE_int32(thread_num, 1, "num of thread to infer");
......@@ -35,8 +35,8 @@ int main(int argc, char** argv) {
std::cerr << "--model_dir need to be defined" << std::endl;
return -1;
}
if (FLAGS_cfg_dir == "") {
std::cerr << "--cfg_dir need to be defined" << std::endl;
if (FLAGS_cfg_file == "") {
std::cerr << "--cfg_flie need to be defined" << std::endl;
return -1;
}
if (FLAGS_image == "" & FLAGS_image_list == "") {
......@@ -46,7 +46,7 @@ int main(int argc, char** argv) {
// 加载模型
PaddleX::Model model;
model.Init(FLAGS_model_dir, FLAGS_cfg_dir, FLAGS_thread_num);
model.Init(FLAGS_model_dir, FLAGS_cfg_file, FLAGS_thread_num);
std::cout << "init is done" << std::endl;
// 进行预测
if (FLAGS_image_list != "") {
......
......@@ -29,7 +29,7 @@
using namespace std::chrono; // NOLINT
DEFINE_string(model_dir, "", "Path of openvino model xml file");
DEFINE_string(cfg_dir, "", "Path of PaddleX model yaml file");
DEFINE_string(cfg_file, "", "Path of PaddleX model yaml file");
DEFINE_string(image, "", "Path of test image file");
DEFINE_string(image_list, "", "Path of test image list file");
DEFINE_int32(thread_num, 1, "num of thread to infer");
......@@ -45,8 +45,8 @@ int main(int argc, char** argv) {
std::cerr << "--model_dir need to be defined" << std::endl;
return -1;
}
if (FLAGS_cfg_dir == "") {
std::cerr << "--cfg_dir need to be defined" << std::endl;
if (FLAGS_cfg_file == "") {
std::cerr << "--cfg_file need to be defined" << std::endl;
return -1;
}
if (FLAGS_image == "" & FLAGS_image_list == "") {
......@@ -56,7 +56,7 @@ int main(int argc, char** argv) {
//
PaddleX::Model model;
model.Init(FLAGS_model_dir, FLAGS_cfg_dir, FLAGS_thread_num);
model.Init(FLAGS_model_dir, FLAGS_cfg_file, FLAGS_thread_num);
int imgs = 1;
auto colormap = PaddleX::GenerateColorMap(model.labels.size());
......
......@@ -25,7 +25,7 @@
DEFINE_string(model_dir, "", "Path of openvino model xml file");
DEFINE_string(cfg_dir, "", "Path of PaddleX model yaml file");
DEFINE_string(cfg_file, "", "Path of PaddleX model yaml file");
DEFINE_string(image, "", "Path of test image file");
DEFINE_string(image_list, "", "Path of test image list file");
DEFINE_string(save_dir, "", "Path to save visualized image");
......@@ -38,8 +38,8 @@ int main(int argc, char** argv) {
std::cerr << "--model_dir need to be defined" << std::endl;
return -1;
}
if (FLAGS_cfg_dir == "") {
std::cerr << "--cfg_dir need to be defined" << std::endl;
if (FLAGS_cfg_file == "") {
std::cerr << "--cfg_file need to be defined" << std::endl;
return -1;
}
if (FLAGS_image == "" & FLAGS_image_list == "") {
......@@ -50,7 +50,7 @@ int main(int argc, char** argv) {
//
std::cout << "init start" << std::endl;
PaddleX::Model model;
model.Init(FLAGS_model_dir, FLAGS_cfg_dir, FLAGS_thread_num);
model.Init(FLAGS_model_dir, FLAGS_cfg_file, FLAGS_thread_num);
std::cout << "init done" << std::endl;
int imgs = 1;
auto colormap = PaddleX::GenerateColorMap(model.labels.size());
......
......@@ -49,13 +49,13 @@ namespace PaddleX {
class Model {
public:
void Init(const std::string& model_dir,
const std::string& cfg_dir,
const std::string& cfg_file,
int thread_num) {
create_predictor(model_dir, cfg_dir, thread_num);
create_predictor(model_dir, cfg_file, thread_num);
}
void create_predictor(const std::string& model_dir,
const std::string& cfg_dir,
const std::string& cfg_file,
int thread_num);
bool load_config(const std::string& model_dir);
......
......@@ -27,28 +27,18 @@ def arg_parser():
default=None,
help="path to openvino model .xml file")
parser.add_argument(
"--img",
"-i",
type=str,
default=None,
help="path to an image files")
"--img", "-i", type=str, default=None, help="path to an image files")
parser.add_argument(
"--img_list",
"-l",
type=str,
default=None,
help="Path to a imglist")
"--img_list", "-l", type=str, default=None, help="Path to a imglist")
parser.add_argument(
"--cfg_dir",
"--cfg_file",
"-c",
type=str,
default=None,
help="Path to PaddelX model yml file")
parser.add_argument(
"--thread_num",
"-t",
......@@ -63,8 +53,6 @@ def arg_parser():
default=None,
help=" image input shape of model [NCHW] like [1,3,224,244] ")
return parser
......@@ -72,16 +60,16 @@ def main():
parser = arg_parser()
args = parser.parse_args()
model_nb = args.model_dir
model_yaml = args.cfg_dir
model_yaml = args.cfg_file
thread_num = args.thread_num
input_shape = args.input_shape
input_shape = input_shape[1:-1].split(",",3)
shape = list(map(int,input_shape))
input_shape = input_shape[1:-1].split(",", 3)
shape = list(map(int, input_shape))
#model init
predictor = deploy.Predictor(model_nb,model_yaml,thread_num,shape)
predictor = deploy.Predictor(model_nb, model_yaml, thread_num, shape)
#predict
if(args.img_list != None):
if (args.img_list != None):
f = open(args.img_list)
lines = f.readlines()
for im_path in lines:
......@@ -92,5 +80,6 @@ def main():
im_path = args.img
predictor.predict(im_path)
if __name__ == "__main__":
main()
......@@ -20,19 +20,19 @@
namespace PaddleX {
void Model::create_predictor(const std::string& model_dir,
const std::string& cfg_dir,
const std::string& cfg_file,
int thread_num) {
paddle::lite_api::MobileConfig config;
config.set_model_from_file(model_dir);
config.set_threads(thread_num);
load_config(cfg_dir);
load_config(cfg_file);
predictor_ =
paddle::lite_api::CreatePaddlePredictor<paddle::lite_api::MobileConfig>(
config);
}
bool Model::load_config(const std::string& cfg_dir) {
YAML::Node config = YAML::LoadFile(cfg_dir);
bool Model::load_config(const std::string& cfg_file) {
YAML::Node config = YAML::LoadFile(cfg_file);
type = config["_Attributes"]["model_type"].as<std::string>();
name = config["Model"].as<std::string>();
bool to_rgb = true;
......
......@@ -71,7 +71,7 @@ ARCH=x86
| --image | 要预测的图片文件路径 |
| --image_list | 按行存储图片路径的.txt文件 |
| --device | 运行的平台,可选项{"CPU","MYRIAD"},默认值为"CPU",如在VPU上请使用"MYRIAD"|
| --cfg_dir | PaddleX model 的.yml配置文件 |
| --cfg_file | PaddleX model 的.yml配置文件 |
| --save_dir | 可视化结果图片保存地址,仅适用于检测任务,默认值为" "既不保存可视化结果 |
### 样例
......@@ -80,7 +80,7 @@ linux系统在CPU下做单张图片的分类任务预测
测试图片 `/path/to/test_img.jpeg`
```shell
./build/classifier --model_dir=/path/to/openvino_model --image=/path/to/test_img.jpeg --cfg_dir=/path/to/PadlleX_model.yml
./build/classifier --model_dir=/path/to/openvino_model --image=/path/to/test_img.jpeg --cfg_file=/path/to/PadlleX_model.yml
```
......@@ -95,7 +95,7 @@ linux系统在CPU下做多张图片的检测任务预测,并保存预测可视
```
```shell
./build/detector --model_dir=/path/to/models/openvino_model --image_list=/root/projects/images_list.txt --cfg_dir=/path/to/PadlleX_model.yml --save_dir ./output
./build/detector --model_dir=/path/to/models/openvino_model --image_list=/root/projects/images_list.txt --cfg_file=/path/to/PadlleX_model.yml --save_dir ./output
```
`样例三`:
......@@ -103,7 +103,7 @@ linux系统在CPU下做多张图片的检测任务预测,并保存预测可视
测试图片 `/path/to/test_img.jpeg`
```shell
./build/classifier --model_dir=/path/to/openvino_model --image=/path/to/test_img.jpeg --cfg_dir=/path/to/PadlleX_model.yml --device=MYRIAD
./build/classifier --model_dir=/path/to/openvino_model --image=/path/to/test_img.jpeg --cfg_file=/path/to/PadlleX_model.yml --device=MYRIAD
```
## 性能测试
......
......@@ -19,7 +19,7 @@
| --img | 要预测的图片文件路径 |
| --image_list | 按行存储图片路径的.txt文件 |
| --device | 运行的平台, 默认值为"CPU" |
| --cfg_dir | PaddleX model 的.yml配置文件 |
| --cfg_file | PaddleX model 的.yml配置文件 |
### 样例
`样例一`
......@@ -28,7 +28,7 @@
```
cd /root/projects/python
python demo.py --model_dir /path/to/openvino_model --img /path/to/test_img.jpeg --cfg_dir /path/to/PadlleX_model.yml
python demo.py --model_dir /path/to/openvino_model --img /path/to/test_img.jpeg --cfg_file /path/to/PadlleX_model.yml
```
样例二`:
......@@ -45,7 +45,5 @@ python demo.py --model_dir /path/to/openvino_model --img /path/to/test_img.jpeg
```
cd /root/projects/python
python demo.py --model_dir /path/to/models/openvino_model --image_list /root/projects/images_list.txt --cfg_dir=/path/to/PadlleX_model.yml
python demo.py --model_dir /path/to/models/openvino_model --image_list /root/projects/images_list.txt --cfg_file=/path/to/PadlleX_model.yml
```
......@@ -81,7 +81,7 @@ cd D:\projects\PaddleX\deploy\openvino\out\build\x64-Release
| --image | 要预测的图片文件路径 |
| --image_list | 按行存储图片路径的.txt文件 |
| --device | 运行的平台,可选项{"CPU","MYRIAD"},默认值为"CPU",如在VPU上请使用"MYRIAD"|
| --cfg_dir | PaddleX model 的.yml配置文件 |
| --cfg_file | PaddleX model 的.yml配置文件 |
| --save_dir | 可视化结果图片保存地址,仅适用于检测任务,默认值为" "既不保存可视化结果 |
### 样例
......@@ -90,7 +90,7 @@ cd D:\projects\PaddleX\deploy\openvino\out\build\x64-Release
测试图片 `/path/to/test_img.jpeg`
```shell
./classifier.exe --model_dir=/path/to/openvino_model --image=/path/to/test_img.jpeg --cfg_dir=/path/to/PadlleX_model.yml
./classifier.exe --model_dir=/path/to/openvino_model --image=/path/to/test_img.jpeg --cfg_file=/path/to/PadlleX_model.yml
```
`样例二`:
......@@ -104,7 +104,7 @@ cd D:\projects\PaddleX\deploy\openvino\out\build\x64-Release
```
```shell
./detector.exe --model_dir=/path/to/models/openvino_model --image_list=/root/projects/images_list.txt --cfg_dir=/path/to/PadlleX_model.yml --save_dir ./output
./detector.exe --model_dir=/path/to/models/openvino_model --image_list=/root/projects/images_list.txt --cfg_file=/path/to/PadlleX_model.yml --save_dir ./output
```
`样例三`:
......@@ -112,5 +112,5 @@ cd D:\projects\PaddleX\deploy\openvino\out\build\x64-Release
测试图片 `/path/to/test_img.jpeg`
```shell
.classifier.exe --model_dir=/path/to/openvino_model --image=/path/to/test_img.jpeg --cfg_dir=/path/to/PadlleX_model.yml --device=MYRIAD
.classifier.exe --model_dir=/path/to/openvino_model --image=/path/to/test_img.jpeg --cfg_file=/path/to/PadlleX_model.yml --device=MYRIAD
```
......@@ -91,7 +91,7 @@ OPENCV_DIR=$(pwd)/deps/opencv/
| --image | 要预测的图片文件路径 |
| --image_list | 按行存储图片路径的.txt文件 |
| --thread_num | 预测的线程数,默认值为1 |
| --cfg_dir | PaddleX model 的.yml配置文件 |
| --cfg_file | PaddleX model 的.yml配置文件 |
| --save_dir | 可视化结果图片保存地址,仅适用于检测和分割任务,默认值为" "既不保存可视化结果 |
### 样例
......@@ -101,7 +101,7 @@ OPENCV_DIR=$(pwd)/deps/opencv/
```shell
./build/classifier --model_dir=/path/to/nb_model
--image=/path/to/test_img.jpeg --cfg_dir=/path/to/PadlleX_model.yml --thread_num=4
--image=/path/to/test_img.jpeg --cfg_file=/path/to/PadlleX_model.yml --thread_num=4
```
......@@ -116,7 +116,7 @@ OPENCV_DIR=$(pwd)/deps/opencv/
```
```shell
./build/segmenter --model_dir=/path/to/models/nb_model --image_list=/root/projects/images_list.txt --cfg_dir=/path/to/PadlleX_model.yml --save_dir ./output --thread_num=4
./build/segmenter --model_dir=/path/to/models/nb_model --image_list=/root/projects/images_list.txt --cfg_file=/path/to/PadlleX_model.yml --save_dir ./output --thread_num=4
```
## 性能测试
......
......@@ -22,7 +22,7 @@ python -m pip install paddlelite
| --model_dir | 模型转换生成的.xml文件路径,请保证模型转换生成的三个文件在同一路径下|
| --img | 要预测的图片文件路径 |
| --image_list | 按行存储图片路径的.txt文件 |
| --cfg_dir | PaddleX model 的.yml配置文件 |
| --cfg_file | PaddleX model 的.yml配置文件 |
| --thread_num | 预测的线程数, 默认值为1 |
| --input_shape | 模型输入中图片输入的大小[N,C,H.W] |
......@@ -33,7 +33,7 @@ python -m pip install paddlelite
```
cd /root/projects/python
python demo.py --model_dir /path/to/openvino_model --img /path/to/test_img.jpeg --cfg_dir /path/to/PadlleX_model.yml --thread_num 4 --input_shape [1,3,224,224]
python demo.py --model_dir /path/to/openvino_model --img /path/to/test_img.jpeg --cfg_file /path/to/PadlleX_model.yml --thread_num 4 --input_shape [1,3,224,224]
```
样例二`:
......@@ -50,5 +50,5 @@ python demo.py --model_dir /path/to/openvino_model --img /path/to/test_img.jpeg
```
cd /root/projects/python
python demo.py --model_dir /path/to/models/openvino_model --image_list /root/projects/images_list.txt --cfg_dir=/path/to/PadlleX_model.yml --thread_num 4 --input_shape [1,3,224,224]
python demo.py --model_dir /path/to/models/openvino_model --image_list /root/projects/images_list.txt --cfg_file=/path/to/PadlleX_model.yml --thread_num 4 --input_shape [1,3,224,224]
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册