forked from mindspore-Ecosystem/mindspore
4-th modification based on retest info
This commit is contained in:
parent
c3dd03f694
commit
9805140507
|
@ -15,10 +15,11 @@
|
|||
*/
|
||||
|
||||
#include "DPN.h"
|
||||
#include "MxBase/DeviceManager/DeviceManager.h"
|
||||
#include "MxBase/Log/Log.h"
|
||||
#include <iostream>
|
||||
#include "MxBase/DeviceManager/DeviceManager.h"
|
||||
#include <opencv2/dnn.hpp>
|
||||
#include "MxBase/Log/Log.h"
|
||||
|
||||
|
||||
using namespace MxBase;
|
||||
using namespace cv::dnn;
|
||||
|
@ -27,7 +28,7 @@ namespace {
|
|||
const uint32_t YUV_BYTE_DE = 2;
|
||||
const uint32_t VPC_H_ALIGN = 2;
|
||||
const uint32_t BATCH_SIZE = 32;
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
APP_ERROR DPN::Init(const InitParam &initParam)
|
||||
{
|
||||
|
|
|
@ -35,31 +35,30 @@ struct InitParam {
|
|||
};
|
||||
|
||||
class DPN {
|
||||
public:
|
||||
APP_ERROR Init(const InitParam &initParam);
|
||||
APP_ERROR DeInit();
|
||||
APP_ERROR ReadImage(const std::string &imgPath, cv::Mat &imageMat);
|
||||
APP_ERROR ResizeImage(const cv::Mat &srcImageMat, cv::Mat &dstImageMat);
|
||||
APP_ERROR CenterCropImage(const cv::Mat &img, cv::Mat &crop_im);
|
||||
APP_ERROR CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase);
|
||||
APP_ERROR Inference(const std::vector<MxBase::TensorBase> &inputs, std::vector<MxBase::TensorBase> &outputs);
|
||||
APP_ERROR PostProcess(const std::vector<MxBase::TensorBase> &inputs,
|
||||
std::vector<std::vector<MxBase::ClassInfo>> &clsInfos);
|
||||
APP_ERROR Process(const std::vector<std::string> &batchImgPaths);
|
||||
// get infer time
|
||||
double GetInferCostMilliSec() const {return inferCostTimeMilliSec;}
|
||||
|
||||
private:
|
||||
APP_ERROR SaveResult(const std::vector<std::string> &batchImgPaths,
|
||||
public:
|
||||
APP_ERROR Init(const InitParam &initParam);
|
||||
APP_ERROR DeInit();
|
||||
APP_ERROR ReadImage(const std::string &imgPath, cv::Mat &imageMat);
|
||||
APP_ERROR ResizeImage(const cv::Mat &srcImageMat, cv::Mat &dstImageMat);
|
||||
APP_ERROR CenterCropImage(const cv::Mat &img, cv::Mat &crop_im);
|
||||
APP_ERROR CVMatToTensorBase(const cv::Mat &imageMat, MxBase::TensorBase &tensorBase);
|
||||
APP_ERROR Inference(const std::vector<MxBase::TensorBase> &inputs, std::vector<MxBase::TensorBase> &outputs);
|
||||
APP_ERROR PostProcess(const std::vector<MxBase::TensorBase> &inputs,
|
||||
std::vector<std::vector<MxBase::ClassInfo>> &clsInfos);
|
||||
APP_ERROR Process(const std::vector<std::string> &batchImgPaths);
|
||||
// get infer time
|
||||
double GetInferCostMilliSec() const {return inferCostTimeMilliSec;}
|
||||
private:
|
||||
APP_ERROR SaveResult(const std::vector<std::string> &batchImgPaths,
|
||||
const std::vector<std::vector<MxBase::ClassInfo>> &batchClsInfos);
|
||||
private:
|
||||
std::shared_ptr<MxBase::DvppWrapper> dvppWrapper_;
|
||||
std::shared_ptr<MxBase::ModelInferenceProcessor> model_;
|
||||
std::shared_ptr<MxBase::Resnet50PostProcess> post_;
|
||||
MxBase::ModelDesc modelDesc_;
|
||||
uint32_t deviceId_ = 0;
|
||||
// infer time
|
||||
double inferCostTimeMilliSec = 0.0;
|
||||
private:
|
||||
std::shared_ptr<MxBase::DvppWrapper> dvppWrapper_;
|
||||
std::shared_ptr<MxBase::ModelInferenceProcessor> model_;
|
||||
std::shared_ptr<MxBase::Resnet50PostProcess> post_;
|
||||
MxBase::ModelDesc modelDesc_;
|
||||
uint32_t deviceId_ = 0;
|
||||
// infer time
|
||||
double inferCostTimeMilliSec = 0.0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,17 +14,16 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "DPN.h"
|
||||
#include "MxBase/Log/Log.h"
|
||||
#include <dirent.h>
|
||||
#include "MxBase/Log/Log.h"
|
||||
#include "DPN.h"
|
||||
|
||||
namespace {
|
||||
const uint32_t CLASS_NUM = 1000;
|
||||
const uint32_t BATCH_SIZE = 32;
|
||||
} // namespace
|
||||
const uint32_t CLASS_NUM = 1000;
|
||||
const uint32_t BATCH_SIZE = 32;
|
||||
} // namespace
|
||||
|
||||
APP_ERROR ScanImages(const std::string &path, std::vector<std::string> &imgFiles)
|
||||
{
|
||||
APP_ERROR ScanImages(const std::string &path, const std::vector<std::string> &imgFiles){
|
||||
DIR *dirPtr = opendir(path.c_str());
|
||||
if (dirPtr == nullptr) {
|
||||
LogError << "opendir failed. dir:" << path;
|
||||
|
@ -43,8 +42,7 @@ APP_ERROR ScanImages(const std::string &path, std::vector<std::string> &imgFiles
|
|||
return APP_ERR_OK;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]){
|
||||
if (argc <= 1) {
|
||||
LogWarn << "Please input image path, such as '../../data/images'.";
|
||||
return APP_ERR_OK;
|
||||
|
@ -74,7 +72,7 @@ int main(int argc, char* argv[])
|
|||
auto startTime = std::chrono::high_resolution_clock::now();
|
||||
int inferImgsCount = 0;
|
||||
LogInfo << "Number of total images load from input data path: " << imgFilePaths.size();
|
||||
for(uint32_t i = 0; i <= imgFilePaths.size() - BATCH_SIZE; i += BATCH_SIZE){
|
||||
for( uint32_t i = 0; i <= imgFilePaths.size() - BATCH_SIZE; i += BATCH_SIZE) {
|
||||
std::vector<std::string>batchImgFilePaths(imgFilePaths.begin()+i, imgFilePaths.begin()+(i+BATCH_SIZE));
|
||||
ret = dpn->Process(batchImgFilePaths);
|
||||
if (ret != APP_ERR_OK) {
|
||||
|
|
|
@ -87,8 +87,8 @@ def _parse_args():
|
|||
help='number of parallel workers')
|
||||
parser.add_argument('--dataset', type=str, default='imagenet-1K',
|
||||
help='train dataset')
|
||||
parser.add_argument('--keep_checkpoint_max', type=int, default=3,
|
||||
help='keep checkpoint max')
|
||||
parser.add_argument('--keep_checkpoint_max', type=int, default=3,
|
||||
help='keep checkpoint max')
|
||||
parser.add_argument('--num_classes', type=int, default=1000,
|
||||
help='number of classes')
|
||||
parser.add_argument('--label_smooth', action='store_true',
|
||||
|
@ -107,13 +107,13 @@ def _parse_args():
|
|||
help='pretrained checkpoint file name')
|
||||
parser.add_argument("--filter_weight", type=ast.literal_eval, default=False,
|
||||
help="Filter head weight parameters, default is False.")
|
||||
parser.add_argument('--eval_each_epoch', type=int, default=0,
|
||||
parser.add_argument('--eval_each_epoch', type=int, default=0,
|
||||
help='evaluate on each epoch')
|
||||
parser.add_argument('--global_step', type=int, default=0,
|
||||
parser.add_argument('--global_step', type=int, default=0,
|
||||
help='global step')
|
||||
parser.add_argument('--epoch_size', type=int, default=1,
|
||||
parser.add_argument('--epoch_size', type=int, default=1,
|
||||
help='epoch size')
|
||||
parser.add_argument('--loss_scale_num', type=int, default=1024,
|
||||
parser.add_argument('--loss_scale_num', type=int, default=1024,
|
||||
help='loss scale num')
|
||||
parser.add_argument('--momentum', type=float, default=0.5,
|
||||
help='momentum')
|
||||
|
@ -131,21 +131,20 @@ def _parse_args():
|
|||
help='max learning rate')
|
||||
parser.add_argument('--factor', type=float, default=0.1,
|
||||
help='decay factor')
|
||||
parser.add_argument('--warmup_epochs', type=int, default=5,
|
||||
parser.add_argument('--warmup_epochs', type=int, default=5,
|
||||
help='warmup epochs')
|
||||
|
||||
# export configs
|
||||
parser.add_argument('--export_dir', type=str, default='',
|
||||
help='dircetory to save exported model, frozen model if not None')
|
||||
parser.add_argument('--width', type=int, default=224,
|
||||
parser.add_argument('--width', type=int, default=224,
|
||||
help='export width')
|
||||
parser.add_argument('--height', type=int, default=224,
|
||||
parser.add_argument('--height', type=int, default=224,
|
||||
help='export height')
|
||||
parser.add_argument('--file_name', type=str, default='dpn92',
|
||||
help='export file name')
|
||||
parser.add_argument('--file_format', type=str, default='AIR',
|
||||
help='export file format')
|
||||
|
||||
# args, _ = parser.parse_known_args()
|
||||
_args = parser.parse_args()
|
||||
return _args
|
||||
|
@ -162,7 +161,7 @@ def filter_weight_by_list(origin_dict, param_filter):
|
|||
def dpn_train(config_args, ma_config):
|
||||
ma_config["training_data"] = config_args.data_path + "/train"
|
||||
ma_config["image_size"] = [config_args.image_size_height, config_args.image_size_width]
|
||||
train_dataset = classification_dataset(ma_config["training_data"],
|
||||
train_dataset = classification_dataset(ma_config["training_data"],
|
||||
image_size=ma_config["image_size"],
|
||||
per_batch_size=config_args.batch_size,
|
||||
max_epoch=1,
|
||||
|
@ -329,7 +328,7 @@ def main():
|
|||
ma_config["rank_save_ckpt_flag"] = 1
|
||||
# data sync
|
||||
mox.file.copy_parallel(config_args.data_url, config_args.data_path)
|
||||
# train
|
||||
# train
|
||||
dpn_train(config_args, ma_config)
|
||||
print('DPN training success!')
|
||||
# export
|
||||
|
|
Loading…
Reference in New Issue