diff --git a/community/cv/ADCAM/.log.txt.swo b/community/cv/ADCAM/.log.txt.swo new file mode 100644 index 0000000000000000000000000000000000000000..8e405cb658d1f0daab3a6748a96198ac539c36ec Binary files /dev/null and b/community/cv/ADCAM/.log.txt.swo differ diff --git a/community/cv/ADCAM/.log.txt.swp b/community/cv/ADCAM/.log.txt.swp new file mode 100644 index 0000000000000000000000000000000000000000..0221fb8134580c49530d3641bad4d708b302f1fe Binary files /dev/null and b/community/cv/ADCAM/.log.txt.swp differ diff --git a/community/cv/ADCAM/ciou.py b/community/cv/ADCAM/ciou.py new file mode 100644 index 0000000000000000000000000000000000000000..f3e1d7a303882669ac9432c61972fbc30804b36e --- /dev/null +++ b/community/cv/ADCAM/ciou.py @@ -0,0 +1,101 @@ +import mindspore +from mindspore import nn, ops +import numpy as np +import mindspore +from mindspore import nn, ops +import math + +class CIou(nn.Cell): + """Calculating CIoU loss""" + def __init__(self): + super(CIou, self).__init__() + self.min = ops.Minimum() + self.max = ops.Maximum() + self.sub = ops.Sub() + self.add = ops.Add() + self.mul = ops.Mul() + self.div = ops.RealDiv() + self.square = ops.Square() + self.sqrt = ops.Sqrt() + self.atan2 = ops.Atan2() + self.eps = 1e-7 + self.pi = mindspore.Tensor(math.pi, mindspore.float32) + self.cast = ops.Cast() + + def construct(self, boxes1, boxes2): + """ + Args: + boxes1: Tensor of shape (..., 4), format [xmin, ymin, xmax, ymax] + boxes2: Tensor of shape (..., 4), format [xmin, ymin, xmax, ymax] + Returns: + cious: Tensor of CIoU loss values + """ + boxes1 = self.cast(boxes1, mindspore.float32) + boxes2 = self.cast(boxes2, mindspore.float32) + + # Widths and heights + w1 = self.sub(boxes1[..., 2], boxes1[..., 0]) + h1 = self.sub(boxes1[..., 3], boxes1[..., 1]) + w2 = self.sub(boxes2[..., 2], boxes2[..., 0]) + h2 = self.sub(boxes2[..., 3], boxes2[..., 1]) + + w1 = self.max(w1, 0.0) + h1 = self.max(h1, 0.0) + w2 = self.max(w2, 0.0) + h2 = self.max(h2, 0.0) + + # Areas + area1 = self.mul(w1, h1) + area2 = self.mul(w2, h2) + + # Intersection + inter_left_up = self.max(boxes1[..., :2], boxes2[..., :2]) + inter_right_down = self.min(boxes1[..., 2:], boxes2[..., 2:]) + inter_wh = self.max(self.sub(inter_right_down, inter_left_up), 0.0) + inter_area = self.mul(inter_wh[..., 0], inter_wh[..., 1]) + + # Union + union_area = self.add(area1, area2) - inter_area + self.eps + + # IoU + ious = self.div(inter_area, union_area) + ious = ops.clip_by_value(ious, 0.0, 1.0) + + # Enclosing box + enclose_left_up = self.min(boxes1[..., :2], boxes2[..., :2]) + enclose_right_down = self.max(boxes1[..., 2:], boxes2[..., 2:]) + enclose_wh = self.max(self.sub(enclose_right_down, enclose_left_up), 0.0) + enclose_c2 = self.square(enclose_wh[..., 0]) + self.square(enclose_wh[..., 1]) + self.eps + + # Center distances + boxes1_center = self.mul(self.add(boxes1[..., :2], boxes1[..., 2:]), 0.5) + boxes2_center = self.mul(self.add(boxes2[..., :2], boxes2[..., 2:]), 0.5) + center_dist = self.square(self.sub(boxes1_center[..., 0], boxes2_center[..., 0])) + \ + self.square(self.sub(boxes1_center[..., 1], boxes2_center[..., 1])) + + # Penalty term v + arctan1 = self.atan2(h1, w1) + arctan2 = self.atan2(h2, w2) + v = (4 / (self.pi ** 2)) * self.square(arctan1 - arctan2) + + # Alpha term + S = 1 - ious + alpha = v / (S + v + self.eps) + + # CIoU + ciou_term = self.div(center_dist, enclose_c2) + cious = ious - (ciou_term + alpha * v) + cious = ops.clip_by_value(cious, -1.0, 1.0) + + return cious + +# 假设有两个边界框 +boxes_pred = mindspore.Tensor([[50, 50, 150, 150]], mindspore.float32) +boxes_target = mindspore.Tensor([[60, 60, 140, 140]], mindspore.float32) + +# 初始化CIoU损失函数 +ciou_loss = CIou() + +# 计算CIoU损失 +loss = ciou_loss(boxes_pred, boxes_target) +print(loss) diff --git a/community/cv/ADCAM/cpp_infer/CMakeLists.txt b/community/cv/ADCAM/cpp_infer/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9db631e98656875af43113d278bfd3dff9ca246a --- /dev/null +++ b/community/cv/ADCAM/cpp_infer/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.14.1) +project(Ascend310Infer) +add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -std=c++17 -Werror -Wall -fPIE -Wl,--allow-shlib-undefined") +set(PROJECT_SRC_ROOT ${CMAKE_CURRENT_LIST_DIR}/) +option(MINDSPORE_PATH "mindspore install path" "") +include_directories(${MINDSPORE_PATH}) +include_directories(${MINDSPORE_PATH}/include) +include_directories(${PROJECT_SRC_ROOT}) +set(TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) +include_directories(${TOP_DIR}/utils/cpp_infer/example/) # common_inc in top dir +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/) # common_inc in local dir +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../) # common_inc in local dir + +if(EXISTS ${MINDSPORE_PATH}/lib/libmindspore-lite.so) + message(--------------- Compile-with-MindSpore-Lite ----------------) + set(MS_LIB ${MINDSPORE_PATH}/lib/libmindspore-lite.so) + set(MD_LIB ${MINDSPORE_PATH}/lib/libminddata-lite.so) + add_compile_definitions(ENABLE_LITE) +else() + message(--------------- Compile-with-MindSpore ----------------) + set(MS_LIB ${MINDSPORE_PATH}/lib/libmindspore.so) + file(GLOB_RECURSE MD_LIB ${MINDSPORE_PATH}/_c_dataengine*) +endif() + +add_executable(main src/main.cc) +target_link_libraries(main ${MS_LIB} ${MD_LIB}) diff --git a/community/cv/ADCAM/cpp_infer/build.sh b/community/cv/ADCAM/cpp_infer/build.sh new file mode 100644 index 0000000000000000000000000000000000000000..5881fce6d0e17f76ddd8b4754e38261a446b7549 --- /dev/null +++ b/community/cv/ADCAM/cpp_infer/build.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +if [ ! -d out ]; then + mkdir out +fi +cd out || exit +if [ $MS_LITE_HOME ];then + MINDSPORE_PATH=$MS_LITE_HOME/runtime +else + MINDSPORE_PATH="`pip show mindspore-ascend | grep Location | awk '{print $2"/mindspore"}' | xargs realpath`" + if [[ ! $MINDSPORE_PATH ]];then + MINDSPORE_PATH="`pip show mindspore | grep Location | awk '{print $2"/mindspore"}' | xargs realpath`" + fi +fi +cmake .. -DMINDSPORE_PATH=$MINDSPORE_PATH +make diff --git a/community/cv/ADCAM/cpp_infer/src/main.cc b/community/cv/ADCAM/cpp_infer/src/main.cc new file mode 100644 index 0000000000000000000000000000000000000000..61c96deeed4ab5a1ef361f1dd660f1418e9ea12d --- /dev/null +++ b/community/cv/ADCAM/cpp_infer/src/main.cc @@ -0,0 +1,113 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common_inc/infer.h" + +DEFINE_string(mindir_path, "", "mindir path"); +DEFINE_string(dataset_path, ".", "dataset path"); +DEFINE_int32(device_id, 0, "device id"); +DEFINE_string(device_type, "CPU", "device type"); +DEFINE_int32(image_height, 640, "image height"); +DEFINE_int32(image_width, 640, "image width"); + +int main(int argc, char **argv) { + if (!ParseCommandLineFlags(argc, argv)) { + std::cout << "Failed to parse args" << std::endl; + return 1; + } + if (RealPath(FLAGS_mindir_path).empty()) { + std::cout << "Invalid mindir" << std::endl; + return 1; + } + + auto ascend310 = std::make_shared(); + ascend310->SetDeviceID(FLAGS_device_id); + ascend310->SetPrecisionMode("preferred_fp32"); + ascend310->SetOpSelectImplMode("high_precision"); + ascend310->SetBufferOptimizeMode("off_optimize"); + mindspore::Model model; + if (!LoadModel(FLAGS_mindir_path, FLAGS_device_type, FLAGS_device_id, ascend310, &model)) { + std::cout << "Failed to load model " << FLAGS_mindir_path << ", device id: " << FLAGS_device_id + << ", device type: " << FLAGS_device_type; + return 1; + } + Status ret; + + auto all_files = GetAllFiles(FLAGS_dataset_path); + std::map costTime_map; + size_t size = all_files.size(); + std::shared_ptr decode(new Decode()); + auto resize = Resize({FLAGS_image_height, FLAGS_image_width}); + Execute composeDecode({decode}); + + for (size_t i = 0; i < size; ++i) { + struct timeval start = {0}; + struct timeval end = {0}; + double startTimeMs; + double endTimeMs; + std::vector inputs; + std::vector outputs; + auto imgDecode = MSTensor(); + auto img = MSTensor(); + composeDecode(ReadFileToTensor(all_files[i]), &imgDecode); + std::vector shape = imgDecode.Shape(); + + if ((static_cast(shape[0]) < static_cast(FLAGS_image_height)) && + (static_cast(shape[1]) < static_cast(FLAGS_image_width))) { + resize = Resize({FLAGS_image_height, FLAGS_image_width}, InterpolationMode::kCubic); + } else if ((static_cast(shape[0]) > static_cast(FLAGS_image_height)) && + (static_cast(shape[1]) > static_cast(FLAGS_image_width))) { + resize = Resize({FLAGS_image_height, FLAGS_image_width}, InterpolationMode::kNearestNeighbour); + } else { + resize = Resize({FLAGS_image_height, FLAGS_image_width}, InterpolationMode::kLinear); + } + if ((sizeof(shape) / sizeof(shape[0])) <= 2) { + std::cout << "image channels is not 3." << std::endl; + return 1; + } + Execute transform(resize); + transform(imgDecode, &img); + + std::vector model_inputs = model.GetInputs(); + inputs.emplace_back(model_inputs[0].Name(), model_inputs[0].DataType(), model_inputs[0].Shape(), + img.Data().get(), img.DataSize()); + gettimeofday(&start, nullptr); + ret = model.Predict(inputs, &outputs); + gettimeofday(&end, nullptr); + if (ret != kSuccess) { + std::cout << "Predict " << all_files[i] << " failed." << std::endl; + return 1; + } + startTimeMs = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; + endTimeMs = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; + costTime_map.insert(std::pair(startTimeMs, endTimeMs)); + WriteResult(all_files[i], outputs); + } + double average = 0.0; + int inferCount = 0; + + for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { + double diff = iter->second - iter->first; + average += diff; + inferCount++; + } + average = average / inferCount; + std::stringstream timeCost; + timeCost << "NN inference cost average time: " << average << " ms of infer_count " << inferCount << std::endl; + std::cout << "NN inference cost average time: " << average << "ms of infer_count " << inferCount << std::endl; + std::string fileName = "./time_Result" + std::string("/test_perform_static.txt"); + std::ofstream fileStream(fileName.c_str(), std::ios::trunc); + fileStream << timeCost.str(); + fileStream.close(); + costTime_map.clear(); + return 0; +} diff --git a/community/cv/ADCAM/default_config.yaml b/community/cv/ADCAM/default_config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..055af1908e3682ebe232850f28c3cef41bd7bb55 --- /dev/null +++ b/community/cv/ADCAM/default_config.yaml @@ -0,0 +1,225 @@ +# 内置配置文件 +enable_modelarts: False +# 本地路径 +data_path: "/cache/data" +output_path: "/cache/train" +load_path: "/cache/checkpoint_path" +device_target: "Ascend" +need_modelarts_dataset_unzip: True +modelarts_dataset_unzip_name: "coco" + +# ============================================================================== +# 训练数据的配置 +data_dir: "/data/coco" +per_batch_size: 16 +yolov5_version: "yolov5s" +pretrained_backbone: "" +resume_yolov5: "" +pretrained_checkpoint: "" +output_dir: "./output" +train_img_dir: "train2017" +train_ann_file: "annotations/instances_train2017.json" + +lr_scheduler: "cosine_annealing" +lr: 0.01 +lr_epochs: "220,250" +lr_gamma: 0.1 +eta_min: 0.0 +T_max: 320 # 当在单个处理器上运行时,设置为320 +max_epoch: 300 # 当在单个处理器上运行时,设置为300 +warmup_epochs: 20 # 当在单个处理器上运行时,设置为4 +weight_decay: 0.0005 +momentum: 0.9 +loss_scale: 1024 +label_smooth: 0 +label_smooth_factor: 0.1 +log_interval: 100 +ckpt_path: "outputs/" +is_distributed: 0 +bind_cpu: True +device_num: 8 +rank: 0 +group_size: 1 +need_profiler: 0 +resize_rate: 10 +filter_weight: False +save_ckpt_interval: 1 +save_ckpt_max_num: 10 + +# 推理过程中的配置 +pretrained: "" +log_path: "outputs/" +ann_val_file: "" +eval_nms_thresh: 0.6 +ignore_threshold: 0.7 +test_ignore_threshold: 0.001 +multi_label: True +multi_label_thresh: 0.1 + +save_prefix: "../eval_parallel" +run_eval: True +eval_epoch_interval: 10 +eval_start_epoch: 100 +eval_parallel: True +val_img_dir: "val2017" +val_ann_file: "annotations/instances_val2017.json" + +# 导出选项 +batch_size: 1 +testing_shape: [640, 640] +ckpt_file: "" +file_name: "yolov5" +file_format: "MINDIR" +dataset_path: "" +ann_file: "" + + +# 其他默认配置 +hue: 0.015 +saturation: 1.5 +value: 0.4 +jitter: 0.3 + +num_classes: 102 +# num_classes: 80 +max_box: 150 +checkpoint_filter_list: ['feature_map.back_block1.conv.weight', 'feature_map.back_block1.conv.bias', + 'feature_map.back_block2.conv.weight', 'feature_map.back_block2.conv.bias', + 'feature_map.back_block3.conv.weight', 'feature_map.back_block3.conv.bias'] + +# h->w +anchor_scales: [[12, 16], + [19, 36], + [40, 28], + [36, 75], + [76, 55], + [72, 146], + [142, 110], + [192, 243], + [459, 401]] + +out_channel: 255 # 3 * (num_classes + 5) + +input_shape: [[3, 32, 64, 128, 256, 512, 1], + [3, 48, 96, 192, 384, 768, 2], + [3, 64, 128, 256, 512, 1024, 3], + [3, 80, 160, 320, 640, 1280, 4]] + +# 测试参数 +test_img_shape: [640, 640] + +# labels: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', +# 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', +# 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', +# 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', +# 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', +# 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', +# 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', +# 'couch', 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', +# 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', +# 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush' ] + +labels: [ 'rice leaf roller', 'rice leaf caterpillar', 'paddy stem maggot', 'asiatic rice borer', + 'yellow rice borer', 'rice gall midge', 'Rice Stemfly', 'brown plant hopper', + 'white backed plant hopper', 'small brown plant hopper', 'rice water weevil', + 'rice leafhopper', 'grain spreader thrips', 'rice shell pest', 'grub', 'mole cricket', + 'wireworm', 'white margined moth', 'black cutworm', 'large cutworm', 'yellow cutworm', + 'red spider', 'corn borer', 'army worm', 'aphids', 'Potosiabre vitarsis', 'peach borer', + 'english grain aphid', 'green bug', 'bird cherry-oataphid', 'wheat blossom midge', + 'penthaleus major', 'longlegged spider mite', 'wheat phloeothrips', 'wheat sawfly', + 'cerodonta denticornis', 'beet fly', 'flea beetle', 'cabbage army worm', + 'beet army worm', 'Beet spot flies', 'meadow moth', 'beet weevil', + 'sericaorient alismots chulsky', 'alfalfa weevil', 'flax budworm', + 'alfalfa plant bug', 'tarnished plant bug', 'Locustoidea', 'lytta polita', + 'legume blister beetle', 'blister beetle', 'therioaphis maculata Buckton', + 'odontothrips loti', 'Thrips', 'alfalfa seed chalcid', 'Pieris canidia', + 'Apolygus lucorum', 'Limacodidae', 'Viteus vitifoliae', 'Colomerus vitis', + 'Brevipoalpus lewisi McGregor', 'oides decempunctata', 'Polyphagotars onemus latus', + 'Pseudococcus comstocki Kuwana', 'parathrene regalis', 'Ampelophaga', + 'Lycorma delicatula', 'Xylotrechus', 'Cicadella viridis', 'Miridae', + 'Trialeurodes vaporariorum', 'Erythroneura apicalis', 'Papilio xuthus', + 'Panonchus citri McGregor', 'Phyllocoptes oleiverus ashmead', 'Icerya purchasi Maskell', + 'Unaspis yanonensis', 'Ceroplastes rubens', 'Chrysomphalus aonidum', + 'Parlatoria zizyphus Lucus', 'Nipaecoccus vastalor', 'Aleurocanthus spiniferus', + 'Tetradacus c Bactrocera minax', 'Dacus dorsalis(Hendel)', 'Bactrocera tsuneonis', + 'Prodenia litura', 'Adristyrannus', 'Phyllocnistis citrella Stainton', + 'Toxoptera citricidus', 'Toxoptera aurantii', 'Aphis citricola Vander Goot', + 'Scirtothrips dorsalis Hood', 'Dasineura sp', 'Lawana imitata Melichar', + 'Salurnis marginella Guerr', 'Deporaus marginatus Pascoe', 'Chlumetia transversa', + 'Mango flat beak leafhopper', 'Rhytidodera bowrinii white', 'Sternochetus frigidus', + 'Cicadellidae' ] + + +# coco_ids: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, +# 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, +# 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, +# 81, 82, 84, 85, 86, 87, 88, 89, 90 ] +coco_ids: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, + 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101] + +result_files: './result_Files' + +--- + +# # 每种配置的帮助说明 +# # 训练选项 +# data_dir: "Train dataset directory." +# per_batch_size: "Batch size for Training." +# pretrained_backbone: "The ckpt file of CspDarkNet53." +# resume_yolov5: "The ckpt file of YOLOv5, which used to fine tune." +# pretrained_checkpoint: "The ckpt file of YOLOv5CspDarkNet53." +# lr_scheduler: "Learning rate scheduler, options: exponential, cosine_annealing." +# lr: "Learning rate." +# lr_epochs: "Epoch of changing of lr changing, split with ','." +# lr_gamma: "Decrease lr by a factor of exponential lr_scheduler." +# eta_min: "Eta_min in cosine_annealing scheduler." +# T_max: "T-max in cosine_annealing scheduler." +# max_epoch: "Max epoch num to train the model." +# warmup_epochs: "Warmup epochs." +# weight_decay: "Weight decay factor." +# momentum: "Momentum." +# loss_scale: "Static loss scale." +# label_smooth: "Whether to use label smooth in CE." +# label_smooth_factor: "Smooth strength of original one-hot." +# log_interval: "Logging interval steps." +# ckpt_path: "Checkpoint save location." +# ckpt_interval: "Save checkpoint interval." +# is_save_on_master: "Save ckpt on master or all rank, 1 for master, 0 for all ranks." +# is_distributed: "Distribute train or not, 1 for yes, 0 for no." +# bind_cpu: "Whether bind cpu when distributed training." +# device_num: "Device numbers per server" +# rank: "Local rank of distributed." +# group_size: "World size of device." +# need_profiler: "Whether use profiler. 0 for no, 1 for yes." +# resize_rate: "Resize rate for multi-scale training." +# ann_file: "path to annotation" +# each_multiscale: "Apply multi-scale for each scale" +# labels: "the label of train data" +# multi_label: "use multi label to nms" +# multi_label_thresh: "multi label thresh" +# train_img_dir: "relative path of training image directory to data_dir" +# train_ann_file: "relative path of training annotation file to data_dir" + +# # 评估参数 +# pretrained: "model_path, local pretrained model to load" +# log_path: "checkpoint save location" +# save_prefix: "../eval_parallel" +# run_eval: "Whether enable validation after a training epoch" +# eval_epoch_interval: "Epoch interval to do validation" +# eval_start_epoch: "After which epoch, start to do validatation" +# eval_parallel: "Whether enable parallel evaluation to accelerate the validataion process" +# val_img_dir: "relative path of validation image directory to data_dir" +# val_ann_file: "relative path of validataion annotation file to data_dir" + + +# # 导出选项 +# device_id: "Device id for export" +# batch_size: "batch size for export" +# testing_shape: "shape for test" +# ckpt_file: "Checkpoint file path for export" +# file_name: "output file name for export" +# file_format: "file format for export" +# result_files: 'path to 310 infer result floder' diff --git a/community/cv/ADCAM/eval.py b/community/cv/ADCAM/eval.py new file mode 100644 index 0000000000000000000000000000000000000000..e89b2afb9c1a275b5eda8b6d3f69b877c9c11e10 --- /dev/null +++ b/community/cv/ADCAM/eval.py @@ -0,0 +1,95 @@ +# YoloV5的评估脚本 +import os +import time +import shutil + +import mindspore +from mindspore import ParallelMode +from mindspore.communication.management import init, get_group_size, get_rank + +from src.yolo import YOLOV5 +from src.logger import get_logger +from src.util import DetectionEngine, EvalWrapper +from src.yolo_dataset import create_yolo_dataset + +from model_utils.config import config +from model_utils.moxing_adapter import moxing_wrapper, modelarts_pre_process + + +def eval_preprocess(): + config.val_img_dir = os.path.join(config.data_dir, config.val_img_dir) + config.val_ann_file = os.path.join(config.data_dir, config.val_ann_file) + device_id = int(os.getenv('DEVICE_ID', '0')) + mindspore.set_context(mode=0, device_target=config.device_target, device_id=device_id) + parallel_mode = ParallelMode.STAND_ALONE + config.eval_parallel = config.is_distributed and config.eval_parallel + device_num = 1 + if config.eval_parallel: + init() + config.rank = get_rank() + config.group_size = get_group_size() + device_num = get_group_size() + parallel_mode = ParallelMode.DATA_PARALLEL + mindspore.reset_auto_parallel_context() + mindspore.set_auto_parallel_context(parallel_mode=parallel_mode, gradients_mean=True, device_num=device_num) + + config.logger = get_logger(config.output_dir, device_id) + + +def load_parameters(network, filename): + config.logger.info("yolov5 pretrained network model: %s", filename) + param_dict = mindspore.load_checkpoint(filename) + param_dict_new = {} + for key, values in param_dict.items(): + if key.startswith('moments.'): + continue + elif key.startswith('yolo_network.'): + param_dict_new[key[13:]] = values + else: + param_dict_new[key] = values + mindspore.load_param_into_net(network, param_dict_new) + config.logger.info('load_model %s success', filename) + + +@moxing_wrapper(pre_process=modelarts_pre_process, pre_args=[config]) +def run_eval(): + eval_preprocess() + start_time = time.time() + config.logger.info('Creating Network....') + dict_version = {'yolov5s': 0, 'yolov5m': 1, 'yolov5l': 2, 'yolov5x': 3} + network = YOLOV5(is_training=False, version=dict_version[config.yolov5_version]) + + if os.path.isfile(config.pretrained): + load_parameters(network, config.pretrained) + else: + raise FileNotFoundError(f"{config.pretrained} is not a filename.") + rank_id = int(os.getenv('RANK_ID', '0')) + if config.eval_parallel: + rank_id = get_rank() + ds = create_yolo_dataset(config.val_img_dir, config.val_ann_file, is_training=False, + batch_size=config.per_batch_size, device_num=config.group_size, + rank=rank_id, shuffle=False, config=config) + + config.logger.info('testing shape : %s', config.test_img_shape) + config.logger.info('total %d images to eval', ds.get_dataset_size() * config.per_batch_size) + + network.set_train(False) + + detection = DetectionEngine(config, config.test_ignore_threshold) + if config.eval_parallel: + if os.path.exists(config.save_prefix): + shutil.rmtree(config.save_prefix, ignore_errors=True) + + config.logger.info('Start inference....') + eval_wrapper = EvalWrapper(config, network, ds, detection) + eval_wrapper.inference() + eval_result, _ = eval_wrapper.get_results() + + cost_time = time.time() - start_time + eval_log_string = '\n=============coco eval result=========\n' + eval_result + config.logger.info(eval_log_string) + config.logger.info('testing cost time %.2f h', cost_time / 3600.) + + +if __name__ == "__main__": + run_eval() diff --git a/community/cv/ADCAM/fusion_result.json b/community/cv/ADCAM/fusion_result.json new file mode 100644 index 0000000000000000000000000000000000000000..23dcbbe9e44730f0ad51860afce5adafbaf8134c --- /dev/null +++ b/community/cv/ADCAM/fusion_result.json @@ -0,0 +1,132 @@ +[{ + "graph_fusion": { + "AABiasaddConvFusion": { + "effect_times": "0", + "match_times": "12" + }, + "AReduceMeanFusionPass": { + "effect_times": "0", + "match_times": "6" + }, + "ARefreshCubeC0FusionPass": { + "effect_times": "71", + "match_times": "71" + }, + "CastRemoveFusionPass": { + "effect_times": "0", + "match_times": "1" + }, + "ConstToAttrPass": { + "effect_times": "16", + "match_times": "18" + }, + "ConstToAttrStridedSliceFusion": { + "effect_times": "22", + "match_times": "22" + }, + "ConvConcatFusionPass": { + "effect_times": "0", + "match_times": "20" + }, + "ConvFormatRefreshFusionPass": { + "effect_times": "0", + "match_times": "71" + }, + "ConvToFullyConnectionFusionPass": { + "effect_times": "0", + "match_times": "71" + }, + "ConvWeightCompressFusionPass": { + "effect_times": "0", + "match_times": "71" + }, + "CubeTransFixpipeFusionPass": { + "effect_times": "71", + "match_times": "71" + }, + "FIXPIPEAPREQUANTFUSIONPASS": { + "effect_times": "0", + "match_times": "71" + }, + "FIXPIPEFUSIONPASS": { + "effect_times": "0", + "match_times": "71" + }, + "ForceFp16CastFusionPass": { + "effect_times": "0", + "match_times": "1" + }, + "MulAddFusionPass": { + "effect_times": "0", + "match_times": "17" + }, + "MulSquareFusionPass": { + "effect_times": "0", + "match_times": "74" + }, + "RealDiv2MulsFusionPass": { + "effect_times": "0", + "match_times": "7" + }, + "RefreshInt64ToInt32FusionPass": { + "effect_times": "1", + "match_times": "1" + }, + "RemoveCastFusionPass": { + "effect_times": "0", + "match_times": "1" + }, + "ReshapeTransposeFusionPass": { + "effect_times": "0", + "match_times": "3" + }, + "SplitConvConcatFusionPass": { + "effect_times": "0", + "match_times": "20" + }, + "StridedSliceRemovePass": { + "effect_times": "0", + "match_times": "22" + }, + "SubFusionPass": { + "effect_times": "0", + "match_times": "4" + }, + "TileConstToAttrFusion": { + "effect_times": "6", + "match_times": "6" + }, + "TransdataCastFusionPass": { + "effect_times": "0", + "match_times": "223" + }, + "TransdataFz2FzgFusionPass": { + "effect_times": "0", + "match_times": "211" + }, + "TransdataFzg2FzFusionPass": { + "effect_times": "0", + "match_times": "211" + }, + "TransposedUpdateFusionPass": { + "effect_times": "10", + "match_times": "10" + }, + "ZConcatDFusionPass": { + "effect_times": "0", + "match_times": "20" + }, + "ZConcatFusionPass": { + "effect_times": "20", + "match_times": "20" + } + }, + "session_and_graph_id": "0_1", + "ub_fusion": { + "AutomaticUbFusion": { + "effect_times": "78", + "match_times": "78", + "repository_hit_times": "0" + } + } +}] \ No newline at end of file diff --git a/community/cv/ADCAM/infer/Dockerfile b/community/cv/ADCAM/infer/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..360861ede17fb0ab697fbcac190acde7c1e29fef --- /dev/null +++ b/community/cv/ADCAM/infer/Dockerfile @@ -0,0 +1,5 @@ +ARG FROM_IMAGE_NAME +FROM ${FROM_IMAGE_NAME} + +COPY requirements.txt . +RUN pip3.7 install -r requirements.txt diff --git a/community/cv/ADCAM/infer/convert/atc_model_convert.sh b/community/cv/ADCAM/infer/convert/atc_model_convert.sh new file mode 100644 index 0000000000000000000000000000000000000000..68b5ebe32719d5b518f7589023a9bdd11542e04d --- /dev/null +++ b/community/cv/ADCAM/infer/convert/atc_model_convert.sh @@ -0,0 +1,13 @@ +model_path=../data/models/yolov5.air +output_model_name=../data/models/yolov5 + +atc --framework=1 \ + --model="${model_path}" \ + --input_shape="actual_input_1:1,12,320,320" \ + --output="${output_model_name}" \ + --enable_small_channel=1 \ + --log=error \ + --soc_version=Ascend310 \ + --op_select_implmode=high_precision \ + --output_type=FP32 +exit 0 diff --git a/community/cv/ADCAM/infer/data/models/coco2017.names b/community/cv/ADCAM/infer/data/models/coco2017.names new file mode 100644 index 0000000000000000000000000000000000000000..1db41f581a4b1b54086cfc44f81a192b262ad63c --- /dev/null +++ b/community/cv/ADCAM/infer/data/models/coco2017.names @@ -0,0 +1,81 @@ +# This file is originally from https://github.com/pjreddie/darknet/blob/master/data/coco.names +person +bicycle +car +motorbike +aeroplane +bus +train +truck +boat +traffic light +fire hydrant +stop sign +parking meter +bench +bird +cat +dog +horse +sheep +cow +elephant +bear +zebra +giraffe +backpack +umbrella +handbag +tie +suitcase +frisbee +skis +snowboard +sports ball +kite +baseball bat +baseball glove +skateboard +surfboard +tennis racket +bottle +wine glass +cup +fork +knife +spoon +bowl +banana +apple +sandwich +orange +broccoli +carrot +hot dog +pizza +donut +cake +chair +sofa +pottedplant +bed +diningtable +toilet +tvmonitor +laptop +mouse +remote +keyboard +cell phone +microwave +oven +toaster +sink +refrigerator +book +clock +vase +scissors +teddy bear +hair drier +toothbrush diff --git a/community/cv/ADCAM/infer/data/models/yolov5.cfg b/community/cv/ADCAM/infer/data/models/yolov5.cfg new file mode 100644 index 0000000000000000000000000000000000000000..45773713c37648c9de4a25c610350f6eaee7f8a9 --- /dev/null +++ b/community/cv/ADCAM/infer/data/models/yolov5.cfg @@ -0,0 +1,10 @@ +CLASS_NUM=80 +BIASES_NUM=18 +BIASES=10,13,16,30,33,23,30,61,62,45,59,119,116,90,156,198,373,326 +SCORE_THRESH=0.001 +OBJECTNESS_THRESH=0.001 +IOU_THRESH=0.6 +YOLO_TYPE=3 +ANCHOR_DIM=3 +MODEL_TYPE=0 + diff --git a/community/cv/ADCAM/infer/docker_start_infer.sh b/community/cv/ADCAM/infer/docker_start_infer.sh new file mode 100644 index 0000000000000000000000000000000000000000..95b80965facfcf209f78e4813034566df7ae988f --- /dev/null +++ b/community/cv/ADCAM/infer/docker_start_infer.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +docker_image=$1 +data_dir=$2 + +function show_help() { + echo "Usage: docker_start.sh docker_image data_dir" +} + +function param_check() { + if [ -z "${docker_image}" ]; then + echo "please input docker_image" + show_help + exit 1 + fi + + if [ -z "${data_dir}" ]; then + echo "please input data_dir" + show_help + exit 1 + fi +} + +param_check + +docker run -it \ + --device=/dev/davinci0 \ + --device=/dev/davinci_manager \ + --device=/dev/devmm_svm \ + --device=/dev/hisi_hdc \ + -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ + -v ${data_dir}:${data_dir} \ + ${docker_image} \ + /bin/bash diff --git a/community/cv/ADCAM/infer/mxbase/CMakeLists.txt b/community/cv/ADCAM/infer/mxbase/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..86df663487d3ab2fa1719bc0782b7f34b98f1f41 --- /dev/null +++ b/community/cv/ADCAM/infer/mxbase/CMakeLists.txt @@ -0,0 +1,52 @@ +cmake_minimum_required(VERSION 3.5.2) +SET(CMAKE_BUILD_TYPE "Debug") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") +SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb") +SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall") +project(yolov5) +add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) + +set(TARGET_LIBRARY yolov5postprocessor) +set(TARGET_MAIN yolov5) + +set(ACL_LIB_PATH $ENV{ASCEND_HOME}/ascend-toolkit/latest/acllib) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +include_directories($ENV{MX_SDK_HOME}/include) +include_directories($ENV{MX_SDK_HOME}/opensource/include) +include_directories($ENV{MX_SDK_HOME}/opensource/include/opencv4) +include_directories($ENV{MX_SDK_HOME}/opensource/include/gstreamer-1.0) +include_directories($ENV{MX_SDK_HOME}/opensource/include/glib-2.0) +include_directories($ENV{MX_SDK_HOME}/opensource/lib/glib-2.0/include) +include_directories($ENV{MX_SDK_HOME}/ascend-toolkit/latest/include) + +link_directories($ENV{MX_SDK_HOME}/lib) +link_directories($ENV{MX_SDK_HOME}/opensource/lib/) + +add_compile_options(-std=c++11 -fPIC -fstack-protector-all -pie -Wno-deprecated-declarations) +add_compile_options("-DPLUGIN_NAME=${PLUGIN_NAME}") +add_compile_options("-Dgoogle=mindxsdk_private") + +add_definitions(-DENABLE_DVPP_INTERFACE) + +include_directories(${ACL_LIB_PATH}/include) +link_directories(${ACL_LIB_PATH}/lib64/) + +add_compile_options(-std=c++11 -fPIC -fstack-protector-all -pie -Wno-deprecated-declarations) +add_compile_options("-DPLUGIN_NAME=${PLUGIN_NAME}") +add_compile_options("-Dgoogle=mindxsdk_private") + +add_library(${TARGET_LIBRARY} SHARED src/PostProcess/Yolov5MindSporePost.cpp) + +target_link_libraries(${TARGET_LIBRARY} glib-2.0 gstreamer-1.0 gobject-2.0 gstbase-1.0 gmodule-2.0) +target_link_libraries(${TARGET_LIBRARY} plugintoolkit mxpidatatype mxbase) +target_link_libraries(${TARGET_LIBRARY} -Wl,-z,relro,-z,now,-z,noexecstack) + +message("TARGET_LIBRARY:${TARGET_LIBRARY}.") + +add_executable(${TARGET_MAIN} src/main.cpp src/Yolov5Detection.cpp) +target_link_libraries(${TARGET_MAIN} glog cpprest mxbase libascendcl.so + libruntime.so libopencv_world.so.4.3 opencv_world) +target_link_libraries(${TARGET_MAIN} ${TARGET_LIBRARY} glog cpprest mxbase libascendcl.so + libruntime.so libopencv_world.so.4.3 opencv_world) diff --git a/community/cv/ADCAM/infer/mxbase/build.sh b/community/cv/ADCAM/infer/mxbase/build.sh new file mode 100644 index 0000000000000000000000000000000000000000..8e46b9eef73ed10140fecb147c73af5c6d22cb8e --- /dev/null +++ b/community/cv/ADCAM/infer/mxbase/build.sh @@ -0,0 +1,47 @@ +#!/bin/bash +path_cur=$(dirname $0) + +function check_env() +{ + # set ASCEND_VERSION to ascend-toolkit/latest when it was not specified by user + if [ ! "${ASCEND_HOME}" ]; then + export ASCEND_HOME=/usr/local/Ascend/ + echo "Set ASCEND_HOME to the default value: ${ASCEND_HOME}" + else + echo "ASCEND_HOME is set to ${ASCEND_HOME} by user" + fi + + if [ ! "${ASCEND_VERSION}" ]; then + export ASCEND_VERSION=nnrt/latest + echo "Set ASCEND_VERSION to the default value: ${ASCEND_VERSION}" + else + echo "ASCEND_VERSION is set to ${ASCEND_VERSION} by user" + fi + + if [ ! "${ARCH_PATTERN}" ]; then + # set ARCH_PATTERN to ./ when it was not specified by user + export ARCH_PATTERN=./ + echo "ARCH_PATTERN is set to the default value: ${ARCH_PATTERN}" + else + echo "ARCH_PATTERN is set to ${ARCH_PATTERN} by user" + fi +} + +function build_east() +{ + cd $path_cur + rm -rf build + mkdir -p build + cd build + cmake .. + make + ret=$? + if [ ${ret} -ne 0 ]; then + echo "Failed to build east." + exit ${ret} + fi + make install +} + +check_env +build_east diff --git a/community/cv/ADCAM/infer/mxbase/src/PostProcess/Yolov5MindSporePost.cpp b/community/cv/ADCAM/infer/mxbase/src/PostProcess/Yolov5MindSporePost.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bc9c6eb54d20c2296b5485b308efed945a903f97 --- /dev/null +++ b/community/cv/ADCAM/infer/mxbase/src/PostProcess/Yolov5MindSporePost.cpp @@ -0,0 +1,276 @@ + +#include "Yolov5MindSporePost.h" +#include +#include +#include +#include "MxBase/Log/Log.h" +#include "MxBase/CV/ObjectDetection/Nms/Nms.h" + +namespace { + const int SCALE = 32; + const int BIASESDIM = 2; + const int OFFSETWIDTH = 2; + const int OFFSETHEIGHT = 3; + const int OFFSETBIASES = 1; + const int OFFSETOBJECTNESS = 1; + + const int NHWC_HEIGHTINDEX = 1; + const int NHWC_WIDTHINDEX = 2; + const int NCHW_HEIGHTINDEX = 2; + const int NCHW_WIDTHINDEX = 3; + const int YOLO_INFO_DIM = 5; + + auto uint8Deleter = [] (uint8_t* p) { }; +} // namespace + +namespace localParameter { + const uint32_t VECTOR_FIRST_INDEX = 0; + const uint32_t VECTOR_SECOND_INDEX = 1; + const uint32_t VECTOR_THIRD_INDEX = 2; + const uint32_t VECTOR_FOURTH_INDEX = 3; + const uint32_t VECTOR_FIFTH_INDEX = 4; +} + +namespace MxBase { + Yolov5PostProcess& Yolov5PostProcess::operator=(const Yolov5PostProcess &other) { + if (this == &other) { + return *this; + } + ObjectPostProcessBase::operator=(other); + objectnessThresh_ = other.objectnessThresh_; // Threshold of objectness value + iouThresh_ = other.iouThresh_; + anchorDim_ = other.anchorDim_; + biasesNum_ = other.biasesNum_; + yoloType_ = other.yoloType_; + modelType_ = other.modelType_; + inputType_ = other.inputType_; + biases_ = other.biases_; + return *this; + } + + APP_ERROR Yolov5PostProcess::Init(const std::map>& postConfig) { + LogDebug << "Start to Init Yolov5PostProcess."; + APP_ERROR ret = ObjectPostProcessBase::Init(postConfig); + if (ret != APP_ERR_OK) { + LogError << GetError(ret) << "Fail to superInit in ObjectPostProcessBase."; + return ret; + } + + configData_.GetFileValue("BIASES_NUM", biasesNum_); + std::string str; + configData_.GetFileValue("BIASES", str); + configData_.GetFileValue("OBJECTNESS_THRESH", objectnessThresh_); + configData_.GetFileValue("IOU_THRESH", iouThresh_); + configData_.GetFileValue("YOLO_TYPE", yoloType_); + configData_.GetFileValue("MODEL_TYPE", modelType_); + configData_.GetFileValue("YOLO_VERSION", yoloVersion_); + configData_.GetFileValue("INPUT_TYPE", inputType_); + configData_.GetFileValue("ANCHOR_DIM", anchorDim_); + ret = GetBiases(&str); + if (ret != APP_ERR_OK) { + LogError << GetError(ret) << "Failed to get biases."; + return ret; + } + LogDebug << "End to Init Yolov5PostProcess."; + return APP_ERR_OK; + } + + APP_ERROR Yolov5PostProcess::DeInit() { + return APP_ERR_OK; + } + + bool Yolov5PostProcess::IsValidTensors(const std::vector &tensors) const { + if (tensors.size() != (size_t)yoloType_) { + LogError << "number of tensors (" << tensors.size() << ") " << "is unequal to yoloType_(" + << yoloType_ << ")"; + return false; + } + if (yoloVersion_ == YOLOV5_VERSION) { + for (size_t i = 0; i < tensors.size(); i++) { + auto shape = tensors[i].GetShape(); + if (shape.size() < localParameter::VECTOR_FIFTH_INDEX) { + LogError << "dimensions of tensor [" << i << "] is less than " << + localParameter::VECTOR_FIFTH_INDEX << "."; + return false; + } + uint32_t channelNumber = 1; + int startIndex = modelType_ ? localParameter::VECTOR_SECOND_INDEX : localParameter::VECTOR_FOURTH_INDEX; + int endIndex = modelType_ ? (shape.size() - localParameter::VECTOR_THIRD_INDEX) : shape.size(); + for (int j = startIndex; j < endIndex; j++) { + channelNumber *= shape[j]; + } + if (channelNumber != anchorDim_ * (classNum_ + YOLO_INFO_DIM)) { + LogError << "channelNumber(" << channelNumber << ") != anchorDim_ * (classNum_ + 5)."; + return false; + } + } + } + return true; + } + + void Yolov5PostProcess::ObjectDetectionOutput(const std::vector& tensors, + std::vector> *objectInfos, + const std::vector& resizedImageInfos) { + LogDebug << "Yolov5PostProcess start to write results."; + if (tensors.size() == 0) { + return; + } + auto shape = tensors[0].GetShape(); + if (shape.size() == 0) { + return; + } + uint32_t batchSize = shape[0]; + for (uint32_t i = 0; i < batchSize; i++) { + std::vector> featLayerData = {}; + std::vector> featLayerShapes = {}; + for (uint32_t j = 0; j < tensors.size(); j++) { + auto dataPtr = reinterpret_cast (tensors[j].GetBuffer()) + + i * tensors[j].GetByteSize() / batchSize; + std::shared_ptr tmpPointer; + tmpPointer.reset(dataPtr, uint8Deleter); + featLayerData.push_back(tmpPointer); + shape = tensors[j].GetShape(); + std::vector featLayerShape(shape.size()); + transform(shape.begin(), shape.end(), featLayerShape.begin(), [](uint32_t s) { return (size_t)s; }); + featLayerShapes.push_back(featLayerShape); + } + std::vector objectInfo; + GenerateBbox(featLayerData, &objectInfo, featLayerShapes, resizedImageInfos[i].widthResize, + resizedImageInfos[i].heightResize); + MxBase::NmsSort(objectInfo, iouThresh_); + objectInfos->push_back(objectInfo); + } + LogDebug << "Yolov5PostProcess write results success."; + } + + APP_ERROR Yolov5PostProcess::Process(const std::vector &tensors, + std::vector> &objectInfos, + const std::vector &resizedImageInfos, + const std::map> &configParamMap) { + LogDebug << "Start to Process Yolov5PostProcess."; + APP_ERROR ret = APP_ERR_OK; + auto inputs = tensors; + ret = CheckAndMoveTensors(inputs); + if (ret != APP_ERR_OK) { + LogError << "CheckAndMoveTensors failed. ret=" << ret; + return ret; + } + + ObjectDetectionOutput(inputs, &objectInfos, resizedImageInfos); + + for (uint32_t i = 0; i < resizedImageInfos.size(); i++) { + CoordinatesReduction(i, resizedImageInfos[i], objectInfos[i]); + } + LogObjectInfos(objectInfos); + LogDebug << "End to Process Yolov5PostProcess."; + return APP_ERR_OK; + } + + void Yolov5PostProcess::CompareProb(int *classID, float *maxProb, float classProb, int classNum) { + if (classProb > (*maxProb)) { + (*maxProb) = classProb; + (*classID) = classNum; + } + } + + void Yolov5PostProcess::SelectClassNHWC(std::shared_ptr netout, NetInfo info, + std::vector *detBoxes, int stride) { + const int offsetY = 1; + for (int j = 0; j < stride; ++j) { + for (int k = 0; k < info.anchorDim; ++k) { + int bIdx = (info.bboxDim + 1 + info.classNum) * info.anchorDim * j + + k * (info.bboxDim + 1 + info.classNum); + int oIdx = bIdx + info.bboxDim; // objectness index + float objectness = static_cast(netout.get())[oIdx]; + if (objectness < objectnessThresh_) { + continue; + } + int classID = -1; + float maxProb = scoreThresh_; + for (int c = 0; c < info.classNum; ++c) { + float clsProb = static_cast(netout.get())[bIdx + (info.bboxDim + + OFFSETOBJECTNESS + c)] * objectness; + CompareProb(&classID, &maxProb, clsProb, c); + } + if (classID < 0) continue; + MxBase::ObjectInfo det; + float x = static_cast(netout.get())[bIdx]; + float y = static_cast(netout.get())[bIdx + offsetY]; + float width = static_cast(netout.get())[bIdx + OFFSETWIDTH]; + float height = static_cast(netout.get())[bIdx + OFFSETHEIGHT]; + det.x0 = std::max(0.0f, x - width / COORDINATE_PARAM); + det.x1 = std::min(1.0f, x + width / COORDINATE_PARAM); + det.y0 = std::max(0.0f, y - height / COORDINATE_PARAM); + det.y1 = std::min(1.0f, y + height / COORDINATE_PARAM); + det.classId = classID; + det.className = configData_.GetClassName(classID); + det.confidence = maxProb; + if (det.confidence < separateScoreThresh_[classID]) continue; + detBoxes->emplace_back(det); + } + } + } + + void Yolov5PostProcess::GenerateBbox(std::vector> featLayerData, + std::vector *detBoxes, + const std::vector>& featLayerShapes, const int netWidth, + const int netHeight) { + NetInfo netInfo; + netInfo.anchorDim = anchorDim_; + netInfo.bboxDim = BOX_DIM; + netInfo.classNum = classNum_; + netInfo.netWidth = netWidth; + netInfo.netHeight = netHeight; + for (int i = 0; i < yoloType_; ++i) { + int widthIndex_ = modelType_ ? NCHW_WIDTHINDEX : NHWC_WIDTHINDEX; + int heightIndex_ = modelType_ ? NCHW_HEIGHTINDEX : NHWC_HEIGHTINDEX; + OutputLayer layer = {featLayerShapes[i][widthIndex_], featLayerShapes[i][heightIndex_]}; + int logOrder = log(featLayerShapes[i][widthIndex_] * SCALE / netWidth) / log(BIASESDIM); + int startIdx = (yoloType_ - 1 - logOrder) * netInfo.anchorDim * BIASESDIM; + int endIdx = startIdx + netInfo.anchorDim * BIASESDIM; + int idx = 0; + for (int j = startIdx; j < endIdx; ++j) { + layer.anchors[idx++] = biases_[j]; + } + int stride = layer.width * layer.height; + std::shared_ptr netout = featLayerData[i]; + SelectClassNHWC(netout, netInfo, detBoxes, stride); + } + } + + APP_ERROR Yolov5PostProcess::GetBiases(std::string *strBiases) { + if (biasesNum_ <= 0) { + LogError << GetError(APP_ERR_COMM_INVALID_PARAM) << "Failed to get biasesNum (" << biasesNum_ << ")."; + return APP_ERR_COMM_INVALID_PARAM; + } + biases_.clear(); + int i = 0; + int num = strBiases->find(","); + while (num >= 0 && i < biasesNum_) { + std::string tmp = strBiases->substr(0, num); + num++; + (*strBiases) = strBiases->substr(num, strBiases->size()); + biases_.push_back(stof(tmp)); + i++; + num = strBiases->find(","); + } + if (i != biasesNum_ - 1 || strBiases->size() == 0) { + LogError << GetError(APP_ERR_COMM_INVALID_PARAM) << "biasesNum (" << biasesNum_ + << ") is not equal to total number of biases (" << (*strBiases) <<")."; + return APP_ERR_COMM_INVALID_PARAM; + } + biases_.push_back(stof((*strBiases))); + return APP_ERR_OK; + } + +#ifndef ENABLE_POST_PROCESS_INSTANCE + extern "C" { + std::shared_ptr GetObjectInstance() { + LogInfo << "Begin to get Yolov5PostProcess instance."; + auto instance = std::make_shared(); + LogInfo << "End to get Yolov5PostProcess instance."; + return instance; + } + } +#endif +} // namespace MxBase diff --git a/community/cv/ADCAM/infer/mxbase/src/PostProcess/Yolov5MindSporePost.h b/community/cv/ADCAM/infer/mxbase/src/PostProcess/Yolov5MindSporePost.h new file mode 100644 index 0000000000000000000000000000000000000000..c8356f1bae49490ba80a582f49cc218f8ef940e0 --- /dev/null +++ b/community/cv/ADCAM/infer/mxbase/src/PostProcess/Yolov5MindSporePost.h @@ -0,0 +1,90 @@ + +#ifndef YOLOV5_POST_PROCESS_H +#define YOLOV5_POST_PROCESS_H +#include +#include +#include +#include +#include +#include +#include "MxBase/ErrorCode/ErrorCode.h" +#include "MxBase/CV/Core/DataType.h" +#include "MxBase/PostProcessBases/ObjectPostProcessBase.h" + +const float DEFAULT_OBJECTNESS_THRESH = 0.3; +const float DEFAULT_IOU_THRESH = 0.6; +const int DEFAULT_ANCHOR_DIM = 3; +const int DEFAULT_BIASES_NUM = 18; +const int DEFAULT_YOLO_TYPE = 3; +const int DEFAULT_YOLO_VERSION = 5; +const int YOLOV3_VERSION = 3; +const int YOLOV4_VERSION = 4; +const int YOLOV5_VERSION = 5; +const int ANCHOR_NUM = 9; +struct OutputLayer { + size_t width; + size_t height; + float anchors[ANCHOR_NUM]; +}; + +struct NetInfo { + int anchorDim; + int classNum; + int bboxDim; + int netWidth; + int netHeight; +}; + +namespace MxBase { +class Yolov5PostProcess : public ObjectPostProcessBase { + public: + Yolov5PostProcess() = default; + + ~Yolov5PostProcess() = default; + + Yolov5PostProcess(const Yolov5PostProcess &other) = default; + + Yolov5PostProcess &operator=(const Yolov5PostProcess &other); + + APP_ERROR Init(const std::map> &postConfig) override; + + APP_ERROR DeInit() override; + + APP_ERROR Process(const std::vector &tensors, std::vector> &objectInfos, + const std::vector &resizedImageInfos = {}, + const std::map> &configParamMap = {}) override; + + protected: + bool IsValidTensors(const std::vector &tensors) const; + + void ObjectDetectionOutput(const std::vector &tensors, + std::vector> *objectInfos, + const std::vector &resizedImageInfos = {}); + + void CompareProb(int *classID, float *maxProb, float classProb, int classNum); + void SelectClassNHWC(std::shared_ptr netout, NetInfo info, std::vector *detBoxes, + int stride); + void GenerateBbox(std::vector> featLayerData, + std::vector *detBoxes, + const std::vector>& featLayerShapes, + const int netWidth, const int netHeight); + APP_ERROR GetBiases(std::string *strBiases); + + protected: + float objectnessThresh_ = DEFAULT_OBJECTNESS_THRESH; // Threshold of objectness value + float iouThresh_ = DEFAULT_IOU_THRESH; // Non-Maximum Suppression threshold + int anchorDim_ = DEFAULT_ANCHOR_DIM; + int biasesNum_ = DEFAULT_BIASES_NUM; // anchors, generate from train data, coco dataset + int yoloType_ = DEFAULT_YOLO_TYPE; + int modelType_ = 0; + int yoloVersion_ = DEFAULT_YOLO_VERSION; + int inputType_ = 0; + std::vector biases_ = {}; +}; +#ifndef ENABLE_POST_PROCESS_INSTANCE + extern "C" { + std::shared_ptr GetObjectInstance(); + } +#endif +} // namespace MxBase +#endif diff --git a/community/cv/ADCAM/infer/mxbase/src/Yolov5Detection.cpp b/community/cv/ADCAM/infer/mxbase/src/Yolov5Detection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e683067c3232576aec722880846df03a0f6a025e --- /dev/null +++ b/community/cv/ADCAM/infer/mxbase/src/Yolov5Detection.cpp @@ -0,0 +1,335 @@ +#include "Yolov5Detection.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "MxBase/DeviceManager/DeviceManager.h" + +namespace { + const uint32_t MODEL_HEIGHT = 640; + const uint32_t MODEL_WIDTH = 640; + const uint32_t MODEL_CHANNEL = 12; + const uint32_t BATCH_NUM = 1; + const std::vector MEAN = {0.485, 0.456, 0.406}; + const std::vector STD = {0.229, 0.224, 0.225}; + const float MODEL_MAX = 255.0; + const int DATA_SIZE = 1228800; + const int coco_class_nameid[80] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, + 67, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90}; +} // namespace + +APP_ERROR Yolov5Detection::LoadLabels(const std::string &labelPath, std::map *labelMap) { + std::ifstream infile; + // open label file + infile.open(labelPath, std::ios_base::in); + std::string s; + // check label file validity + if (infile.fail()) { + LogError << "Failed to open label file: " << labelPath << "."; + return APP_ERR_COMM_OPEN_FAIL; + } + labelMap->clear(); + // construct label map + int count = 0; + while (std::getline(infile, s)) { + if (s[0] == '#') { + continue; + } + size_t eraseIndex = s.find_last_not_of("\r\n\t"); + if (eraseIndex != std::string::npos) { + s.erase(eraseIndex + 1, s.size() - eraseIndex); + } + labelMap->insert(std::pair(count, s)); + count++; + } + infile.close(); + return APP_ERR_OK; +} + +APP_ERROR Yolov5Detection::Init(const InitParam &initParam) { + deviceId_ = initParam.deviceId; + APP_ERROR ret = MxBase::DeviceManager::GetInstance()->InitDevices(); + if (ret != APP_ERR_OK) { + LogError << "Init devices failed, ret=" << ret << "."; + return ret; + } + ret = MxBase::TensorContext::GetInstance()->SetContext(initParam.deviceId); + if (ret != APP_ERR_OK) { + LogError << "Set context failed, ret=" << ret << "."; + return ret; + } + + model_ = std::make_shared(); + ret = model_->Init(initParam.modelPath, modelDesc_); + if (ret != APP_ERR_OK) { + LogError << "ModelInferenceProcessor init failed, ret=" << ret << "."; + return ret; + } + MxBase::ConfigData configData; + const std::string checkTensor = initParam.checkTensor ? "true" : "false"; + configData.SetJsonValue("CLASS_NUM", std::to_string(initParam.classNum)); + configData.SetJsonValue("BIASES_NUM", std::to_string(initParam.biasesNum)); + configData.SetJsonValue("BIASES", initParam.biases); + configData.SetJsonValue("OBJECTNESS_THRESH", initParam.objectnessThresh); + configData.SetJsonValue("IOU_THRESH", initParam.iouThresh); + configData.SetJsonValue("SCORE_THRESH", initParam.scoreThresh); + configData.SetJsonValue("YOLO_TYPE", std::to_string(initParam.yoloType)); + configData.SetJsonValue("MODEL_TYPE", std::to_string(initParam.modelType)); + configData.SetJsonValue("INPUT_TYPE", std::to_string(initParam.inputType)); + configData.SetJsonValue("ANCHOR_DIM", std::to_string(initParam.anchorDim)); + configData.SetJsonValue("CHECK_MODEL", checkTensor); + + auto jsonStr = configData.GetCfgJson().serialize(); + std::map> config; + config["postProcessConfigContent"] = std::make_shared(jsonStr); + config["labelPath"] = std::make_shared(initParam.labelPath); + + post_ = std::make_shared(); + ret = post_->Init(config); + if (ret != APP_ERR_OK) { + LogError << "Yolov5PostProcess init failed, ret=" << ret << "."; + return ret; + } + // load labels from file + ret = LoadLabels(initParam.labelPath, &labelMap_); + if (ret != APP_ERR_OK) { + LogError << "Failed to load labels, ret=" << ret << "."; + return ret; + } + LogInfo << "End to Init Yolov5DetectionOpencv."; + return APP_ERR_OK; +} + +APP_ERROR Yolov5Detection::DeInit() { + model_->DeInit(); + MxBase::DeviceManager::GetInstance()->DestroyDevices(); + return APP_ERR_OK; +} + +APP_ERROR Yolov5Detection::ReadImage(const std::string &imgPath, cv::Mat *imageMat) { + (*imageMat) = cv::imread(imgPath, cv::IMREAD_COLOR); + imageWidth_ = (*imageMat).cols; + imageHeight_ = (*imageMat).rows; + + return APP_ERR_OK; +} + +APP_ERROR Yolov5Detection::Resize(cv::Mat *srcImageMat, cv::Mat *dstImageMat) { + cv::resize((*srcImageMat), (*dstImageMat), cv::Size(MODEL_WIDTH, MODEL_HEIGHT)); + + return APP_ERR_OK; +} + +APP_ERROR Yolov5Detection::WhcToChw(const cv::Mat &srcImageMat, std::vector *imgData) { + int channel = srcImageMat.channels(); + std::vector bgrChannels(channel); + cv::split(srcImageMat, bgrChannels); + for (int i = channel - 1; i >= 0; i--) { + std::vector data = std::vector(bgrChannels[i].reshape(1, 1)); + std::transform(data.begin(), data.end(), data.begin(), + [&](float item) {return ((item / MODEL_MAX - MEAN[channel - i - 1]) / STD[channel - i - 1]); }); + imgData->insert(imgData->end(), data.begin(), data.end()); + } + + return APP_ERR_OK; +} + +APP_ERROR Yolov5Detection::Focus(const cv::Mat &srcImageMat, float* data) { + int outIdx = 0; + int imgIdx = 0; + int height = static_cast(srcImageMat.rows); + int width = static_cast(srcImageMat.cols); + int channel = static_cast(srcImageMat.channels()); + int newHeight = height / 2; + int newWidth = width / 2; + int newChannel = MODEL_CHANNEL; + + std::vector tmp; + WhcToChw(srcImageMat, &tmp); + + for (int newC = 0; newC < newChannel; newC++) { + int c = newC % channel; + for (int newH = 0; newH < newHeight; newH++) { + for (int newW = 0; newW < newWidth; newW++) { + if (newC < channel) { + outIdx = newC * newHeight * newWidth + newH * newWidth + newW; + imgIdx = c * height * width + newH * 2 * width + newW * 2; + } else if (channel <= newC && newC < channel * 2) { + outIdx = newC * newHeight * newWidth + newH * newWidth + newW; + imgIdx = c * height * width + static_cast((newH + 0.5) * 2 * width) + newW * 2; + } else if (channel * 2 <= newC && newC < channel * 3) { + outIdx = newC * newHeight * newWidth + newH * newWidth + newW; + imgIdx = c * height * width + newH * 2 * width + static_cast((newW + 0.5) * 2); + } else if (channel * 3 <= newC && newC < channel * 4) { + outIdx = newC * newHeight * newWidth + newH * newWidth + newW; + imgIdx = c * height * width + static_cast((newH + 0.5) * 2 * width) + + static_cast((newW + 0.5) * 2); + } else { + LogError << "new channels Out of range."; + return APP_ERR_OK; + } + data[outIdx] = tmp[imgIdx]; + } + } + } + + return APP_ERR_OK; +} + +APP_ERROR Yolov5Detection::CVMatToTensorBase(float* data, MxBase::TensorBase *tensorBase) { + uint32_t height = MODEL_HEIGHT / 2; + uint32_t width = MODEL_WIDTH / 2; + const uint32_t dataSize = MODEL_CHANNEL * height * width * sizeof(float); + MxBase::MemoryData memoryDataDst(dataSize, MxBase::MemoryData::MEMORY_DEVICE, deviceId_); + MxBase::MemoryData memoryDataSrc(data, dataSize, MxBase::MemoryData::MEMORY_HOST_MALLOC); + + APP_ERROR ret = MxBase::MemoryHelper::MxbsMallocAndCopy(memoryDataDst, memoryDataSrc); + if (ret != APP_ERR_OK) { + LogError << GetError(ret) << "Memory malloc failed."; + return ret; + } + std::vector shape = {BATCH_NUM, MODEL_CHANNEL, height, width}; + (*tensorBase) = MxBase::TensorBase(memoryDataDst, false, shape, MxBase::TENSOR_DTYPE_FLOAT32); + return APP_ERR_OK; +} + +APP_ERROR Yolov5Detection::Inference(const std::vector &inputs, + std::vector *outputs) { + auto dtypes = model_->GetOutputDataType(); + for (size_t i = 0; i < modelDesc_.outputTensors.size(); ++i) { + std::vector shape = {}; + for (size_t j = 0; j < modelDesc_.outputTensors[i].tensorDims.size(); ++j) { + shape.push_back((uint32_t)modelDesc_.outputTensors[i].tensorDims[j]); + } + MxBase::TensorBase tensor(shape, dtypes[i], MxBase::MemoryData::MemoryType::MEMORY_DEVICE, deviceId_); + APP_ERROR ret = MxBase::TensorBase::TensorBaseMalloc(tensor); + if (ret != APP_ERR_OK) { + LogError << "TensorBaseMalloc failed, ret=" << ret << "."; + return ret; + } + (*outputs).push_back(tensor); + } + + MxBase::DynamicInfo dynamicInfo = {}; + dynamicInfo.dynamicType = MxBase::DynamicType::STATIC_BATCH; + auto startTime = std::chrono::high_resolution_clock::now(); + APP_ERROR ret = model_->ModelInference(inputs, (*outputs), dynamicInfo); + auto endTime = std::chrono::high_resolution_clock::now(); + double costMs = std::chrono::duration(endTime - startTime).count(); + g_inferCost.push_back(costMs); + if (ret != APP_ERR_OK) { + LogError << "ModelInference failed, ret=" << ret << "."; + return ret; + } + + return APP_ERR_OK; +} + +APP_ERROR Yolov5Detection::PostProcess(const std::vector& tensors, + std::vector> *objInfos) { + MxBase::ResizedImageInfo imgInfo; + imgInfo.widthOriginal = imageWidth_; + imgInfo.heightOriginal = imageHeight_; + imgInfo.widthResize = MODEL_WIDTH; + imgInfo.heightResize = MODEL_HEIGHT; + imgInfo.resizeType = MxBase::RESIZER_STRETCHING; + std::vector imageInfoVec = {}; + imageInfoVec.push_back(imgInfo); + + APP_ERROR ret = post_->Process(tensors, (*objInfos), imageInfoVec); + if (ret != APP_ERR_OK) { + LogInfo << "Process failed, ret=" << ret << "."; + return ret; + } + + return APP_ERR_OK; +} + +APP_ERROR Yolov5Detection::WriteResult(const std::vector> &objInfos, + const std::string &imgPath, std::vector *jsonText) { + uint32_t batchSize = objInfos.size(); + + int pos = imgPath.rfind('/'); + std::string fileName(imgPath, pos + 1); + fileName = fileName.substr(0, fileName.find('.')); + // write inference result into file + int image_id = std::stoi(fileName), cnt = 0; + for (uint32_t i = 0; i < batchSize; i++) { + for (auto &obj : objInfos[i]) { + jsonText->push_back("{\"image_id\": " + std::to_string(image_id) + ", \"category_id\": " + + std::to_string(coco_class_nameid[static_cast(obj.classId)]) + ", \"bbox\": [" + + std::to_string(obj.x0) + ", " + std::to_string(obj.y0) + ", " + + std::to_string(obj.x1 - obj.x0) + ", " + std::to_string(obj.y1 - obj.y0) + "], " + + "\"score\": " + std::to_string(obj.confidence) + "}"); + cnt++; + } + } + return APP_ERR_OK; +} + +APP_ERROR Yolov5Detection::Process(const std::string &imgPath, std::vector *jsonText) { + // process image + cv::Mat imageMat; + APP_ERROR ret = ReadImage(imgPath, &imageMat); + if (ret != APP_ERR_OK) { + LogError << "ReadImage failed, ret=" << ret << "."; + return ret; + } + + ret = Resize(&imageMat, &imageMat); + if (ret != APP_ERR_OK) { + LogError << "Resize failed, ret=" << ret << "."; + return ret; + } + + float data[DATA_SIZE]; + ret = Focus(imageMat, data); + + if (ret != APP_ERR_OK) { + LogError << "Focus failed, ret=" << ret << "."; + return ret; + } + + std::vector inputs = {}; + std::vector outputs = {}; + MxBase::TensorBase tensorBase; + ret = CVMatToTensorBase(data, &tensorBase); + + if (ret != APP_ERR_OK) { + LogError << "CVMatToTensorBase failed, ret=" << ret << "."; + return ret; + } + + inputs.push_back(tensorBase); + ret = Inference(inputs, &outputs); + if (ret != APP_ERR_OK) { + LogError << "Inference failed, ret=" << ret << "."; + return ret; + } + + + std::vector> objInfos; + ret = PostProcess(outputs, &objInfos); + if (ret != APP_ERR_OK) { + LogError << "PostProcess failed, ret=" << ret << "."; + return ret; + } + + ret = WriteResult(objInfos, imgPath, jsonText); + if (ret != APP_ERR_OK) { + LogError << "WriteResult failed, ret=" << ret << "."; + return ret; + } + + imageMat.release(); + return APP_ERR_OK; +} diff --git a/community/cv/ADCAM/infer/mxbase/src/Yolov5Detection.h b/community/cv/ADCAM/infer/mxbase/src/Yolov5Detection.h new file mode 100644 index 0000000000000000000000000000000000000000..f186b27b9235e2de4b0d43c97ae6c789fe61673d --- /dev/null +++ b/community/cv/ADCAM/infer/mxbase/src/Yolov5Detection.h @@ -0,0 +1,68 @@ +#ifndef YOLOV5_RECOGNITION_H +#define YOLOV5_RECOGNITION_H + +#include +#include +#include +#include + +#include + +#include "MxBase/DvppWrapper/DvppWrapper.h" +#include "MxBase/ModelInfer/ModelInferenceProcessor.h" +#include "MxBase/DeviceManager/DeviceManager.h" +#include "MxBase/Tensor/TensorContext/TensorContext.h" +#include "PostProcess/Yolov5MindSporePost.h" +#include "MxBase/PostProcessBases/TextObjectPostProcessBase.h" + + +extern std::vector g_inferCost; + +struct InitParam { + uint32_t deviceId; + std::string labelPath; + bool checkTensor; + std::string modelPath; + uint32_t classNum; + uint32_t biasesNum; + std::string biases; + std::string objectnessThresh; + std::string iouThresh; + std::string scoreThresh; + uint32_t yoloType; + uint32_t modelType; + uint32_t inputType; + uint32_t anchorDim; +}; + +class Yolov5Detection { + public: + APP_ERROR Init(const InitParam &initParam); + APP_ERROR DeInit(); + APP_ERROR ReadImage(const std::string &imgPath, cv::Mat *imageMat); + APP_ERROR Resize(cv::Mat *srcImageMat, cv::Mat *dstImageMat); + APP_ERROR WhcToChw(const cv::Mat &srcImageMat, std::vector *imgData); + APP_ERROR Focus(const cv::Mat &srcImageMat, float* data); + APP_ERROR CVMatToTensorBase(float* data, MxBase::TensorBase *tensorBase); + APP_ERROR LoadLabels(const std::string &labelPath, std::map *labelMap); + APP_ERROR Inference(const std::vector &inputs, std::vector *outputs); + APP_ERROR PostProcess(const std::vector& tensors, + std::vector> *objInfos); + APP_ERROR WriteResult(const std::vector> &objInfos, + const std::string &imgPath, std::vector *jsonText); + APP_ERROR Process(const std::string &imgPath, std::vector *jsonText); + // get infer time + double GetInferCostMilliSec() const {return inferCostTimeMilliSec;} + + private: + std::shared_ptr model_; + std::shared_ptr post_; + MxBase::ModelDesc modelDesc_; + std::map labelMap_; + uint32_t deviceId_ = 0; + uint32_t imageWidth_ = 0; + uint32_t imageHeight_ = 0; + // infer time + double inferCostTimeMilliSec = 0.0; +}; +#endif diff --git a/community/cv/ADCAM/infer/mxbase/src/main.cpp b/community/cv/ADCAM/infer/mxbase/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b2d7d4aaaaee9ad6f3bbc68249926449f5887546 --- /dev/null +++ b/community/cv/ADCAM/infer/mxbase/src/main.cpp @@ -0,0 +1,139 @@ +#include +#include +#include +#include +#include +#include "Yolov5Detection.h" +#include "MxBase/Log/Log.h" + +std::vector g_inferCost; + +void ShowUsage() { + LogInfo << "Usage : ./yolov5 <--image or --dir> [Option]" << std::endl; + LogInfo << "Options :" << std::endl; + LogInfo << " --image infer_image_path the path of single infer image, such as " + "./yolov5 --image /home/infer/images/test.jpg." << std::endl; + LogInfo << " --dir infer_image_dir the dir of batch infer images, such as " + "./yolov5 --dir /home/infer/images." << std::endl; + return; +} + +void InitYolov4TinyParam(InitParam *initParam) { + initParam->deviceId = 0; + initParam->labelPath = "../../data/models/coco2017.names"; + initParam->checkTensor = true; + initParam->modelPath = "../../data/models/yolov5.om"; + initParam->classNum = 80; + initParam->biasesNum = 18; + initParam->biases = "12,16,19,36,40,28,36,75,76,55,72,146,142,110,192,243,459,401"; + initParam->objectnessThresh = "0.001"; + initParam->iouThresh = "0.6"; + initParam->scoreThresh = "0.001"; + initParam->yoloType = 3; + initParam->modelType = 0; + initParam->inputType = 0; + initParam->anchorDim = 3; +} + +APP_ERROR saveResult(const std::vector &jsonText, const std::string &savePath) { + // create result directory when it does not exit + std::string resultPath = savePath; + if (access(resultPath.c_str(), 0) != 0) { + int ret = mkdir(resultPath.c_str(), S_IRUSR | S_IWUSR | S_IXUSR); + if (ret != 0) { + LogError << "Failed to create result directory: " << resultPath << ", ret = " << ret; + return APP_ERR_COMM_OPEN_FAIL; + } + } + // create result file under result directory + resultPath = resultPath + "/predict.json"; + std::ofstream tfile(resultPath, std::ofstream::out|std::ofstream::trunc); + if (tfile.fail()) { + LogError << "Failed to open result file: " << resultPath; + return APP_ERR_COMM_OPEN_FAIL; + } + tfile << "["; + for (uint32_t i = 0; i < jsonText.size(); i++) { + tfile << jsonText[i]; + if (i != jsonText.size() - 1) tfile << ", "; + } + tfile << "]"; + tfile.close(); + + return APP_ERR_OK; +} + +APP_ERROR ReadImagesPath(const std::string& dir, std::vector *imagesPath) { + DIR *dirPtr = opendir(dir.c_str()); + if (dirPtr == nullptr) { + LogError << "opendir failed. dir: " << dir; + return APP_ERR_INTERNAL_ERROR; + } + dirent *direntPtr = nullptr; + while ((direntPtr = readdir(dirPtr)) != nullptr) { + std::string fileName = direntPtr->d_name; + if (fileName == "." || fileName == "..") { + continue; + } + (*imagesPath).emplace_back(dir + "/" + fileName); + } + closedir(dirPtr); + return APP_ERR_OK; +} + +int main(int argc, char* argv[]) { + if (argc != 3) { + LogInfo << "Please use as follows." << std::endl; + ShowUsage(); + return APP_ERR_OK; + } + + std::string option = argv[1]; + std::string imgPath = argv[2]; + + if (option != "--image" && option != "--dir") { + LogInfo << "Please use as follows." << std::endl; + ShowUsage(); + return APP_ERR_OK; + } + + InitParam initParam = {}; + InitYolov4TinyParam(&initParam); + auto yolov5 = std::make_shared(); + APP_ERROR ret = yolov5->Init(initParam); + if (ret != APP_ERR_OK) { + LogInfo << "Yolov5DetectionOpencv init failed, ret=" << ret << "."; + return ret; + } + LogInfo << "End to Init yolov5."; + + std::vector imagesPath; + if (option == "--image") { + imagesPath.emplace_back(imgPath); + } else { + ret = ReadImagesPath(imgPath, &imagesPath); + } + + if (ret != APP_ERR_OK) { + LogInfo << "read file failed, ret=" << ret << "."; + return ret; + } + LogInfo << "read file success."; + std::vector jsonText; + for (auto path : imagesPath) { + LogInfo << "read image path " << path; + yolov5->Process(path, &jsonText); + } + + std::string resultPathName = "../result/"; + saveResult(jsonText, resultPathName); + + yolov5->DeInit(); + double costSum = 0; + for (uint32_t i = 0; i < g_inferCost.size(); i++) { + costSum += g_inferCost[i]; + } + LogInfo << "Infer images sum " << g_inferCost.size() << ", cost total time: " << costSum << " ms."; + LogInfo << "The throughput: " << g_inferCost.size() * 1000 / costSum << " images/sec."; + return APP_ERR_OK; +} diff --git a/community/cv/ADCAM/infer/requirements.txt b/community/cv/ADCAM/infer/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..1e199daef6f7f5b00d9a3af9f6d5f20c4e65bffb --- /dev/null +++ b/community/cv/ADCAM/infer/requirements.txt @@ -0,0 +1,4 @@ +numpy +pillow +opencv-python +pycocotools >= 2.0.5 \ No newline at end of file diff --git a/community/cv/ADCAM/infer/sdk/api/infer.py b/community/cv/ADCAM/infer/sdk/api/infer.py new file mode 100644 index 0000000000000000000000000000000000000000..849206b363f58950a0797164c99eacd8545f9ae0 --- /dev/null +++ b/community/cv/ADCAM/infer/sdk/api/infer.py @@ -0,0 +1,137 @@ + +""" +Inference Api +""" +import json +import logging +from config import config as cfg +import MxpiDataType_pb2 as MxpiDataType +from StreamManagerApi import StreamManagerApi, MxDataInput, InProtobufVector, MxProtobufIn + + +class SdkApi: + """ + Manage pieline stream + """ + INFER_TIMEOUT = cfg.INFER_TIMEOUT + STREAM_NAME = cfg.STREAM_NAME + + def __init__(self, pipeline_cfg): + """ + Parameter initialization + """ + self.pipeline_cfg = pipeline_cfg + self._stream_api = None + self._data_input = None + self._device_id = None + + def init(self): + """ + Stream initialization + """ + with open(self.pipeline_cfg, 'r') as fp: + self._device_id = int(json.loads(fp.read())[self.STREAM_NAME]["stream_config"]["deviceId"]) + + print(f"The device id: {self._device_id}.") + + # create api + self._stream_api = StreamManagerApi() + + # init stream mgr + ret = self._stream_api.InitManager() + if ret != 0: + print(f"Failed to init stream manager, ret={ret}.") + return False + + # create streams + with open(self.pipeline_cfg, 'rb') as fp: + pipe_line = fp.read() + + ret = self._stream_api.CreateMultipleStreams(pipe_line) + if ret != 0: + print(f"Failed to create stream, ret={ret}.") + return False + + self._data_input = MxDataInput() + return True + + def __del__(self): + if not self._stream_api: + return + + self._stream_api.DestroyAllStreams() + + def send_data_input(self, stream_name, plugin_id, input_data): + data_input = MxDataInput() + data_input.data = input_data + unique_id = self._stream_api.SendData(stream_name, plugin_id, + data_input) + if unique_id < 0: + logging.error("Fail to send data to stream.") + return False + return True + + def get_protobuf(self, stream_name, plugin_id, keyVec): + result = self._stream_api.GetProtobuf(stream_name, plugin_id, keyVec) + return result + + def _send_protobuf(self, stream_name, plugin_id, element_name, buf_type, + pkg_list): + """ + Input image data + """ + protobuf = MxProtobufIn() + protobuf.key = element_name.encode("utf-8") + protobuf.type = buf_type + protobuf.protobuf = pkg_list.SerializeToString() + protobuf_vec = InProtobufVector() + protobuf_vec.push_back(protobuf) + err_code = self._stream_api.SendProtobuf(stream_name, plugin_id, + protobuf_vec) + if err_code != 0: + logging.error( + "Failed to send data to stream, stream_name(%s), plugin_id(%s), element_name(%s), " + "buf_type(%s), err_code(%s).", stream_name, plugin_id, + element_name, buf_type, err_code) + return False + return True + + def send_img_input(self, stream_name, plugin_id, element_name, input_data, + img_size): + """ + input image data after preprocess + """ + vision_list = MxpiDataType.MxpiVisionList() + vision_vec = vision_list.visionVec.add() + vision_vec.visionInfo.format = 1 + vision_vec.visionInfo.width = img_size[1] + vision_vec.visionInfo.height = img_size[0] + vision_vec.visionInfo.widthAligned = img_size[1] + vision_vec.visionInfo.heightAligned = img_size[0] + vision_vec.visionData.memType = 0 + vision_vec.visionData.dataStr = input_data + vision_vec.visionData.dataSize = len(input_data) + + buf_type = b"MxTools.MxpiVisionList" + return self._send_protobuf(stream_name, plugin_id, element_name, + buf_type, vision_list) + + def send_tensor_input(self, stream_name, plugin_id, element_name, + input_data, input_shape, data_type): + """ + get image tensor + """ + tensor_list = MxpiDataType.MxpiTensorPackageList() + tensor_pkg = tensor_list.tensorPackageVec.add() + # init tensor vector + tensor_vec = tensor_pkg.tensorVec.add() + tensor_vec.deviceId = self._device_id + tensor_vec.memType = 0 + tensor_vec.tensorShape.extend(input_shape) + tensor_vec.tensorDataType = data_type + tensor_vec.dataStr = input_data + tensor_vec.tensorDataSize = len(input_data) + + buf_type = b"MxTools.MxpiTensorPackageList" + return self._send_protobuf(stream_name, plugin_id, element_name, + buf_type, tensor_list) diff --git a/community/cv/ADCAM/infer/sdk/api/postprocess.py b/community/cv/ADCAM/infer/sdk/api/postprocess.py new file mode 100644 index 0000000000000000000000000000000000000000..837b2c6636620fb555e502af90a030de9e087785 --- /dev/null +++ b/community/cv/ADCAM/infer/sdk/api/postprocess.py @@ -0,0 +1,240 @@ +import sys + +from collections import defaultdict +import numpy as np +from pycocotools.coco import COCO +from pycocotools.cocoeval import COCOeval + + +class Redirct: + def __init__(self): + self.content = "" + + def write(self, content): + self.content += content + + def flush(self): + self.content = "" + + +class DetectionEngine: + """Detection engine.""" + + def __init__(self, args_detection): + self.ignore_threshold = args_detection.ignore_threshold + self.args = args_detection + self.labels = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', + 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', + 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', + 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', + 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', + 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', + 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', + 'couch', 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', + 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', + 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] + self.num_classes = len(self.labels) + self.results = {} + self.file_path = '' + self.ann_file = args_detection.ann_file + self._coco = COCO(self.ann_file) + self._img_ids = list(sorted(self._coco.imgs.keys())) + self.det_boxes = [] + self.nms_thresh = args_detection.nms_thresh + self.multi_label = args_detection.multi_label + self.multi_label_thresh = args_detection.multi_label_thresh + self.coco_catIds = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, + 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, + 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, + 81, 82, 84, 85, 86, 87, 88, 89, 90] + + + def do_nms_for_results(self): + """Get result boxes.""" + for image_id in self.results: + for clsi in self.results[image_id]: + dets = self.results[image_id][clsi] + dets = np.array(dets) + keep_index = self._diou_nms(dets, thresh=self.nms_thresh) + + keep_box = [{'image_id': int(image_id), 'category_id': int(clsi), + 'bbox': list(dets[i][:4].astype(float)), + 'score': dets[i][4].astype(float)} for i in keep_index] + self.det_boxes.extend(keep_box) + + def _nms(self, predicts, threshold): + """Calculate NMS.""" + # convert xywh -> xmin ymin xmax ymax + x1 = predicts[:, 0] + y1 = predicts[:, 1] + x2 = x1 + predicts[:, 2] + y2 = y1 + predicts[:, 3] + scores = predicts[:, 4] + + areas = (x2 - x1 + 1) * (y2 - y1 + 1) + order = scores.argsort()[::-1] + + reserved_boxes = [] + while order.size > 0: + i = order[0] + reserved_boxes.append(i) + max_x1 = np.maximum(x1[i], x1[order[1:]]) + max_y1 = np.maximum(y1[i], y1[order[1:]]) + min_x2 = np.minimum(x2[i], x2[order[1:]]) + min_y2 = np.minimum(y2[i], y2[order[1:]]) + + intersect_w = np.maximum(0.0, min_x2 - max_x1 + 1) + intersect_h = np.maximum(0.0, min_y2 - max_y1 + 1) + intersect_area = intersect_w * intersect_h + ovr = intersect_area / (areas[i] + areas[order[1:]] - intersect_area) + + indexes = np.where(ovr <= threshold)[0] + order = order[indexes + 1] + return reserved_boxes + + def _diou_nms(self, dets, thresh=0.5): + """ + convert xywh -> xmin ymin xmax ymax + """ + x1 = dets[:, 0] + y1 = dets[:, 1] + x2 = x1 + dets[:, 2] + y2 = y1 + dets[:, 3] + scores = dets[:, 4] + areas = (x2 - x1 + 1) * (y2 - y1 + 1) + order = scores.argsort()[::-1] + keep = [] + while order.size > 0: + i = order[0] + keep.append(i) + xx1 = np.maximum(x1[i], x1[order[1:]]) + yy1 = np.maximum(y1[i], y1[order[1:]]) + xx2 = np.minimum(x2[i], x2[order[1:]]) + yy2 = np.minimum(y2[i], y2[order[1:]]) + + w = np.maximum(0.0, xx2 - xx1 + 1) + h = np.maximum(0.0, yy2 - yy1 + 1) + inter = w * h + ovr = inter / (areas[i] + areas[order[1:]] - inter) + center_x1 = (x1[i] + x2[i]) / 2 + center_x2 = (x1[order[1:]] + x2[order[1:]]) / 2 + center_y1 = (y1[i] + y2[i]) / 2 + center_y2 = (y1[order[1:]] + y2[order[1:]]) / 2 + inter_diag = (center_x2 - center_x1) ** 2 + (center_y2 - center_y1) ** 2 + out_max_x = np.maximum(x2[i], x2[order[1:]]) + out_max_y = np.maximum(y2[i], y2[order[1:]]) + out_min_x = np.minimum(x1[i], x1[order[1:]]) + out_min_y = np.minimum(y1[i], y1[order[1:]]) + outer_diag = (out_max_x - out_min_x) ** 2 + (out_max_y - out_min_y) ** 2 + diou = ovr - inter_diag / outer_diag + diou = np.clip(diou, -1, 1) + inds = np.where(diou <= thresh)[0] + order = order[inds + 1] + return keep + + def write_result(self): + """Save result to file.""" + import json + try: + self.file_path = self.args.result_files + '/predict' + '.json' + f = open(self.file_path, 'w') + json.dump(self.det_boxes, f) + except IOError as e: + raise RuntimeError("Unable to open json file to dump. What(): {}".format(str(e))) + else: + f.close() + return self.file_path + + def get_eval_result(self): + """Get eval result.""" + coco_gt = COCO(self.ann_file) + coco_dt = coco_gt.loadRes(self.file_path) + coco_eval = COCOeval(coco_gt, coco_dt, 'bbox') + coco_eval.evaluate() + coco_eval.accumulate() + rdct = Redirct() + stdout = sys.stdout + sys.stdout = rdct + coco_eval.summarize() + sys.stdout = stdout + return rdct.content + + def detect(self, outputs, batch, img_shape, image_id): + """Detect boxes.""" + outputs_num = len(outputs) + # output [|32, 52, 52, 3, 85| ] + for batch_id in range(batch): + for out_id in range(outputs_num): + # 32, 52, 52, 3, 85 + out_item = outputs[out_id] + # 52, 52, 3, 85 + out_item_single = out_item[batch_id, :] + # get number of items in one head, [B, gx, gy, anchors, 5+80] + dimensions = out_item_single.shape[:-1] + out_num = 1 + for d in dimensions: + out_num *= d + ori_w, ori_h = img_shape[batch_id] + img_id = int(image_id[batch_id]) + x = out_item_single[..., 0] * ori_w + y = out_item_single[..., 1] * ori_h + w = out_item_single[..., 2] * ori_w + h = out_item_single[..., 3] * ori_h + + conf = out_item_single[..., 4:5] + cls_emb = out_item_single[..., 5:] + cls_argmax = np.expand_dims(np.argmax(cls_emb, axis=-1), axis=-1) + x = x.reshape(-1) + y = y.reshape(-1) + w = w.reshape(-1) + h = h.reshape(-1) + x_top_left = x - w / 2. + y_top_left = y - h / 2. + cls_emb = cls_emb.reshape(-1, self.num_classes) + if self.multi_label: + conf = conf.reshape(-1, 1) + # create all False + confidence = cls_emb * conf + flag = cls_emb > self.multi_label_thresh + flag = flag.nonzero() + for index in range(len(flag[0])): + i = flag[0][index] + j = flag[1][index] + confi = confidence[i][j] + if confi < self.ignore_threshold: + continue + if img_id not in self.results: + self.results[img_id] = defaultdict(list) + x_lefti = max(0, x_top_left[i]) + y_lefti = max(0, y_top_left[i]) + wi = min(w[i], ori_w) + hi = min(h[i], ori_h) + clsi = j + # transform catId to match coco + coco_clsi = self.coco_catIds[clsi] + self.results[img_id][coco_clsi].append([x_lefti, y_lefti, wi, hi, confi]) + else: + cls_argmax = np.expand_dims(np.argmax(cls_emb, axis=-1), axis=-1) + conf = conf.reshape(-1) + cls_argmax = cls_argmax.reshape(-1) + + # create all False + flag = np.random.random(cls_emb.shape) > sys.maxsize + for i in range(flag.shape[0]): + c = cls_argmax[i] + flag[i, c] = True + confidence = cls_emb[flag] * conf + + for x_lefti, y_lefti, wi, hi, confi, clsi in zip(x_top_left, y_top_left, w, h, confidence, + cls_argmax): + if confi < self.ignore_threshold: + continue + if img_id not in self.results: + self.results[img_id] = defaultdict(list) + x_lefti = max(0, x_lefti) + y_lefti = max(0, y_lefti) + wi = min(wi, ori_w) + hi = min(hi, ori_h) + # transform catId to match coco + coco_clsi = self.coco_catIds[clsi] + self.results[img_id][coco_clsi].append([x_lefti, y_lefti, wi, hi, confi]) diff --git a/community/cv/ADCAM/infer/sdk/config/config.py b/community/cv/ADCAM/infer/sdk/config/config.py new file mode 100644 index 0000000000000000000000000000000000000000..4c7b7a7cac162ef434ffc3b484820c15f5d03e60 --- /dev/null +++ b/community/cv/ADCAM/infer/sdk/config/config.py @@ -0,0 +1,14 @@ +""" +Inference parameter configuration +""" +MODEL_WIDTH = 640 +MODEL_HEIGHT = 640 +NUM_CLASSES = 80 +SCORE_THRESH = 0.3 +STREAM_NAME = "im_yolov5" + +INFER_TIMEOUT = 100000 + +TENSOR_DTYPE_FLOAT32 = 0 +TENSOR_DTYPE_FLOAT16 = 1 +TENSOR_DTYPE_INT8 = 2 diff --git a/community/cv/ADCAM/infer/sdk/config/yolov5.pipeline b/community/cv/ADCAM/infer/sdk/config/yolov5.pipeline new file mode 100644 index 0000000000000000000000000000000000000000..34e2ac343b84f423a3b44f1d423ac915f79b635f --- /dev/null +++ b/community/cv/ADCAM/infer/sdk/config/yolov5.pipeline @@ -0,0 +1,30 @@ +{ + "im_yolov5": { + "stream_config": { + "deviceId": "0" + }, + "appsrc0": { + "props": { + "blocksize": "409600" + }, + "factory": "appsrc", + "next": "mxpi_tensorinfer0" + }, + "mxpi_tensorinfer0": { + "props": { + "dataSource": "appsrc0", + "modelPath": "../data/models/yolov5.om", + "waitingTime": "2000", + "outputDeviceId": "-1" + }, + "factory": "mxpi_tensorinfer", + "next": "appsink0" + }, + "appsink0": { + "props": { + "blocksize": "4096000" + }, + "factory": "appsink" + } + } +} diff --git a/community/cv/ADCAM/infer/sdk/eval/eval_by_sdk.py b/community/cv/ADCAM/infer/sdk/eval/eval_by_sdk.py new file mode 100644 index 0000000000000000000000000000000000000000..fac958f46ed7f102ff302ecd3a359bc0841e1a95 --- /dev/null +++ b/community/cv/ADCAM/infer/sdk/eval/eval_by_sdk.py @@ -0,0 +1,23 @@ +import argparse +from pycocotools.coco import COCO +from pycocotools.cocoeval import COCOeval + + +def get_eval_result(ann_file, result_file): + """Get eval result.""" + coco_gt = COCO(ann_file) + coco_dt = coco_gt.loadRes(result_file) + coco_eval = COCOeval(coco_gt, coco_dt, 'bbox') + coco_eval.evaluate() + coco_eval.accumulate() + coco_eval.summarize() + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="yolov5 eval") + parser.add_argument('--ann_file', type=str, default='', help='path to annotation') + parser.add_argument('--result_file', type=str, default='', help='path to annotation') + + args = parser.parse_args() + + get_eval_result(args.ann_file, args.result_file) diff --git a/community/cv/ADCAM/infer/sdk/main.py b/community/cv/ADCAM/infer/sdk/main.py new file mode 100644 index 0000000000000000000000000000000000000000..7719abc009b4fcdc046161a956d8f7262bc00cf1 --- /dev/null +++ b/community/cv/ADCAM/infer/sdk/main.py @@ -0,0 +1,124 @@ +# !/usr/bin/env python + +""" +Sdk internece +""" +import argparse +import os +import time +import ast +import numpy as np + +from PIL import Image +from pycocotools.coco import COCO + +from api.infer import SdkApi +from api.postprocess import DetectionEngine +import MxpiDataType_pb2 as MxpiDataType +from StreamManagerApi import StringVector +from config import config as cfg + + +def parser_args(): + """ + configuration parameter, input from outside + """ + parser = argparse.ArgumentParser(description="yolov5 inference") + parser.add_argument("--pipeline_path", type=str, required=False, default="config/yolov5.pipeline", + help="pipeline file path. The default is 'config/centernet.pipeline'. ") + + parser.add_argument('--nms_thresh', type=float, default=0.6, help='threshold for NMS') + parser.add_argument('--ann_file', type=str, default='', help='path to annotation') + parser.add_argument('--ignore_threshold', type=float, default=0.001, help='threshold to throw low quality boxes') + + parser.add_argument('--dataset_path', type=str, default='', help='path of image dataset') + parser.add_argument('--result_files', type=str, default='./result', help='path to 310 infer result path') + parser.add_argument('--multi_label', type=ast.literal_eval, default=True, help='whether to use multi label') + parser.add_argument('--multi_label_thresh', type=float, default=0.1, help='threshold to throw low quality boxes') + + arg = parser.parse_args() + return arg + + +def process_img(img_file): + """ + Preprocessing the images + """ + # Computed from random subset of ImageNet training images + mean = np.array([0.485, 0.456, 0.406], dtype=np.float32) + std = np.array([0.229, 0.224, 0.225], dtype=np.float32) + img = Image.open(img_file).convert("RGB") + img = img.resize((cfg.MODEL_HEIGHT, cfg.MODEL_WIDTH), 0) + img = np.array(img, dtype=np.float32) + img = img / 255. + img = (img - mean) / std + img = img.transpose(2, 0, 1) + img = np.expand_dims(img, 0) + img = np.concatenate((img[..., ::2, ::2], img[..., 1::2, ::2], img[..., ::2, 1::2], img[..., 1::2, 1::2]), axis=1) + + return img + + +def image_inference(pipeline_path, stream_name, img_dir, detection): + """ + image inference: get inference for images + """ + sdk_api = SdkApi(pipeline_path) + if not sdk_api.init(): + return + + img_data_plugin_id = 0 + print(f"\nBegin to inference for {img_dir}.\n") + + file_list = os.listdir(img_dir) + coco = COCO(args.ann_file) + start_time = time.time() + + for file_name in file_list: + if not file_name.lower().endswith((".jpg", "jpeg")): + continue + + img_ids_name = file_name.split('.')[0] + img_id_ = int(np.squeeze(img_ids_name)) + imgIds = coco.getImgIds(imgIds=[img_id_]) + img = coco.loadImgs(imgIds[np.random.randint(0, len(imgIds))])[0] + image_shape = ((img['width'], img['height']),) + img_id_ = (np.squeeze(img_ids_name),) + + imgs = process_img(os.path.join(img_dir, file_name)) + sdk_api.send_tensor_input(stream_name, + img_data_plugin_id, "appsrc0", + imgs.tobytes(), imgs.shape, cfg.TENSOR_DTYPE_FLOAT32) + + keys = [b"mxpi_tensorinfer0"] + keyVec = StringVector() + for key in keys: + keyVec.push_back(key) + infer_result = sdk_api. get_protobuf(stream_name, 0, keyVec) + + result = MxpiDataType.MxpiTensorPackageList() + result.ParseFromString(infer_result[0].messageBuf) + output_small = np.frombuffer(result.tensorPackageVec[0].tensorVec[0].dataStr, + dtype='float32').reshape((1, 20, 20, 3, 85)) + output_me = np.frombuffer(result.tensorPackageVec[0].tensorVec[1].dataStr, + dtype='float32').reshape((1, 40, 40, 3, 85)) + output_big = np.frombuffer(result.tensorPackageVec[0].tensorVec[2].dataStr, + dtype='float32').reshape((1, 80, 80, 3, 85)) + print('process {}...'.format(file_name)) + detection.detect([output_small, output_me, output_big], 1, image_shape, img_id_) + + print('do_nms_for_results...') + detection.do_nms_for_results() + detection.write_result() + + cost_time = time.time() - start_time + print('testing cost time {:.2f}h'.format(cost_time / 3600.)) + + +if __name__ == "__main__": + args = parser_args() + detections = DetectionEngine(args) + stream_name0 = cfg.STREAM_NAME.encode("utf-8") + print("stream_name0:") + print(stream_name0) + image_inference(args.pipeline_path, stream_name0, args.dataset_path, detections) diff --git a/community/cv/ADCAM/infer/sdk/run.sh b/community/cv/ADCAM/infer/sdk/run.sh new file mode 100644 index 0000000000000000000000000000000000000000..4b67802251bcaf5b522ee1fb4b16e46e47c34539 --- /dev/null +++ b/community/cv/ADCAM/infer/sdk/run.sh @@ -0,0 +1,49 @@ +#!/bin/bash +pipeline_path=./config/yolov5.pipeline +dataset_path=../data/image/ +ann_file=../data/instances_val2017.json +result_files=./result +# help message +if [[ $1 == --help || $1 == -h ]];then + echo "usage:bash ./run.sh " + echo "parameter explain: + --pipeline_path set SDK infer pipeline, e.g. --pipeline_path=./config/yolov5.pipeline + --dataset_path root path of processed images, e.g. --dataset_path=../data/image + --ann_file the folder to save the semantic mask images, default: --ann_file=./result + -h/--help show help message + " + exit 1 +fi + +for para in "$@" +do + if [[ $para == --pipeline_path* ]];then + pipeline_path=`echo ${para#*=}` + elif [[ $para == --dataset_path* ]];then + dataset_path=`echo ${para#*=}` + elif [[ $para == --ann_file* ]];then + ann_file=`echo ${para#*=}` + elif [[ $para == --result_files* ]];then + result_files=`echo ${para#*=}` + fi +done + +if [[ $pipeline_path == "" ]];then + echo "[Error] para \"pipeline_path \" must be config" + exit 1 +fi +if [[ $dataset_path == "" ]];then + echo "[Error] para \"dataset_path \" must be config" + exit 1 +fi +if [[ $ann_file == "" ]];then + echo "[Error] para \"ann_file \" must be config" + exit 1 +fi + +python3 main.py --pipeline_path=$pipeline_path \ + --dataset_path=$dataset_path \ + --ann_file=$ann_file \ + --result_files=$result_files + +exit 0 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84868_bt.log b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84868_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84869_bt.log b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84869_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84870_bt.log b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84870_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84871_bt.log b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84871_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84872_bt.log b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84872_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84873_bt.log b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84873_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84874_bt.log b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84874_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84875_bt.log b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/83917_84875_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84868.txt b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84868.txt new file mode 100644 index 0000000000000000000000000000000000000000..eab7c301c669b4f3fac063f6dba2adeaed2eb913 --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84868.txt @@ -0,0 +1,162 @@ +281453984752096.11 +281456605344224.36 +281454798873056.55 +281455545463264.61 +281454815658464.75 +281455537070560.94 +281455545463264.108 +281455528677856.130 +281454807265760.151 +281454807265760.194 +281456135582176.235 +281456135582176.260 +281453984752096.327 +281454001537504.337 +281453993144800.353 +281455537070560.360 +281455537070560.377 +281454798873056.422 +281454807265760.429 +281454807265760.435 +281454807265760.443 +281455528677856.454 +281455528677856.466 +281456135582176.475 +281456152367584.535 +281456152367584.541 +281456143974880.546 +281455553855968.547 +281456135582176.548 +281456152367584.549 +281456152367584.554 +281456152367584.558 +281456152367584.561 +281456152367584.564 +281456152367584.568 +281454790480352.1467 +281455528677856.1493 +281456605344224.1503 +281456605344224.1514 +281456605344224.1528 +281456605344224.1545 +281456605344224.1566 +281456605344224.1597 +281456605344224.1618 +281456605344224.1719 +281456135582176.1748 +281456605344224.1770 +281454001537504.1818 +281454001537504.1828 +281453984752096.1836 +281453984752096.1852 +281453984752096.1877 +281455553855968.2034 +281455537070560.2085 +281455537070560.2101 +281454815658464.2166 +281454815658464.2171 +281454815658464.2176 +281454815658464.2181 +281454815658464.2186 +281454815658464.2203 +281453993144800.2210 +281453993144800.2214 +281455545463264.2259 +281456135582176.2285 +281456135582176.2296 +281456143974880.2316 +281455553855968.2327 +281455553855968.2331 +281454790480352.2446 +281454790480352.2476 +281454790480352.2502 +281454790480352.2576 +281454790480352.2600 +281454790480352.2682 +281454790480352.2894 +281454790480352.2924 +281454790480352.3192 +281454790480352.3215 +281454790480352.3279 +281456605344224.3290 +281456605344224.3293 +281456605344224.3316 +281456605344224.3319 +281456605344224.3322 +281456605344224.3334 +281456605344224.3340 +281456605344224.3411 +281456605344224.3415 +281456605344224.3425 +281456605344224.3441 +281456605344224.3449 +281456605344224.3455 +281456605344224.3460 +281456605344224.3475 +281456605344224.3490 +281456605344224.3498 +281456605344224.3512 +281456605344224.3533 +281456143974880.3618 +281454790480352.3629 +281454790480352.3636 +281454790480352.3639 +281454790480352.3643 +281454790480352.3647 +281454790480352.3661 +281454790480352.3688 +281454790480352.3714 +281454790480352.3762 +281454790480352.3772 +281454790480352.3783 +281454790480352.3787 +281454790480352.3847 +281454790480352.3859 +281454790480352.3884 +281454790480352.3889 +281454790480352.3911 +281454790480352.3929 +281454790480352.3944 +281454790480352.3945 +281454790480352.3950 +281454790480352.3998 +281454790480352.4000 +281454790480352.4004 +281454790480352.4047 +281454790480352.4112 +281454790480352.4156 +281454790480352.4159 +281454790480352.4167 +281454790480352.4173 +281454790480352.4188 +281454790480352.4221 +281454790480352.4227 +281454790480352.4232 +281454790480352.4238 +281454790480352.4243 +281454790480352.4246 +281454790480352.4250 +281454790480352.4259 +281454790480352.4272 +281454790480352.4276 +281454790480352.4282 +281454790480352.4286 +281454790480352.4294 +281454790480352.4303 +281454790480352.4327 +281453984752096.4350 +281453984752096.4355 +281456152367584.4376 +281456152367584.4389 +281456152367584.4392 +281455545463264.4547 +281456613736928.4559 +281454790480352.4885 +281454790480352.4912 +281454790480352.4940 +281454790480352.4991 +281453984752096.5011 +281453993144800.5061 +281455545463264.5150 +281456152367584.5202 +281454815658464.5217 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84869.txt b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84869.txt new file mode 100644 index 0000000000000000000000000000000000000000..31602e2b4480ec6534ba675145c169aee6740dba --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84869.txt @@ -0,0 +1,140 @@ +281456613736928.8 +281456605344224.27 +281456605344224.39 +281454815658464.59 +281455537070560.73 +281456152367584.91 +281454815658464.106 +281456152367584.139 +281456152367584.165 +281455553855968.199 +281455553855968.223 +281455553855968.234 +281456143974880.271 +281453984752096.329 +281453993144800.354 +281455537070560.363 +281455537070560.379 +281455537070560.387 +281455545463264.390 +281455545463264.397 +281454798873056.401 +281455545463264.426 +281454807265760.432 +281454807265760.439 +281455528677856.464 +281455528677856.469 +281455553855968.480 +281456135582176.499 +281456135582176.508 +281455553855968.513 +281456152367584.576 +281454001537504.600 +281456605344224.689 +281455553855968.740 +281453984752096.756 +281455545463264.947 +281456143974880.1051 +281454807265760.1234 +281453984752096.1842 +281456143974880.1890 +281456605344224.1920 +281456613736928.1935 +281456613736928.1945 +281456605344224.1959 +281455553855968.1989 +281455553855968.2032 +281455537070560.2083 +281456605344224.2137 +281456605344224.2143 +281454815658464.2160 +281454815658464.2165 +281454815658464.2170 +281454815658464.2174 +281454815658464.2180 +281453993144800.2238 +281455545463264.2250 +281455545463264.2256 +281455528677856.2274 +281455528677856.2282 +281456135582176.2294 +281456143974880.2315 +281455553855968.2325 +281455553855968.2341 +281454790480352.2379 +281454790480352.2393 +281454790480352.2427 +281454790480352.2470 +281454790480352.2491 +281454790480352.2517 +281454790480352.2544 +281454790480352.2584 +281454790480352.2659 +281454790480352.2686 +281454790480352.2706 +281454790480352.2800 +281454790480352.3198 +281454790480352.3272 +281456605344224.3285 +281456605344224.3294 +281456605344224.3363 +281456605344224.3369 +281456605344224.3376 +281456605344224.3382 +281456605344224.3385 +281456605344224.3408 +281456605344224.3410 +281456605344224.3414 +281456605344224.3438 +281456605344224.3447 +281456605344224.3456 +281453984752096.3503 +281453984752096.3505 +281456605344224.3506 +281456605344224.3528 +281456152367584.3576 +281456152367584.3598 +281455545463264.3606 +281454790480352.3626 +281454790480352.3634 +281454790480352.3658 +281454790480352.3696 +281454790480352.3713 +281454790480352.3715 +281454790480352.3773 +281454790480352.3798 +281454790480352.3861 +281454790480352.3868 +281454790480352.3885 +281454790480352.3887 +281454790480352.3905 +281454790480352.3925 +281454790480352.3930 +281454790480352.3949 +281454790480352.3997 +281454790480352.4174 +281454790480352.4207 +281454790480352.4258 +281454790480352.4269 +281454790480352.4273 +281454790480352.4280 +281454790480352.4283 +281454790480352.4287 +281454790480352.4296 +281454790480352.4310 +281454790480352.4345 +281453984752096.4353 +281453984752096.4368 +281456152367584.4374 +281456152367584.4380 +281456152367584.4395 +281456605344224.4494 +281454001537504.4556 +281454790480352.4877 +281454790480352.4905 +281454790480352.4925 +281454790480352.4988 +281454790480352.5005 +281455553855968.5040 +281453984752096.5144 +281455545463264.5216 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84870.txt b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84870.txt new file mode 100644 index 0000000000000000000000000000000000000000..596af0e595f8b17677a0233bfce5ee36aa71f53b --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84870.txt @@ -0,0 +1,143 @@ +281454001537504.3 +281454790480352.31 +281454790480352.40 +281454815658464.64 +281455528677856.78 +281455528677856.102 +281456135582176.118 +281454815658464.134 +281456143974880.161 +281455553855968.208 +281455553855968.229 +281456152367584.248 +281456135582176.274 +281456613736928.331 +281456605344224.339 +281456605344224.342 +281453993144800.357 +281455537070560.364 +281455545463264.419 +281454807265760.431 +281454807265760.437 +281454807265760.445 +281455528677856.449 +281455528677856.463 +281455528677856.467 +281455553855968.477 +281456143974880.497 +281456143974880.509 +281456135582176.514 +281456152367584.577 +281454001537504.602 +281455553855968.741 +281453984752096.780 +281454798873056.898 +281454001537504.1005 +281454807265760.1230 +281454790480352.1466 +281455528677856.1490 +281455528677856.1495 +281456605344224.1512 +281456605344224.1524 +281456605344224.1538 +281456605344224.1547 +281456605344224.1574 +281456605344224.1612 +281456605344224.1694 +281456605344224.1711 +281456135582176.1756 +281456605344224.1811 +281453984752096.1827 +281453984752096.1848 +281456143974880.1888 +281456605344224.1922 +281456613736928.1939 +281456605344224.1957 +281456605344224.1982 +281456605344224.2013 +281455553855968.2042 +281455537070560.2089 +281453993144800.2213 +281453993144800.2217 +281453993144800.2219 +281453993144800.2223 +281453993144800.2227 +281454798873056.2231 +281453993144800.2241 +281453993144800.2246 +281455545463264.2251 +281456152367584.2270 +281456135582176.2284 +281456135582176.2289 +281454001537504.2310 +281456613736928.2317 +281455553855968.2323 +281455553855968.2330 +281454790480352.2357 +281454790480352.2364 +281454790480352.2378 +281454790480352.2413 +281454790480352.2441 +281454790480352.2475 +281454790480352.2495 +281454790480352.2503 +281454790480352.2583 +281454790480352.2657 +281454790480352.2679 +281454790480352.2694 +281454790480352.2724 +281454790480352.2889 +281454790480352.2902 +281454790480352.3216 +281456605344224.3286 +281456605344224.3296 +281456605344224.3364 +281456605344224.3370 +281456605344224.3381 +281456605344224.3442 +281456605344224.3474 +281456605344224.3485 +281456605344224.3494 +281456605344224.3504 +281456605344224.3522 +281453984752096.3538 +281456605344224.3541 +281454790480352.3621 +281454790480352.3637 +281454790480352.3644 +281454790480352.3650 +281454790480352.3673 +281454790480352.3684 +281454790480352.3691 +281454790480352.3701 +281454790480352.3761 +281454790480352.3775 +281454790480352.3780 +281454790480352.3788 +281454790480352.3850 +281454790480352.3860 +281454790480352.3878 +281454790480352.4048 +281454790480352.4155 +281454790480352.4169 +281454790480352.4181 +281454790480352.4189 +281454790480352.4237 +281454790480352.4241 +281454790480352.4251 +281454790480352.4255 +281454790480352.4267 +281454790480352.4270 +281454790480352.4298 +281454790480352.4317 +281453984752096.4346 +281455537070560.4554 +281453993144800.4565 +281454790480352.4887 +281454790480352.4924 +281454790480352.4931 +281454790480352.4992 +281453984752096.5012 +281456152367584.5081 +281455528677856.5147 +281456135582176.5246 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84871.txt b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84871.txt new file mode 100644 index 0000000000000000000000000000000000000000..7f03b07c16c7503c1d6675b02d30174d2dcf1296 --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84871.txt @@ -0,0 +1,165 @@ +281453984752096.12 +281453993144800.23 +281455537070560.57 +281455537070560.62 +281454798873056.76 +281456143974880.95 +281455553855968.107 +281455537070560.132 +281455545463264.146 +281456135582176.175 +281456135582176.217 +281455528677856.236 +281456143974880.250 +281456152367584.280 +281456613736928.332 +281453993144800.356 +281455537070560.362 +281454815658464.382 +281454815658464.392 +281455545463264.400 +281454798873056.404 +281455545463264.406 +281454815658464.408 +281454798873056.420 +281454807265760.430 +281454807265760.444 +281455528677856.448 +281456135582176.478 +281455553855968.498 +281456135582176.505 +281455553855968.510 +281455553855968.516 +281456135582176.517 +281456135582176.521 +281456143974880.538 +281455553855968.543 +281455553855968.551 +281456152367584.557 +281456152367584.565 +281456152367584.570 +281456605344224.682 +281456143974880.745 +281453993144800.799 +281455528677856.954 +281455553855968.1045 +281455537070560.1310 +281454815658464.1333 +281454815658464.1337 +281454815658464.1351 +281453993144800.1361 +281454815658464.1371 +281453993144800.1386 +281453993144800.1399 +281454798873056.1420 +281455545463264.1442 +281455545463264.1450 +281454790480352.1461 +281456605344224.1502 +281456605344224.1523 +281456605344224.1542 +281456605344224.1548 +281456605344224.1575 +281456605344224.1613 +281456605344224.1696 +281456605344224.1700 +281456135582176.1744 +281456135582176.1754 +281456605344224.1786 +281454001537504.1825 +281453984752096.1833 +281453984752096.1850 +281456605344224.1919 +281456613736928.1937 +281456605344224.1950 +281456605344224.1981 +281456605344224.2015 +281456605344224.2052 +281455537070560.2087 +281455537070560.2099 +281454815658464.2161 +281454815658464.2175 +281454815658464.2179 +281454815658464.2185 +281453993144800.2207 +281453993144800.2226 +281454798873056.2229 +281454798873056.2233 +281453993144800.2243 +281455545463264.2247 +281455545463264.2252 +281455528677856.2273 +281455528677856.2281 +281454001537504.2309 +281456143974880.2314 +281455553855968.2322 +281456605344224.3333 +281456605344224.3337 +281456605344224.3407 +281456605344224.3409 +281456605344224.3413 +281456605344224.3422 +281456605344224.3440 +281456605344224.3450 +281456605344224.3467 +281456605344224.3482 +281456605344224.3493 +281456605344224.3518 +281453984752096.3546 +281454798873056.3566 +281454790480352.3624 +281454790480352.3645 +281454790480352.3653 +281454790480352.3686 +281454790480352.3699 +281454790480352.3759 +281454790480352.3770 +281454790480352.3776 +281454790480352.3800 +281454790480352.3855 +281454790480352.3863 +281454790480352.3873 +281454790480352.3888 +281454790480352.3902 +281454790480352.3927 +281454790480352.3948 +281454790480352.4001 +281454790480352.4005 +281454790480352.4102 +281454790480352.4158 +281454790480352.4168 +281454790480352.4175 +281454790480352.4179 +281454790480352.4186 +281454790480352.4194 +281454790480352.4201 +281454790480352.4204 +281454790480352.4209 +281454790480352.4216 +281454790480352.4219 +281454790480352.4252 +281454790480352.4257 +281454790480352.4262 +281454790480352.4268 +281454790480352.4277 +281454790480352.4279 +281454790480352.4284 +281454790480352.4289 +281454790480352.4304 +281454790480352.4344 +281453984752096.4351 +281453984752096.4360 +281453984752096.4362 +281453984752096.4363 +281456152367584.4382 +281454807265760.4555 +281455528677856.4567 +281454790480352.4881 +281454790480352.4907 +281454790480352.4936 +281454790480352.4995 +281454807265760.5022 +281454790480352.5084 +281454815658464.5153 +281455545463264.5215 +281455545463264.5443 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84872.txt b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84872.txt new file mode 100644 index 0000000000000000000000000000000000000000..f4f0fcf759535b5a52b8d25947a8aaa20e73adaa --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84872.txt @@ -0,0 +1,157 @@ +281453993144800.16 +281455545463264.66 +281455528677856.83 +281455537070560.104 +281455528677856.140 +281456143974880.196 +281456143974880.220 +281456135582176.239 +281455553855968.269 +281456613736928.330 +281456605344224.338 +281456605344224.340 +281454790480352.345 +281454790480352.347 +281454790480352.349 +281453993144800.352 +281455537070560.367 +281454815658464.388 +281455545463264.394 +281454815658464.402 +281455545463264.411 +281454798873056.416 +281454798873056.418 +281455545463264.423 +281454807265760.434 +281454807265760.440 +281455528677856.452 +281455528677856.470 +281456143974880.479 +281456143974880.503 +281456143974880.506 +281456135582176.511 +281456143974880.515 +281456143974880.518 +281456143974880.526 +281455553855968.539 +281456135582176.544 +281456135582176.552 +281456152367584.559 +281456152367584.563 +281456152367584.573 +281456152367584.574 +281456152367584.578 +281454001537504.607 +281455545463264.729 +281456135582176.743 +281453993144800.797 +281455528677856.952 +281456613736928.1149 +281454807265760.1229 +281454815658464.1348 +281453993144800.1360 +281453993144800.1368 +281453993144800.1384 +281453993144800.1389 +281453993144800.1401 +281454798873056.1424 +281455545463264.1449 +281455545463264.1454 +281454790480352.1465 +281455537070560.2095 +281456605344224.2141 +281454815658464.2159 +281454815658464.2164 +281453993144800.2222 +281453993144800.2224 +281453993144800.2236 +281453993144800.2239 +281453993144800.2244 +281455545463264.2249 +281455545463264.2254 +281455545463264.2258 +281456135582176.2286 +281456135582176.2295 +281454001537504.2311 +281456613736928.2320 +281455553855968.2328 +281455553855968.2342 +281454790480352.2397 +281454790480352.2421 +281454790480352.2438 +281454790480352.2451 +281454790480352.2487 +281454790480352.2507 +281454790480352.2520 +281454790480352.2601 +281454790480352.2681 +281454790480352.2803 +281454790480352.2898 +281454790480352.3186 +281454790480352.3213 +281454790480352.3228 +281454790480352.3277 +281456605344224.3288 +281456605344224.3318 +281456605344224.3321 +281456605344224.3327 +281456605344224.3335 +281456605344224.3386 +281456605344224.3444 +281456605344224.3454 +281456605344224.3463 +281456605344224.3473 +281456605344224.3479 +281456605344224.3488 +281456605344224.3496 +281456605344224.3508 +281456605344224.3530 +281456605344224.3539 +281456152367584.3599 +281456135582176.3612 +281454790480352.3623 +281454790480352.3631 +281454790480352.3642 +281454790480352.3651 +281454790480352.3660 +281454790480352.3678 +281454790480352.3689 +281454790480352.3694 +281454790480352.3712 +281454790480352.3779 +281454790480352.3784 +281454790480352.3793 +281454790480352.3848 +281454790480352.3858 +281454790480352.3869 +281454790480352.3874 +281454790480352.3910 +281454790480352.3946 +281454790480352.3996 +281454790480352.3999 +281454790480352.4003 +281454790480352.4046 +281454790480352.4107 +281454790480352.4164 +281454790480352.4172 +281455553855968.4184 +281454790480352.4190 +281454790480352.4196 +281454790480352.4200 +281454790480352.4226 +281454790480352.4231 +281454790480352.4236 +281454790480352.4239 +281454790480352.4244 +281454790480352.4256 +281454790480352.4260 +281454790480352.4288 +281454790480352.4297 +281454790480352.4311 +281453984752096.4347 +281453984752096.4354 +281456152367584.4373 +281455537070560.5056 +281456143974880.5146 +281456143974880.5267 +281456152367584.5411 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84873.txt b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84873.txt new file mode 100644 index 0000000000000000000000000000000000000000..482adf5db42892b426303ef2bff728917f339633 --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84873.txt @@ -0,0 +1,177 @@ +281453993144800.20 +281454807265760.74 +281454807265760.103 +281454807265760.112 +281455528677856.167 +281456135582176.209 +281456135582176.230 +281455528677856.254 +281456152367584.262 +281456152367584.300 +281454001537504.333 +281454001537504.335 +281454790480352.344 +281453993144800.355 +281455537070560.361 +281454815658464.384 +281455537070560.385 +281454798873056.391 +281454815658464.399 +281454798873056.407 +281455545463264.409 +281455545463264.427 +281454807265760.436 +281455528677856.447 +281455528677856.450 +281455528677856.472 +281456143974880.476 +281456135582176.481 +281455553855968.504 +281455553855968.507 +281456143974880.512 +281454001537504.603 +281456605344224.685 +281453993144800.708 +281454798873056.723 +281456135582176.742 +281453984752096.774 +281454798873056.891 +281455545463264.935 +281454790480352.1106 +281456613736928.1146 +281455537070560.1308 +281455537070560.1314 +281454815658464.1335 +281454815658464.1347 +281454815658464.1358 +281454815658464.1363 +281453993144800.1376 +281453993144800.1387 +281453993144800.1392 +281453993144800.1408 +281454798873056.1422 +281455545463264.1451 +281454790480352.1462 +281455528677856.1489 +281455528677856.1492 +281456605344224.1501 +281456605344224.1513 +281456605344224.1525 +281456605344224.1544 +281456605344224.1565 +281456605344224.1614 +281456605344224.1697 +281456605344224.1712 +281456135582176.1746 +281456605344224.1769 +281456605344224.1790 +281454001537504.1831 +281454001537504.1837 +281453984752096.1839 +281454815658464.2184 +281454815658464.2201 +281453993144800.2206 +281453993144800.2211 +281453993144800.2216 +281453993144800.2218 +281453993144800.2221 +281453993144800.2225 +281453993144800.2230 +281453993144800.2237 +281453993144800.2240 +281453993144800.2245 +281455545463264.2257 +281455528677856.2283 +281454001537504.2308 +281456143974880.2313 +281456613736928.2321 +281455553855968.2329 +281454790480352.2353 +281454790480352.2377 +281454790480352.2392 +281454790480352.2426 +281454790480352.2442 +281454790480352.2477 +281454790480352.2501 +281454790480352.2524 +281454790480352.2532 +281454790480352.2578 +281454790480352.2605 +281454790480352.2613 +281454790480352.2664 +281454790480352.2721 +281454790480352.3090 +281454790480352.3199 +281454790480352.3266 +281454790480352.3283 +281456605344224.3287 +281456605344224.3315 +281456605344224.3317 +281456605344224.3320 +281456605344224.3323 +281456605344224.3330 +281456605344224.3336 +281456605344224.3339 +281456605344224.3342 +281456605344224.3412 +281456605344224.3419 +281456605344224.3439 +281456605344224.3446 +281456605344224.3458 +281456605344224.3464 +281456605344224.3472 +281456605344224.3487 +281456605344224.3520 +281453984752096.3550 +281454815658464.3561 +281455528677856.3610 +281454790480352.3632 +281454790480352.3652 +281454790480352.3675 +281454790480352.3687 +281454790480352.3702 +281454790480352.3763 +281454790480352.3771 +281454790480352.3782 +281454790480352.3790 +281454790480352.3849 +281454790480352.3857 +281454790480352.3866 +281454790480352.3880 +281454790480352.3913 +281454790480352.3947 +281454790480352.3951 +281454790480352.4002 +281454790480352.4051 +281454790480352.4104 +281454790480352.4171 +281454790480352.4177 +281454790480352.4183 +281454790480352.4187 +281454790480352.4195 +281454790480352.4198 +281454790480352.4203 +281454790480352.4214 +281454790480352.4224 +281454790480352.4230 +281454790480352.4278 +281454790480352.4281 +281454790480352.4285 +281454790480352.4293 +281454790480352.4302 +281454790480352.4322 +281453984752096.4349 +281453984752096.4365 +281456152367584.4378 +281456152367584.4381 +281456152367584.4393 +281456605344224.4512 +281454798873056.4558 +281454790480352.4879 +281454790480352.4893 +281454790480352.4926 +281454790480352.4955 +281456605344224.5016 +281456152367584.5082 +281456605344224.5149 +281456143974880.5271 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84874.txt b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84874.txt new file mode 100644 index 0000000000000000000000000000000000000000..b1e3706ba69bc5c96fc844b84bde63803e713a48 --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84874.txt @@ -0,0 +1,146 @@ +281454001537504.5 +281454798873056.60 +281454815658464.96 +281456152367584.110 +281456152367584.129 +281454798873056.148 +281454807265760.186 +281454807265760.211 +281456143974880.232 +281455553855968.255 +281456152367584.284 +281456605344224.334 +281455537070560.365 +281454815658464.380 +281454815658464.386 +281455545463264.425 +281454807265760.438 +281454807265760.446 +281455528677856.462 +281456143974880.473 +281455553855968.520 +281455553855968.528 +281456135582176.540 +281456152367584.545 +281456143974880.550 +281456152367584.556 +281456152367584.560 +281456152367584.567 +281456152367584.572 +281455537070560.714 +281454807265760.735 +281456143974880.744 +281453993144800.791 +281454001537504.998 +281453984752096.1176 +281453984752096.1177 +281454807265760.1228 +281454815658464.1375 +281453993144800.1390 +281453993144800.1410 +281455545463264.1443 +281455545463264.1452 +281454790480352.1463 +281456605344224.1617 +281456605344224.1698 +281456605344224.1720 +281456135582176.1753 +281456605344224.1784 +281453984752096.1824 +281454001537504.1840 +281453984752096.1844 +281456143974880.1873 +281456143974880.1876 +281456143974880.1882 +281456605344224.1921 +281456613736928.1933 +281456605344224.1949 +281456605344224.2011 +281456605344224.2023 +281455537070560.2093 +281455537070560.2103 +281454815658464.2163 +281454815658464.2167 +281454815658464.2172 +281454815658464.2183 +281454815658464.2202 +281453993144800.2208 +281453993144800.2212 +281453993144800.2228 +281453993144800.2235 +281453993144800.2242 +281455545463264.2248 +281455545463264.2255 +281455528677856.2272 +281455528677856.2276 +281456135582176.2288 +281454001537504.2307 +281456143974880.2312 +281456613736928.2319 +281455553855968.2326 +281455553855968.2336 +281455553855968.2338 +281455553855968.2339 +281456605344224.3291 +281456605344224.3362 +281456605344224.3366 +281456605344224.3373 +281456605344224.3380 +281456605344224.3388 +281456605344224.3445 +281456605344224.3448 +281456605344224.3466 +281456605344224.3492 +281456605344224.3500 +281456605344224.3516 +281456605344224.3537 +281456152367584.3575 +281456152367584.3593 +281456152367584.3603 +281454807265760.3614 +281454790480352.3627 +281454790480352.3635 +281454790480352.3640 +281454790480352.3648 +281454790480352.3676 +281454790480352.3683 +281454790480352.3693 +281454790480352.3704 +281454790480352.3769 +281454790480352.3777 +281454790480352.3785 +281454790480352.3845 +281454790480352.3856 +281454790480352.3865 +281454790480352.3871 +281454790480352.3886 +281454790480352.3912 +281454790480352.3928 +281454790480352.3943 +281454790480352.4157 +281454790480352.4160 +281454790480352.4166 +281454790480352.4176 +281455553855968.4182 +281454790480352.4185 +281454790480352.4191 +281454790480352.4197 +281454790480352.4202 +281454790480352.4205 +281454790480352.4211 +281454790480352.4218 +281454790480352.4229 +281454790480352.4265 +281454790480352.4271 +281454790480352.4343 +281453984752096.4352 +281453984752096.4366 +281456152367584.4375 +281456152367584.4387 +281456152367584.4390 +281454790480352.4989 +281454790480352.4998 +281456143974880.5025 +281454798873056.5143 +281456135582176.5204 +281456152367584.5231 diff --git a/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84875.txt b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84875.txt new file mode 100644 index 0000000000000000000000000000000000000000..f0d270de17aeb0dfceb986a4c50822461383f012 --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_11888696854365449242/task_pid_83917_84875.txt @@ -0,0 +1,178 @@ +281456613736928.7 +281454790480352.38 +281454807265760.58 +281454807265760.63 +281455545463264.77 +281456152367584.101 +281455545463264.117 +281455553855968.163 +281456143974880.204 +281456143974880.226 +281455528677856.245 +281456152367584.253 +281453984752096.328 +281456605344224.336 +281456605344224.341 +281454790480352.346 +281454790480352.348 +281454790480352.350 +281453993144800.358 +281455537070560.369 +281455537070560.381 +281455537070560.389 +281454798873056.395 +281454798873056.398 +281455545463264.403 +281455545463264.421 +281454807265760.433 +281454807265760.441 +281455528677856.455 +281455528677856.465 +281455553855968.474 +281456135582176.529 +281456143974880.542 +281456152367584.553 +281456152367584.555 +281456152367584.562 +281456152367584.566 +281456152367584.569 +281453984752096.650 +281456605344224.684 +281453984752096.759 +281454798873056.888 +281454807265760.980 +281454001537504.1001 +281456135582176.1048 +281453984752096.1178 +281454807265760.1231 +281454815658464.1349 +281454815658464.1362 +281454815658464.1379 +281453993144800.1388 +281453993144800.1402 +281453993144800.1412 +281455545463264.1441 +281455545463264.1448 +281455545463264.1453 +281454790480352.1464 +281455528677856.1491 +281455528677856.1494 +281456605344224.1506 +281456605344224.1517 +281456605344224.1534 +281456605344224.1546 +281456605344224.1573 +281456605344224.1598 +281456605344224.1636 +281456605344224.1699 +281456605344224.1721 +281456135582176.1750 +281456605344224.1785 +281454001537504.1822 +281453984752096.1830 +281453984752096.1846 +281456143974880.1879 +281456605344224.1916 +281456605344224.1923 +281456613736928.1943 +281456605344224.1958 +281455553855968.1987 +281455553855968.2022 +281455537070560.2081 +281455537070560.2097 +281454815658464.2162 +281454815658464.2169 +281454815658464.2173 +281454815658464.2178 +281454815658464.2182 +281454815658464.2200 +281453993144800.2209 +281455545463264.2253 +281455528677856.2271 +281455528677856.2275 +281456135582176.2287 +281454807265760.2306 +281456613736928.2318 +281455553855968.2324 +281455553855968.2340 +281455553855968.2344 +281454790480352.2372 +281454790480352.2383 +281454790480352.2389 +281454790480352.2402 +281454790480352.2428 +281454790480352.2462 +281454790480352.2490 +281454790480352.2519 +281454790480352.2598 +281454790480352.2625 +281454790480352.2665 +281454790480352.2765 +281454790480352.2896 +281454790480352.3055 +281454790480352.3197 +281454790480352.3220 +281454790480352.3240 +281454790480352.3278 +281456605344224.3289 +281456605344224.3361 +281456605344224.3365 +281456605344224.3371 +281456605344224.3379 +281456605344224.3383 +281456605344224.3443 +281456605344224.3457 +281456605344224.3465 +281456605344224.3468 +281456605344224.3502 +281456605344224.3510 +281456605344224.3526 +281453984752096.3545 +281455537070560.3556 +281454790480352.3622 +281454790480352.3630 +281454790480352.3633 +281454790480352.3659 +281454790480352.3677 +281454790480352.3685 +281454790480352.3690 +281454790480352.3697 +281454790480352.3698 +281454790480352.3707 +281454790480352.3764 +281454790480352.3774 +281454790480352.3799 +281454790480352.3801 +281454790480352.3862 +281454790480352.3870 +281454790480352.3876 +281454790480352.4056 +281454790480352.4103 +281454790480352.4162 +281454790480352.4217 +281454790480352.4228 +281454790480352.4235 +281454790480352.4242 +281454790480352.4245 +281454790480352.4248 +281454790480352.4290 +281454790480352.4299 +281454790480352.4318 +281453984752096.4348 +281453984752096.4364 +281456152367584.4377 +281456152367584.4379 +281456152367584.4391 +281456605344224.4528 +281456143974880.4557 +281454790480352.4873 +281454790480352.4875 +281454790480352.4889 +281454790480352.4908 +281454790480352.4928 +281454790480352.5002 +281454001537504.5029 +281454001537504.5138 +281455545463264.5151 +281454798873056.5214 +281454798873056.5245 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23720_bt.log b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23720_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23721_bt.log b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23721_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23722_bt.log b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23722_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23723_bt.log b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23723_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23724_bt.log b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23724_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23725_bt.log b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23725_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23726_bt.log b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23726_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23727_bt.log b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/22814_23727_bt.log new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/buildPidInfo.json b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/buildPidInfo.json new file mode 100644 index 0000000000000000000000000000000000000000..926f02c9fb06732e844cfc6aac36863ec857bb1a --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/buildPidInfo.json @@ -0,0 +1,6 @@ +[ + [ + 22814, + "/home/ma-user/work/YOLOv5-最终版/kernel_meta/kernel_meta_10325095174471029764" + ] +] \ No newline at end of file diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23720.txt b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23720.txt new file mode 100644 index 0000000000000000000000000000000000000000..53e0802b761839601a2183d952ef8cab00832c36 --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23720.txt @@ -0,0 +1,139 @@ +281455735587296.8 +281452577227232.31 +281452256571872.48 +281453716173280.70 +281453716173280.86 +281454190997984.137 +281454207783392.174 +281454199390688.257 +281454207783392.277 +281452264964576.334 +281452577227232.340 +281452256571872.345 +281452256571872.346 +281452256571872.348 +281452256571872.350 +281455727194592.363 +281453859602912.384 +281453732958688.463 +281453732958688.467 +281454199390688.497 +281454182605280.524 +281454190997984.539 +281454190997984.542 +281454207783392.554 +281454190997984.559 +281454190997984.561 +281454199390688.712 +281455727194592.795 +281452577227232.1138 +281453732958688.1183 +281454207783392.1414 +281454207783392.1438 +281454182605280.1506 +281453724565984.1527 +281453724565984.1533 +281453724565984.1539 +281452264964576.1553 +281452264964576.1558 +281452776042976.1595 +281454199390688.1607 +281454199390688.1625 +281454199390688.1645 +281454199390688.1667 +281454199390688.1699 +281453732958688.1795 +281454199390688.1818 +281453716173280.1849 +281453851210208.2079 +281454199390688.2101 +281454199390688.2103 +281454199390688.2105 +281454182605280.2120 +281454182605280.2138 +281454199390688.2187 +281454199390688.2210 +281453724565984.2259 +281455735587296.2283 +281455735587296.2293 +281452264964576.2326 +281453859602912.2398 +281453859602912.2408 +281453859602912.2443 +281453859602912.2461 +281453859602912.2490 +281453859602912.2525 +281453859602912.2543 +281453859602912.2563 +281453859602912.2602 +281453859602912.2698 +281453859602912.2725 +281453732958688.2767 +281455727194592.3100 +281455727194592.3132 +281453859602912.3287 +281453859602912.3321 +281453716173280.3352 +281453851210208.3370 +281452577227232.3386 +281452577227232.3391 +281452577227232.3405 +281454199390688.3414 +281454199390688.3420 +281454199390688.3442 +281454199390688.3444 +281454199390688.3446 +281454199390688.3448 +281454199390688.3454 +281454199390688.3462 +281454199390688.3536 +281454199390688.3538 +281454199390688.3542 +281454199390688.3551 +281454199390688.3569 +281454199390688.3579 +281454199390688.3601 +281454199390688.3610 +281454199390688.3638 +281453716173280.3650 +281453716173280.3666 +281453859602912.3679 +281453859602912.3685 +281453859602912.3732 +281453724565984.3743 +281453859602912.3749 +281453859602912.3771 +281453859602912.3828 +281453859602912.3843 +281453859602912.3868 +281453859602912.3870 +281453859602912.3931 +281453859602912.3939 +281453859602912.3943 +281453859602912.3979 +281453859602912.4016 +281453859602912.4065 +281453859602912.4068 +281453859602912.4072 +281453859602912.4115 +281453859602912.4224 +281453859602912.4235 +281453859602912.4243 +281453859602912.4281 +281453859602912.4284 +281453859602912.4315 +281453859602912.4323 +281453859602912.4333 +281453859602912.4341 +281453859602912.4347 +281453859602912.4351 +281453859602912.4358 +281453859602912.4368 +281453859602912.4392 +281452577227232.4423 +281453716173280.4572 +281455727194592.4856 +281453859602912.5014 +281453859602912.5042 +281452256571872.5175 +281452577227232.5244 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23721.txt b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23721.txt new file mode 100644 index 0000000000000000000000000000000000000000..135d4a876567945048fa1a81b8581ed272914d74 --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23721.txt @@ -0,0 +1,140 @@ +281455727194592.19 +281453859602912.84 +281454182605280.135 +281454207783392.158 +281454207783392.246 +281455735587296.328 +281452577227232.336 +281455727194592.361 +281453859602912.375 +281453859602912.390 +281453716173280.406 +281453851210208.428 +281453851210208.436 +281453724565984.445 +281454182605280.474 +281454199390688.480 +281454182605280.504 +281454199390688.521 +281454182605280.536 +281454190997984.548 +281454207783392.569 +281453724565984.861 +281453859602912.901 +281452256571872.969 +281455735587296.1027 +281453724565984.1083 +281452248179168.1299 +281452776042976.1335 +281453851210208.1377 +281453851210208.1383 +281454207783392.1406 +281453851210208.1424 +281454182605280.1503 +281454182605280.1520 +281453724565984.1531 +281455735587296.1538 +281452264964576.1551 +281452264964576.1555 +281452776042976.1592 +281452776042976.1598 +281454199390688.1614 +281454199390688.1629 +281454199390688.1647 +281453732958688.1801 +281454199390688.1821 +281452256571872.1874 +281453851210208.2085 +281454182605280.2129 +281454199390688.2162 +281454207783392.2169 +281453724565984.2281 +281452264964576.2324 +281452577227232.2359 +281452776042976.2364 +281453859602912.2492 +281453859602912.2516 +281453859602912.2551 +281453859602912.2595 +281453859602912.2619 +281453859602912.2701 +281453859602912.2789 +281453859602912.2827 +281453859602912.2913 +281453859602912.2918 +281453859602912.2922 +281453859602912.2948 +281453859602912.3079 +281455727194592.3094 +281452577227232.3399 +281452577227232.3401 +281452577227232.3404 +281454199390688.3415 +281454199390688.3443 +281454199390688.3445 +281454199390688.3447 +281454199390688.3449 +281454199390688.3460 +281454199390688.3464 +281454199390688.3537 +281454199390688.3540 +281454199390688.3544 +281454199390688.3567 +281454199390688.3575 +281454199390688.3587 +281454199390688.3594 +281454199390688.3596 +281454199390688.3609 +281454199390688.3619 +281454199390688.3625 +281454199390688.3630 +281454199390688.3640 +281453716173280.3653 +281453716173280.3667 +281453859602912.3680 +281453859602912.3684 +281453859602912.3703 +281453859602912.3716 +281453859602912.3744 +281453859602912.3765 +281453859602912.3766 +281453859602912.3826 +281453859602912.3840 +281453859602912.3851 +281453859602912.3856 +281453859602912.3916 +281453859602912.3928 +281453859602912.3947 +281453859602912.4117 +281453859602912.4181 +281453859602912.4227 +281453859602912.4238 +281453859602912.4247 +281453859602912.4252 +281453859602912.4260 +281453859602912.4263 +281453859602912.4268 +281453859602912.4276 +281453859602912.4283 +281453859602912.4296 +281453859602912.4301 +281453859602912.4302 +281453859602912.4307 +281453859602912.4311 +281453859602912.4317 +281453859602912.4324 +281453859602912.4337 +281453859602912.4342 +281453859602912.4344 +281453859602912.4349 +281453859602912.4354 +281453859602912.4367 +281453859602912.4387 +281454207783392.4420 +281454190997984.4588 +281453859602912.4983 +281453859602912.4995 +281453859602912.5018 +281453859602912.5097 +281453724565984.5166 +281452264964576.5201 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23722.txt b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23722.txt new file mode 100644 index 0000000000000000000000000000000000000000..36a35c1b76003b81af5bb64391a3c6fdb2ace1d1 --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23722.txt @@ -0,0 +1,153 @@ +281455727194592.16 +281453859602912.69 +281453724565984.82 +281453724565984.103 +281453716173280.127 +281453732958688.152 +281454190997984.276 +281452264964576.333 +281452577227232.339 +281452256571872.344 +281455727194592.353 +281452776042976.354 +281453859602912.385 +281453716173280.394 +281453716173280.403 +281453851210208.412 +281453851210208.432 +281453724565984.439 +281453732958688.465 +281454182605280.501 +281454199390688.517 +281454182605280.528 +281454207783392.541 +281454207783392.552 +281454207783392.577 +281454182605280.711 +281452256571872.781 +281454190997984.877 +281452248179168.1291 +281452248179168.1295 +281453851210208.1343 +281453851210208.1371 +281453851210208.1387 +281453851210208.1401 +281453851210208.1419 +281454207783392.1441 +281454182605280.1489 +281454182605280.1509 +281455735587296.1528 +281455735587296.1534 +281452264964576.1556 +281452776042976.1594 +281454199390688.1604 +281454199390688.1618 +281454199390688.1639 +281454199390688.1649 +281454199390688.1676 +281454199390688.1719 +281454199390688.1822 +281454199390688.1877 +281455727194592.1894 +281454199390688.1937 +281454199390688.2031 +281453851210208.2048 +281454182605280.2114 +281454182605280.2141 +281454199390688.2188 +281453724565984.2257 +281453724565984.2279 +281454199390688.2292 +281455735587296.2303 +281452776042976.2362 +281453859602912.2404 +281453859602912.2441 +281453859602912.2466 +281453859602912.2505 +281453859602912.2538 +281453859602912.2620 +281453859602912.2705 +281453859602912.2740 +281453859602912.2824 +281453859602912.2920 +281453859602912.2926 +281455727194592.3096 +281455727194592.3110 +281453859602912.3239 +281453859602912.3245 +281453859602912.3262 +281453859602912.3324 +281453716173280.3354 +281452256571872.3365 +281452577227232.3388 +281452577227232.3402 +281454199390688.3450 +281454199390688.3461 +281454199390688.3491 +281454199390688.3494 +281454199390688.3500 +281454199390688.3509 +281454199390688.3515 +281454199390688.3573 +281454199390688.3584 +281454199390688.3589 +281454199390688.3604 +281454199390688.3615 +281454199390688.3623 +281454199390688.3629 +281454199390688.3639 +281454199390688.3644 +281453716173280.3654 +281453716173280.3669 +281453859602912.3674 +281453859602912.3689 +281453859602912.3691 +281453859602912.3697 +281453859602912.3707 +281453859602912.3714 +281453859602912.3728 +281453859602912.3740 +281453732958688.3753 +281453859602912.3758 +281453859602912.3774 +281453859602912.3830 +281453859602912.3839 +281453859602912.3848 +281453859602912.3853 +281453859602912.3862 +281453859602912.3917 +281453859602912.3927 +281453859602912.3938 +281453859602912.3945 +281453859602912.4125 +281453859602912.4172 +281453859602912.4228 +281453859602912.4236 +281453859602912.4245 +281453859602912.4250 +281453859602912.4256 +281453859602912.4262 +281453859602912.4267 +281453859602912.4270 +281453859602912.4279 +281453859602912.4286 +281453859602912.4293 +281453859602912.4300 +281453859602912.4304 +281453859602912.4309 +281453859602912.4320 +281453859602912.4332 +281453859602912.4335 +281453859602912.4362 +281453859602912.4376 +281455727194592.4413 +281454199390688.4553 +281452256571872.4584 +281453859602912.4985 +281453859602912.4999 +281453859602912.5032 +281453859602912.5104 +281455735587296.5172 +281452577227232.5218 +281455735587296.5237 +281455735587296.5250 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23723.txt b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23723.txt new file mode 100644 index 0000000000000000000000000000000000000000..13f6f249fd14aa04fd91ab87be6ef35046d527ea --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23723.txt @@ -0,0 +1,124 @@ +281452248179168.12 +281452577227232.28 +281452776042976.47 +281453716173280.83 +281453732958688.104 +281453851210208.130 +281454207783392.149 +281454207783392.241 +281454199390688.275 +281455735587296.332 +281455727194592.359 +281453859602912.374 +281453716173280.393 +281453716173280.408 +281453851210208.424 +281453732958688.462 +281454199390688.478 +281454190997984.557 +281452248179168.594 +281452248179168.610 +281455727194592.670 +281452776042976.684 +281453859602912.696 +281454199390688.713 +281455727194592.797 +281452577227232.1136 +281452577227232.1141 +281453716173280.1192 +281453851210208.1430 +281454190997984.1475 +281454199390688.1603 +281454199390688.1624 +281454199390688.1643 +281454199390688.1666 +281454199390688.1715 +281453732958688.1805 +281455727194592.1839 +281455727194592.1880 +281455727194592.1903 +281454199390688.1942 +281453851210208.2050 +281453851210208.2100 +281454182605280.2123 +281454182605280.2135 +281454199390688.2186 +281454199390688.2192 +281453724565984.2261 +281454199390688.2280 +281455735587296.2285 +281455735587296.2310 +281452776042976.2363 +281453859602912.2407 +281453859602912.2442 +281453859602912.2477 +281453859602912.2506 +281453859602912.2539 +281453859602912.2624 +281453859602912.2644 +281453859602912.2683 +281453732958688.2769 +281455727194592.3102 +281455727194592.3112 +281453859602912.3263 +281453716173280.3334 +281453716173280.3355 +281454182605280.3375 +281452577227232.3390 +281452577227232.3394 +281454199390688.3416 +281454199390688.3466 +281454199390688.3492 +281454199390688.3498 +281454199390688.3502 +281454199390688.3510 +281454199390688.3571 +281454199390688.3603 +281454199390688.3605 +281454199390688.3617 +281454199390688.3624 +281454199390688.3632 +281454199390688.3643 +281453716173280.3651 +281453716173280.3656 +281453859602912.3676 +281453859602912.3683 +281453859602912.3687 +281453859602912.3730 +281452776042976.3745 +281452264964576.3755 +281453859602912.3760 +281453859602912.3779 +281453859602912.3845 +281453859602912.3869 +281453859602912.3924 +281453859602912.3934 +281453859602912.3940 +281453859602912.3955 +281453859602912.3981 +281453859602912.3998 +281453859602912.4013 +281453859602912.4014 +281453859602912.4020 +281453859602912.4071 +281453859602912.4120 +281453859602912.4173 +281453859602912.4240 +281453859602912.4246 +281453859602912.4249 +281453859602912.4253 +281453859602912.4291 +281453859602912.4295 +281453859602912.4343 +281453859602912.4346 +281453859602912.4350 +281453859602912.4355 +281453859602912.4364 +281453859602912.4382 +281452248179168.4418 +281453724565984.4576 +281453859602912.4981 +281453859602912.4993 +281453859602912.5031 +281454190997984.5171 +281453851210208.5226 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23724.txt b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23724.txt new file mode 100644 index 0000000000000000000000000000000000000000..937e218a8720ece2118827b701db1376b1beb466 --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23724.txt @@ -0,0 +1,114 @@ +281452248179168.11 +281455727194592.20 +281452256571872.50 +281453859602912.73 +281453724565984.89 +281453851210208.107 +281453716173280.136 +281454199390688.183 +281454190997984.260 +281452248179168.329 +281452577227232.337 +281452577227232.341 +281452256571872.347 +281452256571872.349 +281455727194592.352 +281453859602912.379 +281453716173280.399 +281453716173280.409 +281453851210208.426 +281453724565984.435 +281453724565984.441 +281454182605280.473 +281454190997984.555 +281454207783392.570 +281454199390688.931 +281452248179168.1297 +281452776042976.1333 +281453851210208.1359 +281453851210208.1379 +281454207783392.1388 +281453851210208.1405 +281454207783392.1462 +281454182605280.1491 +281454182605280.1518 +281455735587296.1530 +281455735587296.1536 +281452248179168.1546 +281454199390688.1698 +281454199390688.1737 +281454199390688.1816 +281454199390688.1854 +281454199390688.1921 +281454199390688.1960 +281454199390688.2033 +281453851210208.2052 +281454207783392.2099 +281454182605280.2150 +281453724565984.2267 +281455735587296.2289 +281452264964576.2322 +281452577227232.2347 +281452577227232.2350 +281452577227232.2355 +281452776042976.2365 +281452248179168.2531 +281455727194592.3098 +281455727194592.3130 +281453859602912.3260 +281453859602912.3267 +281453859602912.3313 +281453859602912.3330 +281453716173280.3335 +281453716173280.3362 +281452577227232.3385 +281454199390688.3457 +281454199390688.3463 +281454199390688.3467 +281454199390688.3539 +281454199390688.3543 +281454199390688.3554 +281454199390688.3570 +281454199390688.3578 +281454199390688.3586 +281454199390688.3593 +281454199390688.3597 +281454199390688.3626 +281454199390688.3635 +281454199390688.3642 +281453716173280.3652 +281453716173280.3661 +281453716173280.3663 +281453716173280.3664 +281453859602912.3686 +281453859602912.3731 +281453859602912.3742 +281453859602912.3752 +281453859602912.3756 +281453859602912.3761 +281453859602912.3780 +281453859602912.3782 +281453859602912.3844 +281453859602912.3849 +281453859602912.3867 +281453859602912.3932 +281453859602912.3942 +281453859602912.3957 +281453859602912.3971 +281453859602912.3996 +281453859602912.4018 +281453859602912.4066 +281453859602912.4242 +281453859602912.4254 +281453859602912.4306 +281453859602912.4313 +281453859602912.4359 +281453859602912.4369 +281453859602912.4410 +281454199390688.4537 +281452248179168.4682 +281453859602912.5030 +281453859602912.5046 +281452776042976.5173 +281452776042976.5258 +281454207783392.5399 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23725.txt b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23725.txt new file mode 100644 index 0000000000000000000000000000000000000000..f42141ec1d0460487ad171fb6ac01f9968bbbea3 --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23725.txt @@ -0,0 +1,149 @@ +281452264964576.5 +281452256571872.42 +281452776042976.64 +281453859602912.81 +281453732958688.99 +281454199390688.124 +281453732958688.143 +281454190997984.186 +281454207783392.273 +281452248179168.331 +281452776042976.356 +281452776042976.372 +281453859602912.388 +281453716173280.400 +281453716173280.404 +281453851210208.411 +281453724565984.433 +281453724565984.451 +281453732958688.469 +281454190997984.493 +281454190997984.515 +281454199390688.529 +281454199390688.540 +281454199390688.546 +281454199390688.549 +281452264964576.593 +281452264964576.609 +281452256571872.661 +281455727194592.678 +281453851210208.690 +281454182605280.710 +281452264964576.748 +281454190997984.876 +281453859602912.1146 +281454207783392.1454 +281454182605280.1490 +281454182605280.1515 +281455735587296.1532 +281453724565984.1537 +281452248179168.1547 +281454199390688.1714 +281453732958688.1799 +281454199390688.1820 +281454199390688.1856 +281455727194592.1886 +281454199390688.1936 +281454199390688.2029 +281454199390688.2035 +281453851210208.2076 +281454182605280.2126 +281454182605280.2147 +281453724565984.2263 +281455735587296.2287 +281455735587296.2307 +281452577227232.2329 +281452577227232.2330 +281452577227232.2349 +281454190997984.2354 +281453859602912.2392 +281453859602912.2417 +281453859602912.2453 +281453859602912.2485 +281453859602912.2510 +281453859602912.2520 +281453859602912.2603 +281453859602912.2700 +281453732958688.2773 +281455727194592.3106 +281453859602912.3135 +281455727194592.3138 +281453859602912.3233 +281453859602912.3244 +281453859602912.3246 +281453859602912.3275 +281453859602912.3319 +281453859602912.3326 +281453716173280.3358 +281453724565984.3382 +281452577227232.3389 +281452577227232.3393 +281452577227232.3407 +281454199390688.3413 +281454199390688.3417 +281454199390688.3423 +281454199390688.3493 +281454199390688.3499 +281454199390688.3508 +281454199390688.3511 +281454199390688.3514 +281454199390688.3517 +281454199390688.3574 +281454199390688.3577 +281454199390688.3595 +281454199390688.3612 +281454199390688.3621 +281454199390688.3628 +281454199390688.3637 +281453716173280.3649 +281453716173280.3665 +281453859602912.3675 +281453859602912.3682 +281453859602912.3688 +281452256571872.3694 +281453859602912.3695 +281453859602912.3706 +281453859602912.3708 +281453859602912.3738 +281453851210208.3754 +281453859602912.3763 +281453859602912.3781 +281453859602912.3838 +281453859602912.3846 +281453859602912.3854 +281453859602912.3914 +281453859602912.3925 +281453859602912.3929 +281453859602912.3949 +281453859602912.3982 +281453859602912.4015 +281453859602912.4019 +281453859602912.4067 +281453859602912.4069 +281453859602912.4073 +281453859602912.4116 +281453859602912.4176 +281453859602912.4233 +281453859602912.4241 +281453859602912.4251 +281453859602912.4259 +281453859602912.4265 +281453859602912.4272 +281453859602912.4322 +281453859602912.4327 +281453859602912.4334 +281453859602912.4338 +281453859602912.4345 +281453859602912.4348 +281453859602912.4352 +281453859602912.4361 +281453859602912.4375 +281453859602912.4408 +281452577227232.4424 +281452264964576.4582 +281453859602912.4979 +281453859602912.4991 +281453859602912.5013 +281453859602912.5061 +281452264964576.5200 +281452256571872.5440 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23726.txt b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23726.txt new file mode 100644 index 0000000000000000000000000000000000000000..fbb4c6f480e309c8a709bdc2d81e036099e48db6 --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23726.txt @@ -0,0 +1,127 @@ +281452264964576.3 +281452776042976.45 +281453859602912.67 +281453716173280.74 +281453851210208.93 +281453724565984.108 +281454182605280.185 +281454182605280.270 +281455735587296.330 +281452577227232.338 +281452577227232.342 +281455727194592.355 +281452776042976.369 +281453724565984.440 +281453732958688.472 +281454182605280.485 +281454182605280.510 +281454182605280.532 +281454207783392.538 +281454199390688.543 +281454207783392.572 +281452264964576.1101 +281453851210208.1350 +281453851210208.1381 +281454207783392.1390 +281454207783392.1408 +281454207783392.1432 +281452577227232.1469 +281452776042976.1593 +281454199390688.1602 +281454199390688.1615 +281454199390688.1635 +281454199390688.1648 +281454199390688.1675 +281454199390688.1718 +281453732958688.1807 +281455727194592.1837 +281454199390688.1875 +281455727194592.1891 +281454199390688.1938 +281453851210208.2032 +281453851210208.2094 +281454182605280.2117 +281454182605280.2144 +281453724565984.2277 +281452264964576.2325 +281453859602912.2368 +281453859602912.2372 +281453859602912.2379 +281453859602912.2387 +281453859602912.2394 +281453859602912.2412 +281453859602912.2436 +281453859602912.2457 +281453859602912.2502 +281453859602912.2518 +281453859602912.2617 +281453859602912.2676 +281453859602912.2684 +281453732958688.2771 +281455727194592.3104 +281455727194592.3122 +281455727194592.3126 +281455727194592.3128 +281452577227232.3392 +281454190997984.3409 +281454199390688.3421 +281454199390688.3490 +281454199390688.3495 +281454199390688.3505 +281454199390688.3512 +281454199390688.3572 +281454199390688.3583 +281454199390688.3592 +281454199390688.3602 +281454199390688.3607 +281454199390688.3618 +281454199390688.3633 +281453716173280.3647 +281453859602912.3693 +281453859602912.3698 +281453859602912.3702 +281453859602912.3713 +281455735587296.3757 +281453859602912.3764 +281453859602912.3768 +281453859602912.3829 +281453859602912.3841 +281453859602912.3852 +281453859602912.3859 +281453859602912.3918 +281453859602912.3926 +281453859602912.3935 +281453859602912.3953 +281453859602912.3958 +281453859602912.3980 +281453859602912.3997 +281453859602912.4012 +281453859602912.4225 +281453859602912.4229 +281453859602912.4237 +281453859602912.4244 +281453859602912.4248 +281453859602912.4255 +281453859602912.4261 +281453859602912.4266 +281453859602912.4269 +281453859602912.4274 +281453859602912.4282 +281453859602912.4292 +281453859602912.4297 +281453859602912.4303 +281453859602912.4308 +281453859602912.4310 +281453859602912.4316 +281453859602912.4321 +281453859602912.4325 +281453859602912.4353 +281453859602912.4363 +281453859602912.4383 +281455727194592.4414 +281453716173280.4571 +281453851210208.4686 +281453859602912.5034 +281452264964576.5178 +281454199390688.5181 +281452776042976.5268 diff --git a/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23727.txt b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23727.txt new file mode 100644 index 0000000000000000000000000000000000000000..86b0ad029817147378f5b8d429c11e1567bf0f88 --- /dev/null +++ b/community/cv/ADCAM/kernel_meta_temp_5308307909033023050/task_pid_22814_23727.txt @@ -0,0 +1,130 @@ +281455735587296.7 +281452577227232.32 +281453716173280.68 +281453724565984.79 +281453851210208.97 +281453732958688.116 +281453851210208.139 +281454182605280.259 +281452248179168.327 +281452264964576.335 +281455727194592.357 +281452776042976.371 +281453859602912.386 +281453716173280.402 +281453732958688.466 +281454190997984.490 +281454207783392.576 +281453716173280.702 +281452264964576.742 +281452248179168.766 +281453859602912.885 +281454182605280.928 +281452776042976.1331 +281453851210208.1347 +281453851210208.1375 +281454207783392.1392 +281454207783392.1410 +281454207783392.1458 +281454182605280.1512 +281453724565984.1529 +281453724565984.1535 +281455735587296.1540 +281452264964576.1554 +281452264964576.1559 +281452776042976.1597 +281454199390688.1613 +281454199390688.1626 +281454199390688.1646 +281454199390688.1674 +281454199390688.1713 +281453732958688.1797 +281454199390688.1819 +281454199390688.1872 +281455727194592.1884 +281454199390688.1922 +281454199390688.2025 +281454199390688.2037 +281454199390688.2077 +281454199390688.2080 +281453851210208.2082 +281454207783392.2102 +281454182605280.2132 +281454199390688.2164 +281454207783392.2175 +281453724565984.2265 +281454199390688.2288 +281455735587296.2291 +281452264964576.2323 +281452577227232.2353 +281452776042976.2361 +281453859602912.2393 +281453859602912.2428 +281453859602912.2456 +281453859602912.2491 +281453859602912.2536 +281453859602912.2597 +281453859602912.2632 +281453859602912.2678 +281453859602912.2713 +281453859602912.2743 +281453732958688.2775 +281455727194592.3108 +281455727194592.3134 +281453859602912.3325 +281453716173280.3357 +281454207783392.3380 +281452577227232.3387 +281452577227232.3403 +281454199390688.3412 +281454199390688.3418 +281454199390688.3469 +281454199390688.3541 +281454199390688.3548 +281454199390688.3568 +281454199390688.3576 +281454199390688.3585 +281454199390688.3627 +281454199390688.3634 +281453716173280.3648 +281453716173280.3655 +281453859602912.3677 +281453859602912.3699 +281453859602912.3700 +281453859602912.3705 +281453859602912.3715 +281453859602912.3733 +281453859602912.3746 +281453859602912.3769 +281453859602912.3831 +281453859602912.3842 +281453859602912.3857 +281453859602912.3919 +281453859602912.3930 +281453859602912.3937 +281453859602912.3954 +281453859602912.3956 +281453859602912.3974 +281453859602912.3994 +281453859602912.3999 +281453859602912.4017 +281453859602912.4070 +281453859602912.4074 +281453859602912.4171 +281453859602912.4226 +281453859602912.4231 +281453859602912.4289 +281453859602912.4294 +281453859602912.4330 +281453859602912.4336 +281453859602912.4409 +281454199390688.4521 +281454207783392.4655 +281453859602912.4987 +281453859602912.5011 +281453859602912.5037 +281453859602912.5111 +281452264964576.5179 +281454182605280.5183 +281453851210208.5199 +281454182605280.5202 diff --git a/community/cv/ADCAM/log.txt b/community/cv/ADCAM/log.txt new file mode 100644 index 0000000000000000000000000000000000000000..3f32f45ec4a4dbe80ffb7b8e1a2ca7175c8ab410 --- /dev/null +++ b/community/cv/ADCAM/log.txt @@ -0,0 +1,1311 @@ +nohup: ignoring input +/home/ma-user/anaconda3/envs/MindSpore/lib/python3.9/site-packages/numpy/core/getlimits.py:499: UserWarning: The value of the smallest subnormal for type is zero. + setattr(self, word, getattr(machar, word).flat[0]) +/home/ma-user/anaconda3/envs/MindSpore/lib/python3.9/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for type is zero. + return self._float_to_str(self.smallest_subnormal) +/home/ma-user/anaconda3/envs/MindSpore/lib/python3.9/site-packages/numpy/core/getlimits.py:499: UserWarning: The value of the smallest subnormal for type is zero. + setattr(self, word, getattr(machar, word).flat[0]) +/home/ma-user/anaconda3/envs/MindSpore/lib/python3.9/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for type is zero. + return self._float_to_str(self.smallest_subnormal) +{'data_dir': 'Train dataset directory.', 'per_batch_size': 'Batch size for Training.', 'pretrained_backbone': 'The ckpt file of CspDarkNet53.', 'resume_yolov5': 'The ckpt file of YOLOv5, which used to fine tune.', 'pretrained_checkpoint': 'The ckpt file of YOLOv5CspDarkNet53.', 'lr_scheduler': 'Learning rate scheduler, options: exponential, cosine_annealing.', 'lr': 'Learning rate.', 'lr_epochs': "Epoch of changing of lr changing, split with ','.", 'lr_gamma': 'Decrease lr by a factor of exponential lr_scheduler.', 'eta_min': 'Eta_min in cosine_annealing scheduler.', 'T_max': 'T-max in cosine_annealing scheduler.', 'max_epoch': 'Max epoch num to train the model.', 'warmup_epochs': 'Warmup epochs.', 'weight_decay': 'Weight decay factor.', 'momentum': 'Momentum.', 'loss_scale': 'Static loss scale.', 'label_smooth': 'Whether to use label smooth in CE.', 'label_smooth_factor': 'Smooth strength of original one-hot.', 'log_interval': 'Logging interval steps.', 'ckpt_path': 'Checkpoint save location.', 'ckpt_interval': 'Save checkpoint interval.', 'is_save_on_master': 'Save ckpt on master or all rank, 1 for master, 0 for all ranks.', 'is_distributed': 'Distribute train or not, 1 for yes, 0 for no.', 'bind_cpu': 'Whether bind cpu when distributed training.', 'device_num': 'Device numbers per server', 'rank': 'Local rank of distributed.', 'group_size': 'World size of device.', 'need_profiler': 'Whether use profiler. 0 for no, 1 for yes.', 'resize_rate': 'Resize rate for multi-scale training.', 'ann_file': 'path to annotation', 'each_multiscale': 'Apply multi-scale for each scale', 'labels': 'the label of train data', 'multi_label': 'use multi label to nms', 'multi_label_thresh': 'multi label thresh', 'train_img_dir': 'relative path of training image directory to data_dir', 'train_ann_file': 'relative path of training annotation file to data_dir', 'pretrained': 'model_path, local pretrained model to load', 'log_path': 'checkpoint save location', 'save_prefix': '../eval_parallel', 'run_eval': 'Whether enable validation after a training epoch', 'eval_epoch_interval': 'Epoch interval to do validation', 'eval_start_epoch': 'After which epoch, start to do validatation', 'eval_parallel': 'Whether enable parallel evaluation to accelerate the validataion process', 'val_img_dir': 'relative path of validation image directory to data_dir', 'val_ann_file': 'relative path of validataion annotation file to data_dir', 'device_id': 'Device id for export', 'batch_size': 'batch size for export', 'testing_shape': 'shape for test', 'ckpt_file': 'Checkpoint file path for export', 'file_name': 'output file name for export', 'file_format': 'file format for export', 'result_files': 'path to 310 infer result floder'} +2024-09-20 20:38:15,263:INFO:Args: +2024-09-20 20:38:15,263:INFO:--> enable_modelarts: False +2024-09-20 20:38:15,263:INFO:--> data_url: +2024-09-20 20:38:15,263:INFO:--> train_url: +2024-09-20 20:38:15,263:INFO:--> checkpoint_url: +2024-09-20 20:38:15,263:INFO:--> outputs_url: +2024-09-20 20:38:15,263:INFO:--> data_path: /cache/data +2024-09-20 20:38:15,263:INFO:--> output_path: /cache/train +2024-09-20 20:38:15,263:INFO:--> load_path: /cache/checkpoint_path +2024-09-20 20:38:15,264:INFO:--> device_target: Ascend +2024-09-20 20:38:15,264:INFO:--> need_modelarts_dataset_unzip: True +2024-09-20 20:38:15,264:INFO:--> modelarts_dataset_unzip_name: coco +2024-09-20 20:38:15,264:INFO:--> data_dir: ../coco-mini +2024-09-20 20:38:15,264:INFO:--> per_batch_size: 32 +2024-09-20 20:38:15,264:INFO:--> yolov5_version: yolov5s +2024-09-20 20:38:15,264:INFO:--> pretrained_backbone: +2024-09-20 20:38:15,264:INFO:--> resume_yolov5: +2024-09-20 20:38:15,264:INFO:--> pretrained_checkpoint: +2024-09-20 20:38:15,264:INFO:--> output_dir: ./output +2024-09-20 20:38:15,264:INFO:--> train_img_dir: ../coco-mini/train2017 +2024-09-20 20:38:15,264:INFO:--> train_ann_file: ../coco-mini/annotations/instances_train2017.json +2024-09-20 20:38:15,264:INFO:--> lr_scheduler: cosine_annealing +2024-09-20 20:38:15,264:INFO:--> lr: 0.001 +2024-09-20 20:38:15,265:INFO:--> lr_epochs: [220, 250] +2024-09-20 20:38:15,265:INFO:--> lr_gamma: 0.1 +2024-09-20 20:38:15,265:INFO:--> eta_min: 0.0 +2024-09-20 20:38:15,265:INFO:--> T_max: 300 +2024-09-20 20:38:15,265:INFO:--> max_epoch: 300 +2024-09-20 20:38:15,265:INFO:--> warmup_epochs: 4 +2024-09-20 20:38:15,265:INFO:--> weight_decay: 0.0005 +2024-09-20 20:38:15,265:INFO:--> momentum: 0.9 +2024-09-20 20:38:15,265:INFO:--> loss_scale: 1024 +2024-09-20 20:38:15,265:INFO:--> label_smooth: 0 +2024-09-20 20:38:15,265:INFO:--> label_smooth_factor: 0.1 +2024-09-20 20:38:15,265:INFO:--> log_interval: 100 +2024-09-20 20:38:15,265:INFO:--> ckpt_path: ./best.ckpt +2024-09-20 20:38:15,265:INFO:--> is_distributed: 0 +2024-09-20 20:38:15,266:INFO:--> bind_cpu: True +2024-09-20 20:38:15,266:INFO:--> device_num: 8 +2024-09-20 20:38:15,266:INFO:--> rank: 0 +2024-09-20 20:38:15,266:INFO:--> group_size: 1 +2024-09-20 20:38:15,266:INFO:--> need_profiler: 0 +2024-09-20 20:38:15,266:INFO:--> resize_rate: 10 +2024-09-20 20:38:15,266:INFO:--> filter_weight: False +2024-09-20 20:38:15,266:INFO:--> save_ckpt_interval: 1 +2024-09-20 20:38:15,266:INFO:--> save_ckpt_max_num: 10 +2024-09-20 20:38:15,266:INFO:--> pretrained: +2024-09-20 20:38:15,266:INFO:--> log_path: outputs/ +2024-09-20 20:38:15,266:INFO:--> ann_val_file: +2024-09-20 20:38:15,266:INFO:--> eval_nms_thresh: 0.6 +2024-09-20 20:38:15,266:INFO:--> ignore_threshold: 0.7 +2024-09-20 20:38:15,267:INFO:--> test_ignore_threshold: 0.001 +2024-09-20 20:38:15,267:INFO:--> multi_label: True +2024-09-20 20:38:15,267:INFO:--> multi_label_thresh: 0.1 +2024-09-20 20:38:15,267:INFO:--> save_prefix: ../eval_parallel +2024-09-20 20:38:15,267:INFO:--> run_eval: True +2024-09-20 20:38:15,267:INFO:--> eval_epoch_interval: 10 +2024-09-20 20:38:15,267:INFO:--> eval_start_epoch: 100 +2024-09-20 20:38:15,267:INFO:--> eval_parallel: True +2024-09-20 20:38:15,267:INFO:--> val_img_dir: val2017 +2024-09-20 20:38:15,267:INFO:--> val_ann_file: annotations/instances_val2017.json +2024-09-20 20:38:15,267:INFO:--> device_id: 0 +2024-09-20 20:38:15,267:INFO:--> batch_size: 16 +2024-09-20 20:38:15,267:INFO:--> testing_shape: [640, 640] +2024-09-20 20:38:15,267:INFO:--> ckpt_file: +2024-09-20 20:38:15,268:INFO:--> file_name: yolov5 +2024-09-20 20:38:15,268:INFO:--> file_format: MINDIR +2024-09-20 20:38:15,268:INFO:--> dataset_path: +2024-09-20 20:38:15,268:INFO:--> ann_file: +2024-09-20 20:38:15,268:INFO:--> hue: 0.015 +2024-09-20 20:38:15,268:INFO:--> saturation: 1.5 +2024-09-20 20:38:15,268:INFO:--> value: 0.4 +2024-09-20 20:38:15,268:INFO:--> jitter: 0.3 +2024-09-20 20:38:15,268:INFO:--> num_classes: 80 +2024-09-20 20:38:15,268:INFO:--> max_box: 150 +2024-09-20 20:38:15,268:INFO:--> checkpoint_filter_list: ['feature_map.back_block1.conv.weight', 'feature_map.back_block1.conv.bias', 'feature_map.back_block2.conv.weight', 'feature_map.back_block2.conv.bias', 'feature_map.back_block3.conv.weight', 'feature_map.back_block3.conv.bias'] +2024-09-20 20:38:15,268:INFO:--> anchor_scales: [[12, 16], [19, 36], [40, 28], [36, 75], [76, 55], [72, 146], [142, 110], [192, 243], [459, 401]] +2024-09-20 20:38:15,268:INFO:--> out_channel: 255 +2024-09-20 20:38:15,268:INFO:--> input_shape: [[3, 32, 64, 128, 256, 512, 1], [3, 48, 96, 192, 384, 768, 2], [3, 64, 128, 256, 512, 1024, 3], [3, 80, 160, 320, 640, 1280, 4]] +2024-09-20 20:38:15,269:INFO:--> test_img_shape: [640, 640] +2024-09-20 20:38:15,269:INFO:--> labels: ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'] +2024-09-20 20:38:15,269:INFO:--> coco_ids: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90] +2024-09-20 20:38:15,269:INFO:--> result_files: ./result_Files +2024-09-20 20:38:15,269:INFO:--> config_path: /home/ma-user/work/YOLOv5/model_utils/../default_config.yaml +2024-09-20 20:38:15,269:INFO:--> logger: +2024-09-20 20:38:15,269:INFO: +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-20-20:38:39.345.318 [mindspore/dataset/core/config.py:679] The shared memory is on, multiprocessing performance will be improved. Note: the required shared memory can't exceeds 80% of the available shared memory. +************----------******************** +************----------******************** +************----------******************** +************----------******************** +loading annotations into memory... +Done (t=2.27s) +creating index... +index created! +2024-09-20 20:38:43,670:INFO:Finish loading train dataset +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-20-20:38:43.670.622 [mindspore/dataset/core/config.py:679] The shared memory is on, multiprocessing performance will be improved. Note: the required shared memory can't exceeds 80% of the available shared memory. +loading annotations into memory... +Done (t=0.15s) +creating index... +index created! +2024-09-20 20:38:43,837:INFO:Finish loading val dataset! +loading annotations into memory... +Done (t=0.06s) +creating index... +index created! +- \ | / - \ | / - \ | / - \ | / - \ | 2024-09-20 20:42:50,859:INFO:epoch[1], iter[1], loss:8232.443359, fps:0.13 imgs/sec, lr:1.3736263326791232e-06, per step time: 244646.13676071167ms +2024-09-20 20:43:22,154:INFO:epoch[1], iter[101], loss:1635.491831, fps:102.26 imgs/sec, lr:0.00013873625721316785, per step time: 312.918221950531ms +2024-09-20 20:43:54,457:INFO:epoch[2], iter[19], loss:379.567307, fps:99.06 imgs/sec, lr:2.609890179883223e-05, per step time: 323.02595138549805ms +2024-09-20 20:44:31,415:INFO:epoch[2], iter[119], loss:284.538519, fps:86.59 imgs/sec, lr:0.0001634615327930078, per step time: 369.5520877838135ms +2024-09-20 20:45:11,873:INFO:epoch[3], iter[37], loss:259.798242, fps:79.10 imgs/sec, lr:5.082417555968277e-05, per step time: 404.5535373687744ms +2024-09-20 20:45:44,656:INFO:epoch[3], iter[137], loss:249.637430, fps:97.62 imgs/sec, lr:0.00018818680837284774, per step time: 327.8089237213135ms +2024-09-20 20:46:19,821:INFO:epoch[4], iter[55], loss:242.391006, fps:91.01 imgs/sec, lr:7.554944750154391e-05, per step time: 351.6108751296997ms +2024-09-20 20:46:54,010:INFO:epoch[4], iter[155], loss:241.564582, fps:93.61 imgs/sec, lr:0.00021291208395268768, per step time: 341.86078548431396ms +2024-09-20 20:47:29,226:INFO:epoch[5], iter[73], loss:239.173665, fps:90.90 imgs/sec, lr:0.00010027472308138385, per step time: 352.0437812805176ms +2024-09-20 20:48:02,185:INFO:epoch[5], iter[173], loss:231.036626, fps:97.09 imgs/sec, lr:0.00023763735953252763, per step time: 329.5803236961365ms +2024-09-20 20:48:37,390:INFO:epoch[6], iter[91], loss:236.062115, fps:90.90 imgs/sec, lr:0.0001250000059371814, per step time: 352.0443081855774ms +2024-09-20 20:49:11,790:INFO:epoch[7], iter[9], loss:227.038043, fps:93.04 imgs/sec, lr:1.2362637789919972e-05, per step time: 343.93641233444214ms +2024-09-20 20:49:45,498:INFO:epoch[7], iter[109], loss:221.241216, fps:94.93 imgs/sec, lr:0.00014972528151702136, per step time: 337.0745921134949ms +2024-09-20 20:50:21,675:INFO:epoch[8], iter[27], loss:218.565192, fps:88.49 imgs/sec, lr:3.708791336975992e-05, per step time: 361.63804292678833ms +2024-09-20 20:50:56,182:INFO:epoch[8], iter[127], loss:217.056685, fps:92.74 imgs/sec, lr:0.00017445054254494607, per step time: 345.06128549575806ms +2024-09-20 20:51:30,571:INFO:epoch[9], iter[45], loss:221.970747, fps:93.06 imgs/sec, lr:6.181318894959986e-05, per step time: 343.85826349258423ms +2024-09-20 20:52:05,421:INFO:epoch[9], iter[145], loss:213.194906, fps:91.83 imgs/sec, lr:0.00019917581812478602, per step time: 348.4550881385803ms +2024-09-20 20:52:40,516:INFO:epoch[10], iter[63], loss:210.969816, fps:91.19 imgs/sec, lr:8.653846452943981e-05, per step time: 350.9298014640808ms +2024-09-20 20:53:14,762:INFO:epoch[10], iter[163], loss:213.390212, fps:93.46 imgs/sec, lr:0.00022390109370462596, per step time: 342.4058413505554ms +2024-09-20 20:53:50,334:INFO:epoch[11], iter[81], loss:207.196398, fps:89.96 imgs/sec, lr:0.00011126373283332214, per step time: 355.7024383544922ms +2024-09-20 20:54:24,989:INFO:epoch[11], iter[181], loss:208.877977, fps:92.34 imgs/sec, lr:0.0002486263692844659, per step time: 346.54064655303955ms +2024-09-20 20:55:02,388:INFO:epoch[12], iter[99], loss:205.797969, fps:85.57 imgs/sec, lr:0.0001359890156891197, per step time: 373.9790344238281ms +2024-09-20 20:55:39,971:INFO:epoch[13], iter[17], loss:207.403760, fps:85.15 imgs/sec, lr:2.3351647541858256e-05, per step time: 375.823712348938ms +2024-09-20 20:56:13,835:INFO:epoch[13], iter[117], loss:206.428211, fps:94.51 imgs/sec, lr:0.00016071429126895964, per step time: 338.58036279678345ms +2024-09-20 20:56:49,626:INFO:epoch[14], iter[35], loss:203.309553, fps:89.41 imgs/sec, lr:4.80769231216982e-05, per step time: 357.9053544998169ms +2024-09-20 20:57:22,910:INFO:epoch[14], iter[135], loss:203.472365, fps:96.17 imgs/sec, lr:0.00018543956684879959, per step time: 332.7311396598816ms +2024-09-20 20:57:57,530:INFO:epoch[15], iter[53], loss:201.225273, fps:92.44 imgs/sec, lr:7.280219870153815e-05, per step time: 346.1832022666931ms +2024-09-20 20:58:31,925:INFO:epoch[15], iter[153], loss:198.550593, fps:93.04 imgs/sec, lr:0.00021016484242863953, per step time: 343.9479398727417ms +2024-09-20 20:59:09,567:INFO:epoch[16], iter[71], loss:196.258699, fps:85.01 imgs/sec, lr:9.752747428137809e-05, per step time: 376.40615463256836ms +2024-09-20 20:59:47,314:INFO:epoch[16], iter[171], loss:198.804929, fps:84.78 imgs/sec, lr:0.00023489010345656425, per step time: 377.43704319000244ms +2024-09-20 21:00:23,438:INFO:epoch[17], iter[89], loss:196.063281, fps:88.59 imgs/sec, lr:0.00012225274986121804, per step time: 361.23491048812866ms +2024-09-20 21:00:59,618:INFO:epoch[18], iter[7], loss:197.726127, fps:88.45 imgs/sec, lr:9.6153844424407e-06, per step time: 361.80007219314575ms +2024-09-20 21:01:33,217:INFO:epoch[18], iter[107], loss:195.047802, fps:95.25 imgs/sec, lr:0.00014697802544105798, per step time: 335.9593439102173ms +2024-09-20 21:02:08,043:INFO:epoch[19], iter[25], loss:192.136686, fps:91.89 imgs/sec, lr:3.4340660931775346e-05, per step time: 348.2558488845825ms +2024-09-20 21:02:42,612:INFO:epoch[19], iter[125], loss:194.515766, fps:92.57 imgs/sec, lr:0.00017170330102089792, per step time: 345.6795287132263ms +2024-09-20 21:03:17,710:INFO:epoch[20], iter[43], loss:190.357037, fps:91.18 imgs/sec, lr:5.9065932873636484e-05, per step time: 350.9641981124878ms +2024-09-20 21:03:52,355:INFO:epoch[20], iter[143], loss:189.743661, fps:92.37 imgs/sec, lr:0.00019642857660073787, per step time: 346.43357038497925ms +2024-09-20 21:04:26,175:INFO:epoch[21], iter[61], loss:188.974920, fps:94.64 imgs/sec, lr:8.379120845347643e-05, per step time: 338.11294078826904ms +2024-09-20 21:04:59,985:INFO:epoch[21], iter[161], loss:185.768755, fps:94.65 imgs/sec, lr:0.00022115385218057781, per step time: 338.0937957763672ms +2024-09-20 21:05:35,458:INFO:epoch[22], iter[79], loss:188.624068, fps:90.22 imgs/sec, lr:0.00010851648403331637, per step time: 354.6868300437927ms +2024-09-20 21:06:09,801:INFO:epoch[22], iter[179], loss:186.376819, fps:93.19 imgs/sec, lr:0.00024587911320850253, per step time: 343.3828401565552ms +2024-09-20 21:06:47,192:INFO:epoch[23], iter[97], loss:185.691389, fps:85.59 imgs/sec, lr:0.00013324175961315632, per step time: 373.8930606842041ms +2024-09-20 21:07:24,574:INFO:epoch[24], iter[15], loss:186.194818, fps:85.60 imgs/sec, lr:2.0604395103873685e-05, per step time: 373.813259601593ms +2024-09-20 21:08:00,815:INFO:epoch[24], iter[115], loss:185.067050, fps:88.31 imgs/sec, lr:0.00015796703519299626, per step time: 362.37717390060425ms +2024-09-20 21:08:36,118:INFO:epoch[25], iter[33], loss:184.215949, fps:90.66 imgs/sec, lr:4.532967068371363e-05, per step time: 352.9836940765381ms +2024-09-20 21:09:12,391:INFO:epoch[25], iter[133], loss:186.066897, fps:88.23 imgs/sec, lr:0.0001826923107728362, per step time: 362.69441843032837ms +2024-09-20 21:09:49,354:INFO:epoch[26], iter[51], loss:183.716000, fps:86.60 imgs/sec, lr:7.005494262557477e-05, per step time: 369.527325630188ms +2024-09-20 21:10:24,980:INFO:epoch[26], iter[151], loss:179.878236, fps:89.83 imgs/sec, lr:0.00020741758635267615, per step time: 356.2378215789795ms +2024-09-20 21:10:59,956:INFO:epoch[27], iter[69], loss:174.863488, fps:91.49 imgs/sec, lr:9.478021820541471e-05, per step time: 349.7494840621948ms +2024-09-20 21:11:37,159:INFO:epoch[27], iter[169], loss:182.142492, fps:86.02 imgs/sec, lr:0.0002321428619325161, per step time: 372.02134370803833ms +2024-09-20 21:12:13,868:INFO:epoch[28], iter[87], loss:184.886755, fps:87.18 imgs/sec, lr:0.00011950549378525466, per step time: 367.0735836029053ms +2024-09-20 21:12:48,706:INFO:epoch[29], iter[5], loss:179.664401, fps:91.86 imgs/sec, lr:6.868132004456129e-06, per step time: 348.36087465286255ms +2024-09-20 21:13:23,672:INFO:epoch[29], iter[105], loss:184.392660, fps:91.53 imgs/sec, lr:0.0001442307693650946, per step time: 349.61004972457886ms +2024-09-20 21:13:59,331:INFO:epoch[30], iter[23], loss:177.369892, fps:89.74 imgs/sec, lr:3.159340485581197e-05, per step time: 356.58050775527954ms +2024-09-20 21:14:37,263:INFO:epoch[30], iter[123], loss:182.469617, fps:84.38 imgs/sec, lr:0.00016895604494493455, per step time: 379.2527651786804ms +2024-09-20 21:15:13,304:INFO:epoch[31], iter[41], loss:180.184063, fps:88.79 imgs/sec, lr:5.631868043565191e-05, per step time: 360.40727853775024ms +2024-09-20 21:15:46,666:INFO:epoch[31], iter[141], loss:178.512740, fps:95.94 imgs/sec, lr:0.0001936813205247745, per step time: 333.53742599487305ms +2024-09-20 21:16:21,383:INFO:epoch[32], iter[59], loss:176.911033, fps:92.18 imgs/sec, lr:8.104395965347067e-05, per step time: 347.1579623222351ms +2024-09-20 21:16:54,630:INFO:epoch[32], iter[159], loss:175.369219, fps:96.26 imgs/sec, lr:0.00021840659610461444, per step time: 332.43263006210327ms +2024-09-20 21:17:29,833:INFO:epoch[33], iter[77], loss:173.749172, fps:90.91 imgs/sec, lr:0.000105769227957353, per step time: 351.98877334594727ms +2024-09-20 21:18:03,504:INFO:epoch[33], iter[177], loss:174.079372, fps:95.04 imgs/sec, lr:0.00024313187168445438, per step time: 336.70371294021606ms +2024-09-20 21:18:38,004:INFO:epoch[34], iter[95], loss:172.442899, fps:92.76 imgs/sec, lr:0.00013049450353719294, per step time: 344.9911308288574ms +2024-09-20 21:19:12,563:INFO:epoch[35], iter[13], loss:176.389585, fps:92.60 imgs/sec, lr:1.7857142665889114e-05, per step time: 345.58303356170654ms +2024-09-20 21:19:46,229:INFO:epoch[35], iter[113], loss:170.996665, fps:95.07 imgs/sec, lr:0.00015521977911703289, per step time: 336.59409284591675ms +2024-09-20 21:20:21,019:INFO:epoch[36], iter[31], loss:173.318495, fps:91.99 imgs/sec, lr:4.258241824572906e-05, per step time: 347.86720991134644ms +2024-09-20 21:20:54,733:INFO:epoch[36], iter[131], loss:175.465918, fps:94.92 imgs/sec, lr:0.00017994505469687283, per step time: 337.1288251876831ms +2024-09-20 21:21:28,543:INFO:epoch[37], iter[49], loss:171.194805, fps:94.67 imgs/sec, lr:6.7307693825569e-05, per step time: 338.02669763565063ms +2024-09-20 21:22:04,261:INFO:epoch[37], iter[149], loss:170.482717, fps:89.59 imgs/sec, lr:0.00020467033027671278, per step time: 357.1651244163513ms +2024-09-20 21:22:38,218:INFO:epoch[38], iter[67], loss:173.549819, fps:94.25 imgs/sec, lr:9.203296940540895e-05, per step time: 339.51587677001953ms +2024-09-20 21:23:12,620:INFO:epoch[38], iter[167], loss:173.177820, fps:93.02 imgs/sec, lr:0.00022939560585655272, per step time: 344.0142631530762ms +2024-09-20 21:23:47,224:INFO:epoch[39], iter[85], loss:171.788161, fps:92.48 imgs/sec, lr:0.0001167582449852489, per step time: 346.0296845436096ms +2024-09-20 21:24:21,266:INFO:epoch[40], iter[3], loss:169.060913, fps:94.01 imgs/sec, lr:4.120879111724207e-06, per step time: 340.3794002532959ms +2024-09-20 21:24:56,519:INFO:epoch[40], iter[103], loss:171.852288, fps:90.78 imgs/sec, lr:0.00014148351328913122, per step time: 352.49982357025146ms +2024-09-20 21:25:31,981:INFO:epoch[41], iter[21], loss:167.581189, fps:90.24 imgs/sec, lr:2.88461542368168e-05, per step time: 354.6098828315735ms +2024-09-20 21:26:05,945:INFO:epoch[41], iter[121], loss:172.317983, fps:94.22 imgs/sec, lr:0.00016620878886897117, per step time: 339.6301460266113ms +2024-09-20 21:26:42,277:INFO:epoch[42], iter[39], loss:169.277906, fps:88.08 imgs/sec, lr:5.357142799766734e-05, per step time: 363.31345081329346ms +2024-09-20 21:27:15,189:INFO:epoch[42], iter[139], loss:167.309349, fps:97.23 imgs/sec, lr:0.00019093406444881111, per step time: 329.1130590438843ms +2024-09-20 21:27:49,843:INFO:epoch[43], iter[57], loss:171.980741, fps:92.35 imgs/sec, lr:7.829670357750729e-05, per step time: 346.4952754974365ms +2024-09-20 21:28:25,044:INFO:epoch[43], iter[157], loss:164.546216, fps:90.91 imgs/sec, lr:0.00021565934002865106, per step time: 351.977334022522ms +2024-09-20 21:28:59,317:INFO:epoch[44], iter[75], loss:165.177979, fps:93.37 imgs/sec, lr:0.00010302197915734723, per step time: 342.7172875404358ms +2024-09-20 21:29:32,621:INFO:epoch[44], iter[175], loss:165.744374, fps:96.09 imgs/sec, lr:0.000240384615608491, per step time: 333.03441762924194ms +2024-09-20 21:30:06,863:INFO:epoch[45], iter[93], loss:166.381015, fps:93.45 imgs/sec, lr:0.00012774724746122956, per step time: 342.4121356010437ms +2024-09-20 21:30:39,507:INFO:epoch[46], iter[11], loss:167.646526, fps:98.03 imgs/sec, lr:1.5109890227904543e-05, per step time: 326.4290523529053ms +2024-09-20 21:31:11,851:INFO:epoch[46], iter[111], loss:165.937793, fps:98.94 imgs/sec, lr:0.0001524725230410695, per step time: 323.4223985671997ms +2024-09-20 21:31:46,489:INFO:epoch[47], iter[29], loss:165.006547, fps:92.39 imgs/sec, lr:3.983516580774449e-05, per step time: 346.35788917541504ms +2024-09-20 21:32:20,432:INFO:epoch[47], iter[129], loss:170.198429, fps:94.28 imgs/sec, lr:0.00017719779862090945, per step time: 339.41574573516846ms +2024-09-20 21:32:55,539:INFO:epoch[48], iter[47], loss:161.166297, fps:91.16 imgs/sec, lr:6.456043774960563e-05, per step time: 351.04949951171875ms +2024-09-20 21:33:27,475:INFO:epoch[48], iter[147], loss:165.667333, fps:100.20 imgs/sec, lr:0.0002019230742007494, per step time: 319.35426235198975ms +2024-09-20 21:34:01,305:INFO:epoch[49], iter[65], loss:164.810640, fps:94.61 imgs/sec, lr:8.928571332944557e-05, per step time: 338.2222843170166ms +2024-09-20 21:34:33,557:INFO:epoch[49], iter[165], loss:163.738724, fps:99.23 imgs/sec, lr:0.00022664834978058934, per step time: 322.485249042511ms +2024-09-20 21:35:08,813:INFO:epoch[50], iter[83], loss:163.532195, fps:90.77 imgs/sec, lr:0.00011401098890928552, per step time: 352.5384521484375ms +2024-09-20 21:35:42,513:INFO:epoch[51], iter[1], loss:162.805244, fps:94.96 imgs/sec, lr:1.3736263326791232e-06, per step time: 336.98166370391846ms +2024-09-20 21:36:15,681:INFO:epoch[51], iter[101], loss:162.901613, fps:96.48 imgs/sec, lr:0.00013873625721316785, per step time: 331.66080713272095ms +2024-09-20 21:36:48,568:INFO:epoch[52], iter[19], loss:157.572873, fps:97.32 imgs/sec, lr:2.609890179883223e-05, per step time: 328.8250923156738ms +2024-09-20 21:37:19,924:INFO:epoch[52], iter[119], loss:162.347995, fps:102.05 imgs/sec, lr:0.0001634615327930078, per step time: 313.56247186660767ms +2024-09-20 21:37:52,574:INFO:epoch[53], iter[37], loss:162.534500, fps:98.01 imgs/sec, lr:5.082417555968277e-05, per step time: 326.4931583404541ms +2024-09-20 21:38:26,481:INFO:epoch[53], iter[137], loss:162.036097, fps:94.39 imgs/sec, lr:0.00018818680837284774, per step time: 339.0352153778076ms +2024-09-20 21:38:59,143:INFO:epoch[54], iter[55], loss:158.908228, fps:97.98 imgs/sec, lr:7.554944750154391e-05, per step time: 326.5941333770752ms +2024-09-20 21:39:30,907:INFO:epoch[54], iter[155], loss:162.760122, fps:100.75 imgs/sec, lr:0.00021291208395268768, per step time: 317.6235771179199ms +2024-09-20 21:40:03,250:INFO:epoch[55], iter[73], loss:158.558570, fps:98.94 imgs/sec, lr:0.00010027472308138385, per step time: 323.42546701431274ms +2024-09-20 21:40:37,750:INFO:epoch[55], iter[173], loss:160.993930, fps:92.78 imgs/sec, lr:0.00023763735953252763, per step time: 344.9108290672302ms +2024-09-20 21:41:10,957:INFO:epoch[56], iter[91], loss:161.391681, fps:96.37 imgs/sec, lr:0.0001250000059371814, per step time: 332.06607818603516ms +2024-09-20 21:41:43,665:INFO:epoch[57], iter[9], loss:155.147552, fps:97.84 imgs/sec, lr:1.2362637789919972e-05, per step time: 327.07436084747314ms +2024-09-20 21:42:16,022:INFO:epoch[57], iter[109], loss:161.393431, fps:98.90 imgs/sec, lr:0.00014972528151702136, per step time: 323.5515260696411ms +2024-09-20 21:42:49,116:INFO:epoch[58], iter[27], loss:156.464277, fps:96.70 imgs/sec, lr:3.708791336975992e-05, per step time: 330.9329032897949ms +2024-09-20 21:43:23,999:INFO:epoch[58], iter[127], loss:159.262215, fps:91.75 imgs/sec, lr:0.00017445054254494607, per step time: 348.77492666244507ms +2024-09-20 21:43:57,121:INFO:epoch[59], iter[45], loss:158.936300, fps:96.62 imgs/sec, lr:6.181318894959986e-05, per step time: 331.20915174484253ms +2024-09-20 21:44:29,776:INFO:epoch[59], iter[145], loss:158.284368, fps:98.00 imgs/sec, lr:0.00019917581812478602, per step time: 326.52979612350464ms +2024-09-20 21:45:01,548:INFO:epoch[60], iter[63], loss:157.811885, fps:100.73 imgs/sec, lr:8.653846452943981e-05, per step time: 317.6934504508972ms +2024-09-20 21:45:34,391:INFO:epoch[60], iter[163], loss:155.766814, fps:97.44 imgs/sec, lr:0.00022390109370462596, per step time: 328.41283559799194ms +2024-09-20 21:46:11,029:INFO:epoch[61], iter[81], loss:152.094056, fps:87.34 imgs/sec, lr:0.00011126373283332214, per step time: 366.36342763900757ms +2024-09-20 21:46:44,832:INFO:epoch[61], iter[181], loss:158.110130, fps:94.67 imgs/sec, lr:0.0002486263692844659, per step time: 338.02892684936523ms +2024-09-20 21:47:20,068:INFO:epoch[62], iter[99], loss:151.901756, fps:90.82 imgs/sec, lr:0.0001359890156891197, per step time: 352.3538041114807ms +2024-09-20 21:47:52,701:INFO:epoch[63], iter[17], loss:158.217242, fps:98.07 imgs/sec, lr:2.3351647541858256e-05, per step time: 326.29603385925293ms +2024-09-20 21:48:23,760:INFO:epoch[63], iter[117], loss:154.572700, fps:103.03 imgs/sec, lr:0.00016071429126895964, per step time: 310.58462619781494ms +2024-09-20 21:48:57,263:INFO:epoch[64], iter[35], loss:154.398029, fps:95.53 imgs/sec, lr:4.80769231216982e-05, per step time: 334.96533393859863ms +2024-09-20 21:49:27,851:INFO:epoch[64], iter[135], loss:158.328652, fps:104.62 imgs/sec, lr:0.00018543956684879959, per step time: 305.86830377578735ms +2024-09-20 21:50:03,425:INFO:epoch[65], iter[53], loss:155.277468, fps:89.96 imgs/sec, lr:7.280219870153815e-05, per step time: 355.69942235946655ms +2024-09-20 21:50:37,121:INFO:epoch[65], iter[153], loss:160.024713, fps:94.99 imgs/sec, lr:0.00021016484242863953, per step time: 336.8784785270691ms +2024-09-20 21:51:14,459:INFO:epoch[66], iter[71], loss:152.461989, fps:85.71 imgs/sec, lr:9.752747428137809e-05, per step time: 373.3534789085388ms +2024-09-20 21:51:49,843:INFO:epoch[66], iter[171], loss:157.592418, fps:90.44 imgs/sec, lr:0.00023489010345656425, per step time: 353.8389539718628ms +2024-09-20 21:52:24,282:INFO:epoch[67], iter[89], loss:155.461052, fps:92.93 imgs/sec, lr:0.00012225274986121804, per step time: 344.34686183929443ms +2024-09-20 21:52:57,200:INFO:epoch[68], iter[7], loss:155.832418, fps:97.21 imgs/sec, lr:9.6153844424407e-06, per step time: 329.17086362838745ms +2024-09-20 21:53:30,291:INFO:epoch[68], iter[107], loss:155.650930, fps:96.71 imgs/sec, lr:0.00014697802544105798, per step time: 330.90046644210815ms +2024-09-20 21:54:03,192:INFO:epoch[69], iter[25], loss:150.243763, fps:97.28 imgs/sec, lr:3.4340660931775346e-05, per step time: 328.95777702331543ms +2024-09-20 21:54:35,957:INFO:epoch[69], iter[125], loss:153.429515, fps:97.69 imgs/sec, lr:0.00017170330102089792, per step time: 327.57076025009155ms +2024-09-20 21:55:11,344:INFO:epoch[70], iter[43], loss:150.329384, fps:90.43 imgs/sec, lr:5.9065932873636484e-05, per step time: 353.86638879776ms +2024-09-20 21:55:42,080:INFO:epoch[70], iter[143], loss:154.454830, fps:104.11 imgs/sec, lr:0.00019642857660073787, per step time: 307.35687017440796ms +2024-09-20 21:56:14,727:INFO:epoch[71], iter[61], loss:152.532954, fps:98.03 imgs/sec, lr:8.379120845347643e-05, per step time: 326.445095539093ms +2024-09-20 21:56:46,089:INFO:epoch[71], iter[161], loss:152.145872, fps:102.04 imgs/sec, lr:0.00022115385218057781, per step time: 313.610155582428ms +2024-09-20 21:57:17,686:INFO:epoch[72], iter[79], loss:152.520683, fps:101.29 imgs/sec, lr:0.00010851648403331637, per step time: 315.91702938079834ms +2024-09-20 21:57:48,582:INFO:epoch[72], iter[179], loss:150.744934, fps:103.57 imgs/sec, lr:0.00024587911320850253, per step time: 308.9599084854126ms +2024-09-20 21:58:19,922:INFO:epoch[73], iter[97], loss:151.995328, fps:102.11 imgs/sec, lr:0.00013324175961315632, per step time: 313.39543104171753ms +2024-09-20 21:58:52,009:INFO:epoch[74], iter[15], loss:150.920654, fps:99.73 imgs/sec, lr:2.0604395103873685e-05, per step time: 320.86198568344116ms +2024-09-20 21:59:22,661:INFO:epoch[74], iter[115], loss:150.474606, fps:104.44 imgs/sec, lr:0.00015796703519299626, per step time: 306.40920877456665ms +2024-09-20 21:59:53,990:INFO:epoch[75], iter[33], loss:149.201177, fps:102.15 imgs/sec, lr:4.532967068371363e-05, per step time: 313.2607626914978ms +2024-09-20 22:00:25,218:INFO:epoch[75], iter[133], loss:148.884801, fps:102.48 imgs/sec, lr:0.0001826923107728362, per step time: 312.26702213287354ms +2024-09-20 22:00:57,372:INFO:epoch[76], iter[51], loss:150.163727, fps:99.54 imgs/sec, lr:7.005494262557477e-05, per step time: 321.46626710891724ms +2024-09-20 22:01:28,614:INFO:epoch[76], iter[151], loss:148.129418, fps:102.43 imgs/sec, lr:0.00020741758635267615, per step time: 312.41174936294556ms +2024-09-20 22:02:00,823:INFO:epoch[77], iter[69], loss:148.318274, fps:99.35 imgs/sec, lr:9.478021820541471e-05, per step time: 322.083158493042ms +2024-09-20 22:02:31,991:INFO:epoch[77], iter[169], loss:151.497935, fps:102.68 imgs/sec, lr:0.0002321428619325161, per step time: 311.64862632751465ms +2024-09-20 22:03:03,620:INFO:epoch[78], iter[87], loss:151.563946, fps:101.18 imgs/sec, lr:0.00011950549378525466, per step time: 316.27243757247925ms +2024-09-20 22:03:35,670:INFO:epoch[79], iter[5], loss:148.694604, fps:99.86 imgs/sec, lr:6.868132004456129e-06, per step time: 320.45562267303467ms +2024-09-20 22:04:07,608:INFO:epoch[79], iter[105], loss:146.027500, fps:100.20 imgs/sec, lr:0.0001442307693650946, per step time: 319.3700122833252ms +2024-09-20 22:04:40,371:INFO:epoch[80], iter[23], loss:150.672054, fps:97.69 imgs/sec, lr:3.159340485581197e-05, per step time: 327.57768392562866ms +2024-09-20 22:05:11,090:INFO:epoch[80], iter[123], loss:147.066246, fps:104.17 imgs/sec, lr:0.00016895604494493455, per step time: 307.17960119247437ms +2024-09-20 22:05:43,199:INFO:epoch[81], iter[41], loss:147.401557, fps:99.67 imgs/sec, lr:5.631868043565191e-05, per step time: 321.07030630111694ms +2024-09-20 22:06:14,750:INFO:epoch[81], iter[141], loss:147.319270, fps:101.43 imgs/sec, lr:0.0001936813205247745, per step time: 315.50060987472534ms +2024-09-20 22:06:46,195:INFO:epoch[82], iter[59], loss:146.813549, fps:101.79 imgs/sec, lr:8.104395965347067e-05, per step time: 314.37256813049316ms +2024-09-20 22:07:16,656:INFO:epoch[82], iter[159], loss:145.159589, fps:105.06 imgs/sec, lr:0.00021840659610461444, per step time: 304.5960593223572ms +2024-09-20 22:07:47,774:INFO:epoch[83], iter[77], loss:143.019820, fps:102.84 imgs/sec, lr:0.000105769227957353, per step time: 311.172239780426ms +2024-09-20 22:08:19,974:INFO:epoch[83], iter[177], loss:148.320587, fps:99.39 imgs/sec, lr:0.00024313187168445438, per step time: 321.97513818740845ms +2024-09-20 22:08:53,300:INFO:epoch[84], iter[95], loss:144.329873, fps:96.03 imgs/sec, lr:0.00013049450353719294, per step time: 333.236608505249ms +2024-09-20 22:09:26,016:INFO:epoch[85], iter[13], loss:141.702216, fps:97.82 imgs/sec, lr:1.7857142665889114e-05, per step time: 327.13752031326294ms +2024-09-20 22:09:59,076:INFO:epoch[85], iter[113], loss:146.870482, fps:96.80 imgs/sec, lr:0.00015521977911703289, per step time: 330.56878566741943ms +2024-09-20 22:10:32,803:INFO:epoch[86], iter[31], loss:143.263632, fps:94.89 imgs/sec, lr:4.258241824572906e-05, per step time: 337.24496364593506ms +2024-09-20 22:11:05,024:INFO:epoch[86], iter[131], loss:144.984645, fps:99.32 imgs/sec, lr:0.00017994505469687283, per step time: 322.2056746482849ms +2024-09-20 22:11:41,391:INFO:epoch[87], iter[49], loss:141.346455, fps:88.00 imgs/sec, lr:6.7307693825569e-05, per step time: 363.63133668899536ms +2024-09-20 22:12:13,657:INFO:epoch[87], iter[149], loss:142.917471, fps:99.21 imgs/sec, lr:0.00020467033027671278, per step time: 322.5620436668396ms +2024-09-20 22:12:47,970:INFO:epoch[88], iter[67], loss:143.583124, fps:93.28 imgs/sec, lr:9.203296940540895e-05, per step time: 343.0643320083618ms +2024-09-20 22:13:23,259:INFO:epoch[88], iter[167], loss:141.979642, fps:90.69 imgs/sec, lr:0.00022939560585655272, per step time: 352.85550594329834ms +2024-09-20 22:13:58,403:INFO:epoch[89], iter[85], loss:139.215054, fps:91.05 imgs/sec, lr:0.0001167582449852489, per step time: 351.44089221954346ms +2024-09-20 22:14:35,292:INFO:epoch[90], iter[3], loss:146.141584, fps:86.75 imgs/sec, lr:4.120879111724207e-06, per step time: 368.85833978652954ms +2024-09-20 22:15:06,645:INFO:epoch[90], iter[103], loss:143.469516, fps:102.07 imgs/sec, lr:0.00014148351328913122, per step time: 313.5232186317444ms +2024-09-20 22:15:44,042:INFO:epoch[91], iter[21], loss:145.293606, fps:85.62 imgs/sec, lr:2.88461542368168e-05, per step time: 373.7307071685791ms +2024-09-20 22:16:20,105:INFO:epoch[91], iter[121], loss:144.661702, fps:88.74 imgs/sec, lr:0.00016620878886897117, per step time: 360.6104254722595ms +2024-09-20 22:16:54,002:INFO:epoch[92], iter[39], loss:141.956459, fps:94.41 imgs/sec, lr:5.357142799766734e-05, per step time: 338.95548582077026ms +2024-09-20 22:17:29,874:INFO:epoch[92], iter[139], loss:143.123322, fps:89.23 imgs/sec, lr:0.00019093406444881111, per step time: 358.6300492286682ms +2024-09-20 22:18:06,965:INFO:epoch[93], iter[57], loss:142.552534, fps:86.28 imgs/sec, lr:7.829670357750729e-05, per step time: 370.9001851081848ms +2024-09-20 22:18:40,129:INFO:epoch[93], iter[157], loss:145.616326, fps:96.49 imgs/sec, lr:0.00021565934002865106, per step time: 331.6291904449463ms +2024-09-20 22:19:13,719:INFO:epoch[94], iter[75], loss:139.510727, fps:95.27 imgs/sec, lr:0.00010302197915734723, per step time: 335.89946031570435ms +2024-09-20 22:19:49,412:INFO:epoch[94], iter[175], loss:143.996249, fps:89.66 imgs/sec, lr:0.000240384615608491, per step time: 356.91224336624146ms +2024-09-20 22:20:24,178:INFO:epoch[95], iter[93], loss:141.205793, fps:92.08 imgs/sec, lr:0.00012774724746122956, per step time: 347.54215478897095ms +2024-09-20 22:21:00,967:INFO:epoch[96], iter[11], loss:139.397462, fps:86.98 imgs/sec, lr:1.5109890227904543e-05, per step time: 367.8854036331177ms +2024-09-20 22:21:37,076:INFO:epoch[96], iter[111], loss:141.283533, fps:88.63 imgs/sec, lr:0.0001524725230410695, per step time: 361.07147693634033ms +2024-09-20 22:22:14,721:INFO:epoch[97], iter[29], loss:143.144139, fps:85.01 imgs/sec, lr:3.983516580774449e-05, per step time: 376.4404296875ms +2024-09-20 22:22:49,614:INFO:epoch[97], iter[129], loss:141.568348, fps:91.72 imgs/sec, lr:0.00017719779862090945, per step time: 348.8882374763489ms +2024-09-20 22:23:24,737:INFO:epoch[98], iter[47], loss:138.773077, fps:91.11 imgs/sec, lr:6.456043774960563e-05, per step time: 351.21087551116943ms +2024-09-20 22:23:59,121:INFO:epoch[98], iter[147], loss:138.208182, fps:93.08 imgs/sec, lr:0.0002019230742007494, per step time: 343.80407333374023ms +2024-09-20 22:24:34,986:INFO:epoch[99], iter[65], loss:136.405245, fps:89.23 imgs/sec, lr:8.928571332944557e-05, per step time: 358.63898038864136ms +2024-09-20 22:25:09,571:INFO:epoch[99], iter[165], loss:140.206702, fps:92.53 imgs/sec, lr:0.00022664834978058934, per step time: 345.8346700668335ms +2024-09-20 22:25:44,550:INFO:epoch[100], iter[83], loss:141.009416, fps:91.49 imgs/sec, lr:0.00011401098890928552, per step time: 349.78076934814453ms +2024-09-20 22:26:19,115:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-20-22:26:19.690.498 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-20 22:26:19,700:INFO:Load train network success +/ - 2024-09-20 22:26:52,760:INFO:Processing... 0.00% +2024-09-20 22:27:02,303:INFO:Calculating mAP... +2024-09-20 22:27:24,360:INFO:Save bbox prediction result. +2024-09-20 22:27:26,998:INFO:Result file path: ./output/predict_2024_09_20_22_27_24.json +Loading and preparing results... +DONE (t=1.64s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=9.17s). +Accumulating evaluation results... +DONE (t=4.13s). +2024-09-20 22:27:42,625:INFO:Best result 0.1110619974854106 at 100 epoch +2024-09-20 22:27:42,625:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.111 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.216 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.105 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.072 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.155 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.160 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.134 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.243 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.283 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.161 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.344 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.348 + +2024-09-20 22:27:42,625:INFO:Ending inference... +2024-09-20 22:27:42,932:INFO:epoch[101], iter[1], loss:141.600147, fps:27.03 imgs/sec, lr:1.3736263326791232e-06, per step time: 1183.8081192970276ms +2024-09-20 22:28:16,385:INFO:epoch[101], iter[101], loss:138.457713, fps:95.66 imgs/sec, lr:0.00013873625721316785, per step time: 334.52548027038574ms +2024-09-20 22:28:49,779:INFO:epoch[102], iter[19], loss:136.188911, fps:95.84 imgs/sec, lr:2.609890179883223e-05, per step time: 333.8826251029968ms +2024-09-20 22:29:24,641:INFO:epoch[102], iter[119], loss:137.029183, fps:91.79 imgs/sec, lr:0.0001634615327930078, per step time: 348.6081051826477ms +2024-09-20 22:30:02,675:INFO:epoch[103], iter[37], loss:138.784330, fps:84.14 imgs/sec, lr:5.082417555968277e-05, per step time: 380.3004026412964ms +2024-09-20 22:30:39,112:INFO:epoch[103], iter[137], loss:137.646188, fps:87.84 imgs/sec, lr:0.00018818680837284774, per step time: 364.3139934539795ms +2024-09-20 22:31:16,562:INFO:epoch[104], iter[55], loss:138.308470, fps:85.45 imgs/sec, lr:7.554944750154391e-05, per step time: 374.4712567329407ms +2024-09-20 22:31:50,839:INFO:epoch[104], iter[155], loss:137.853747, fps:93.36 imgs/sec, lr:0.00021291208395268768, per step time: 342.7631378173828ms +2024-09-20 22:32:26,081:INFO:epoch[105], iter[73], loss:138.198822, fps:90.81 imgs/sec, lr:0.00010027472308138385, per step time: 352.37709283828735ms +2024-09-20 22:33:00,105:INFO:epoch[105], iter[173], loss:139.009576, fps:94.05 imgs/sec, lr:0.00023763735953252763, per step time: 340.234739780426ms +2024-09-20 22:33:36,567:INFO:epoch[106], iter[91], loss:135.846067, fps:87.76 imgs/sec, lr:0.0001250000059371814, per step time: 364.6113181114197ms +2024-09-20 22:34:11,172:INFO:epoch[107], iter[9], loss:137.811632, fps:92.48 imgs/sec, lr:1.2362637789919972e-05, per step time: 346.0334897041321ms +2024-09-20 22:34:45,445:INFO:epoch[107], iter[109], loss:136.146617, fps:93.37 imgs/sec, lr:0.00014972528151702136, per step time: 342.71581172943115ms +2024-09-20 22:35:22,137:INFO:epoch[108], iter[27], loss:135.352033, fps:87.23 imgs/sec, lr:3.708791336975992e-05, per step time: 366.8640923500061ms +2024-09-20 22:35:57,814:INFO:epoch[108], iter[127], loss:135.529634, fps:89.70 imgs/sec, lr:0.00017445054254494607, per step time: 356.7450261116028ms +2024-09-20 22:36:30,855:INFO:epoch[109], iter[45], loss:137.869560, fps:96.86 imgs/sec, lr:6.181318894959986e-05, per step time: 330.39077281951904ms +2024-09-20 22:37:01,290:INFO:epoch[109], iter[145], loss:133.558005, fps:105.15 imgs/sec, lr:0.00019917581812478602, per step time: 304.3353271484375ms +2024-09-20 22:37:36,117:INFO:epoch[110], iter[63], loss:133.134623, fps:91.89 imgs/sec, lr:8.653846452943981e-05, per step time: 348.2349157333374ms +2024-09-20 22:38:10,938:INFO:epoch[110], iter[163], loss:137.515189, fps:91.90 imgs/sec, lr:0.00022390109370462596, per step time: 348.2085418701172ms +2024-09-20 22:38:18,340:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-20-22:38:18.925.634 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-20 22:38:18,936:INFO:Load train network success +2024-09-20 22:38:24,780:INFO:Processing... 0.00% +2024-09-20 22:38:37,278:INFO:Calculating mAP... +2024-09-20 22:39:26,557:INFO:Save bbox prediction result. +2024-09-20 22:39:30,775:INFO:Result file path: ./output/predict_2024_09_20_22_39_26.json +Loading and preparing results... +DONE (t=3.50s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=10.18s). +Accumulating evaluation results... +DONE (t=6.87s). +2024-09-20 22:39:52,494:INFO:Best result 0.1231775223269493 at 110 epoch +2024-09-20 22:39:52,494:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.123 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.244 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.113 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.077 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.178 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.170 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.149 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.265 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.321 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.184 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.394 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.397 + +2024-09-20 22:39:52,495:INFO:Ending inference... +2024-09-20 22:40:17,791:INFO:epoch[111], iter[81], loss:136.622819, fps:25.23 imgs/sec, lr:0.00011126373283332214, per step time: 1268.522024154663ms +2024-09-20 22:40:49,079:INFO:epoch[111], iter[181], loss:134.872264, fps:102.31 imgs/sec, lr:0.0002486263692844659, per step time: 312.76689529418945ms +2024-09-20 22:41:25,130:INFO:epoch[112], iter[99], loss:134.460122, fps:88.77 imgs/sec, lr:0.0001359890156891197, per step time: 360.50086975097656ms +2024-09-20 22:42:00,390:INFO:epoch[113], iter[17], loss:135.340879, fps:90.76 imgs/sec, lr:2.3351647541858256e-05, per step time: 352.5795364379883ms +2024-09-20 22:42:33,919:INFO:epoch[113], iter[117], loss:135.050139, fps:95.45 imgs/sec, lr:0.00016071429126895964, per step time: 335.2613925933838ms +2024-09-20 22:43:08,734:INFO:epoch[114], iter[35], loss:138.282317, fps:91.92 imgs/sec, lr:4.80769231216982e-05, per step time: 348.1263303756714ms +2024-09-20 22:43:43,763:INFO:epoch[114], iter[135], loss:133.098676, fps:91.36 imgs/sec, lr:0.00018543956684879959, per step time: 350.27921438217163ms +2024-09-20 22:44:18,715:INFO:epoch[115], iter[53], loss:136.715493, fps:91.55 imgs/sec, lr:7.280219870153815e-05, per step time: 349.51882123947144ms +2024-09-20 22:44:54,087:INFO:epoch[115], iter[153], loss:131.230342, fps:90.49 imgs/sec, lr:0.00021016484242863953, per step time: 353.6300587654114ms +2024-09-20 22:45:26,684:INFO:epoch[116], iter[71], loss:130.659897, fps:98.18 imgs/sec, lr:9.752747428137809e-05, per step time: 325.9447693824768ms +2024-09-20 22:46:02,105:INFO:epoch[116], iter[171], loss:132.432459, fps:90.34 imgs/sec, lr:0.00023489010345656425, per step time: 354.20682191848755ms +2024-09-20 22:46:38,669:INFO:epoch[117], iter[89], loss:133.966663, fps:87.54 imgs/sec, lr:0.00012225274986121804, per step time: 365.549156665802ms +2024-09-20 22:47:11,931:INFO:epoch[118], iter[7], loss:133.449753, fps:96.21 imgs/sec, lr:9.6153844424407e-06, per step time: 332.6113748550415ms +2024-09-20 22:47:45,012:INFO:epoch[118], iter[107], loss:133.328710, fps:96.74 imgs/sec, lr:0.00014697802544105798, per step time: 330.7812166213989ms +2024-09-20 22:48:21,632:INFO:epoch[119], iter[25], loss:133.396037, fps:87.39 imgs/sec, lr:3.4340660931775346e-05, per step time: 366.18098497390747ms +2024-09-20 22:48:58,268:INFO:epoch[119], iter[125], loss:134.920489, fps:87.36 imgs/sec, lr:0.00017170330102089792, per step time: 366.30735874176025ms +2024-09-20 22:49:34,195:INFO:epoch[120], iter[43], loss:133.619881, fps:89.08 imgs/sec, lr:5.9065932873636484e-05, per step time: 359.23635482788086ms +2024-09-20 22:50:07,317:INFO:epoch[120], iter[143], loss:132.518920, fps:96.62 imgs/sec, lr:0.00019642857660073787, per step time: 331.1810636520386ms +2024-09-20 22:50:20,168:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-20-22:50:20.756.705 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-20 22:50:20,770:INFO:Load train network success +2024-09-20 22:50:26,434:INFO:Processing... 0.00% +2024-09-20 22:50:39,640:INFO:Calculating mAP... +2024-09-20 22:52:02,616:INFO:Save bbox prediction result. +2024-09-20 22:52:08,232:INFO:Result file path: ./output/predict_2024_09_20_22_52_02.json +Loading and preparing results... +DONE (t=4.52s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=12.15s). +Accumulating evaluation results... +DONE (t=5.59s). +2024-09-20 22:52:31,229:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.122 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.243 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.111 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.068 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.178 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.179 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.151 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.291 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.346 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.190 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.418 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.426 + +2024-09-20 22:52:31,237:INFO:Ending inference... +2024-09-20 22:52:50,274:INFO:epoch[121], iter[61], loss:130.612318, fps:19.64 imgs/sec, lr:8.379120845347643e-05, per step time: 1629.53284740448ms +2024-09-20 22:53:21,081:INFO:epoch[121], iter[161], loss:131.075849, fps:103.88 imgs/sec, lr:0.00022115385218057781, per step time: 308.0540657043457ms +2024-09-20 22:53:53,887:INFO:epoch[122], iter[79], loss:129.474422, fps:97.55 imgs/sec, lr:0.00010851648403331637, per step time: 328.04887533187866ms +2024-09-20 22:54:25,650:INFO:epoch[122], iter[179], loss:132.204048, fps:100.76 imgs/sec, lr:0.00024587911320850253, per step time: 317.58118629455566ms +2024-09-20 22:55:01,378:INFO:epoch[123], iter[97], loss:130.524952, fps:89.57 imgs/sec, lr:0.00013324175961315632, per step time: 357.2697687149048ms +2024-09-20 22:55:35,582:INFO:epoch[124], iter[15], loss:130.489772, fps:93.57 imgs/sec, lr:2.0604395103873685e-05, per step time: 341.9764828681946ms +2024-09-20 22:56:08,769:INFO:epoch[124], iter[115], loss:133.005465, fps:96.42 imgs/sec, lr:0.00015796703519299626, per step time: 331.8655300140381ms +2024-09-20 22:56:43,701:INFO:epoch[125], iter[33], loss:130.063612, fps:91.61 imgs/sec, lr:4.532967068371363e-05, per step time: 349.3101501464844ms +2024-09-20 22:57:15,365:INFO:epoch[125], iter[133], loss:130.396058, fps:101.07 imgs/sec, lr:0.0001826923107728362, per step time: 316.5994453430176ms +2024-09-20 22:57:51,815:INFO:epoch[126], iter[51], loss:132.246413, fps:87.81 imgs/sec, lr:7.005494262557477e-05, per step time: 364.4360399246216ms +2024-09-20 22:58:24,583:INFO:epoch[126], iter[151], loss:130.512584, fps:97.66 imgs/sec, lr:0.00020741758635267615, per step time: 327.6693058013916ms +2024-09-20 22:58:59,702:INFO:epoch[127], iter[69], loss:128.498721, fps:91.15 imgs/sec, lr:9.478021820541471e-05, per step time: 351.07710361480713ms +2024-09-20 22:59:32,010:INFO:epoch[127], iter[169], loss:131.827710, fps:99.05 imgs/sec, lr:0.0002321428619325161, per step time: 323.07223320007324ms +2024-09-20 23:00:09,650:INFO:epoch[128], iter[87], loss:129.822132, fps:85.02 imgs/sec, lr:0.00011950549378525466, per step time: 376.391818523407ms +2024-09-20 23:00:44,641:INFO:epoch[129], iter[5], loss:129.149267, fps:91.47 imgs/sec, lr:6.868132004456129e-06, per step time: 349.82423305511475ms +2024-09-20 23:01:17,753:INFO:epoch[129], iter[105], loss:128.333799, fps:96.68 imgs/sec, lr:0.0001442307693650946, per step time: 330.98079919815063ms +2024-09-20 23:01:53,992:INFO:epoch[130], iter[23], loss:128.456444, fps:88.31 imgs/sec, lr:3.159340485581197e-05, per step time: 362.34421014785767ms +2024-09-20 23:02:29,200:INFO:epoch[130], iter[123], loss:132.896715, fps:90.90 imgs/sec, lr:0.00016895604494493455, per step time: 352.05196619033813ms +2024-09-20 23:02:49,034:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-20-23:02:49.505.754 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-20 23:02:49,524:INFO:Load train network success +2024-09-20 23:02:55,574:INFO:Processing... 0.00% +2024-09-20 23:03:08,061:INFO:Calculating mAP... +2024-09-20 23:04:42,963:INFO:Save bbox prediction result. +2024-09-20 23:04:49,573:INFO:Result file path: ./output/predict_2024_09_20_23_04_42.json +Loading and preparing results... +DONE (t=5.31s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=12.72s). +Accumulating evaluation results... +DONE (t=6.35s). +2024-09-20 23:05:15,108:INFO:Best result 0.12646614598067252 at 130 epoch +2024-09-20 23:05:15,108:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.126 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.249 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.126 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.071 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.184 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.184 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.155 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.295 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.360 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.209 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.440 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.438 + +2024-09-20 23:05:15,108:INFO:Ending inference... +2024-09-20 23:05:28,410:INFO:epoch[131], iter[41], loss:128.724253, fps:17.86 imgs/sec, lr:5.631868043565191e-05, per step time: 1792.0935678482056ms +2024-09-20 23:05:59,308:INFO:epoch[131], iter[141], loss:128.469667, fps:103.57 imgs/sec, lr:0.0001936813205247745, per step time: 308.9651083946228ms +2024-09-20 23:06:34,634:INFO:epoch[132], iter[59], loss:128.619658, fps:90.59 imgs/sec, lr:8.104395965347067e-05, per step time: 353.24661016464233ms +2024-09-20 23:07:07,343:INFO:epoch[132], iter[159], loss:130.061288, fps:97.85 imgs/sec, lr:0.00021840659610461444, per step time: 327.0430827140808ms +2024-09-20 23:07:41,863:INFO:epoch[133], iter[77], loss:128.241758, fps:92.70 imgs/sec, lr:0.000105769227957353, per step time: 345.1941442489624ms +2024-09-20 23:08:16,083:INFO:epoch[133], iter[177], loss:126.442736, fps:93.52 imgs/sec, lr:0.00024313187168445438, per step time: 342.18738555908203ms +2024-09-20 23:08:50,779:INFO:epoch[134], iter[95], loss:129.999414, fps:92.23 imgs/sec, lr:0.00013049450353719294, per step time: 346.95367097854614ms +2024-09-20 23:09:22,477:INFO:epoch[135], iter[13], loss:125.969845, fps:100.96 imgs/sec, lr:1.7857142665889114e-05, per step time: 316.9525361061096ms +2024-09-20 23:09:56,699:INFO:epoch[135], iter[113], loss:126.938308, fps:93.51 imgs/sec, lr:0.00015521977911703289, per step time: 342.1990466117859ms +2024-09-20 23:10:30,384:INFO:epoch[136], iter[31], loss:125.439331, fps:95.00 imgs/sec, lr:4.258241824572906e-05, per step time: 336.8393588066101ms +2024-09-20 23:11:02,912:INFO:epoch[136], iter[131], loss:128.038167, fps:98.41 imgs/sec, lr:0.00017994505469687283, per step time: 325.15729665756226ms +2024-09-20 23:11:38,187:INFO:epoch[137], iter[49], loss:128.029880, fps:90.72 imgs/sec, lr:6.7307693825569e-05, per step time: 352.72708892822266ms +2024-09-20 23:12:10,860:INFO:epoch[137], iter[149], loss:127.116728, fps:97.94 imgs/sec, lr:0.00020467033027671278, per step time: 326.7266917228699ms +2024-09-20 23:12:45,625:INFO:epoch[138], iter[67], loss:125.463853, fps:92.05 imgs/sec, lr:9.203296940540895e-05, per step time: 347.6414728164673ms +2024-09-20 23:13:20,065:INFO:epoch[138], iter[167], loss:127.292950, fps:92.92 imgs/sec, lr:0.00022939560585655272, per step time: 344.37768936157227ms +2024-09-20 23:13:53,970:INFO:epoch[139], iter[85], loss:126.317208, fps:94.39 imgs/sec, lr:0.0001167582449852489, per step time: 339.0366721153259ms +2024-09-20 23:14:27,383:INFO:epoch[140], iter[3], loss:125.929605, fps:95.80 imgs/sec, lr:4.120879111724207e-06, per step time: 334.02865409851074ms +2024-09-20 23:14:59,616:INFO:epoch[140], iter[103], loss:126.942285, fps:99.31 imgs/sec, lr:0.00014148351328913122, per step time: 322.2372889518738ms +2024-09-20 23:15:26,253:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-20-23:15:26.809.422 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-20 23:15:26,830:INFO:Load train network success +2024-09-20 23:15:32,926:INFO:Processing... 0.00% +2024-09-20 23:15:44,969:INFO:Calculating mAP... +2024-09-20 23:17:26,767:INFO:Save bbox prediction result. +2024-09-20 23:17:33,635:INFO:Result file path: ./output/predict_2024_09_20_23_17_26.json +Loading and preparing results... +DONE (t=5.09s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=12.89s). +Accumulating evaluation results... +DONE (t=6.81s). +2024-09-20 23:17:59,555:INFO:Best result 0.1297615189628833 at 140 epoch +2024-09-20 23:17:59,555:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.130 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.250 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.129 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.068 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.194 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.185 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.158 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.307 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.369 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.211 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.447 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.453 + +2024-09-20 23:17:59,555:INFO:Ending inference... +2024-09-20 23:18:09,144:INFO:epoch[141], iter[21], loss:125.165137, fps:16.88 imgs/sec, lr:2.88461542368168e-05, per step time: 1895.2597951889038ms +2024-09-20 23:18:40,348:INFO:epoch[141], iter[121], loss:124.948088, fps:102.55 imgs/sec, lr:0.00016620878886897117, per step time: 312.0321750640869ms +2024-09-20 23:19:12,251:INFO:epoch[142], iter[39], loss:125.667701, fps:100.31 imgs/sec, lr:5.357142799766734e-05, per step time: 318.9992880821228ms +2024-09-20 23:19:45,790:INFO:epoch[142], iter[139], loss:125.683373, fps:95.42 imgs/sec, lr:0.00019093406444881111, per step time: 335.3760242462158ms +2024-09-20 23:20:18,820:INFO:epoch[143], iter[57], loss:128.012079, fps:96.89 imgs/sec, lr:7.829670357750729e-05, per step time: 330.25548934936523ms +2024-09-20 23:20:51,669:INFO:epoch[143], iter[157], loss:121.850427, fps:97.42 imgs/sec, lr:0.00021565934002865106, per step time: 328.4816575050354ms +2024-09-20 23:21:25,066:INFO:epoch[144], iter[75], loss:123.128417, fps:95.83 imgs/sec, lr:0.00010302197915734723, per step time: 333.90763759613037ms +2024-09-20 23:21:56,731:INFO:epoch[144], iter[175], loss:124.338549, fps:101.07 imgs/sec, lr:0.000240384615608491, per step time: 316.6258239746094ms +2024-09-20 23:22:32,748:INFO:epoch[145], iter[93], loss:123.793945, fps:88.86 imgs/sec, lr:0.00012774724746122956, per step time: 360.1122212409973ms +2024-09-20 23:23:05,772:INFO:epoch[146], iter[11], loss:123.769950, fps:96.91 imgs/sec, lr:1.5109890227904543e-05, per step time: 330.18821001052856ms +2024-09-20 23:23:39,045:INFO:epoch[146], iter[111], loss:124.394664, fps:96.21 imgs/sec, lr:0.0001524725230410695, per step time: 332.60732889175415ms +2024-09-20 23:24:12,116:INFO:epoch[147], iter[29], loss:121.802347, fps:96.76 imgs/sec, lr:3.983516580774449e-05, per step time: 330.705726146698ms +2024-09-20 23:24:45,609:INFO:epoch[147], iter[129], loss:125.513135, fps:95.56 imgs/sec, lr:0.00017719779862090945, per step time: 334.86868619918823ms +2024-09-20 23:25:20,801:INFO:epoch[148], iter[47], loss:121.482717, fps:90.93 imgs/sec, lr:6.456043774960563e-05, per step time: 351.91351890563965ms +2024-09-20 23:25:52,800:INFO:epoch[148], iter[147], loss:123.419275, fps:100.03 imgs/sec, lr:0.0002019230742007494, per step time: 319.9073338508606ms +2024-09-20 23:26:25,958:INFO:epoch[149], iter[65], loss:122.111397, fps:96.53 imgs/sec, lr:8.928571332944557e-05, per step time: 331.4860200881958ms +2024-09-20 23:26:59,153:INFO:epoch[149], iter[165], loss:125.449110, fps:96.41 imgs/sec, lr:0.00022664834978058934, per step time: 331.92606687545776ms +2024-09-20 23:27:32,582:INFO:epoch[150], iter[83], loss:120.971199, fps:95.74 imgs/sec, lr:0.00011401098890928552, per step time: 334.2355489730835ms +2024-09-20 23:28:05,237:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-20-23:28:05.611.411 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-20 23:28:05,620:INFO:Load train network success +2024-09-20 23:28:11,701:INFO:Processing... 0.00% +2024-09-20 23:28:24,078:INFO:Calculating mAP... +2024-09-20 23:30:22,539:INFO:Save bbox prediction result. +2024-09-20 23:30:29,716:INFO:Result file path: ./output/predict_2024_09_20_23_30_22.json +Loading and preparing results... +DONE (t=5.79s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=13.64s). +Accumulating evaluation results... +DONE (t=9.43s). +2024-09-20 23:30:59,839:INFO:Best result 0.13634703904597942 at 150 epoch +2024-09-20 23:30:59,840:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.136 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.256 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.140 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.077 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.204 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.189 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.163 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.315 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.377 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.219 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.456 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.462 + +2024-09-20 23:30:59,840:INFO:Ending inference... +2024-09-20 23:31:00,140:INFO:epoch[151], iter[1], loss:123.446616, fps:15.42 imgs/sec, lr:1.3736263326791232e-06, per step time: 2075.5417490005493ms +2024-09-20 23:31:32,852:INFO:epoch[151], iter[101], loss:125.950405, fps:97.82 imgs/sec, lr:0.00013873625721316785, per step time: 327.1178150177002ms +2024-09-20 23:32:05,101:INFO:epoch[152], iter[19], loss:120.440224, fps:99.23 imgs/sec, lr:2.609890179883223e-05, per step time: 322.4720025062561ms +2024-09-20 23:32:37,563:INFO:epoch[152], iter[119], loss:122.634608, fps:98.59 imgs/sec, lr:0.0001634615327930078, per step time: 324.57486152648926ms +2024-09-20 23:33:12,952:INFO:epoch[153], iter[37], loss:120.341624, fps:90.43 imgs/sec, lr:5.082417555968277e-05, per step time: 353.87375354766846ms +2024-09-20 23:33:47,886:INFO:epoch[153], iter[137], loss:123.097799, fps:91.60 imgs/sec, lr:0.00018818680837284774, per step time: 349.33199405670166ms +2024-09-20 23:34:21,119:INFO:epoch[154], iter[55], loss:122.685954, fps:96.29 imgs/sec, lr:7.554944750154391e-05, per step time: 332.32348442077637ms +2024-09-20 23:34:55,011:INFO:epoch[154], iter[155], loss:123.991807, fps:94.42 imgs/sec, lr:0.00021291208395268768, per step time: 338.9163017272949ms +2024-09-20 23:35:29,634:INFO:epoch[155], iter[73], loss:122.615857, fps:92.43 imgs/sec, lr:0.00010027472308138385, per step time: 346.2205743789673ms +2024-09-20 23:36:04,808:INFO:epoch[155], iter[173], loss:121.483161, fps:91.00 imgs/sec, lr:0.00023763735953252763, per step time: 351.66131019592285ms +2024-09-20 23:36:39,190:INFO:epoch[156], iter[91], loss:118.269241, fps:93.08 imgs/sec, lr:0.0001250000059371814, per step time: 343.78196954727173ms +2024-09-20 23:37:14,780:INFO:epoch[157], iter[9], loss:124.154228, fps:89.93 imgs/sec, lr:1.2362637789919972e-05, per step time: 355.84038257598877ms +2024-09-20 23:37:50,163:INFO:epoch[157], iter[109], loss:119.266597, fps:90.44 imgs/sec, lr:0.00014972528151702136, per step time: 353.8176465034485ms +2024-09-20 23:38:26,139:INFO:epoch[158], iter[27], loss:120.144343, fps:88.95 imgs/sec, lr:3.708791336975992e-05, per step time: 359.7498083114624ms +2024-09-20 23:38:59,198:INFO:epoch[158], iter[127], loss:121.026466, fps:96.80 imgs/sec, lr:0.00017445054254494607, per step time: 330.5803060531616ms +2024-09-20 23:39:31,758:INFO:epoch[159], iter[45], loss:120.075502, fps:98.28 imgs/sec, lr:6.181318894959986e-05, per step time: 325.593843460083ms +2024-09-20 23:40:05,542:INFO:epoch[159], iter[145], loss:120.720975, fps:94.73 imgs/sec, lr:0.00019917581812478602, per step time: 337.8160834312439ms +2024-09-20 23:40:41,370:INFO:epoch[160], iter[63], loss:119.142794, fps:89.32 imgs/sec, lr:8.653846452943981e-05, per step time: 358.2783341407776ms +2024-09-20 23:41:14,850:INFO:epoch[160], iter[163], loss:118.383065, fps:95.59 imgs/sec, lr:0.00022390109370462596, per step time: 334.76643562316895ms +2024-09-20 23:41:22,025:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-20-23:41:22.522.351 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-20 23:41:22,542:INFO:Load train network success +2024-09-20 23:41:27,747:INFO:Processing... 0.00% +2024-09-20 23:41:40,084:INFO:Calculating mAP... +2024-09-20 23:43:39,357:INFO:Save bbox prediction result. +2024-09-20 23:43:46,970:INFO:Result file path: ./output/predict_2024_09_20_23_43_39.json +Loading and preparing results... +DONE (t=6.43s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=13.98s). +Accumulating evaluation results... +DONE (t=8.60s). +2024-09-20 23:44:17,215:INFO:Best result 0.1408401868998129 at 160 epoch +2024-09-20 23:44:17,216:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.141 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.262 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.141 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.082 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.197 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.197 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.163 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.318 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.377 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.219 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.458 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.461 + +2024-09-20 23:44:17,216:INFO:Ending inference... +2024-09-20 23:44:42,504:INFO:epoch[161], iter[81], loss:119.034469, fps:15.41 imgs/sec, lr:0.00011126373283332214, per step time: 2076.493308544159ms +2024-09-20 23:45:13,151:INFO:epoch[161], iter[181], loss:122.939383, fps:104.42 imgs/sec, lr:0.0002486263692844659, per step time: 306.46456718444824ms +2024-09-20 23:45:46,432:INFO:epoch[162], iter[99], loss:119.536736, fps:96.16 imgs/sec, lr:0.0001359890156891197, per step time: 332.7889156341553ms +2024-09-20 23:46:20,113:INFO:epoch[163], iter[17], loss:120.382381, fps:95.01 imgs/sec, lr:2.3351647541858256e-05, per step time: 336.7985200881958ms +2024-09-20 23:46:52,713:INFO:epoch[163], iter[117], loss:121.309205, fps:98.17 imgs/sec, lr:0.00016071429126895964, per step time: 325.955011844635ms +2024-09-20 23:47:26,772:INFO:epoch[164], iter[35], loss:116.924814, fps:93.96 imgs/sec, lr:4.80769231216982e-05, per step time: 340.56528091430664ms +2024-09-20 23:47:59,137:INFO:epoch[164], iter[135], loss:118.611944, fps:98.87 imgs/sec, lr:0.00018543956684879959, per step time: 323.6450386047363ms +2024-09-20 23:48:33,896:INFO:epoch[165], iter[53], loss:121.020307, fps:92.07 imgs/sec, lr:7.280219870153815e-05, per step time: 347.5626587867737ms +2024-09-20 23:49:09,947:INFO:epoch[165], iter[153], loss:119.003034, fps:88.77 imgs/sec, lr:0.00021016484242863953, per step time: 360.497190952301ms +2024-09-20 23:49:43,021:INFO:epoch[166], iter[71], loss:121.656607, fps:96.76 imgs/sec, lr:9.752747428137809e-05, per step time: 330.7194685935974ms +2024-09-20 23:50:16,444:INFO:epoch[166], iter[171], loss:118.265737, fps:95.77 imgs/sec, lr:0.00023489010345656425, per step time: 334.14984464645386ms +2024-09-20 23:50:51,873:INFO:epoch[167], iter[89], loss:119.264357, fps:90.32 imgs/sec, lr:0.00012225274986121804, per step time: 354.28125858306885ms +2024-09-20 23:51:24,583:INFO:epoch[168], iter[7], loss:118.865781, fps:97.84 imgs/sec, lr:9.6153844424407e-06, per step time: 327.05182552337646ms +2024-09-20 23:51:57,200:INFO:epoch[168], iter[107], loss:119.554023, fps:98.13 imgs/sec, lr:0.00014697802544105798, per step time: 326.08696460723877ms +2024-09-20 23:52:31,295:INFO:epoch[169], iter[25], loss:117.754039, fps:93.86 imgs/sec, lr:3.4340660931775346e-05, per step time: 340.9225130081177ms +2024-09-20 23:53:04,681:INFO:epoch[169], iter[125], loss:116.770246, fps:95.86 imgs/sec, lr:0.00017170330102089792, per step time: 333.8299226760864ms +2024-09-20 23:53:39,118:INFO:epoch[170], iter[43], loss:119.711896, fps:92.96 imgs/sec, lr:5.9065932873636484e-05, per step time: 344.23110485076904ms +2024-09-20 23:54:14,751:INFO:epoch[170], iter[143], loss:116.990155, fps:89.81 imgs/sec, lr:0.00019642857660073787, per step time: 356.29607677459717ms +2024-09-20 23:54:27,375:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-20-23:54:27.900.687 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-20 23:54:27,912:INFO:Load train network success +2024-09-20 23:54:33,472:INFO:Processing... 0.00% +2024-09-20 23:54:47,185:INFO:Calculating mAP... +2024-09-20 23:56:57,325:INFO:Save bbox prediction result. +2024-09-20 23:57:06,078:INFO:Result file path: ./output/predict_2024_09_20_23_56_57.json +Loading and preparing results... +DONE (t=4.19s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=16.17s). +Accumulating evaluation results... +DONE (t=7.63s). +2024-09-20 23:57:35,494:INFO:Best result 0.14800970232176494 at 170 epoch +2024-09-20 23:57:35,494:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.148 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.272 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.147 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.088 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.211 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.201 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.167 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.317 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.385 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.232 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.471 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.466 + +2024-09-20 23:57:35,495:INFO:Ending inference... +2024-09-20 23:57:56,670:INFO:epoch[171], iter[61], loss:118.260703, fps:14.42 imgs/sec, lr:8.379120845347643e-05, per step time: 2219.1401195526123ms +2024-09-20 23:58:27,035:INFO:epoch[171], iter[161], loss:117.735702, fps:105.39 imgs/sec, lr:0.00022115385218057781, per step time: 303.64450216293335ms +2024-09-20 23:58:59,715:INFO:epoch[172], iter[79], loss:113.439224, fps:97.92 imgs/sec, lr:0.00010851648403331637, per step time: 326.79879426956177ms +2024-09-20 23:59:33,185:INFO:epoch[172], iter[179], loss:117.891864, fps:95.62 imgs/sec, lr:0.00024587911320850253, per step time: 334.6550989151001ms +2024-09-21 00:00:08,022:INFO:epoch[173], iter[97], loss:113.850960, fps:91.86 imgs/sec, lr:0.00013324175961315632, per step time: 348.36323499679565ms +2024-09-21 00:00:43,687:INFO:epoch[174], iter[15], loss:119.238884, fps:89.72 imgs/sec, lr:2.0604395103873685e-05, per step time: 356.6509938240051ms +2024-09-21 00:01:16,992:INFO:epoch[174], iter[115], loss:115.311836, fps:96.08 imgs/sec, lr:0.00015796703519299626, per step time: 333.0439352989197ms +2024-09-21 00:01:51,890:INFO:epoch[175], iter[33], loss:115.578916, fps:91.71 imgs/sec, lr:4.532967068371363e-05, per step time: 348.9119529724121ms +2024-09-21 00:02:23,758:INFO:epoch[175], iter[133], loss:113.022321, fps:100.42 imgs/sec, lr:0.0001826923107728362, per step time: 318.67212772369385ms +2024-09-21 00:02:57,049:INFO:epoch[176], iter[51], loss:115.366304, fps:96.13 imgs/sec, lr:7.005494262557477e-05, per step time: 332.89384603500366ms +2024-09-21 00:03:30,228:INFO:epoch[176], iter[151], loss:115.544753, fps:96.45 imgs/sec, lr:0.00020741758635267615, per step time: 331.78191900253296ms +2024-09-21 00:04:05,774:INFO:epoch[177], iter[69], loss:115.040966, fps:90.04 imgs/sec, lr:9.478021820541471e-05, per step time: 355.3860807418823ms +2024-09-21 00:04:37,123:INFO:epoch[177], iter[169], loss:113.594740, fps:102.08 imgs/sec, lr:0.0002321428619325161, per step time: 313.4677982330322ms +2024-09-21 00:05:10,962:INFO:epoch[178], iter[87], loss:115.535444, fps:94.57 imgs/sec, lr:0.00011950549378525466, per step time: 338.36917877197266ms +2024-09-21 00:05:45,322:INFO:epoch[179], iter[5], loss:119.144962, fps:93.16 imgs/sec, lr:6.868132004456129e-06, per step time: 343.4821653366089ms +2024-09-21 00:06:17,538:INFO:epoch[179], iter[105], loss:115.050396, fps:99.33 imgs/sec, lr:0.0001442307693650946, per step time: 322.14702129364014ms +2024-09-21 00:06:50,490:INFO:epoch[180], iter[23], loss:116.403519, fps:97.14 imgs/sec, lr:3.159340485581197e-05, per step time: 329.4316816329956ms +2024-09-21 00:07:22,679:INFO:epoch[180], iter[123], loss:113.556513, fps:99.41 imgs/sec, lr:0.00016895604494493455, per step time: 321.88705921173096ms +2024-09-21 00:07:41,504:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-21-00:07:41.979.010 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-21 00:07:41,987:INFO:Load train network success +2024-09-21 00:07:47,218:INFO:Processing... 0.00% +2024-09-21 00:07:59,755:INFO:Calculating mAP... +2024-09-21 00:10:20,200:INFO:Save bbox prediction result. +2024-09-21 00:10:28,387:INFO:Result file path: ./output/predict_2024_09_21_00_10_20.json +Loading and preparing results... +DONE (t=6.74s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=15.00s). +Accumulating evaluation results... +DONE (t=8.70s). +2024-09-21 00:11:00,102:INFO:Best result 0.15060400063685253 at 180 epoch +2024-09-21 00:11:00,103:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.151 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.273 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.150 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.085 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.206 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.206 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.168 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.322 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.392 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.239 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.474 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.470 + +2024-09-21 00:11:00,103:INFO:Ending inference... +2024-09-21 00:11:15,779:INFO:epoch[181], iter[41], loss:115.428275, fps:13.73 imgs/sec, lr:5.631868043565191e-05, per step time: 2330.987057685852ms +2024-09-21 00:11:46,845:INFO:epoch[181], iter[141], loss:115.537684, fps:103.01 imgs/sec, lr:0.0001936813205247745, per step time: 310.66256761550903ms +2024-09-21 00:12:20,440:INFO:epoch[182], iter[59], loss:112.614738, fps:95.28 imgs/sec, lr:8.104395965347067e-05, per step time: 335.8647131919861ms +2024-09-21 00:12:52,910:INFO:epoch[182], iter[159], loss:114.101927, fps:98.56 imgs/sec, lr:0.00021840659610461444, per step time: 324.6911883354187ms +2024-09-21 00:13:24,875:INFO:epoch[183], iter[77], loss:114.945649, fps:100.11 imgs/sec, lr:0.000105769227957353, per step time: 319.63618516921997ms +2024-09-21 00:13:57,032:INFO:epoch[183], iter[177], loss:113.025270, fps:99.52 imgs/sec, lr:0.00024313187168445438, per step time: 321.55378103256226ms +2024-09-21 00:14:31,038:INFO:epoch[184], iter[95], loss:114.319051, fps:94.11 imgs/sec, lr:0.00013049450353719294, per step time: 340.0417447090149ms +2024-09-21 00:15:09,743:INFO:epoch[185], iter[13], loss:113.715316, fps:82.69 imgs/sec, lr:1.7857142665889114e-05, per step time: 386.9735527038574ms +2024-09-21 00:15:42,864:INFO:epoch[185], iter[113], loss:113.252966, fps:96.65 imgs/sec, lr:0.00015521977911703289, per step time: 331.0768461227417ms +2024-09-21 00:16:15,295:INFO:epoch[186], iter[31], loss:111.970683, fps:98.70 imgs/sec, lr:4.258241824572906e-05, per step time: 324.2266583442688ms +2024-09-21 00:16:47,036:INFO:epoch[186], iter[131], loss:112.523618, fps:100.82 imgs/sec, lr:0.00017994505469687283, per step time: 317.40036249160767ms +2024-09-21 00:17:19,245:INFO:epoch[187], iter[49], loss:112.097350, fps:99.36 imgs/sec, lr:6.7307693825569e-05, per step time: 322.0676517486572ms +2024-09-21 00:17:51,565:INFO:epoch[187], iter[149], loss:114.005003, fps:99.02 imgs/sec, lr:0.00020467033027671278, per step time: 323.1631898880005ms +2024-09-21 00:18:25,868:INFO:epoch[188], iter[67], loss:113.292285, fps:93.29 imgs/sec, lr:9.203296940540895e-05, per step time: 343.02366495132446ms +2024-09-21 00:18:59,672:INFO:epoch[188], iter[167], loss:111.581020, fps:94.72 imgs/sec, lr:0.00022939560585655272, per step time: 337.8440546989441ms +2024-09-21 00:19:32,815:INFO:epoch[189], iter[85], loss:111.043287, fps:96.56 imgs/sec, lr:0.0001167582449852489, per step time: 331.41053915023804ms +2024-09-21 00:20:04,926:INFO:epoch[190], iter[3], loss:114.982169, fps:99.66 imgs/sec, lr:4.120879111724207e-06, per step time: 321.0889458656311ms +2024-09-21 00:20:37,368:INFO:epoch[190], iter[103], loss:112.699812, fps:98.66 imgs/sec, lr:0.00014148351328913122, per step time: 324.3621802330017ms +2024-09-21 00:21:03,177:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-21-00:21:03.768.890 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-21 00:21:03,780:INFO:Load train network success +2024-09-21 00:21:10,284:INFO:Processing... 0.00% +2024-09-21 00:21:22,706:INFO:Calculating mAP... +2024-09-21 00:24:16,880:INFO:Save bbox prediction result. +2024-09-21 00:24:25,337:INFO:Result file path: ./output/predict_2024_09_21_00_24_16.json +Loading and preparing results... +DONE (t=4.71s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=17.95s). +Accumulating evaluation results... +DONE (t=10.48s). +2024-09-21 00:24:59,870:INFO:Best result 0.15421206301338905 at 190 epoch +2024-09-21 00:24:59,871:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.154 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.277 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.151 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.092 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.216 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.211 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.171 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.329 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.400 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.255 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.485 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.474 + +2024-09-21 00:24:59,871:INFO:Ending inference... +2024-09-21 00:25:09,213:INFO:epoch[191], iter[21], loss:110.804914, fps:11.77 imgs/sec, lr:2.88461542368168e-05, per step time: 2718.399441242218ms +2024-09-21 00:25:40,371:INFO:epoch[191], iter[121], loss:110.722188, fps:102.71 imgs/sec, lr:0.00016620878886897117, per step time: 311.56973361968994ms +2024-09-21 00:26:11,991:INFO:epoch[192], iter[39], loss:111.495396, fps:101.24 imgs/sec, lr:5.357142799766734e-05, per step time: 316.0904884338379ms +2024-09-21 00:26:45,583:INFO:epoch[192], iter[139], loss:110.760905, fps:95.28 imgs/sec, lr:0.00019093406444881111, per step time: 335.8361577987671ms +2024-09-21 00:27:19,441:INFO:epoch[193], iter[57], loss:110.585617, fps:94.53 imgs/sec, lr:7.829670357750729e-05, per step time: 338.52656841278076ms +2024-09-21 00:27:53,664:INFO:epoch[193], iter[157], loss:111.564965, fps:93.52 imgs/sec, lr:0.00021565934002865106, per step time: 342.1712064743042ms +2024-09-21 00:28:27,717:INFO:epoch[194], iter[75], loss:112.315055, fps:93.98 imgs/sec, lr:0.00010302197915734723, per step time: 340.5134987831116ms +2024-09-21 00:29:01,514:INFO:epoch[194], iter[175], loss:113.397694, fps:94.68 imgs/sec, lr:0.000240384615608491, per step time: 337.96521186828613ms +2024-09-21 00:29:35,976:INFO:epoch[195], iter[93], loss:113.045242, fps:92.87 imgs/sec, lr:0.00012774724746122956, per step time: 344.5646357536316ms +2024-09-21 00:30:10,984:INFO:epoch[196], iter[11], loss:110.331654, fps:91.42 imgs/sec, lr:1.5109890227904543e-05, per step time: 350.0251531600952ms +2024-09-21 00:30:43,807:INFO:epoch[196], iter[111], loss:110.620744, fps:97.50 imgs/sec, lr:0.0001524725230410695, per step time: 328.1929683685303ms +2024-09-21 00:31:19,105:INFO:epoch[197], iter[29], loss:111.132546, fps:90.66 imgs/sec, lr:3.983516580774449e-05, per step time: 352.96184062957764ms +2024-09-21 00:31:50,396:INFO:epoch[197], iter[129], loss:111.026616, fps:102.27 imgs/sec, lr:0.00017719779862090945, per step time: 312.8979206085205ms +2024-09-21 00:32:22,605:INFO:epoch[198], iter[47], loss:112.588395, fps:99.36 imgs/sec, lr:6.456043774960563e-05, per step time: 322.06270456314087ms +2024-09-21 00:32:56,085:INFO:epoch[198], iter[147], loss:111.955262, fps:95.59 imgs/sec, lr:0.0002019230742007494, per step time: 334.76970195770264ms +2024-09-21 00:33:30,586:INFO:epoch[199], iter[65], loss:114.626836, fps:92.75 imgs/sec, lr:8.928571332944557e-05, per step time: 345.0027823448181ms +2024-09-21 00:34:04,004:INFO:epoch[199], iter[165], loss:110.639565, fps:95.76 imgs/sec, lr:0.00022664834978058934, per step time: 334.17805910110474ms +2024-09-21 00:34:36,088:INFO:epoch[200], iter[83], loss:110.743324, fps:99.74 imgs/sec, lr:0.00011401098890928552, per step time: 320.8319282531738ms +2024-09-21 00:35:11,402:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-21-00:35:12.559.14 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-21 00:35:12,065:INFO:Load train network success +2024-09-21 00:35:17,935:INFO:Processing... 0.00% +2024-09-21 00:35:30,214:INFO:Calculating mAP... +2024-09-21 00:38:20,697:INFO:Save bbox prediction result. +2024-09-21 00:38:29,196:INFO:Result file path: ./output/predict_2024_09_21_00_38_20.json +Loading and preparing results... +DONE (t=4.68s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=18.20s). +Accumulating evaluation results... +DONE (t=9.10s). +2024-09-21 00:39:02,563:INFO:Best result 0.1574923839246626 at 200 epoch +2024-09-21 00:39:02,564:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.157 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.280 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.159 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.096 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.216 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.219 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.171 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.332 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.400 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.260 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.482 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.471 + +2024-09-21 00:39:02,565:INFO:Ending inference... +2024-09-21 00:39:02,883:INFO:epoch[201], iter[1], loss:110.846965, fps:11.99 imgs/sec, lr:1.3736263326791232e-06, per step time: 2667.8743767738342ms +2024-09-21 00:39:36,523:INFO:epoch[201], iter[101], loss:109.308204, fps:95.13 imgs/sec, lr:0.00013873625721316785, per step time: 336.39429807662964ms +2024-09-21 00:40:08,905:INFO:epoch[202], iter[19], loss:109.350490, fps:98.86 imgs/sec, lr:2.609890179883223e-05, per step time: 323.69808435440063ms +2024-09-21 00:40:42,717:INFO:epoch[202], iter[119], loss:109.096971, fps:94.65 imgs/sec, lr:0.0001634615327930078, per step time: 338.0984830856323ms +2024-09-21 00:41:19,191:INFO:epoch[203], iter[37], loss:111.076856, fps:87.74 imgs/sec, lr:5.082417555968277e-05, per step time: 364.72336530685425ms +2024-09-21 00:41:51,733:INFO:epoch[203], iter[137], loss:108.868444, fps:98.36 imgs/sec, lr:0.00018818680837284774, per step time: 325.3274869918823ms +2024-09-21 00:42:26,095:INFO:epoch[204], iter[55], loss:108.611211, fps:93.16 imgs/sec, lr:7.554944750154391e-05, per step time: 343.49340200424194ms +2024-09-21 00:42:59,861:INFO:epoch[204], iter[155], loss:110.332093, fps:94.77 imgs/sec, lr:0.00021291208395268768, per step time: 337.6479482650757ms +2024-09-21 00:43:34,989:INFO:epoch[205], iter[73], loss:109.997431, fps:91.10 imgs/sec, lr:0.00010027472308138385, per step time: 351.2586188316345ms +2024-09-21 00:44:07,059:INFO:epoch[205], iter[173], loss:108.475287, fps:99.81 imgs/sec, lr:0.00023763735953252763, per step time: 320.6119894981384ms +2024-09-21 00:44:41,127:INFO:epoch[206], iter[91], loss:108.602098, fps:93.93 imgs/sec, lr:0.0001250000059371814, per step time: 340.66203594207764ms +2024-09-21 00:45:15,334:INFO:epoch[207], iter[9], loss:108.641388, fps:93.56 imgs/sec, lr:1.2362637789919972e-05, per step time: 342.02704906463623ms +2024-09-21 00:45:50,113:INFO:epoch[207], iter[109], loss:108.145791, fps:92.01 imgs/sec, lr:0.00014972528151702136, per step time: 347.7795100212097ms +2024-09-21 00:46:24,887:INFO:epoch[208], iter[27], loss:109.536302, fps:92.05 imgs/sec, lr:3.708791336975992e-05, per step time: 347.6230525970459ms +2024-09-21 00:46:59,663:INFO:epoch[208], iter[127], loss:108.619650, fps:92.04 imgs/sec, lr:0.00017445054254494607, per step time: 347.6665234565735ms +2024-09-21 00:47:33,595:INFO:epoch[209], iter[45], loss:110.110516, fps:94.31 imgs/sec, lr:6.181318894959986e-05, per step time: 339.29962635040283ms +2024-09-21 00:48:05,422:INFO:epoch[209], iter[145], loss:109.327173, fps:100.55 imgs/sec, lr:0.00019917581812478602, per step time: 318.2611894607544ms +2024-09-21 00:48:40,695:INFO:epoch[210], iter[63], loss:106.435007, fps:90.73 imgs/sec, lr:8.653846452943981e-05, per step time: 352.7129030227661ms +2024-09-21 00:49:16,406:INFO:epoch[210], iter[163], loss:106.152759, fps:89.62 imgs/sec, lr:0.00022390109370462596, per step time: 357.0780873298645ms +2024-09-21 00:49:23,569:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-21-00:49:24.105.927 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-21 00:49:24,115:INFO:Load train network success +2024-09-21 00:49:29,832:INFO:Processing... 0.00% +2024-09-21 00:49:41,809:INFO:Calculating mAP... +2024-09-21 00:52:37,896:INFO:Save bbox prediction result. +2024-09-21 00:52:46,948:INFO:Result file path: ./output/predict_2024_09_21_00_52_37.json +Loading and preparing results... +DONE (t=7.43s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=15.59s). +Accumulating evaluation results... +DONE (t=12.01s). +2024-09-21 00:53:23,530:INFO:Best result 0.15828163654422248 at 210 epoch +2024-09-21 00:53:23,530:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.158 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.283 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.159 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.095 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.216 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.221 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.174 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.332 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.403 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.255 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.484 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.478 + +2024-09-21 00:53:23,531:INFO:Ending inference... +2024-09-21 00:53:49,668:INFO:epoch[211], iter[81], loss:107.345529, fps:11.71 imgs/sec, lr:0.00011126373283332214, per step time: 2732.609555721283ms +2024-09-21 00:54:20,564:INFO:epoch[211], iter[181], loss:106.935943, fps:103.58 imgs/sec, lr:0.0002486263692844659, per step time: 308.93269538879395ms +2024-09-21 00:54:56,342:INFO:epoch[212], iter[99], loss:106.046121, fps:89.44 imgs/sec, lr:0.0001359890156891197, per step time: 357.76999950408936ms +2024-09-21 00:55:31,579:INFO:epoch[213], iter[17], loss:105.710254, fps:90.83 imgs/sec, lr:2.3351647541858256e-05, per step time: 352.29787826538086ms +2024-09-21 00:56:06,277:INFO:epoch[213], iter[117], loss:108.458076, fps:92.22 imgs/sec, lr:0.00016071429126895964, per step time: 346.9790267944336ms +2024-09-21 00:56:39,609:INFO:epoch[214], iter[35], loss:108.163204, fps:96.05 imgs/sec, lr:4.80769231216982e-05, per step time: 333.15407037734985ms +2024-09-21 00:57:13,589:INFO:epoch[214], iter[135], loss:105.456129, fps:94.18 imgs/sec, lr:0.00018543956684879959, per step time: 339.7778630256653ms +2024-09-21 00:57:47,061:INFO:epoch[215], iter[53], loss:106.574297, fps:95.61 imgs/sec, lr:7.280219870153815e-05, per step time: 334.70808506011963ms +2024-09-21 00:58:22,286:INFO:epoch[215], iter[153], loss:108.578318, fps:90.85 imgs/sec, lr:0.00021016484242863953, per step time: 352.2442364692688ms +2024-09-21 00:58:58,708:INFO:epoch[216], iter[71], loss:103.133637, fps:87.86 imgs/sec, lr:9.752747428137809e-05, per step time: 364.21026706695557ms +2024-09-21 00:59:34,653:INFO:epoch[216], iter[171], loss:105.798803, fps:89.03 imgs/sec, lr:0.00023489010345656425, per step time: 359.43918228149414ms +2024-09-21 01:00:10,346:INFO:epoch[217], iter[89], loss:106.720617, fps:89.65 imgs/sec, lr:0.00012225274986121804, per step time: 356.9267249107361ms +2024-09-21 01:00:48,575:INFO:epoch[218], iter[7], loss:106.656699, fps:83.71 imgs/sec, lr:9.6153844424407e-06, per step time: 382.2763919830322ms +2024-09-21 01:01:27,342:INFO:epoch[218], iter[107], loss:105.030803, fps:82.56 imgs/sec, lr:0.00014697802544105798, per step time: 387.5902223587036ms +2024-09-21 01:02:02,704:INFO:epoch[219], iter[25], loss:109.696712, fps:90.49 imgs/sec, lr:3.4340660931775346e-05, per step time: 353.6153793334961ms +2024-09-21 01:02:38,551:INFO:epoch[219], iter[125], loss:103.583971, fps:89.28 imgs/sec, lr:0.00017170330102089792, per step time: 358.44090461730957ms +2024-09-21 01:03:11,993:INFO:epoch[220], iter[43], loss:107.751505, fps:95.70 imgs/sec, lr:5.9065932873636484e-05, per step time: 334.3674945831299ms +2024-09-21 01:03:44,731:INFO:epoch[220], iter[143], loss:105.318164, fps:97.77 imgs/sec, lr:0.00019642857660073787, per step time: 327.2945499420166ms +2024-09-21 01:03:58,653:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-21-01:03:59.168.907 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-21 01:03:59,183:INFO:Load train network success +2024-09-21 01:04:04,752:INFO:Processing... 0.00% +2024-09-21 01:04:16,979:INFO:Calculating mAP... +2024-09-21 01:07:39,764:INFO:Save bbox prediction result. +2024-09-21 01:07:48,784:INFO:Result file path: ./output/predict_2024_09_21_01_07_39.json +Loading and preparing results... +DONE (t=7.36s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=15.55s). +Accumulating evaluation results... +DONE (t=8.71s). +2024-09-21 01:08:22,408:INFO:Best result 0.15929884195834573 at 220 epoch +2024-09-21 01:08:22,409:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.159 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.286 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.164 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.095 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.214 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.224 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.172 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.337 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.407 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.254 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.487 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.482 + +2024-09-21 01:08:22,409:INFO:Ending inference... +2024-09-21 01:08:44,484:INFO:epoch[221], iter[61], loss:106.205163, fps:10.68 imgs/sec, lr:8.379120845347643e-05, per step time: 2997.520442008972ms +2024-09-21 01:09:14,819:INFO:epoch[221], iter[161], loss:107.671929, fps:105.49 imgs/sec, lr:0.00022115385218057781, per step time: 303.33712100982666ms +2024-09-21 01:09:56,031:INFO:epoch[222], iter[79], loss:105.758871, fps:77.65 imgs/sec, lr:0.00010851648403331637, per step time: 412.11477756500244ms +2024-09-21 01:10:33,412:INFO:epoch[222], iter[179], loss:104.668535, fps:85.61 imgs/sec, lr:0.00024587911320850253, per step time: 373.7975311279297ms +2024-09-21 01:11:09,931:INFO:epoch[223], iter[97], loss:108.189060, fps:87.64 imgs/sec, lr:0.00013324175961315632, per step time: 365.1454210281372ms +2024-09-21 01:11:48,916:INFO:epoch[224], iter[15], loss:105.254298, fps:82.09 imgs/sec, lr:2.0604395103873685e-05, per step time: 389.83566999435425ms +2024-09-21 01:12:22,408:INFO:epoch[224], iter[115], loss:105.202182, fps:95.55 imgs/sec, lr:0.00015796703519299626, per step time: 334.89675998687744ms +2024-09-21 01:12:57,374:INFO:epoch[225], iter[33], loss:105.708615, fps:91.54 imgs/sec, lr:4.532967068371363e-05, per step time: 349.5786643028259ms +2024-09-21 01:13:30,622:INFO:epoch[225], iter[133], loss:104.891730, fps:96.25 imgs/sec, lr:0.0001826923107728362, per step time: 332.4567747116089ms +2024-09-21 01:14:03,589:INFO:epoch[226], iter[51], loss:104.031852, fps:97.07 imgs/sec, lr:7.005494262557477e-05, per step time: 329.6577763557434ms +2024-09-21 01:14:39,582:INFO:epoch[226], iter[151], loss:106.583851, fps:88.92 imgs/sec, lr:0.00020741758635267615, per step time: 359.8873519897461ms +2024-09-21 01:15:13,712:INFO:epoch[227], iter[69], loss:105.371586, fps:93.76 imgs/sec, lr:9.478021820541471e-05, per step time: 341.28636598587036ms +2024-09-21 01:15:47,821:INFO:epoch[227], iter[169], loss:103.095665, fps:93.83 imgs/sec, lr:0.0002321428619325161, per step time: 341.0434937477112ms +2024-09-21 01:16:22,148:INFO:epoch[228], iter[87], loss:102.885346, fps:93.26 imgs/sec, lr:0.00011950549378525466, per step time: 343.1217384338379ms +2024-09-21 01:16:56,907:INFO:epoch[229], iter[5], loss:103.788390, fps:92.07 imgs/sec, lr:6.868132004456129e-06, per step time: 347.57811546325684ms +2024-09-21 01:17:32,529:INFO:epoch[229], iter[105], loss:106.039294, fps:89.83 imgs/sec, lr:0.0001442307693650946, per step time: 356.2116837501526ms +2024-09-21 01:18:09,257:INFO:epoch[230], iter[23], loss:102.637995, fps:87.13 imgs/sec, lr:3.159340485581197e-05, per step time: 367.2716236114502ms +2024-09-21 01:18:41,701:INFO:epoch[230], iter[123], loss:103.370950, fps:98.65 imgs/sec, lr:0.00016895604494493455, per step time: 324.3719291687012ms +2024-09-21 01:19:02,582:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-21-01:19:03.223.435 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-21 01:19:03,239:INFO:Load train network success +2024-09-21 01:19:09,009:INFO:Processing... 0.00% +2024-09-21 01:19:22,081:INFO:Calculating mAP... +2024-09-21 01:22:35,043:INFO:Save bbox prediction result. +2024-09-21 01:22:44,055:INFO:Result file path: ./output/predict_2024_09_21_01_22_35.json +Loading and preparing results... +DONE (t=6.33s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=15.88s). +Accumulating evaluation results... +DONE (t=7.38s). +2024-09-21 01:23:14,984:INFO:Best result 0.16179979410804873 at 230 epoch +2024-09-21 01:23:14,984:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.162 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.289 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.164 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.100 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.217 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.225 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.175 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.337 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.405 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.247 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.486 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.482 + +2024-09-21 01:23:14,985:INFO:Ending inference... +2024-09-21 01:23:32,170:INFO:epoch[231], iter[41], loss:106.964702, fps:11.02 imgs/sec, lr:5.631868043565191e-05, per step time: 2904.6818017959595ms +2024-09-21 01:24:02,605:INFO:epoch[231], iter[141], loss:103.546995, fps:105.15 imgs/sec, lr:0.0001936813205247745, per step time: 304.3398904800415ms +2024-09-21 01:24:40,124:INFO:epoch[232], iter[59], loss:105.007529, fps:85.29 imgs/sec, lr:8.104395965347067e-05, per step time: 375.1826286315918ms +2024-09-21 01:25:14,906:INFO:epoch[232], iter[159], loss:104.446439, fps:92.00 imgs/sec, lr:0.00021840659610461444, per step time: 347.8108334541321ms +2024-09-21 01:25:50,769:INFO:epoch[233], iter[77], loss:104.257355, fps:89.23 imgs/sec, lr:0.000105769227957353, per step time: 358.6232352256775ms +2024-09-21 01:26:26,741:INFO:epoch[233], iter[177], loss:103.802149, fps:88.96 imgs/sec, lr:0.00024313187168445438, per step time: 359.7097587585449ms +2024-09-21 01:27:05,288:INFO:epoch[234], iter[95], loss:100.860221, fps:83.02 imgs/sec, lr:0.00013049450353719294, per step time: 385.47006607055664ms +2024-09-21 01:27:40,724:INFO:epoch[235], iter[13], loss:101.302827, fps:90.32 imgs/sec, lr:1.7857142665889114e-05, per step time: 354.304940700531ms +2024-09-21 01:28:16,501:INFO:epoch[235], iter[113], loss:103.039566, fps:89.45 imgs/sec, lr:0.00015521977911703289, per step time: 357.75513648986816ms +2024-09-21 01:28:51,744:INFO:epoch[236], iter[31], loss:103.450643, fps:90.81 imgs/sec, lr:4.258241824572906e-05, per step time: 352.4001479148865ms +2024-09-21 01:29:26,657:INFO:epoch[236], iter[131], loss:104.062603, fps:91.67 imgs/sec, lr:0.00017994505469687283, per step time: 349.09101963043213ms +2024-09-21 01:30:00,331:INFO:epoch[237], iter[49], loss:102.766699, fps:95.03 imgs/sec, lr:6.7307693825569e-05, per step time: 336.73019647598267ms +2024-09-21 01:30:36,878:INFO:epoch[237], iter[149], loss:103.612374, fps:87.56 imgs/sec, lr:0.00020467033027671278, per step time: 365.4478120803833ms +2024-09-21 01:31:12,834:INFO:epoch[238], iter[67], loss:100.308233, fps:89.00 imgs/sec, lr:9.203296940540895e-05, per step time: 359.5512342453003ms +2024-09-21 01:31:49,012:INFO:epoch[238], iter[167], loss:103.036277, fps:88.46 imgs/sec, lr:0.00022939560585655272, per step time: 361.72833919525146ms +2024-09-21 01:32:23,995:INFO:epoch[239], iter[85], loss:104.501099, fps:91.50 imgs/sec, lr:0.0001167582449852489, per step time: 349.7322082519531ms +2024-09-21 01:33:00,739:INFO:epoch[240], iter[3], loss:103.350141, fps:87.09 imgs/sec, lr:4.120879111724207e-06, per step time: 367.4223732948303ms +2024-09-21 01:33:36,216:INFO:epoch[240], iter[103], loss:99.844349, fps:90.20 imgs/sec, lr:0.00014148351328913122, per step time: 354.77328062057495ms +2024-09-21 01:34:04,746:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-21-01:34:05.318.521 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-21 01:34:05,340:INFO:Load train network success +2024-09-21 01:34:10,448:INFO:Processing... 0.00% +2024-09-21 01:34:23,155:INFO:Calculating mAP... +2024-09-21 01:37:43,155:INFO:Save bbox prediction result. +2024-09-21 01:37:53,253:INFO:Result file path: ./output/predict_2024_09_21_01_37_43.json +Loading and preparing results... +DONE (t=5.77s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=16.10s). +Accumulating evaluation results... +DONE (t=8.78s). +2024-09-21 01:38:25,348:INFO:Best result 0.16408360334447608 at 240 epoch +2024-09-21 01:38:25,349:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.164 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.292 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.167 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.099 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.222 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.225 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.176 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.338 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.403 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.246 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.487 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.480 + +2024-09-21 01:38:25,349:INFO:Ending inference... +2024-09-21 01:38:33,375:INFO:epoch[241], iter[21], loss:104.931218, fps:10.77 imgs/sec, lr:2.88461542368168e-05, per step time: 2971.549229621887ms +2024-09-21 01:39:04,158:INFO:epoch[241], iter[121], loss:103.869737, fps:103.95 imgs/sec, lr:0.00016620878886897117, per step time: 307.826030254364ms +2024-09-21 01:39:36,715:INFO:epoch[242], iter[39], loss:100.463753, fps:98.29 imgs/sec, lr:5.357142799766734e-05, per step time: 325.5591917037964ms +2024-09-21 01:40:13,907:INFO:epoch[242], iter[139], loss:103.241060, fps:86.04 imgs/sec, lr:0.00019093406444881111, per step time: 371.90855741500854ms +2024-09-21 01:40:49,588:INFO:epoch[243], iter[57], loss:99.986859, fps:89.69 imgs/sec, lr:7.829670357750729e-05, per step time: 356.7718005180359ms +2024-09-21 01:41:25,109:INFO:epoch[243], iter[157], loss:102.844812, fps:90.09 imgs/sec, lr:0.00021565934002865106, per step time: 355.2116632461548ms +2024-09-21 01:42:01,158:INFO:epoch[244], iter[75], loss:101.428895, fps:88.77 imgs/sec, lr:0.00010302197915734723, per step time: 360.4797124862671ms +2024-09-21 01:42:36,858:INFO:epoch[244], iter[175], loss:102.718701, fps:89.64 imgs/sec, lr:0.000240384615608491, per step time: 356.99182748794556ms +2024-09-21 01:43:11,622:INFO:epoch[245], iter[93], loss:103.320339, fps:92.06 imgs/sec, lr:0.00012774724746122956, per step time: 347.61569023132324ms +2024-09-21 01:43:49,849:INFO:epoch[246], iter[11], loss:101.772940, fps:83.72 imgs/sec, lr:1.5109890227904543e-05, per step time: 382.2208309173584ms +2024-09-21 01:44:23,632:INFO:epoch[246], iter[111], loss:101.031256, fps:94.72 imgs/sec, lr:0.0001524725230410695, per step time: 337.8207230567932ms +2024-09-21 01:45:02,911:INFO:epoch[247], iter[29], loss:101.483630, fps:81.48 imgs/sec, lr:3.983516580774449e-05, per step time: 392.7195906639099ms +2024-09-21 01:45:36,104:INFO:epoch[247], iter[129], loss:102.069765, fps:96.41 imgs/sec, lr:0.00017719779862090945, per step time: 331.9024348258972ms +2024-09-21 01:46:09,496:INFO:epoch[248], iter[47], loss:100.551149, fps:95.85 imgs/sec, lr:6.456043774960563e-05, per step time: 333.86699199676514ms +2024-09-21 01:46:41,376:INFO:epoch[248], iter[147], loss:103.169801, fps:100.38 imgs/sec, lr:0.0002019230742007494, per step time: 318.7882709503174ms +2024-09-21 01:47:15,925:INFO:epoch[249], iter[65], loss:104.868891, fps:92.63 imgs/sec, lr:8.928571332944557e-05, per step time: 345.44233560562134ms +2024-09-21 01:47:50,608:INFO:epoch[249], iter[165], loss:99.652566, fps:92.28 imgs/sec, lr:0.00022664834978058934, per step time: 346.7794871330261ms +2024-09-21 01:48:27,890:INFO:epoch[250], iter[83], loss:100.465626, fps:85.84 imgs/sec, lr:0.00011401098890928552, per step time: 372.7812695503235ms +2024-09-21 01:49:00,846:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-21-01:49:01.288.000 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-21 01:49:01,299:INFO:Load train network success +2024-09-21 01:49:07,344:INFO:Processing... 0.00% +2024-09-21 01:49:20,452:INFO:Calculating mAP... +2024-09-21 01:52:48,458:INFO:Save bbox prediction result. +2024-09-21 01:52:57,610:INFO:Result file path: ./output/predict_2024_09_21_01_52_48.json +Loading and preparing results... +DONE (t=8.46s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=15.88s). +Accumulating evaluation results... +DONE (t=8.07s). +2024-09-21 01:53:31,384:INFO:Best result 0.16418845729079806 at 250 epoch +2024-09-21 01:53:31,385:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.164 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.293 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.169 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.099 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.222 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.227 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.176 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.338 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.403 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.247 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.486 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.481 + +2024-09-21 01:53:31,385:INFO:Ending inference... +2024-09-21 01:53:31,690:INFO:epoch[251], iter[1], loss:101.727802, fps:10.53 imgs/sec, lr:1.3736263326791232e-06, per step time: 3037.923424243927ms +2024-09-21 01:54:04,182:INFO:epoch[251], iter[101], loss:100.414302, fps:98.49 imgs/sec, lr:0.00013873625721316785, per step time: 324.9137878417969ms +2024-09-21 01:54:37,037:INFO:epoch[252], iter[19], loss:100.676193, fps:97.40 imgs/sec, lr:2.609890179883223e-05, per step time: 328.54721784591675ms +2024-09-21 01:55:11,045:INFO:epoch[252], iter[119], loss:98.680011, fps:94.10 imgs/sec, lr:0.0001634615327930078, per step time: 340.05770683288574ms +2024-09-21 01:55:45,871:INFO:epoch[253], iter[37], loss:100.099604, fps:91.89 imgs/sec, lr:5.082417555968277e-05, per step time: 348.2437252998352ms +2024-09-21 01:56:18,770:INFO:epoch[253], iter[137], loss:100.940127, fps:97.30 imgs/sec, lr:0.00018818680837284774, per step time: 328.8898992538452ms +2024-09-21 01:56:54,434:INFO:epoch[254], iter[55], loss:98.980455, fps:89.74 imgs/sec, lr:7.554944750154391e-05, per step time: 356.6008758544922ms +2024-09-21 01:57:26,864:INFO:epoch[254], iter[155], loss:96.909853, fps:98.69 imgs/sec, lr:0.00021291208395268768, per step time: 324.24798488616943ms +2024-09-21 01:58:03,763:INFO:epoch[255], iter[73], loss:99.934509, fps:86.72 imgs/sec, lr:0.00010027472308138385, per step time: 368.9879012107849ms +2024-09-21 01:58:40,467:INFO:epoch[255], iter[173], loss:99.605865, fps:87.19 imgs/sec, lr:0.00023763735953252763, per step time: 367.0340919494629ms +2024-09-21 01:59:13,562:INFO:epoch[256], iter[91], loss:99.332318, fps:96.70 imgs/sec, lr:0.0001250000059371814, per step time: 330.9368300437927ms +2024-09-21 01:59:47,043:INFO:epoch[257], iter[9], loss:99.973760, fps:95.59 imgs/sec, lr:1.2362637789919972e-05, per step time: 334.7782635688782ms +2024-09-21 02:00:21,424:INFO:epoch[257], iter[109], loss:99.453517, fps:93.07 imgs/sec, lr:0.00014972528151702136, per step time: 343.8093829154968ms +2024-09-21 02:00:56,169:INFO:epoch[258], iter[27], loss:100.230536, fps:92.11 imgs/sec, lr:3.708791336975992e-05, per step time: 347.40156173706055ms +2024-09-21 02:01:29,606:INFO:epoch[258], iter[127], loss:100.919558, fps:95.70 imgs/sec, lr:0.00017445054254494607, per step time: 334.3640351295471ms +2024-09-21 02:02:02,274:INFO:epoch[259], iter[45], loss:100.877679, fps:97.96 imgs/sec, lr:6.181318894959986e-05, per step time: 326.6474676132202ms +2024-09-21 02:02:35,478:INFO:epoch[259], iter[145], loss:100.003663, fps:96.40 imgs/sec, lr:0.00019917581812478602, per step time: 331.9456195831299ms +2024-09-21 02:03:07,560:INFO:epoch[260], iter[63], loss:99.853905, fps:99.75 imgs/sec, lr:8.653846452943981e-05, per step time: 320.7917618751526ms +2024-09-21 02:03:40,012:INFO:epoch[260], iter[163], loss:98.166496, fps:98.63 imgs/sec, lr:0.00022390109370462596, per step time: 324.43671226501465ms +2024-09-21 02:03:47,087:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-21-02:03:47.576.931 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-21 02:03:47,588:INFO:Load train network success +2024-09-21 02:03:52,402:INFO:Processing... 0.00% +2024-09-21 02:04:05,362:INFO:Calculating mAP... +2024-09-21 02:07:24,817:INFO:Save bbox prediction result. +2024-09-21 02:07:33,927:INFO:Result file path: ./output/predict_2024_09_21_02_07_24.json +Loading and preparing results... +DONE (t=5.43s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=20.84s). +Accumulating evaluation results... +DONE (t=7.68s). +2024-09-21 02:08:09,335:INFO:Best result 0.16679977711852476 at 260 epoch +2024-09-21 02:08:09,336:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.167 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.293 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.169 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.099 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.225 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.232 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.178 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.341 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.406 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.246 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.489 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.484 + +2024-09-21 02:08:09,336:INFO:Ending inference... +2024-09-21 02:08:38,150:INFO:epoch[261], iter[81], loss:100.210162, fps:10.73 imgs/sec, lr:0.00011126373283332214, per step time: 2981.3609957695007ms +2024-09-21 02:09:08,556:INFO:epoch[261], iter[181], loss:98.628066, fps:105.25 imgs/sec, lr:0.0002486263692844659, per step time: 304.0320372581482ms +2024-09-21 02:09:44,564:INFO:epoch[262], iter[99], loss:98.719335, fps:88.87 imgs/sec, lr:0.0001359890156891197, per step time: 360.07885456085205ms +2024-09-21 02:10:17,052:INFO:epoch[263], iter[17], loss:99.309418, fps:98.52 imgs/sec, lr:2.3351647541858256e-05, per step time: 324.81441259384155ms +2024-09-21 02:10:50,554:INFO:epoch[263], iter[117], loss:99.339334, fps:95.53 imgs/sec, lr:0.00016071429126895964, per step time: 334.9618911743164ms +2024-09-21 02:11:25,637:INFO:epoch[264], iter[35], loss:98.792808, fps:91.22 imgs/sec, lr:4.80769231216982e-05, per step time: 350.8132863044739ms +2024-09-21 02:12:00,205:INFO:epoch[264], iter[135], loss:102.522406, fps:92.58 imgs/sec, lr:0.00018543956684879959, per step time: 345.6363534927368ms +2024-09-21 02:12:33,913:INFO:epoch[265], iter[53], loss:101.486275, fps:94.94 imgs/sec, lr:7.280219870153815e-05, per step time: 337.0504927635193ms +2024-09-21 02:13:07,037:INFO:epoch[265], iter[153], loss:100.031415, fps:96.61 imgs/sec, lr:0.00021016484242863953, per step time: 331.23554944992065ms +2024-09-21 02:13:42,571:INFO:epoch[266], iter[71], loss:99.869630, fps:90.06 imgs/sec, lr:9.752747428137809e-05, per step time: 355.3026056289673ms +2024-09-21 02:14:18,642:INFO:epoch[266], iter[171], loss:98.645450, fps:88.72 imgs/sec, lr:0.00023489010345656425, per step time: 360.6828188896179ms +2024-09-21 02:14:52,289:INFO:epoch[267], iter[89], loss:99.677745, fps:95.11 imgs/sec, lr:0.00012225274986121804, per step time: 336.44834756851196ms +2024-09-21 02:15:26,222:INFO:epoch[268], iter[7], loss:101.477592, fps:94.32 imgs/sec, lr:9.6153844424407e-06, per step time: 339.27759885787964ms +2024-09-21 02:16:01,819:INFO:epoch[268], iter[107], loss:99.154685, fps:89.90 imgs/sec, lr:0.00014697802544105798, per step time: 355.93775272369385ms +2024-09-21 02:16:37,706:INFO:epoch[269], iter[25], loss:97.778235, fps:89.17 imgs/sec, lr:3.4340660931775346e-05, per step time: 358.8568091392517ms +2024-09-21 02:17:13,249:INFO:epoch[269], iter[125], loss:98.657375, fps:90.04 imgs/sec, lr:0.00017170330102089792, per step time: 355.41645765304565ms +2024-09-21 02:17:49,520:INFO:epoch[270], iter[43], loss:100.197611, fps:88.23 imgs/sec, lr:5.9065932873636484e-05, per step time: 362.7056956291199ms +2024-09-21 02:18:23,069:INFO:epoch[270], iter[143], loss:96.866933, fps:95.39 imgs/sec, lr:0.00019642857660073787, per step time: 335.4771018028259ms +2024-09-21 02:18:37,632:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-21-02:18:38.784.15 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-21 02:18:38,086:INFO:Load train network success +2024-09-21 02:18:43,961:INFO:Processing... 0.00% +2024-09-21 02:18:55,767:INFO:Calculating mAP... +2024-09-21 02:22:28,682:INFO:Save bbox prediction result. +2024-09-21 02:22:37,702:INFO:Result file path: ./output/predict_2024_09_21_02_22_28.json +Loading and preparing results... +DONE (t=5.86s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=15.91s). +Accumulating evaluation results... +DONE (t=9.45s). +2024-09-21 02:23:10,605:INFO:Best result 0.16746052332564468 at 270 epoch +2024-09-21 02:23:10,606:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.167 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.291 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.173 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.099 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.224 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.233 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.182 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.341 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.406 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.247 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.489 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.485 + +2024-09-21 02:23:10,606:INFO:Ending inference... +2024-09-21 02:23:29,255:INFO:epoch[271], iter[61], loss:100.101068, fps:10.45 imgs/sec, lr:8.379120845347643e-05, per step time: 3061.852023601532ms +2024-09-21 02:23:59,756:INFO:epoch[271], iter[161], loss:99.247961, fps:104.92 imgs/sec, lr:0.00022115385218057781, per step time: 304.99377965927124ms +2024-09-21 02:24:33,188:INFO:epoch[272], iter[79], loss:96.658621, fps:95.72 imgs/sec, lr:0.00010851648403331637, per step time: 334.3132734298706ms +2024-09-21 02:25:06,032:INFO:epoch[272], iter[179], loss:98.204699, fps:97.43 imgs/sec, lr:0.00024587911320850253, per step time: 328.4265732765198ms +2024-09-21 02:25:41,505:INFO:epoch[273], iter[97], loss:98.994626, fps:90.21 imgs/sec, lr:0.00013324175961315632, per step time: 354.72496509552ms +2024-09-21 02:26:14,703:INFO:epoch[274], iter[15], loss:98.358375, fps:96.40 imgs/sec, lr:2.0604395103873685e-05, per step time: 331.9534993171692ms +2024-09-21 02:26:48,510:INFO:epoch[274], iter[115], loss:97.940947, fps:94.66 imgs/sec, lr:0.00015796703519299626, per step time: 338.0462050437927ms +2024-09-21 02:27:23,478:INFO:epoch[275], iter[33], loss:99.486855, fps:91.51 imgs/sec, lr:4.532967068371363e-05, per step time: 349.6713352203369ms +2024-09-21 02:27:56,849:INFO:epoch[275], iter[133], loss:97.445463, fps:95.90 imgs/sec, lr:0.0001826923107728362, per step time: 333.66881132125854ms +2024-09-21 02:28:31,983:INFO:epoch[276], iter[51], loss:98.427274, fps:91.08 imgs/sec, lr:7.005494262557477e-05, per step time: 351.3303518295288ms +2024-09-21 02:29:07,731:INFO:epoch[276], iter[151], loss:99.068699, fps:89.52 imgs/sec, lr:0.00020741758635267615, per step time: 357.46906042099ms +2024-09-21 02:29:41,675:INFO:epoch[277], iter[69], loss:97.209692, fps:94.28 imgs/sec, lr:9.478021820541471e-05, per step time: 339.4301199913025ms +2024-09-21 02:30:16,066:INFO:epoch[277], iter[169], loss:99.305627, fps:93.05 imgs/sec, lr:0.0002321428619325161, per step time: 343.89946460723877ms +2024-09-21 02:30:51,071:INFO:epoch[278], iter[87], loss:100.588543, fps:91.42 imgs/sec, lr:0.00011950549378525466, per step time: 350.046021938324ms +2024-09-21 02:31:25,503:INFO:epoch[279], iter[5], loss:97.487091, fps:92.95 imgs/sec, lr:6.868132004456129e-06, per step time: 344.2851662635803ms +2024-09-21 02:32:00,401:INFO:epoch[279], iter[105], loss:99.411735, fps:91.70 imgs/sec, lr:0.0001442307693650946, per step time: 348.9669108390808ms +2024-09-21 02:32:34,917:INFO:epoch[280], iter[23], loss:98.099377, fps:92.72 imgs/sec, lr:3.159340485581197e-05, per step time: 345.12584924697876ms +2024-09-21 02:33:08,623:INFO:epoch[280], iter[123], loss:98.186613, fps:94.94 imgs/sec, lr:0.00016895604494493455, per step time: 337.0433807373047ms +2024-09-21 02:33:28,764:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-21-02:33:29.219.624 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-21 02:33:29,228:INFO:Load train network success +2024-09-21 02:33:33,751:INFO:Processing... 0.00% +2024-09-21 02:33:47,739:INFO:Calculating mAP... +2024-09-21 02:37:25,392:INFO:Save bbox prediction result. +2024-09-21 02:37:34,963:INFO:Result file path: ./output/predict_2024_09_21_02_37_25.json +Loading and preparing results... +DONE (t=6.66s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=15.48s). +Accumulating evaluation results... +DONE (t=9.31s). +2024-09-21 02:38:07,846:INFO:Best result 0.168560602099284 at 280 epoch +2024-09-21 02:38:07,846:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.169 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.294 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.177 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.099 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.226 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.234 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.183 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.342 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.407 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.247 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.489 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.486 + +2024-09-21 02:38:07,846:INFO:Ending inference... +2024-09-21 02:38:24,390:INFO:epoch[281], iter[41], loss:97.167551, fps:10.13 imgs/sec, lr:5.631868043565191e-05, per step time: 3157.6283073425293ms +2024-09-21 02:38:54,711:INFO:epoch[281], iter[141], loss:98.703898, fps:105.54 imgs/sec, lr:0.0001936813205247745, per step time: 303.20557594299316ms +2024-09-21 02:39:29,127:INFO:epoch[282], iter[59], loss:99.626869, fps:92.98 imgs/sec, lr:8.104395965347067e-05, per step time: 344.1483473777771ms +2024-09-21 02:40:03,759:INFO:epoch[282], iter[159], loss:100.838488, fps:92.45 imgs/sec, lr:0.00021840659610461444, per step time: 346.15044355392456ms +2024-09-21 02:40:37,310:INFO:epoch[283], iter[77], loss:96.717542, fps:95.40 imgs/sec, lr:0.000105769227957353, per step time: 335.43871879577637ms +2024-09-21 02:41:14,454:INFO:epoch[283], iter[177], loss:97.164522, fps:86.15 imgs/sec, lr:0.00024313187168445438, per step time: 371.4268183708191ms +2024-09-21 02:41:48,935:INFO:epoch[284], iter[95], loss:98.487192, fps:92.81 imgs/sec, lr:0.00013049450353719294, per step time: 344.78867053985596ms +2024-09-21 02:42:23,716:INFO:epoch[285], iter[13], loss:98.696825, fps:92.01 imgs/sec, lr:1.7857142665889114e-05, per step time: 347.7974200248718ms +2024-09-21 02:42:57,923:INFO:epoch[285], iter[113], loss:98.623033, fps:93.56 imgs/sec, lr:0.00015521977911703289, per step time: 342.0439553260803ms +2024-09-21 02:43:32,486:INFO:epoch[286], iter[31], loss:99.741983, fps:92.62 imgs/sec, lr:4.258241824572906e-05, per step time: 345.5075740814209ms +2024-09-21 02:44:07,640:INFO:epoch[286], iter[131], loss:98.298402, fps:91.04 imgs/sec, lr:0.00017994505469687283, per step time: 351.4984917640686ms +2024-09-21 02:44:41,214:INFO:epoch[287], iter[49], loss:96.255177, fps:95.33 imgs/sec, lr:6.7307693825569e-05, per step time: 335.6849408149719ms +2024-09-21 02:45:13,845:INFO:epoch[287], iter[149], loss:99.268111, fps:98.07 imgs/sec, lr:0.00020467033027671278, per step time: 326.29367113113403ms +2024-09-21 02:45:48,593:INFO:epoch[288], iter[67], loss:98.441852, fps:92.10 imgs/sec, lr:9.203296940540895e-05, per step time: 347.44492053985596ms +2024-09-21 02:46:23,540:INFO:epoch[288], iter[167], loss:97.293067, fps:91.57 imgs/sec, lr:0.00022939560585655272, per step time: 349.46417331695557ms +2024-09-21 02:46:57,543:INFO:epoch[289], iter[85], loss:97.943324, fps:94.12 imgs/sec, lr:0.0001167582449852489, per step time: 340.008544921875ms +2024-09-21 02:47:32,075:INFO:epoch[290], iter[3], loss:97.967894, fps:92.67 imgs/sec, lr:4.120879111724207e-06, per step time: 345.2943158149719ms +2024-09-21 02:48:07,677:INFO:epoch[290], iter[103], loss:97.368401, fps:89.89 imgs/sec, lr:0.00014148351328913122, per step time: 355.9759497642517ms +2024-09-21 02:48:36,640:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-21-02:48:37.132.752 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-21 02:48:37,140:INFO:Load train network success +2024-09-21 02:48:43,261:INFO:Processing... 0.00% +2024-09-21 02:48:56,034:INFO:Calculating mAP... +2024-09-21 02:52:28,310:INFO:Save bbox prediction result. +2024-09-21 02:52:37,529:INFO:Result file path: ./output/predict_2024_09_21_02_52_28.json +Loading and preparing results... +DONE (t=14.02s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=17.33s). +Accumulating evaluation results... +DONE (t=9.59s). +2024-09-21 02:53:20,073:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.168 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.295 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.176 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.099 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.228 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.233 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.183 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.341 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.406 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.246 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.490 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.484 + +2024-09-21 02:53:20,086:INFO:Ending inference... +2024-09-21 02:53:30,550:INFO:epoch[291], iter[21], loss:99.068033, fps:9.91 imgs/sec, lr:2.88461542368168e-05, per step time: 3228.7298583984375ms +2024-09-21 02:54:02,399:INFO:epoch[291], iter[121], loss:98.055027, fps:100.48 imgs/sec, lr:0.00016620878886897117, per step time: 318.48345041275024ms +2024-09-21 02:54:35,673:INFO:epoch[292], iter[39], loss:101.962235, fps:96.17 imgs/sec, lr:5.357142799766734e-05, per step time: 332.7272367477417ms +2024-09-21 02:55:10,022:INFO:epoch[292], iter[139], loss:98.012014, fps:93.17 imgs/sec, lr:0.00019093406444881111, per step time: 343.4580326080322ms +2024-09-21 02:55:54,043:INFO:epoch[293], iter[57], loss:98.340951, fps:72.70 imgs/sec, lr:7.829670357750729e-05, per step time: 440.1771664619446ms +2024-09-21 02:56:30,972:INFO:epoch[293], iter[157], loss:96.235552, fps:86.66 imgs/sec, lr:0.00021565934002865106, per step time: 369.277184009552ms +2024-09-21 02:57:06,731:INFO:epoch[294], iter[75], loss:97.841894, fps:89.49 imgs/sec, lr:0.00010302197915734723, per step time: 357.57514476776123ms +2024-09-21 02:57:41,903:INFO:epoch[294], iter[175], loss:99.685440, fps:90.99 imgs/sec, lr:0.000240384615608491, per step time: 351.67325019836426ms +2024-09-21 02:58:18,292:INFO:epoch[295], iter[93], loss:98.285404, fps:87.94 imgs/sec, lr:0.00012774724746122956, per step time: 363.87001752853394ms +2024-09-21 02:58:55,487:INFO:epoch[296], iter[11], loss:97.930838, fps:86.06 imgs/sec, lr:1.5109890227904543e-05, per step time: 371.8289279937744ms +2024-09-21 02:59:29,507:INFO:epoch[296], iter[111], loss:97.529477, fps:94.08 imgs/sec, lr:0.0001524725230410695, per step time: 340.1310157775879ms +2024-09-21 03:00:06,668:INFO:epoch[297], iter[29], loss:97.202245, fps:86.11 imgs/sec, lr:3.983516580774449e-05, per step time: 371.5985107421875ms +2024-09-21 03:00:43,147:INFO:epoch[297], iter[129], loss:98.215842, fps:87.74 imgs/sec, lr:0.00017719779862090945, per step time: 364.6944761276245ms +2024-09-21 03:01:19,700:INFO:epoch[298], iter[47], loss:99.090368, fps:87.55 imgs/sec, lr:6.456043774960563e-05, per step time: 365.5206370353699ms +2024-09-21 03:01:52,212:INFO:epoch[298], iter[147], loss:93.161310, fps:98.43 imgs/sec, lr:0.0002019230742007494, per step time: 325.1123809814453ms +2024-09-21 03:02:26,864:INFO:epoch[299], iter[65], loss:98.138431, fps:92.36 imgs/sec, lr:8.928571332944557e-05, per step time: 346.4606022834778ms +2024-09-21 03:02:58,700:INFO:epoch[299], iter[165], loss:99.560005, fps:100.53 imgs/sec, lr:0.00022664834978058934, per step time: 318.3164119720459ms +2024-09-21 03:03:33,966:INFO:epoch[300], iter[83], loss:96.483178, fps:90.74 imgs/sec, lr:0.00011401098890928552, per step time: 352.6567769050598ms +2024-09-21 03:04:09,707:INFO:Load parameters of train network +[WARNING] ME(1389:281473236787376,MainProcess):2024-09-21-03:04:10.209.422 [mindspore/train/serialization.py:1546] For 'load_param_into_net', remove parameter prefix name: network.yolo_network., continue to load. +2024-09-21 03:04:10,217:INFO:Load train network success +2024-09-21 03:04:15,523:INFO:Processing... 0.00% +2024-09-21 03:04:28,046:INFO:Calculating mAP... +2024-09-21 03:07:59,445:INFO:Save bbox prediction result. +2024-09-21 03:08:08,729:INFO:Result file path: ./output/predict_2024_09_21_03_07_59.json +Loading and preparing results... +DONE (t=6.03s) +creating index... +index created! +Running per image evaluation... +Evaluate annotation type *bbox* +DONE (t=16.56s). +Accumulating evaluation results... +DONE (t=9.15s). +2024-09-21 03:08:41,689:INFO: Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.168 + Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.295 + Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.176 + Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.099 + Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.227 + Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.233 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.183 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.341 + Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.406 + Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.246 + Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.490 + Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.484 + +2024-09-21 03:08:41,700:INFO:Ending inference... +2024-09-21 03:08:41,704:INFO:==========end training=============== diff --git a/community/cv/ADCAM/mindspore_hub_conf.py b/community/cv/ADCAM/mindspore_hub_conf.py new file mode 100644 index 0000000000000000000000000000000000000000..692af5a50407e2380bc521bfa08e9b740fb3abaa --- /dev/null +++ b/community/cv/ADCAM/mindspore_hub_conf.py @@ -0,0 +1,7 @@ +from src.yolo import YOLOV5s + +def create_network(name, *args, **kwargs): + if name == "yolov5s": + yolov5s_net = YOLOV5s(is_training=True) + return yolov5s_net + raise NotImplementedError(f"{name} is not implemented in the repo") diff --git a/community/cv/ADCAM/model_utils/__init__.py b/community/cv/ADCAM/model_utils/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/community/cv/ADCAM/model_utils/config.py b/community/cv/ADCAM/model_utils/config.py new file mode 100644 index 0000000000000000000000000000000000000000..a33a1f2b1e097bcf99139e93bd1f4455aef8233b --- /dev/null +++ b/community/cv/ADCAM/model_utils/config.py @@ -0,0 +1,111 @@ +# Parse arguments + +import os +import ast +import argparse +from pprint import pformat +import yaml + +class Config: + """ + Configuration namespace. Convert dictionary to members. + """ + def __init__(self, cfg_dict): + for k, v in cfg_dict.items(): + if isinstance(v, (list, tuple)): + setattr(self, k, [Config(x) if isinstance(x, dict) else x for x in v]) + else: + setattr(self, k, Config(v) if isinstance(v, dict) else v) + + def __str__(self): + return pformat(self.__dict__) + + def __repr__(self): + return self.__str__() + + +def parse_cli_to_yaml(parser, cfg, helper=None, choices=None, cfg_path="default_config.yaml"): + """ + Parse command line arguments to the configuration according to the default yaml. + + Args: + parser: Parent parser. + cfg: Base configuration. + helper: Helper description. + cfg_path: Path to the default yaml config. + """ + parser = argparse.ArgumentParser(description="[REPLACE THIS at config.py]", + parents=[parser]) + helper = {} if helper is None else helper + choices = {} if choices is None else choices + for item in cfg: + if not isinstance(cfg[item], list) and not isinstance(cfg[item], dict): + help_description = helper[item] if item in helper else "Please reference to {}".format(cfg_path) + choice = choices[item] if item in choices else None + if isinstance(cfg[item], bool): + parser.add_argument("--" + item, type=ast.literal_eval, default=cfg[item], choices=choice, + help=help_description) + else: + parser.add_argument("--" + item, type=type(cfg[item]), default=cfg[item], choices=choice, + help=help_description) + args = parser.parse_args() + return args + + +def parse_yaml(yaml_path): + """ + Parse the yaml config file. + + Args: + yaml_path: Path to the yaml config. + """ + with open(yaml_path, 'r') as fin: + try: + cfgs = yaml.load_all(fin.read(), Loader=yaml.FullLoader) + cfgs = [x for x in cfgs] + if len(cfgs) == 1: + cfg_helper = {} + cfg = cfgs[0] + cfg_choices = {} + elif len(cfgs) == 2: + cfg, cfg_helper = cfgs + cfg_choices = {} + elif len(cfgs) == 3: + cfg, cfg_helper, cfg_choices = cfgs + else: + raise ValueError("At most 3 docs (config, description for help, choices) are supported in config yaml") + print(cfg_helper) + except: + raise ValueError("Failed to parse yaml") + return cfg, cfg_helper, cfg_choices + + +def merge(args, cfg): + """ + Merge the base config from yaml file and command line arguments. + + Args: + args: Command line arguments. + cfg: Base configuration. + """ + args_var = vars(args) + for item in args_var: + cfg[item] = args_var[item] + return cfg + + +def get_config(): + """ + Get Config according to the yaml file and cli arguments. + """ + parser = argparse.ArgumentParser(description="default name", add_help=False) + current_dir = os.path.dirname(os.path.abspath(__file__)) + parser.add_argument("--config_path", type=str, default=os.path.join(current_dir, "../default_config.yaml"), + help="Config file path") + path_args, _ = parser.parse_known_args() + default, helper, choices = parse_yaml(path_args.config_path) + args = parse_cli_to_yaml(parser=parser, cfg=default, helper=helper, choices=choices, cfg_path=path_args.config_path) + final_config = merge(args, default) + return Config(final_config) + +config = get_config() diff --git a/community/cv/ADCAM/model_utils/device_adapter.py b/community/cv/ADCAM/model_utils/device_adapter.py new file mode 100644 index 0000000000000000000000000000000000000000..4aea92f357957d6416a0b50760d8f91a7071332e --- /dev/null +++ b/community/cv/ADCAM/model_utils/device_adapter.py @@ -0,0 +1,12 @@ +# Device adapter for ModelArts + +from .config import config + +if config.enable_modelarts: + from .moxing_adapter import get_device_id, get_device_num, get_rank_id, get_job_id +else: + from .local_adapter import get_device_id, get_device_num, get_rank_id, get_job_id + +__all__ = [ + "get_device_id", "get_device_num", "get_rank_id", "get_job_id" +] diff --git a/community/cv/ADCAM/model_utils/local_adapter.py b/community/cv/ADCAM/model_utils/local_adapter.py new file mode 100644 index 0000000000000000000000000000000000000000..79cb76d19e85e6ef9ae24ac21149843e507958bb --- /dev/null +++ b/community/cv/ADCAM/model_utils/local_adapter.py @@ -0,0 +1,21 @@ +# Local adapter + +import os + +def get_device_id(): + device_id = os.getenv('DEVICE_ID', '0') + return int(device_id) + + +def get_device_num(): + device_num = os.getenv('RANK_SIZE', '1') + return int(device_num) + + +def get_rank_id(): + global_rank_id = os.getenv('RANK_ID', '0') + return int(global_rank_id) + + +def get_job_id(): + return "Local Job" diff --git a/community/cv/ADCAM/model_utils/moxing_adapter.py b/community/cv/ADCAM/model_utils/moxing_adapter.py new file mode 100644 index 0000000000000000000000000000000000000000..abac840f9e0845376170d9fdc5c4c557453fd790 --- /dev/null +++ b/community/cv/ADCAM/model_utils/moxing_adapter.py @@ -0,0 +1,167 @@ +# Moxing adapter for ModelArts + +import os +import functools +import mindspore +import mindspore +from .config import config + +_global_sync_count = 0 + +def get_device_id(): + device_id = os.getenv('DEVICE_ID', '0') + return int(device_id) + + +def get_device_num(): + device_num = os.getenv('RANK_SIZE', '1') + return int(device_num) + + +def get_rank_id(): + global_rank_id = os.getenv('RANK_ID', '0') + return int(global_rank_id) + + +def get_job_id(): + job_id = os.getenv('JOB_ID') + job_id = job_id if job_id != "" else "default" + return job_id + +def sync_data(from_path, to_path): + """ + Download data from remote obs to local directory if the first url is remote url and the second one is local path + Upload data from local directory to remote obs in contrast. + """ + import moxing as mox + import time + global _global_sync_count + sync_lock = "/tmp/copy_sync.lock" + str(_global_sync_count) + _global_sync_count += 1 + + # Each server contains 8 devices as most. + if get_device_id() % min(get_device_num(), 8) == 0 and not os.path.exists(sync_lock): + print("from path: ", from_path) + print("to path: ", to_path) + mox.file.copy_parallel(from_path, to_path) + print("===finish data synchronization===") + try: + os.mknod(sync_lock) + except IOError: + pass + print("===save flag===") + + while True: + if os.path.exists(sync_lock): + break + time.sleep(1) + + print("Finish sync data from {} to {}.".format(from_path, to_path)) + +def modelarts_pre_process(args): + '''modelarts pre process function.''' + def unzip(zip_file, save_dir): + import zipfile + s_time = time.time() + if not os.path.exists(os.path.join(save_dir, args.modelarts_dataset_unzip_name)): + zip_isexist = zipfile.is_zipfile(zip_file) + if zip_isexist: + fz = zipfile.ZipFile(zip_file, 'r') + data_num = len(fz.namelist()) + print("Extract Start...") + print("unzip file num: {}".format(data_num)) + data_print = int(data_num / 100) if data_num > 100 else 1 + i = 0 + for file in fz.namelist(): + if i % data_print == 0: + print("unzip percent: {}%".format(int(i * 100 / data_num)), flush=True) + i += 1 + fz.extract(file, save_dir) + print("cost time: {}min:{}s.".format(int((time.time() - s_time) / 60), + int(int(time.time() - s_time) % 60))) + print("Extract Done.") + else: + print("This is not zip.") + else: + print("Zip has been extracted.") + + if args.need_modelarts_dataset_unzip: + zip_file_1 = os.path.join(args.data_path, args.modelarts_dataset_unzip_name + ".zip") + save_dir_1 = os.path.join(args.data_path) + + sync_lock = "/tmp/unzip_sync.lock" + + # Each server contains 8 devices as most. + if get_device_id() % min(get_device_num(), 8) == 0 and not os.path.exists(sync_lock): + print("Zip file path: ", zip_file_1) + print("Unzip file save dir: ", save_dir_1) + unzip(zip_file_1, save_dir_1) + print("===Finish extract data synchronization===") + try: + os.mknod(sync_lock) + except IOError: + pass + + while True: + if os.path.exists(sync_lock): + break + time.sleep(1) + + print("Device: {}, Finish sync unzip data from {} to {}.".format(get_device_id(), zip_file_1, save_dir_1)) + + args.output_dir = os.path.join(args.output_path, args.output_dir) + args.ckpt_path = os.path.join(args.output_path, args.ckpt_path) + +def modelarts_post_process(): + sync_data(from_path='/cache/output', to_path='obs://hit-cyf/yolov5_npu/outputs/') + +def modelarts_export_preprocess(args): + args.file_name = os.path.join(args.output_path, args.file_name) + +def moxing_wrapper(pre_process=None, post_process=None, **kwargs): + """ + Moxing wrapper to download dataset and upload outputs. + """ + def wrapper(run_func): + @functools.wraps(run_func) + def wrapped_func(*args, **kwargs): + # Download data from data_url + if config.enable_modelarts: + if config.data_url: + sync_data(config.data_url, config.data_path) + print("Dataset downloaded: ", os.listdir(config.data_path)) + if config.checkpoint_url: + sync_data(config.checkpoint_url, config.load_path) + print("Preload downloaded: ", os.listdir(config.load_path)) + if config.train_url: + sync_data(config.train_url, config.output_path) + print("Workspace downloaded: ", os.listdir(config.output_path)) + + mindspore.set_context(save_graphs_path=os.path.join(config.output_path, str(get_rank_id()))) + config.device_num = get_device_num() + config.device_id = get_device_id() + if not os.path.exists(config.output_path): + os.makedirs(config.output_path) + + if pre_process: + if "pre_args" in kwargs.keys(): + pre_process(*kwargs["pre_args"]) + else: + pre_process() + + # Run the main function + run_func(*args, **kwargs) + + # Upload data to train_url + if config.enable_modelarts: + if post_process: + if "post_args" in kwargs.keys(): + post_process(*kwargs["post_args"]) + else: + post_process() + + if config.train_url: + print("Start to copy output directory") + sync_data(config.output_path, config.train_url) + return wrapped_func + return wrapper diff --git a/community/cv/ADCAM/modelarts/train_start.py b/community/cv/ADCAM/modelarts/train_start.py new file mode 100644 index 0000000000000000000000000000000000000000..246068b88ad5c12fc27ace9da63cd1d56ae15809 --- /dev/null +++ b/community/cv/ADCAM/modelarts/train_start.py @@ -0,0 +1,137 @@ +# YoloV5 train +import os +import time +import numpy as np +import mindspore +import mindspore.nn as nn +import mindspore.communication as comm +from mindspore.train.serialization import export, load_checkpoint, load_param_into_net +from mindspore import Tensor + +from src.yolo import YOLOV5, YoloWithLossCell, YOLOV5s_Infer +from src.logger import get_logger +from src.util import AverageMeter, get_param_groups, cpu_affinity +from src.lr_scheduler import get_lr +from src.yolo_dataset import create_yolo_dataset +from src.initializer import default_recurisive_init, load_yolov5_params + +from model_utils.config import config +from model_utils.device_adapter import get_device_id +from model_utils.moxing_adapter import moxing_wrapper, modelarts_pre_process + + +mindspore.set_seed(1) + + +def init_distribute(): + comm.init() + config.rank = comm.get_rank() + config.group_size = comm.get_group_size() + mindspore.set_auto_parallel_context(parallel_mode=mindspore.ParallelMode.DATA_PARALLEL, gradients_mean=True, + device_num=config.group_size) + + +def train_preprocess(): + if config.lr_scheduler == 'cosine_annealing' and config.max_epoch > config.T_max: + config.T_max = config.max_epoch + + config.lr_epochs = list(map(int, config.lr_epochs.split(','))) + config.data_root = os.path.join(config.data_dir, config.train_img_dir) + config.annFile = os.path.join(config.data_dir, config.train_json_file) + if config.pretrained_checkpoint: + config.pretrained_checkpoint = os.path.join(config.load_path, config.pretrained_checkpoint) + device_id = get_device_id() + mindspore.set_context(mode=0, device_target=config.device_target, device_id=device_id) + + if config.is_distributed: + # init distributed + init_distribute() + + # for promoting performance in GPU device + if config.device_target == "GPU" and config.bind_cpu: + cpu_affinity(config.rank, min(config.group_size, config.device_num)) + + # logger module is managed by config, it is used in other function. e.x. config.logger.info("xxx") + config.logger = get_logger(config.output_dir, config.rank) + config.logger.save_args(config) + + +def export_models(ckpt_path): + config.logger.info("exporting best model....") + dict_version = {'yolov5s': 0, 'yolov5m': 1, 'yolov5l': 2, 'yolov5x': 3} + net = YOLOV5s_Infer(config.testing_shape[0], version=dict_version[config.yolov5_version]) + net.set_train(False) + + outputs_path = os.path.join(config.output_dir, 'yolov5') + param_dict = load_checkpoint(ckpt_path) + load_param_into_net(net, param_dict) + input_arr = Tensor(np.zeros([1, 12, config.testing_shape[0] // 2, config.testing_shape[1] // 2]), mindspore.float32) + export(net, input_arr, file_name=outputs_path, file_format=config.file_format) + config.logger.info("export best model finished....") + + +@moxing_wrapper(pre_process=modelarts_pre_process, pre_args=[config]) +def run_train(): + train_preprocess() + + loss_meter = AverageMeter('loss') + dict_version = {'yolov5s': 0, 'yolov5m': 1, 'yolov5l': 2, 'yolov5x': 3} + network = YOLOV5(is_training=True, version=dict_version[config.yolov5_version]) + # default is kaiming-normal + default_recurisive_init(network) + load_yolov5_params(config, network) + network = YoloWithLossCell(network) + + ds = create_yolo_dataset(image_dir=config.data_root, anno_path=config.annFile, is_training=True, + batch_size=config.per_batch_size, device_num=config.group_size, + rank=config.rank, config=config) + config.logger.info('Finish loading dataset') + + steps_per_epoch = ds.get_dataset_size() + lr = get_lr(config, steps_per_epoch) + opt = nn.Momentum(params=get_param_groups(network), momentum=config.momentum, learning_rate=mindspore.Tensor(lr), + weight_decay=config.weight_decay, loss_scale=config.loss_scale) + network = nn.TrainOneStepCell(network, opt, config.loss_scale // 2) + network.set_train() + + data_loader = ds.create_tuple_iterator(do_copy=False) + first_step = True + t_end = time.time() + + for epoch_idx in range(config.max_epoch): + for step_idx, data in enumerate(data_loader): + images = data[0] + input_shape = images.shape[2:4] + input_shape = mindspore.Tensor(tuple(input_shape[::-1]), mindspore.float32) + loss = network(images, data[2], data[3], data[4], data[5], data[6], + data[7], input_shape) + loss_meter.update(loss.asnumpy()) + + # it is used for loss, performance output per config.log_interval steps. + if (epoch_idx * steps_per_epoch + step_idx) % config.log_interval == 0: + time_used = time.time() - t_end + if first_step: + fps = config.per_batch_size * config.group_size / time_used + per_step_time = time_used * 1000 + first_step = False + else: + fps = config.per_batch_size * config.log_interval * config.group_size / time_used + per_step_time = time_used / config.log_interval * 1000 + config.logger.info('epoch[{}], iter[{}], {}, fps:{:.2f} imgs/sec, ' + 'lr:{}, per step time: {}ms'.format(epoch_idx + 1, step_idx + 1, + loss_meter, fps, lr[step_idx], per_step_time)) + t_end = time.time() + loss_meter.reset() + if config.rank == 0: + ckpt_name = os.path.join(config.output_dir, "yolov5_{}_{}.ckpt".format(epoch_idx + 1, steps_per_epoch)) + mindspore.save_checkpoint(network, ckpt_name) + export_models(ckpt_name) + config.logger.info('==========end training===============') + + if config.enable_modelarts: + import moxing as mox + mox.file.copy_parallel(src_url=config.output_dir, dst_url=config.outputs_url) + + +if __name__ == "__main__": + run_train() diff --git a/community/cv/ADCAM/postprocess.py b/community/cv/ADCAM/postprocess.py new file mode 100644 index 0000000000000000000000000000000000000000..f8c79aeb10a1778ab7069c81fac299671de39777 --- /dev/null +++ b/community/cv/ADCAM/postprocess.py @@ -0,0 +1,49 @@ +import os +import time +import numpy as np +from pycocotools.coco import COCO +from src.logger import get_logger +from src.util import DetectionEngine +from model_utils.config import config + + +if __name__ == "__main__": + start_time = time.time() + config.output_dir = config.log_path + config.logger = get_logger(config.output_dir, 0) + + # 初始化检测引擎通常是指在开始执行任何检测任务之前,设置好所有必要的组件和配置 + detection = DetectionEngine(config, config.test_ignore_threshold) + + coco = COCO(config.ann_file) + result_path = config.result_files + + files = os.listdir(config.dataset_path) + + for file in files: + img_ids_name = file.split('.')[0] + img_id_ = int(np.squeeze(img_ids_name)) + imgIds = coco.getImgIds(imgIds=[img_id_]) + img = coco.loadImgs(imgIds[np.random.randint(0, len(imgIds))])[0] + image_shape = ((img['width'], img['height']),) + img_id_ = (np.squeeze(img_ids_name),) + + result_path_0 = os.path.join(result_path, img_ids_name + "_0.bin") + result_path_1 = os.path.join(result_path, img_ids_name + "_1.bin") + result_path_2 = os.path.join(result_path, img_ids_name + "_2.bin") + + output_small = np.fromfile(result_path_0, dtype=np.float32).reshape(1, 20, 20, 3, 85) + output_me = np.fromfile(result_path_1, dtype=np.float32).reshape(1, 40, 40, 3, 85) + output_big = np.fromfile(result_path_2, dtype=np.float32).reshape(1, 80, 80, 3, 85) + + detection.detect([output_small, output_me, output_big], config.batch_size, image_shape, img_id_) + + config.logger.info('Calculating mAP...') + detection.do_nms_for_results() + detection.write_result() + eval_result, _ = detection.get_eval_result() + + cost_time = time.time() - start_time + config.logger.info('=============coco 310 infer reulst=========') + config.logger.info(eval_result) + config.logger.info('testing cost time {:.2f}h'.format(cost_time / 3600.)) diff --git a/community/cv/ADCAM/requirements.txt b/community/cv/ADCAM/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..74cbc62920a3f893bbd49b13e1a4ccbb9c775d00 --- /dev/null +++ b/community/cv/ADCAM/requirements.txt @@ -0,0 +1,5 @@ +numpy +pillow +opencv-python +pycocotools >= 2.0.5 +onnxruntime-gpu diff --git a/community/cv/ADCAM/scripts/docker_start.sh b/community/cv/ADCAM/scripts/docker_start.sh new file mode 100644 index 0000000000000000000000000000000000000000..79f1ecb4920aac14f1eb98f7efe6839b664e45b5 --- /dev/null +++ b/community/cv/ADCAM/scripts/docker_start.sh @@ -0,0 +1,20 @@ +docker_image=$1 +data_dir=$2 +model_dir=$3 + +docker run -it --ipc=host \ + --device=/dev/davinci0 \ + --device=/dev/davinci1 \ + --device=/dev/davinci2 \ + --device=/dev/davinci3 \ + --device=/dev/davinci4 \ + --device=/dev/davinci5 \ + --device=/dev/davinci6 \ + --device=/dev/davinci7 \ + --device=/dev/davinci_manager \ + --device=/dev/devmm_svm --device=/dev/hisi_hdc \ + -v /usr/local/Ascend/driver:/usr/local/Ascend/driver \ + -v /usr/local/Ascend/add-ons/:/usr/local/Ascend/add-ons/ \ + -v ${model_dir}:${model_dir} \ + -v ${data_dir}:${data_dir} \ + -v /root/ascend/log:/root/ascend/log ${docker_image} /bin/bash \ No newline at end of file diff --git a/community/cv/ADCAM/scripts/run_distribute_eval.sh b/community/cv/ADCAM/scripts/run_distribute_eval.sh new file mode 100644 index 0000000000000000000000000000000000000000..75507cecef270a13bb3e27de6cdcbebfa69f0058 --- /dev/null +++ b/community/cv/ADCAM/scripts/run_distribute_eval.sh @@ -0,0 +1,79 @@ +if [ $# != 3 ] +then + echo "Usage: bash run_eval.sh [DATASET_PATH] [CHECKPOINT_PATH] [RANK_TABLE_FILE]" +exit 1 +fi + +get_real_path(){ + if [ "${1:0:1}" == "/" ]; then + echo "$1" + else + echo "$(realpath -m $PWD/$1)" + fi +} +DATASET_PATH=$(get_real_path $1) +CHECKPOINT_PATH=$(get_real_path $2) +RANK_TABLE_FILE=$(get_real_path $3) +echo $DATASET_PATH +echo $CHECKPOINT_PATH + +if [ ! -d $DATASET_PATH ] +then + echo "error: DATASET_PATH=$PATH1 is not a directory" +exit 1 +fi + +if [ ! -f $CHECKPOINT_PATH ] +then + echo "error: CHECKPOINT_PATH=$PATH2 is not a file" +exit 1 +fi + +if [ ! -f $RANK_TABLE_FILE ] +then + echo "error: RANK_TABLE_FILE=$RANK_TABLE_FILE is not a valid file." + exit 1 +fi + +export DEVICE_NUM=8 +export DEVICE_ID=0 +export RANK_SIZE=$DEVICE_NUM +export RANK_ID=0 +export RANK_TABLE_FILE=$RANK_TABLE_FILE + +if [ -d "eval_parallel" ]; +then + rm -rf ./eval_parallel +fi +mkdir ./eval_parallel + +cpus=`cat /proc/cpuinfo| grep "processor"| wc -l` +avg=`expr $cpus \/ $RANK_SIZE` +gap=`expr $avg \- 1` +start_device_id=0 + +for ((i=0; i<${DEVICE_NUM}; i++)) +do + start=`expr $i \* $avg` + end=`expr $start \+ $gap` + cmdopt=$start"-"$end + export DEVICE_ID=$(($start_device_id + $i)) + export RANK_ID=$i + dir_path=./eval_parallel$i + if [ -d $dir_path ]; then + rm -rf $dir_path + fi + mkdir $dir_path + cp ../*.py $dir_path + cp ../*.yaml $dir_path + cp -r ../src $dir_path + cp -r ../model_utils $dir_path + cd $dir_path || exit + env > env.log + echo "start inferring for rank $RANK_ID, device $DEVICE_ID" + taskset -c $cmdopt python eval.py \ + --is_distributed=1 \ + --data_dir=$DATASET_PATH \ + --pretrained=$CHECKPOINT_PATH > log.txt 2>&1 & + cd .. +done diff --git a/community/cv/ADCAM/scripts/run_distribute_train.sh b/community/cv/ADCAM/scripts/run_distribute_train.sh new file mode 100644 index 0000000000000000000000000000000000000000..6dd2b78135b5d7447921f5ae7becc447ab808a86 --- /dev/null +++ b/community/cv/ADCAM/scripts/run_distribute_train.sh @@ -0,0 +1,62 @@ +if [ $# != 2 ] +then + echo "Usage: bash run_distribute_train.sh [DATASET_PATH] [RANK_TABLE_FILE]" +exit 1 +fi + +get_real_path(){ + if [ "${1:0:1}" == "/" ]; then + echo "$1" + else + echo "$(realpath -m $PWD/$1)" + fi +} + +DATASET_PATH=$(get_real_path $1) +RANK_TABLE_FILE=$(get_real_path $2) +echo $DATASET_PATH +echo $RANK_TABLE_FILE + +if [ ! -d $DATASET_PATH ] +then + echo "error: DATASET_PATH=$DATASET_PATH is not a directory" +exit 1 +fi + +if [ ! -f $RANK_TABLE_FILE ] +then + echo "error: RANK_TABLE_FILE=$RANK_TABLE_FILE is not a file" +exit 1 +fi + +export DEVICE_NUM=8 +export RANK_SIZE=8 +export RANK_TABLE_FILE=$RANK_TABLE_FILE + +cpus=`cat /proc/cpuinfo| grep "processor"| wc -l` +avg=`expr $cpus \/ $DEVICE_NUM` +gap=`expr $avg \- 1` + +for((i=0; i<${DEVICE_NUM}; i++)) +do + start=`expr $i \* $avg` + end=`expr $start \+ $gap` + cmdopt=$start"-"$end + export DEVICE_ID=$i + export RANK_ID=$i + rm -rf ./train_parallel$i + mkdir ./train_parallel$i + cp ../*.py ./train_parallel$i + cp ../*.yaml ./train_parallel$i + cp -r ../src ./train_parallel$i + cp -r ../model_utils ./train_parallel$i + cd ./train_parallel$i || exit + echo "start training for rank $RANK_ID, device $DEVICE_ID" + env > env.log + taskset -c $cmdopt python train.py \ + --data_dir=$DATASET_PATH \ + --is_distributed=1 \ + --lr=0.02 \ + --per_batch_size=16 > log.txt 2>&1 & + cd .. +done diff --git a/community/cv/ADCAM/scripts/run_distribute_train_gpu.sh b/community/cv/ADCAM/scripts/run_distribute_train_gpu.sh new file mode 100644 index 0000000000000000000000000000000000000000..b7faafe5611c7157ab157c4a469bd7fb9d1ebf20 --- /dev/null +++ b/community/cv/ADCAM/scripts/run_distribute_train_gpu.sh @@ -0,0 +1,44 @@ +if [ $# != 2 ] +then + echo "Usage: bash run_distribute_train_gpu.sh [DATASET_PATH] [RANK_SIZE]" +exit 1 +fi + +get_real_path(){ + if [ "${1:0:1}" == "/" ]; then + echo "$1" + else + echo "$(realpath -m $PWD/$1)" + fi +} + +DATASET_PATH=$(get_real_path $1) +echo $DATASET_PATH + +if [ ! -d $DATASET_PATH ] +then + echo "error: DATASET_PATH=$DATASET_PATH is not a directory" +exit 1 +fi + +export RANK_SIZE=$2 + +if [ -d "distribute_train" ]; then + rm -rf ./distribute_train +fi + +mkdir ./distribute_train +cp ../*.py ./distribute_train +cp ../*.yaml ./distribute_train +cp -r ../src ./distribute_train +cp -r ../model_utils ./distribute_train +cd ./distribute_train || exit + +mpirun --allow-run-as-root -n $RANK_SIZE --output-filename log_output --merge-stderr-to-stdout \ +nohup python train.py \ + --device_target=GPU \ + --data_dir=$DATASET_PATH \ + --is_distributed=1 \ + --per_batch_size=32 \ + --lr=0.025 > log.txt 2>&1 & +cd .. diff --git a/community/cv/ADCAM/scripts/run_eval.sh b/community/cv/ADCAM/scripts/run_eval.sh new file mode 100644 index 0000000000000000000000000000000000000000..01f247518cd646bd2ea469caf0e6e0b20d5ece0c --- /dev/null +++ b/community/cv/ADCAM/scripts/run_eval.sh @@ -0,0 +1,51 @@ +if [ $# != 3 ] +then + echo "Usage: bash run_eval.sh [DATASET_PATH] [CHECKPOINT_PATH] [DEVICE_ID]" +exit 1 +fi + +get_real_path(){ + if [ "${1:0:1}" == "/" ]; then + echo "$1" + else + echo "$(realpath -m $PWD/$1)" + fi +} +DATASET_PATH=$(get_real_path $1) +CHECKPOINT_PATH=$(get_real_path $2) +echo $DATASET_PATH +echo $CHECKPOINT_PATH + +if [ ! -d $DATASET_PATH ] +then + echo "error: DATASET_PATH=$PATH1 is not a directory" +exit 1 +fi + +if [ ! -f $CHECKPOINT_PATH ] +then + echo "error: CHECKPOINT_PATH=$PATH2 is not a file" +exit 1 +fi + +export DEVICE_NUM=1 +export DEVICE_ID=$3 +export RANK_SIZE=$DEVICE_NUM +export RANK_ID=0 + +if [ -d "eval" ]; +then + rm -rf ./eval +fi +mkdir ./eval +cp ../*.py ./eval +cp ../*.yaml ./eval +cp -r ../src ./eval +cp -r ../model_utils ./eval +cd ./eval || exit +env > env.log +echo "start inferring for device $DEVICE_ID" +python eval.py \ + --data_dir=$DATASET_PATH \ + --pretrained=$CHECKPOINT_PATH > log.txt 2>&1 & +cd .. diff --git a/community/cv/ADCAM/scripts/run_infer_cpp.sh b/community/cv/ADCAM/scripts/run_infer_cpp.sh new file mode 100644 index 0000000000000000000000000000000000000000..bdee3a90e68b92151d84cf0088ceaa789be55397 --- /dev/null +++ b/community/cv/ADCAM/scripts/run_infer_cpp.sh @@ -0,0 +1,101 @@ +if [[ $# -lt 5 || $# -gt 6 ]]; then + echo "Usage: bash run_infer_cpp.sh [MINDIR_PATH] [DATA_PATH] [ANN_FILE] [DVPP] [DEVICE_TYPE] [DEVICE_ID] + DVPP is mandatory, and must choose from [DVPP|CPU], it's case-insensitive + DEVICE_TYPE can choose from [Ascend, GPU, CPU] + DEVICE_ID is optional, it can be set by environment variable device_id, otherwise the value is zero" +exit 1 +fi + +get_real_path(){ + if [ "${1:0:1}" == "/" ]; then + echo "$1" + else + echo "$(realpath -m $PWD/$1)" + fi +} +model=$(get_real_path $1) +data_path=$(get_real_path $2) +ann_file=$(get_real_path $3) +DVPP=${4^^} + +device_id=0 +if [ $# == 6 ]; then + device_id=$6 +fi + +if [ $5 == 'GPU' ]; then + device_id=0 +fi + +echo "mindir name: "$model +echo "dataset path: "$data_path +echo "ann file: "$ann_file +echo "image process mode: "$DVPP +echo "device id: "$device_id + +if [ $5 == 'Ascend' ] || [ $5 == 'GPU' ] || [ $5 == 'CPU' ]; then + device_type=$5 +else + echo "DEVICE_TYPE can choose from [Ascend, GPU, CPU]" + exit 1 +fi +echo "device type: "$device_type + +if [ $MS_LITE_HOME ]; then + RUNTIME_HOME=$MS_LITE_HOME/runtime + TOOLS_HOME=$MS_LITE_HOME/tools + RUNTIME_LIBS=$RUNTIME_HOME/lib:$RUNTIME_HOME/third_party/glog/:$RUNTIME_HOME/third_party/libjpeg-turbo/lib + RUNTIME_LIBS=$RUNTIME_LIBS:$RUNTIME_HOME/third_party/dnnl/ + export LD_LIBRARY_PATH=$RUNTIME_LIBS:$TOOLS_HOME/converter/lib:$LD_LIBRARY_PATH + echo "Insert LD_LIBRARY_PATH the MindSpore Lite runtime libs path: $RUNTIME_LIBS $TOOLS_HOME/converter/lib" +fi + + +function compile_app() +{ + cd ../cpp_infer || exit + bash build.sh &> build.log +} + +function infer() +{ + cd - || exit + if [ -d result_Files ]; then + rm -rf ./result_Files + fi + if [ -d time_Result ]; then + rm -rf ./time_Result + fi + mkdir result_Files + mkdir time_Result + if [ "$DVPP" == "DVPP" ];then + echo "Only support CPU mode" + exit 1 + elif [ "$DVPP" == "CPU" ]; then + ../cpp_infer/out/main --device_type=$device_type --mindir_path=$model --dataset_path=$data_path --device_id=$device_id --image_height=640 --image_width=640 &> infer.log + else + echo "image process mode must be in [DVPP|CPU]" + exit 1 + fi +} + +function cal_acc() +{ + python ../postprocess.py --result_files=./result_Files --dataset_path=$data_path --ann_file=$ann_file &> acc.log & +} + +compile_app +if [ $? -ne 0 ]; then + echo "compile app code failed" + exit 1 +fi +infer +if [ $? -ne 0 ]; then + echo " execute inference failed" + exit 1 +fi +cal_acc +if [ $? -ne 0 ]; then + echo "calculate accuracy failed" + exit 1 +fi \ No newline at end of file diff --git a/community/cv/ADCAM/scripts/run_standalone_train.sh b/community/cv/ADCAM/scripts/run_standalone_train.sh new file mode 100644 index 0000000000000000000000000000000000000000..b2ec58ffad2dec6ab32a9decf799f0e9017f514a --- /dev/null +++ b/community/cv/ADCAM/scripts/run_standalone_train.sh @@ -0,0 +1,45 @@ +if [ $# != 2 ] +then + echo "Usage: bash run_standalone_train.sh [DATASET_PATH] [DEVICE_ID]" +exit 1 +fi + +get_real_path(){ + if [ "${1:0:1}" == "/" ]; then + echo "$1" + else + echo "$(realpath -m $PWD/$1)" + fi +} + +DATASET_PATH=$(get_real_path $1) +echo $DATASET_PATH + + +if [ ! -d $DATASET_PATH ] +then + echo "error: DATASET_PATH=$DATASET_PATH is not a directory" +exit 1 +fi + + +export DEVICE_NUM=1 +export DEVICE_ID=$2 +export RANK_ID=0 +export RANK_SIZE=1 + +if [ -d "train" ]; +then + rm -rf ./train +fi +mkdir ./train +cp ../*.py ./train +cp ../*.yaml ./train +cp -r ../src ./train +cp -r ../model_utils ./train +cd ./train || exit +echo "start training for device $DEVICE_ID" +env > env.log + +python train.py --data_dir=$DATASET_PATH > log.txt 2>&1 & +cd .. \ No newline at end of file diff --git a/community/cv/ADCAM/scripts/run_standalone_train_gpu.sh b/community/cv/ADCAM/scripts/run_standalone_train_gpu.sh new file mode 100644 index 0000000000000000000000000000000000000000..c07c9fe7c5c813ce8d5d1c756507135648bbba11 --- /dev/null +++ b/community/cv/ADCAM/scripts/run_standalone_train_gpu.sh @@ -0,0 +1,47 @@ +if [ $# != 2 ] +then + echo "Usage: bash run_standalone_train_gpu.sh [DATASET_PATH] [DEVICE_ID]" +exit 1 +fi + +get_real_path(){ + if [ "${1:0:1}" == "/" ]; then + echo "$1" + else + echo "$(realpath -m $PWD/$1)" + fi +} + +DATASET_PATH=$(get_real_path $1) +echo $DATASET_PATH + + +if [ ! -d $DATASET_PATH ] +then + echo "error: DATASET_PATH=$DATASET_PATH is not a directory" +exit 1 +fi + +DEVICE_ID=0 +if [ $# == 2 ]; then + DEVICE_ID=$2 +fi + +export CUDA_VISIBLE_DEVICES=$DEVICE_ID +export RANK_SIZE=1 + +if [ -d "train" ]; +then + rm -rf ./train +fi +mkdir ./train +cp ../*.py ./train +cp ../*.yaml ./train +cp -r ../src ./train +cp -r ../model_utils ./train +cd ./train || exit +echo "======start training======" +env > env.log + +python train.py --data_dir=$DATASET_PATH --device_target=GPU > log.txt 2>&1 & +cd .. diff --git a/community/cv/ADCAM/src/.ipynb_checkpoints/backbone-checkpoint.py b/community/cv/ADCAM/src/.ipynb_checkpoints/backbone-checkpoint.py new file mode 100644 index 0000000000000000000000000000000000000000..b9fafb251a353e1669a2621f6e2726365faaee52 --- /dev/null +++ b/community/cv/ADCAM/src/.ipynb_checkpoints/backbone-checkpoint.py @@ -0,0 +1,253 @@ +# DarkNet model +import mindspore.nn as nn +import mindspore.ops as ops + +############################修改################################# + +class CAAttention(nn.Cell): + def __init__(self, inp, oup, groups=32,act=True): + super(CAAttention, self).__init__() + mip = max(8, inp // groups) + + self.conv1 = nn.Conv2d(inp, mip, kernel_size=1, stride=1, padding=0, has_bias=True) + self.bn1 = nn.BatchNorm2d(mip) + self.conv2 = nn.Conv2d(mip, oup, kernel_size=1, stride=1, padding=0, has_bias=True) + self.conv3 = nn.Conv2d(mip, oup, kernel_size=1, stride=1, padding=0, has_bias=True) + self.relu = SiLU() if act is True else ( + act if isinstance(act, nn.Cell) else ops.Identity()) + + # 定义需要的操作 + self.mean = ops.ReduceMean(keep_dims=True) + self.concat = ops.Concat(axis=2) + self.transpose = ops.Transpose() + self.sigmoid = ops.Sigmoid() + self.tile = ops.Tile() + + def construct(self, x): + identity = x + n, c, h, w = x.shape + + # 沿宽度方向求平均,结果维度为 (n, c, h, 1) + x_h = self.mean(x, 3) + # 沿高度方向求平均,结果维度为 (n, c, 1, w) + x_w = self.mean(x, 2) + x_w = self.transpose(x_w, (0, 1, 3, 2)) + + # 在高度维度上拼接 + y = self.concat((x_h, x_w)) + + y = self.conv1(y) + y = self.bn1(y) + y = self.relu(y) + + # 分割回 x_h 和 x_w + x_h, x_w = y[:, :, :h, :], y[:, :, h:, :] + + # 转置 x_w 回原来的维度 + x_w = self.transpose(x_w, (0, 1, 3, 2)) + + x_h = self.sigmoid(self.conv2(x_h)) + x_w = self.sigmoid(self.conv3(x_w)) + + # 扩展 x_h 和 x_w 以匹配输入的形状 + x_h = self.tile(x_h, (1, 1, 1, w)) + x_w = self.tile(x_w, (1, 1, h, 1)) + + # 加权输入 + y = identity * x_h * x_w + #print('666666666666666666666666666666666666666666666666') + return y+identity + +# if __name__ == '__main__': +# from mindspore import context +# context.set_context(mode=context.PYNATIVE_MODE) +# x = Tensor(np.random.randn(1, 256, 64, 64), mindspore.float32) +# coordatt = CAAttention(256, 256) +# y = coordatt(x) +# print("输入代码的shape为:", x.shape, "输出代码的shape为:", y.shape) + + +###########################END################################### +class Bottleneck(nn.Cell): + # Standard bottleneck + # ch_in, ch_out, shortcut, groups, expansion + def __init__(self, c1, c2, shortcut=True, e=0.5): + super(Bottleneck, self).__init__() + c_ = int(c2 * e) # hidden channels + self.conv1 = Conv(c1, c_, 1, 1) + self.conv2 = Conv(c_, c2, 3, 1) + self.add = shortcut and c1 == c2 + + def construct(self, x): + c1 = self.conv1(x) + c2 = self.conv2(c1) + out = c2 + if self.add: + out = x + out + return out + + +class BottleneckCSP(nn.Cell): + # CSP Bottleneck with 3 convolutions + def __init__(self, c1, c2, n=1, shortcut=True, e=0.5): + super(BottleneckCSP, self).__init__() + c_ = int(c2 * e) # hidden channels + self.conv1 = Conv(c1, c_, 1, 1) + self.conv2 = Conv(c1, c_, 1, 1) + self.conv3 = Conv(2 * c_, c2, 1) # act=FReLU(c2) + self.m = nn.SequentialCell( + [Bottleneck(c_, c_, shortcut, e=1.0) for _ in range(n)]) + self.concat = ops.Concat(axis=1) + + + + def construct(self, x): + c1 = self.conv1(x) + c2 = self.m(c1) + c3 = self.conv2(x) + c4 = self.concat((c2, c3)) + c5 = self.conv3(c4) + return c5 + + +class BottleneckCSPWithCA(nn.Cell): + # CSP Bottleneck with 3 convolutions + def __init__(self, c1, c2, n=1, shortcut=True, e=0.5): + super(BottleneckCSPWithCA, self).__init__() + print("BottleneckCSPWithCA........","c1===", c1, "c2===", c2) + c_ = int(c2 * e) # hidden channels + self.conv1 = Conv(c1, c_, 1, 1) + self.conv2 = Conv(c1, c_, 1, 1) + self.conv3 = Conv(2 * c_, c2, 1) # act=FReLU(c2) + self.m = nn.SequentialCell( + [Bottleneck(c_, c_, shortcut, e=1.0) for _ in range(n)]) + self.concat = ops.Concat(axis=1) + self.coordatt=CAAttention(c1,c2) + + + + def construct(self, x): + c1 = self.conv1(x) + c2 = self.m(c1) + c3 = self.conv2(x) + c4 = self.concat((c2, c3)) + c5 = self.conv3(c4) + #print("输入代码的shape为:", x.shape, "输出代码的shape为:", c5.shape) + # c6=self.coordatt(c5) + # print("dalaohu dalaohu") + # c6=self.coordatt(c5) + return c6 + +class SPP(nn.Cell): + # Spatial pyramid pooling layer used in YOLOv3-SPP + def __init__(self, c1, c2, k=(5, 9, 13)): + super(SPP, self).__init__() + c_ = c1 // 2 # hidden channels + self.conv1 = Conv(c1, c_, 1, 1) + self.conv2 = Conv(c_ * (len(k) + 1), c2, 1, 1) + + self.maxpool1 = nn.MaxPool2d(kernel_size=5, stride=1, pad_mode='same') + self.maxpool2 = nn.MaxPool2d(kernel_size=9, stride=1, pad_mode='same') + self.maxpool3 = nn.MaxPool2d(kernel_size=13, stride=1, pad_mode='same') + self.concat = ops.Concat(axis=1) + + def construct(self, x): + c1 = self.conv1(x) + m1 = self.maxpool1(c1) + m2 = self.maxpool2(c1) + m3 = self.maxpool3(c1) + c4 = self.concat((c1, m1, m2, m3)) + c5 = self.conv2(c4) + return c5 + + +class Focus(nn.Cell): + # Focus wh information into c-space + def __init__(self, c1, c2, k=1, s=1, p=None, act=True): + super(Focus, self).__init__() + self.conv = Conv(c1 * 4, c2, k, s, p, act) + + def construct(self, x): + c1 = self.conv(x) + return c1 + + +class SiLU(nn.Cell): + def __init__(self): + super(SiLU, self).__init__() + self.sigmoid = ops.Sigmoid() + + def construct(self, x): + return x * self.sigmoid(x) + + +def auto_pad(k, p=None): # kernel, padding + # Pad to 'same' + if p is None: + p = k // 2 if isinstance(k, int) else [x // 2 for x in k] # auto-pad + return p + + +class Conv(nn.Cell): + # Standard convolution + def __init__(self, c1, c2, k=1, s=1, p=None, + dilation=1, + alpha=0.1, + momentum=0.97, + eps=1e-3, + pad_mode="same", + act=True): # ch_in, ch_out, kernel, stride, padding + super(Conv, self).__init__() + self.padding = auto_pad(k, p) + self.pad_mode = None + if self.padding == 0: + self.pad_mode = 'same' + elif self.padding == 1: + self.pad_mode = 'pad' + self.conv = nn.Conv2d( + c1, + c2, + k, + s, + padding=self.padding, + pad_mode=self.pad_mode, + has_bias=False) + self.bn = nn.BatchNorm2d(c2, momentum=momentum, eps=eps) + self.act = SiLU() if act is True else ( + act if isinstance(act, nn.Cell) else ops.Identity()) + + def construct(self, x): + return self.act(self.bn(self.conv(x))) + + +class YOLOv5Backbone(nn.Cell): + def __init__(self, shape): + super(YOLOv5Backbone, self).__init__() + self.focus = Focus(shape[0], shape[1], k=3, s=1) + self.conv1 = Conv(shape[1], shape[2], k=3, s=2) + self.CSP1 = BottleneckCSP(shape[2], shape[2], n=1 * shape[6]) + self.conv2 = Conv(shape[2], shape[3], k=3, s=2) + self.CSP2 = BottleneckCSP(shape[3], shape[3], n=3 * shape[6]) + self.conv3 = Conv(shape[3], shape[4], k=3, s=2) + self.CSP3 = BottleneckCSP(shape[4], shape[4], n=3 * shape[6]) + self.conv4 = Conv(shape[4], shape[5], k=3, s=2) + self.spp = SPP(shape[5], shape[5], k=[5, 9, 13]) + self.CSP4 = BottleneckCSP(shape[5], shape[5], n=1 * shape[6], shortcut=False) + + def construct(self, x): + """construct method""" + c1 = self.focus(x) + c2 = self.conv1(c1) + c3 = self.CSP1(c2) + c4 = self.conv2(c3) + # out + c5 = self.CSP2(c4) + c6 = self.conv3(c5) + # out + c7 = self.CSP3(c6) + c8 = self.conv4(c7) + c9 = self.spp(c8) + # out + c10 = self.CSP4(c9) + + return c5, c7, c10 diff --git a/community/cv/ADCAM/src/.ipynb_checkpoints/loss-checkpoint.py b/community/cv/ADCAM/src/.ipynb_checkpoints/loss-checkpoint.py new file mode 100644 index 0000000000000000000000000000000000000000..5a7ec7cde82f4b60fc7bc66131aacbabcf2c784e --- /dev/null +++ b/community/cv/ADCAM/src/.ipynb_checkpoints/loss-checkpoint.py @@ -0,0 +1,32 @@ +# YOLOV5 loss +import mindspore.ops as ops +import mindspore.nn as nn + + +class ConfidenceLoss(nn.Cell): + """Loss for confidence.""" + + def __init__(self): + super(ConfidenceLoss, self).__init__() + self.cross_entropy = ops.SigmoidCrossEntropyWithLogits() + self.reduce_sum = ops.ReduceSum() + + def construct(self, object_mask, predict_confidence, ignore_mask): + confidence_loss = self.cross_entropy(predict_confidence, object_mask) + confidence_loss = object_mask * confidence_loss + (1 - object_mask) * confidence_loss * ignore_mask + confidence_loss = self.reduce_sum(confidence_loss, ()) + return confidence_loss + + +class ClassLoss(nn.Cell): + """Loss for classification.""" + + def __init__(self): + super(ClassLoss, self).__init__() + self.cross_entropy = ops.SigmoidCrossEntropyWithLogits() + self.reduce_sum = ops.ReduceSum() + + def construct(self, object_mask, predict_class, class_probs): + class_loss = object_mask * self.cross_entropy(predict_class, class_probs) + class_loss = self.reduce_sum(class_loss, ()) + return class_loss diff --git a/community/cv/ADCAM/src/.ipynb_checkpoints/lr_scheduler-checkpoint.py b/community/cv/ADCAM/src/.ipynb_checkpoints/lr_scheduler-checkpoint.py new file mode 100644 index 0000000000000000000000000000000000000000..dad12e2ef79ab7adce80952f7714d619d010d480 --- /dev/null +++ b/community/cv/ADCAM/src/.ipynb_checkpoints/lr_scheduler-checkpoint.py @@ -0,0 +1,149 @@ +# Learning rate scheduler +import math +from collections import Counter + +import numpy as np + + +def linear_warmup_lr(current_step, warmup_steps, base_lr, init_lr): + """Linear learning rate.""" + lr_inc = (float(base_lr) - float(init_lr)) / float(warmup_steps) + lr = float(init_lr) + lr_inc * current_step + return lr + + +def warmup_step_lr(lr, lr_epochs, steps_per_epoch, warmup_epochs, max_epoch, gamma=0.1): + """Warmup step learning rate.""" + base_lr = lr + warmup_init_lr = 0 + total_steps = int(max_epoch * steps_per_epoch) + warmup_steps = int(warmup_epochs * steps_per_epoch) + milestones = lr_epochs + milestones_steps = [] + for milestone in milestones: + milestones_step = milestone * steps_per_epoch + milestones_steps.append(milestones_step) + + lr_each_step = [] + lr = base_lr + milestones_steps_counter = Counter(milestones_steps) + for i in range(total_steps): + if i < warmup_steps: + lr = linear_warmup_lr(i + 1, warmup_steps, base_lr, warmup_init_lr) + else: + lr = lr * gamma**milestones_steps_counter[i] + lr_each_step.append(lr) + + return np.array(lr_each_step).astype(np.float32) + + +def multi_step_lr(lr, milestones, steps_per_epoch, max_epoch, gamma=0.1): + return warmup_step_lr(lr, milestones, steps_per_epoch, 0, max_epoch, gamma=gamma) + + +def step_lr(lr, epoch_size, steps_per_epoch, max_epoch, gamma=0.1): + lr_epochs = [] + for i in range(1, max_epoch): + if i % epoch_size == 0: + lr_epochs.append(i) + return multi_step_lr(lr, lr_epochs, steps_per_epoch, max_epoch, gamma=gamma) + + +def warmup_cosine_annealing_lr(lr, steps_per_epoch, warmup_epochs, max_epoch, T_max, eta_min=0): + """Cosine annealing learning rate.""" + base_lr = lr + warmup_init_lr = 0 + total_steps = int(max_epoch * steps_per_epoch) + warmup_steps = int(warmup_epochs * steps_per_epoch) + + lr_each_step = [] + for i in range(total_steps): + last_epoch = i // steps_per_epoch + if i < warmup_steps: + lr = linear_warmup_lr(i + 1, warmup_steps, base_lr, warmup_init_lr) + else: + lr = eta_min + (base_lr - eta_min) * (1. + math.cos(math.pi * last_epoch / T_max)) / 2 + lr_each_step.append(lr) + + return np.array(lr_each_step).astype(np.float32) + + +def warmup_cosine_annealing_lr_V2(lr, steps_per_epoch, warmup_epochs, max_epoch, T_max, eta_min=0): + """Cosine annealing learning rate V2.""" + base_lr = lr + warmup_init_lr = 0 + total_steps = int(max_epoch * steps_per_epoch) + warmup_steps = int(warmup_epochs * steps_per_epoch) + + last_lr = 0 + last_epoch_V1 = 0 + + T_max_V2 = int(max_epoch * 1 / 3) + + lr_each_step = [] + for i in range(total_steps): + last_epoch = i // steps_per_epoch + if i < warmup_steps: + lr = linear_warmup_lr(i + 1, warmup_steps, base_lr, warmup_init_lr) + else: + if i < total_steps * 2 / 3: + lr = eta_min + (base_lr - eta_min) * (1. + math.cos(math.pi * last_epoch / T_max)) / 2 + last_lr = lr + last_epoch_V1 = last_epoch + else: + base_lr = last_lr + last_epoch = last_epoch - last_epoch_V1 + lr = eta_min + (base_lr - eta_min) * (1. + math.cos(math.pi * last_epoch / T_max_V2)) / 2 + + lr_each_step.append(lr) + return np.array(lr_each_step).astype(np.float32) + + +def warmup_cosine_annealing_lr_sample(lr, steps_per_epoch, warmup_epochs, max_epoch, T_max, eta_min=0): + """Warmup cosine annealing learning rate.""" + start_sample_epoch = 60 + step_sample = 2 + tobe_sampled_epoch = 60 + end_sampled_epoch = start_sample_epoch + step_sample * tobe_sampled_epoch + max_sampled_epoch = max_epoch + tobe_sampled_epoch + T_max = max_sampled_epoch + + base_lr = lr + warmup_init_lr = 0 + total_steps = int(max_epoch * steps_per_epoch) + total_sampled_steps = int(max_sampled_epoch * steps_per_epoch) + warmup_steps = int(warmup_epochs * steps_per_epoch) + + lr_each_step = [] + + for i in range(total_sampled_steps): + last_epoch = i // steps_per_epoch + if last_epoch in range(start_sample_epoch, end_sampled_epoch, step_sample): + continue + if i < warmup_steps: + lr = linear_warmup_lr(i + 1, warmup_steps, base_lr, warmup_init_lr) + else: + lr = eta_min + (base_lr - eta_min) * (1. + math.cos(math.pi * last_epoch / T_max)) / 2 + lr_each_step.append(lr) + + assert total_steps == len(lr_each_step) + return np.array(lr_each_step).astype(np.float32) + + +def get_lr(args, steps_per_epoch): + """generate learning rate.""" + if args.lr_scheduler == 'exponential': + lr = warmup_step_lr(args.lr, args.lr_epochs, steps_per_epoch, args.warmup_epochs, args.max_epoch, + gamma=args.lr_gamma) + elif args.lr_scheduler == 'cosine_annealing': + lr = warmup_cosine_annealing_lr(args.lr, steps_per_epoch, args.warmup_epochs, + args.max_epoch, args.T_max, args.eta_min) + elif args.lr_scheduler == 'cosine_annealing_V2': + lr = warmup_cosine_annealing_lr_V2(args.lr, steps_per_epoch, args.warmup_epochs, + args.max_epoch, args.T_max, args.eta_min) + elif args.lr_scheduler == 'cosine_annealing_sample': + lr = warmup_cosine_annealing_lr_sample(args.lr, steps_per_epoch, args.warmup_epochs, + args.max_epoch, args.T_max, args.eta_min) + else: + raise NotImplementedError(args.lr_scheduler) + return lr diff --git a/community/cv/ADCAM/src/.ipynb_checkpoints/transforms-checkpoint.py b/community/cv/ADCAM/src/.ipynb_checkpoints/transforms-checkpoint.py new file mode 100644 index 0000000000000000000000000000000000000000..fa3c39b30114a8a0f68bc8539c8a543c74457e1b --- /dev/null +++ b/community/cv/ADCAM/src/.ipynb_checkpoints/transforms-checkpoint.py @@ -0,0 +1,526 @@ +# Preprocess dataset.""" +import random +import threading +import copy + +import numpy as np +from PIL import Image +import cv2 +import mindspore.dataset.vision as vision + + +def _rand(a=0., b=1.): + return np.random.rand() * (b - a) + a + + +def bbox_iou(bbox_a, bbox_b, offset=0): + if bbox_a.shape[1] < 4 or bbox_b.shape[1] < 4: + raise IndexError("Bounding boxes axis 1 must have at least length 4") + + tl = np.maximum(bbox_a[:, None, :2], bbox_b[:, :2]) + br = np.minimum(bbox_a[:, None, 2:4], bbox_b[:, 2:4]) + + area_i = np.prod(br - tl + offset, axis=2) * (tl < br).all(axis=2) + area_a = np.prod(bbox_a[:, 2:4] - bbox_a[:, :2] + offset, axis=1) + area_b = np.prod(bbox_b[:, 2:4] - bbox_b[:, :2] + offset, axis=1) + return area_i / (area_a[:, None] + area_b - area_i) + + +def get_interp_method(interp, sizes=()): + if interp == 9: + if sizes: + assert len(sizes) == 4 + oh, ow, nh, nw = sizes + if nh > oh and nw > ow: + return 2 + if nh < oh and nw < ow: + return 0 + return 1 + return 2 + if interp == 10: + return random.randint(0, 4) + if interp not in (0, 1, 2, 3, 4): + raise ValueError('Unknown interp method %d' % interp) + return interp + + +def pil_image_reshape(interp): + """Reshape pil image.""" + reshape_type = { + 0: Image.NEAREST, + 1: Image.BILINEAR, + 2: Image.BICUBIC, + 3: Image.NEAREST, + 4: Image.LANCZOS, + } + return reshape_type[interp] + + +def _preprocess_true_boxes(true_boxes, anchors, in_shape, num_classes, max_boxes, label_smooth, + label_smooth_factor=0.1, iou_threshold=0.213): + """ + Introduction + ------------ + preprocessing ground truth box + Parameters + ---------- + true_boxes: ground truth box shape as [boxes, 5], x_min, y_min, x_max, y_max, class_id + """ + anchors = np.array(anchors) + num_layers = anchors.shape[0] // 3 + anchor_mask = [[6, 7, 8], [3, 4, 5], [0, 1, 2]] + true_boxes = np.array(true_boxes, dtype='float32') + input_shape = np.array(in_shape, dtype='int32') + boxes_xy = (true_boxes[..., 0:2] + true_boxes[..., 2:4]) // 2. + # trans to box center point + boxes_wh = true_boxes[..., 2:4] - true_boxes[..., 0:2] + # input_shape is [h, w] + true_boxes[..., 0:2] = boxes_xy / input_shape[::-1] + true_boxes[..., 2:4] = boxes_wh / input_shape[::-1] + # true_boxes = [xywh] + grid_shapes = [input_shape // 32, input_shape // 16, input_shape // 8] + # grid_shape [h, w] + y_true = [np.zeros((grid_shapes[l][0], grid_shapes[l][1], len(anchor_mask[l]), + 5 + num_classes), dtype='float32') for l in range(num_layers)] + # y_true [gridy, gridx] + anchors = np.expand_dims(anchors, 0) + anchors_max = anchors / 2. + anchors_min = -anchors_max + valid_mask = boxes_wh[..., 0] > 0 + wh = boxes_wh[valid_mask] + if wh.size != 0: + wh = np.expand_dims(wh, -2) + # wh shape[box_num, 1, 2] + boxes_max = wh / 2. + boxes_min = -boxes_max + intersect_min = np.maximum(boxes_min, anchors_min) + intersect_max = np.minimum(boxes_max, anchors_max) + intersect_wh = np.maximum(intersect_max - intersect_min, 0.) + intersect_area = intersect_wh[..., 0] * intersect_wh[..., 1] + box_area = wh[..., 0] * wh[..., 1] + anchor_area = anchors[..., 0] * anchors[..., 1] + iou = intersect_area / (box_area + anchor_area - intersect_area) + + # topk iou + topk = 4 + topk_flag = iou.argsort() + topk_flag = topk_flag >= topk_flag.shape[1] - topk + flag = topk_flag.nonzero() + for index in range(len(flag[0])): + t = flag[0][index] + n = flag[1][index] + if iou[t][n] < iou_threshold: + continue + for l in range(num_layers): + if n in anchor_mask[l]: + i = np.floor(true_boxes[t, 0] * grid_shapes[l][1]).astype('int32') # grid_y + j = np.floor(true_boxes[t, 1] * grid_shapes[l][0]).astype('int32') # grid_x + + k = anchor_mask[l].index(n) + c = true_boxes[t, 4].astype('int32') + y_true[l][j, i, k, 0:4] = true_boxes[t, 0:4] + y_true[l][j, i, k, 4] = 1. + + # lable-smooth + if label_smooth: + sigma = label_smooth_factor / (num_classes - 1) + y_true[l][j, i, k, 5:] = sigma + y_true[l][j, i, k, 5 + c] = 1 - label_smooth_factor + else: + y_true[l][j, i, k, 5 + c] = 1. + # best anchor for gt + best_anchor = np.argmax(iou, axis=-1) + for t, n in enumerate(best_anchor): + for l in range(num_layers): + if n in anchor_mask[l]: + i = np.floor(true_boxes[t, 0] * grid_shapes[l][1]).astype('int32') # grid_y + j = np.floor(true_boxes[t, 1] * grid_shapes[l][0]).astype('int32') # grid_x + + k = anchor_mask[l].index(n) + c = true_boxes[t, 4].astype('int32') + y_true[l][j, i, k, 0:4] = true_boxes[t, 0:4] + y_true[l][j, i, k, 4] = 1. + + # lable-smooth + if label_smooth: + sigma = label_smooth_factor / (num_classes - 1) + y_true[l][j, i, k, 5:] = sigma + y_true[l][j, i, k, 5 + c] = 1 - label_smooth_factor + else: + y_true[l][j, i, k, 5 + c] = 1. + + # pad_gt_boxes for avoiding dynamic shape + pad_gt_box0 = np.zeros(shape=[max_boxes, 4], dtype=np.float32) + pad_gt_box1 = np.zeros(shape=[max_boxes, 4], dtype=np.float32) + pad_gt_box2 = np.zeros(shape=[max_boxes, 4], dtype=np.float32) + + mask0 = np.reshape(y_true[0][..., 4:5], [-1]) + gt_box0 = np.reshape(y_true[0][..., 0:4], [-1, 4]) + # gt_box [boxes, [x,y,w,h]] + gt_box0 = gt_box0[mask0 == 1] + # gt_box0: get all boxes which have object + if gt_box0.shape[0] < max_boxes: + pad_gt_box0[:gt_box0.shape[0]] = gt_box0 + else: + pad_gt_box0 = gt_box0[:max_boxes] + # gt_box0.shape[0]: total number of boxes in gt_box0 + # top N of pad_gt_box0 is real box, and after are pad by zero + + mask1 = np.reshape(y_true[1][..., 4:5], [-1]) + gt_box1 = np.reshape(y_true[1][..., 0:4], [-1, 4]) + gt_box1 = gt_box1[mask1 == 1] + if gt_box1.shape[0] < max_boxes: + pad_gt_box1[:gt_box1.shape[0]] = gt_box1 + else: + pad_gt_box1 = gt_box1[:max_boxes] + + mask2 = np.reshape(y_true[2][..., 4:5], [-1]) + gt_box2 = np.reshape(y_true[2][..., 0:4], [-1, 4]) + + gt_box2 = gt_box2[mask2 == 1] + if gt_box2.shape[0] < max_boxes: + pad_gt_box2[:gt_box2.shape[0]] = gt_box2 + else: + pad_gt_box2 = gt_box2[:max_boxes] + return y_true[0], y_true[1], y_true[2], pad_gt_box0, pad_gt_box1, pad_gt_box2 + + +class PreprocessTrueBox: + def __init__(self, config): + self.anchor_scales = config.anchor_scales + self.num_classes = config.num_classes + self.max_box = config.max_box + self.label_smooth = config.label_smooth + self.label_smooth_factor = config.label_smooth_factor + + def __call__(self, anno, input_shape): + bbox_true_1, bbox_true_2, bbox_true_3, gt_box1, gt_box2, gt_box3 = \ + _preprocess_true_boxes(true_boxes=anno, anchors=self.anchor_scales, in_shape=input_shape, + num_classes=self.num_classes, max_boxes=self.max_box, + label_smooth=self.label_smooth, label_smooth_factor=self.label_smooth_factor) + return anno, np.array(bbox_true_1), np.array(bbox_true_2), np.array(bbox_true_3), \ + np.array(gt_box1), np.array(gt_box2), np.array(gt_box3) + + +def _reshape_data(image, image_size): + """Reshape image.""" + if not isinstance(image, Image.Image): + image = Image.fromarray(image) + ori_w, ori_h = image.size + ori_image_shape = np.array([ori_w, ori_h], np.int32) + # original image shape fir:H sec:W + h, w = image_size + interp = get_interp_method(interp=9, sizes=(ori_h, ori_w, h, w)) + image = image.resize((w, h), pil_image_reshape(interp)) + image_data = np.array(image) + if len(image_data.shape) == 2: + image_data = np.expand_dims(image_data, axis=-1) + image_data = np.concatenate([image_data, image_data, image_data], axis=-1) + return image_data, ori_image_shape + + +def color_distortion(img, hue, sat, val, device_num): + """Color distortion.""" + hue = _rand(-hue, hue) + sat = _rand(1, sat) if _rand() < .5 else 1 / _rand(1, sat) + val = _rand(1, val) if _rand() < .5 else 1 / _rand(1, val) + if device_num != 1: + cv2.setNumThreads(1) + x = cv2.cvtColor(img, cv2.COLOR_RGB2HSV_FULL) + x = x / 255. + x[..., 0] += hue + x[..., 0][x[..., 0] > 1] -= 1 + x[..., 0][x[..., 0] < 0] += 1 + x[..., 1] *= sat + x[..., 2] *= val + x[x > 1] = 1 + x[x < 0] = 0 + x = x * 255. + x = x.astype(np.uint8) + image_data = cv2.cvtColor(x, cv2.COLOR_HSV2RGB_FULL) + return image_data + + +def filp_pil_image(img): + return img.transpose(Image.FLIP_LEFT_RIGHT) + + +def convert_gray_to_color(img): + if len(img.shape) == 2: + img = np.expand_dims(img, axis=-1) + img = np.concatenate([img, img, img], axis=-1) + return img + + +def _is_iou_satisfied_constraint(min_iou, max_iou, box, crop_box): + iou = bbox_iou(box, crop_box) + return min_iou <= iou.min() and max_iou >= iou.max() + + +def _choose_candidate_by_constraints(max_trial, input_w, input_h, image_w, image_h, jitter, box, use_constraints): + """Choose candidate by constraints.""" + if use_constraints: + constraints = ( + (0.1, None), + (0.3, None), + (0.5, None), + (0.7, None), + (0.9, None), + (None, 1), + ) + else: + constraints = ((None, None),) + # add default candidate + candidates = [(0, 0, input_w, input_h)] + for constraint in constraints: + min_iou, max_iou = constraint + min_iou = -np.inf if min_iou is None else min_iou + max_iou = np.inf if max_iou is None else max_iou + + for _ in range(max_trial): + # box_data should have at least one box + new_ar = float(input_w) / float(input_h) * _rand(1 - jitter, 1 + jitter) / _rand(1 - jitter, 1 + jitter) + scale = _rand(0.5, 2) + + if new_ar < 1: + nh = int(scale * input_h) + nw = int(nh * new_ar) + else: + nw = int(scale * input_w) + nh = int(nw / new_ar) + + dx = int(_rand(0, input_w - nw)) + dy = int(_rand(0, input_h - nh)) + + if box.size > 0: + t_box = copy.deepcopy(box) + t_box[:, [0, 2]] = t_box[:, [0, 2]] * float(nw) / float(image_w) + dx + t_box[:, [1, 3]] = t_box[:, [1, 3]] * float(nh) / float(image_h) + dy + + crop_box = np.array((0, 0, input_w, input_h)) + if not _is_iou_satisfied_constraint(min_iou, max_iou, t_box, crop_box[np.newaxis]): + continue + else: + candidates.append((dx, dy, nw, nh)) + else: + raise Exception("!!! annotation box is less than 1") + return candidates + + +def _correct_bbox_by_candidates(candidates, input_w, input_h, image_w, + image_h, flip, box, box_data, allow_outside_center, max_boxes): + """Calculate correct boxes.""" + while candidates: + if len(candidates) > 1: + # ignore default candidate which do not crop + candidate = candidates.pop(np.random.randint(1, len(candidates))) + else: + candidate = candidates.pop(np.random.randint(0, len(candidates))) + dx, dy, nw, nh = candidate + t_box = copy.deepcopy(box) + t_box[:, [0, 2]] = t_box[:, [0, 2]] * float(nw) / float(image_w) + dx + t_box[:, [1, 3]] = t_box[:, [1, 3]] * float(nh) / float(image_h) + dy + if flip: + t_box[:, [0, 2]] = input_w - t_box[:, [2, 0]] + + if allow_outside_center: + pass + else: + t_box = t_box[ + np.logical_and((t_box[:, 0] + t_box[:, 2]) / 2. >= 0., (t_box[:, 1] + t_box[:, 3]) / 2. >= 0.)] + t_box = t_box[np.logical_and((t_box[:, 0] + t_box[:, 2]) / 2. <= input_w, + (t_box[:, 1] + t_box[:, 3]) / 2. <= input_h)] + + # recorrect x, y for case x,y < 0 reset to zero, after dx and dy, some box can smaller than zero + t_box[:, 0:2][t_box[:, 0:2] < 0] = 0 + # recorrect w,h not higher than input size + t_box[:, 2][t_box[:, 2] > input_w] = input_w + t_box[:, 3][t_box[:, 3] > input_h] = input_h + box_w = t_box[:, 2] - t_box[:, 0] + box_h = t_box[:, 3] - t_box[:, 1] + # discard invalid box: w or h smaller than 1 pixel + t_box = t_box[np.logical_and(box_w > 1, box_h > 1)] + + if t_box.shape[0] > 0: + # break if number of find t_box + box_data[: len(t_box)] = t_box + return box_data, candidate + return np.zeros(shape=[max_boxes, 5], dtype=np.float64), (0, 0, nw, nh) + + +def _data_aug(image, box, jitter, hue, sat, val, image_input_size, max_boxes, + anchors, num_classes, max_trial=10, device_num=1): + """Crop an image randomly with bounding box constraints. + + This data augmentation is used in training of + Single Shot Multibox Detector [#]_. More details can be found in + data augmentation section of the original paper. + .. [#] Wei Liu, Dragomir Anguelov, Dumitru Erhan, Christian Szegedy, + Scott Reed, Cheng-Yang Fu, Alexander C. Berg. + SSD: Single Shot MultiBox Detector. ECCV 2016.""" + + if not isinstance(image, Image.Image): + image = Image.fromarray(image) + + image_w, image_h = image.size + input_h, input_w = image_input_size + + np.random.shuffle(box) + if len(box) > max_boxes: + box = box[:max_boxes] + flip = _rand() < .5 + box_data = np.zeros((max_boxes, 5)) + + candidates = _choose_candidate_by_constraints(use_constraints=False, max_trial=max_trial, input_w=input_w, + input_h=input_h, image_w=image_w, image_h=image_h, + jitter=jitter, box=box) + box_data, candidate = _correct_bbox_by_candidates(candidates=candidates, input_w=input_w, input_h=input_h, + image_w=image_w, image_h=image_h, flip=flip, box=box, + box_data=box_data, allow_outside_center=True, max_boxes=max_boxes) + dx, dy, nw, nh = candidate + interp = get_interp_method(interp=10) + image = image.resize((nw, nh), pil_image_reshape(interp)) + # place image, gray color as back graoud + new_image = Image.new('RGB', (input_w, input_h), (128, 128, 128)) + new_image.paste(image, (dx, dy)) + image = new_image + + if flip: + image = filp_pil_image(image) + + image = np.array(image) + image = convert_gray_to_color(image) + image_data = color_distortion(image, hue, sat, val, device_num) + return image_data, box_data + + +def preprocess_fn(image, box, config, input_size, device_num): + """Preprocess data function.""" + config_anchors = config.anchor_scales + anchors = np.array([list(x) for x in config_anchors]) + max_boxes = config.max_box + num_classes = config.num_classes + jitter = config.jitter + hue = config.hue + sat = config.saturation + val = config.value + image, anno = _data_aug(image, box, jitter=jitter, hue=hue, sat=sat, val=val, + image_input_size=input_size, max_boxes=max_boxes, + num_classes=num_classes, anchors=anchors, device_num=device_num) + return image, anno + + +def reshape_fn(image, img_id, config): + input_size = config.test_img_shape + image, ori_image_shape = _reshape_data(image, image_size=input_size) + return image, ori_image_shape, img_id + + +class MultiScaleTrans: + """Multi scale transform.""" + + def __init__(self, config, device_num): + self.config = config + self.seed = 0 + self.size_list = [] + self.resize_rate = config.resize_rate + self.dataset_size = config.dataset_size + self.size_dict = {} + self.seed_num = int(1e6) + self.seed_list = self.generate_seed_list(seed_num=self.seed_num) + self.resize_count_num = int(np.ceil(self.dataset_size / self.resize_rate)) + self.device_num = device_num + self.anchor_scales = config.anchor_scales + self.num_classes = config.num_classes + self.max_box = config.max_box + self.label_smooth = config.label_smooth + self.label_smooth_factor = config.label_smooth_factor + + def generate_seed_list(self, init_seed=1234, seed_num=int(1e6), seed_range=(1, 1000)): + seed_list = [] + random.seed(init_seed) + for _ in range(seed_num): + seed = random.randint(seed_range[0], seed_range[1]) + seed_list.append(seed) + return seed_list + + def __call__(self, img, anno, input_size, mosaic_flag): + if mosaic_flag[0] == 0: + img = vision.Decode(True)(img) + img, anno = preprocess_fn(img, anno, self.config, input_size, self.device_num) + return img, anno, np.array(img.shape[0:2]) + + +def thread_batch_preprocess_true_box(annos, config, input_shape, result_index, batch_bbox_true_1, batch_bbox_true_2, + batch_bbox_true_3, batch_gt_box1, batch_gt_box2, batch_gt_box3): + """Preprocess true box for multi-thread.""" + i = 0 + for anno in annos: + bbox_true_1, bbox_true_2, bbox_true_3, gt_box1, gt_box2, gt_box3 = \ + _preprocess_true_boxes(true_boxes=anno, anchors=config.anchor_scales, in_shape=input_shape, + num_classes=config.num_classes, max_boxes=config.max_box, + label_smooth=config.label_smooth, label_smooth_factor=config.label_smooth_factor) + batch_bbox_true_1[result_index + i] = bbox_true_1 + batch_bbox_true_2[result_index + i] = bbox_true_2 + batch_bbox_true_3[result_index + i] = bbox_true_3 + batch_gt_box1[result_index + i] = gt_box1 + batch_gt_box2[result_index + i] = gt_box2 + batch_gt_box3[result_index + i] = gt_box3 + i = i + 1 + + +def batch_preprocess_true_box(annos, config, input_shape): + """Preprocess true box with multi-thread.""" + batch_bbox_true_1 = [] + batch_bbox_true_2 = [] + batch_bbox_true_3 = [] + batch_gt_box1 = [] + batch_gt_box2 = [] + batch_gt_box3 = [] + threads = [] + + step = 4 + for index in range(0, len(annos), step): + for _ in range(step): + batch_bbox_true_1.append(None) + batch_bbox_true_2.append(None) + batch_bbox_true_3.append(None) + batch_gt_box1.append(None) + batch_gt_box2.append(None) + batch_gt_box3.append(None) + step_anno = annos[index: index + step] + t = threading.Thread(target=thread_batch_preprocess_true_box, + args=(step_anno, config, input_shape, index, batch_bbox_true_1, batch_bbox_true_2, + batch_bbox_true_3, batch_gt_box1, batch_gt_box2, batch_gt_box3)) + t.start() + threads.append(t) + + for t in threads: + t.join() + + return np.array(batch_bbox_true_1), np.array(batch_bbox_true_2), np.array(batch_bbox_true_3), \ + np.array(batch_gt_box1), np.array(batch_gt_box2), np.array(batch_gt_box3) + + +def batch_preprocess_true_box_single(annos, config, input_shape): + """Preprocess true boxes.""" + batch_bbox_true_1 = [] + batch_bbox_true_2 = [] + batch_bbox_true_3 = [] + batch_gt_box1 = [] + batch_gt_box2 = [] + batch_gt_box3 = [] + for anno in annos: + bbox_true_1, bbox_true_2, bbox_true_3, gt_box1, gt_box2, gt_box3 = \ + _preprocess_true_boxes(true_boxes=anno, anchors=config.anchor_scales, in_shape=input_shape, + num_classes=config.num_classes, max_boxes=config.max_box, + label_smooth=config.label_smooth, label_smooth_factor=config.label_smooth_factor) + batch_bbox_true_1.append(bbox_true_1) + batch_bbox_true_2.append(bbox_true_2) + batch_bbox_true_3.append(bbox_true_3) + batch_gt_box1.append(gt_box1) + batch_gt_box2.append(gt_box2) + batch_gt_box3.append(gt_box3) + + return np.array(batch_bbox_true_1), np.array(batch_bbox_true_2), np.array(batch_bbox_true_3), \ + np.array(batch_gt_box1), np.array(batch_gt_box2), np.array(batch_gt_box3) diff --git a/community/cv/ADCAM/src/.ipynb_checkpoints/util-checkpoint.py b/community/cv/ADCAM/src/.ipynb_checkpoints/util-checkpoint.py new file mode 100644 index 0000000000000000000000000000000000000000..4fb25d87160be53e2a059b708722875d9d376495 --- /dev/null +++ b/community/cv/ADCAM/src/.ipynb_checkpoints/util-checkpoint.py @@ -0,0 +1,484 @@ +# Util class or function +import os +import sys +from collections import defaultdict +import datetime +import copy +import json +from typing import Union, List +import numpy as np +from pycocotools.coco import COCO +from pycocotools.cocoeval import COCOeval + +import mindspore +import mindspore.nn as nn +from mindspore import Tensor, ops + +from .yolo import YoloLossBlock + + +class AverageMeter: + """Computes and stores the average and current value""" + + def __init__(self, name, fmt=':f', tb_writer=None): + self.name = name + self.fmt = fmt + self.reset() + self.tb_writer = tb_writer + self.cur_step = 1 + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + self.val = val + self.sum += val * n + self.count += n + self.avg = self.sum / self.count + if self.tb_writer is not None: + self.tb_writer.add_scalar(self.name, self.val, self.cur_step) + self.cur_step += 1 + + def __str__(self): + fmtstr = '{name}:{avg' + self.fmt + '}' + return fmtstr.format(**self.__dict__) + + +def default_wd_filter(x): + """default weight decay filter.""" + parameter_name = x.name + if parameter_name.endswith('.bias'): + # all bias not using weight decay + return False + if parameter_name.endswith('.gamma'): + # bn weight bias not using weight decay, be carefully for now x not + # include BN + return False + if parameter_name.endswith('.beta'): + # bn weight bias not using weight decay, be carefully for now x not + # include BN + return False + + return True + + +def get_param_groups(network): + """Param groups for optimizer.""" + decay_params = [] + no_decay_params = [] + for x in network.trainable_params(): + parameter_name = x.name + if parameter_name.endswith('.bias'): + # all bias not using weight decay + no_decay_params.append(x) + elif parameter_name.endswith('.gamma'): + # bn weight bias not using weight decay, be carefully for now x not + # include BN + no_decay_params.append(x) + elif parameter_name.endswith('.beta'): + # bn weight bias not using weight decay, be carefully for now x not + # include BN + no_decay_params.append(x) + else: + decay_params.append(x) + + return [{'params': no_decay_params, 'weight_decay': 0.0}, + {'params': decay_params}] + + +class ShapeRecord: + """Log image shape.""" + + def __init__(self): + self.shape_record = { + 416: 0, + 448: 0, + 480: 0, + 512: 0, + 544: 0, + 576: 0, + 608: 0, + 640: 0, + 672: 0, + 704: 0, + 736: 0, + 'total': 0 + } + + def set(self, shape): + if len(shape) > 1: + shape = shape[0] + shape = int(shape) + self.shape_record[shape] += 1 + self.shape_record['total'] += 1 + + def show(self, logger): + for key in self.shape_record: + rate = self.shape_record[key] / float(self.shape_record['total']) + logger.info('shape {}: {:.2f}%'.format(key, rate * 100)) + + +def keep_loss_fp32(network): + """Keep loss of network with float32""" + for _, cell in network.cells_and_names(): + if isinstance(cell, (YoloLossBlock,)): + cell.to_float(mindspore.float32) + + +class Redirct: + def __init__(self): + self.content = "" + + def write(self, content): + self.content += content + + def flush(self): + self.content = "" + + +def cpu_affinity(rank_id, device_num): + """Bind CPU cores according to rank_id and device_num.""" + import psutil + cores = psutil.cpu_count() + if cores < device_num: + return + process = psutil.Process() + used_cpu_num = cores // device_num + rank_id = rank_id % device_num + used_cpu_list = [i for i in range(rank_id * used_cpu_num, (rank_id + 1) * used_cpu_num)] + process.cpu_affinity(used_cpu_list) + print(f"==== {rank_id}/{device_num} ==== bind cpu: {used_cpu_list}") + + +class COCOEvaluator: + def __init__(self, detection_config) -> None: + self.coco_gt = COCO(detection_config.val_ann_file) + self.coco_catIds = self.coco_gt.getCatIds() + self.coco_imgIds = list(sorted(self.coco_gt.imgs.keys())) + self.coco_transformed_catIds = detection_config.coco_ids + self.logger = detection_config.logger + self.last_mAP = 0.0 + + def get_mAP(self, coco_dt_ann_file: Union[str, List[str]]): + if isinstance(coco_dt_ann_file, str): + return self.get_mAP_single_file(coco_dt_ann_file) + if isinstance(coco_dt_ann_file, list): + return self.get_mAP_multiple_file(coco_dt_ann_file) + raise ValueError("Invalid 'coco_dt_ann_file' type. Support str or List[str].") + + def merge_result_files(self, file_path: List[str]) -> List: + dt_list = [] + dt_ids_set = set([]) + self.logger.info(f"Total {len(file_path)} json files") + self.logger.info(f"File list: {file_path}") + + for path in file_path: + ann_list = [] + try: + with open(path, 'r') as f: + ann_list = json.load(f) + except json.decoder.JSONDecodeError: + pass # json file is empty + else: + ann_ids = set(ann['image_id'] for ann in ann_list) + diff_ids = ann_ids - dt_ids_set + ann_list = [ann for ann in ann_list if ann['image_id'] in diff_ids] + dt_ids_set = dt_ids_set | diff_ids + dt_list.extend(ann_list) + return dt_list + + def get_coco_from_dt_list(self, dt_list) -> COCO: + cocoDt = COCO() + cocoDt.dataset = {} + cocoDt.dataset['images'] = [img for img in self.coco_gt.dataset['images']] + cocoDt.dataset['categories'] = copy.deepcopy(self.coco_gt.dataset['categories']) + self.logger.info(f"Number of dt boxes: {len(dt_list)}") + for idx, ann in enumerate(dt_list): + bb = ann['bbox'] + x1, x2, y1, y2 = [bb[0], bb[0] + bb[2], bb[1], bb[1] + bb[3]] + if 'segmentation' not in ann: + ann['segmentation'] = [[x1, y1, x1, y2, x2, y2, x2, y1]] + ann['area'] = bb[2] * bb[3] + ann['id'] = idx + 1 + ann['iscrowd'] = 0 + cocoDt.dataset['annotations'] = dt_list + cocoDt.createIndex() + return cocoDt + + def get_mAP_multiple_file(self, coco_dt_ann_file: List[str]) -> str: + dt_list = self.merge_result_files(coco_dt_ann_file) + coco_dt = self.get_coco_from_dt_list(dt_list) + return self.compute_coco_mAP(coco_dt) + + def get_mAP_single_file(self, coco_dt_ann_file: str) -> str: + coco_dt = self.coco_gt.loadRes(coco_dt_ann_file) + return self.compute_coco_mAP(coco_dt) + + def compute_coco_mAP(self, coco_dt: COCO) -> str: + coco_eval = COCOeval(self.coco_gt, coco_dt, 'bbox') + coco_eval.evaluate() + coco_eval.accumulate() + rdct = Redirct() + stdout = sys.stdout + sys.stdout = rdct + coco_eval.summarize() + sys.stdout = stdout + self.last_mAP = coco_eval.stats[0] + return rdct.content + + +class DetectionEngine: + """Detection engine.""" + + def __init__(self, args_detection, threshold): + self.ignore_threshold = threshold + self.labels = args_detection.labels + self.num_classes = len(self.labels) + self.results = {} + self.file_path = '' + self.save_prefix = args_detection.output_dir + self.ann_file = args_detection.val_ann_file + self.det_boxes = [] + self.nms_thresh = args_detection.eval_nms_thresh + self.multi_label = args_detection.multi_label + self.multi_label_thresh = args_detection.multi_label_thresh + + self.logger = args_detection.logger + self.eval_parallel = args_detection.eval_parallel + if self.eval_parallel: + self.save_prefix = args_detection.save_prefix + self.rank_id = args_detection.rank + self.dir_path = '' + self.coco_evaluator = COCOEvaluator(args_detection) + self.coco_catids = self.coco_evaluator.coco_gt.getCatIds() + self.coco_catIds = args_detection.coco_ids + self._img_ids = list(sorted(self.coco_evaluator.coco_gt.imgs.keys())) + + def do_nms_for_results(self): + """Get result boxes.""" + for img_id in self.results: + for clsi in self.results[img_id]: + dets = self.results[img_id][clsi] + dets = np.array(dets) + keep_index = self._diou_nms(dets, thresh=self.nms_thresh) + + keep_box = [{'image_id': int(img_id), 'category_id': int(clsi), + 'bbox': list(dets[i][:4].astype(float)), + 'score': dets[i][4].astype(float)} for i in keep_index] + self.det_boxes.extend(keep_box) + + def _nms(self, predicts, threshold): + """Calculate NMS.""" + # convert xywh -> xmin ymin xmax ymax + x1 = predicts[:, 0] + y1 = predicts[:, 1] + x2 = x1 + predicts[:, 2] + y2 = y1 + predicts[:, 3] + scores = predicts[:, 4] + + areas = (x2 - x1 + 1) * (y2 - y1 + 1) + order = scores.argsort()[::-1] + + reserved_boxes = [] + while order.size > 0: + i = order[0] + reserved_boxes.append(i) + max_x1 = np.maximum(x1[i], x1[order[1:]]) + max_y1 = np.maximum(y1[i], y1[order[1:]]) + min_x2 = np.minimum(x2[i], x2[order[1:]]) + min_y2 = np.minimum(y2[i], y2[order[1:]]) + + intersect_w = np.maximum(0.0, min_x2 - max_x1 + 1) + intersect_h = np.maximum(0.0, min_y2 - max_y1 + 1) + intersect_area = intersect_w * intersect_h + ovr = intersect_area / \ + (areas[i] + areas[order[1:]] - intersect_area) + + indexes = np.where(ovr <= threshold)[0] + order = order[indexes + 1] + return reserved_boxes + + def _diou_nms(self, dets, thresh=0.5): + """ + convert xywh -> xmin ymin xmax ymax + """ + x1 = dets[:, 0] + y1 = dets[:, 1] + x2 = x1 + dets[:, 2] + y2 = y1 + dets[:, 3] + scores = dets[:, 4] + areas = (x2 - x1 + 1) * (y2 - y1 + 1) + order = scores.argsort()[::-1] + keep = [] + while order.size > 0: + i = order[0] + keep.append(i) + xx1 = np.maximum(x1[i], x1[order[1:]]) + yy1 = np.maximum(y1[i], y1[order[1:]]) + xx2 = np.minimum(x2[i], x2[order[1:]]) + yy2 = np.minimum(y2[i], y2[order[1:]]) + + w = np.maximum(0.0, xx2 - xx1 + 1) + h = np.maximum(0.0, yy2 - yy1 + 1) + inter = w * h + ovr = inter / (areas[i] + areas[order[1:]] - inter) + center_x1 = (x1[i] + x2[i]) / 2 + center_x2 = (x1[order[1:]] + x2[order[1:]]) / 2 + center_y1 = (y1[i] + y2[i]) / 2 + center_y2 = (y1[order[1:]] + y2[order[1:]]) / 2 + inter_diag = (center_x2 - center_x1) ** 2 + (center_y2 - center_y1) ** 2 + out_max_x = np.maximum(x2[i], x2[order[1:]]) + out_max_y = np.maximum(y2[i], y2[order[1:]]) + out_min_x = np.minimum(x1[i], x1[order[1:]]) + out_min_y = np.minimum(y1[i], y1[order[1:]]) + outer_diag = (out_max_x - out_min_x) ** 2 + (out_max_y - out_min_y) ** 2 + diou = ovr - inter_diag / outer_diag + diou = np.core.umath.clip(diou, -1, 1) + inds = np.where(diou <= thresh)[0] + order = order[inds + 1] + return keep + + def write_result(self, cur_epoch=0, cur_step=0): + """Save result to file.""" + self.logger.info("Save bbox prediction result.") + if self.eval_parallel: + rank_id = self.rank_id + self.dir_path = os.path.join(self.save_prefix, f"eval_epoch{cur_epoch}-step{cur_step}") + if not os.path.exists(self.dir_path): + os.makedirs(self.dir_path, exist_ok=True) + file_name = f"epoch{cur_epoch}-step{cur_step}-rank{rank_id}.json" + self.file_path = os.path.join(self.dir_path, file_name) + else: + t = datetime.datetime.now().strftime('_%Y_%m_%d_%H_%M_%S') + self.file_path = self.save_prefix + '/predict' + t + '.json' + try: + with open(self.file_path, 'w') as f: + json.dump(self.det_boxes, f) + except IOError as e: + raise RuntimeError("Unable to open json file to dump. What(): {}".format(str(e))) + else: + self.logger.info(f'Result file path: {self.file_path}') + self.det_boxes.clear() + + def get_eval_result(self): + """Get eval result.""" + if self.eval_parallel: + file_paths = [os.path.join(self.dir_path, path) for path in os.listdir(self.dir_path)] + eval_results = self.coco_evaluator.get_mAP(file_paths) + else: + eval_results = self.coco_evaluator.get_mAP(self.file_path) + mAP = self.coco_evaluator.last_mAP + return eval_results, mAP + + def detect(self, outputs, batch, image_shape, image_id): + """Detect boxes.""" + # output [|32, 52, 52, 3, 85| ] + for batch_id in range(batch): + for out_item in outputs: + # 52, 52, 3, 85 + out_item_single = out_item[batch_id, :] + ori_w, ori_h = image_shape[batch_id] + img_id = int(image_id[batch_id]) + if img_id not in self.results: + self.results[img_id] = defaultdict(list) + x = ori_w * out_item_single[..., 0].reshape(-1) + y = ori_h * out_item_single[..., 1].reshape(-1) + w = ori_w * out_item_single[..., 2].reshape(-1) + h = ori_h * out_item_single[..., 3].reshape(-1) + conf = out_item_single[..., 4:5] + cls_emb = out_item_single[..., 5:] + x_top_left = x - w / 2. + y_top_left = y - h / 2. + cls_emb = cls_emb.reshape(-1, self.num_classes) + if self.multi_label: + conf = conf.reshape(-1, 1) + confidence = conf * cls_emb + # create all False + flag = (cls_emb > self.multi_label_thresh) & (confidence >= self.ignore_threshold) + i, j = flag.nonzero() + x_left, y_left = np.maximum(0, x_top_left[i]), np.maximum(0, y_top_left[i]) + w, h = np.minimum(ori_w, w[i]), np.minimum(ori_h, h[i]) + cls_id = np.array(self.coco_catIds)[j] + conf = confidence[i, j] + for (x_i, y_i, w_i, h_i, conf_i, cls_id_i) in zip(x_left, y_left, w, h, conf, cls_id): + self.results[img_id][cls_id_i].append([x_i, y_i, w_i, h_i, conf_i]) + else: + cls_argmax = np.argmax(cls_emb, axis=-1) + # create all False + flag = np.random.random(cls_emb.shape) > sys.maxsize + for i in range(flag.shape[0]): + c = cls_argmax[i] + flag[i, c] = True + confidence = conf.reshape(-1) * cls_emb[flag] + for x_lefti, y_lefti, wi, hi, confi, clsi in zip(x_top_left, y_top_left, + w, h, confidence, cls_argmax): + if confi < self.ignore_threshold: + continue + x_lefti, y_lefti = max(0, x_lefti), max(0, y_lefti) + wi, hi = min(wi, ori_w), min(hi, ori_h) + # transform catId to match coco + coco_clsi = self.coco_catids[clsi] + self.results[img_id][coco_clsi].append([x_lefti, y_lefti, wi, hi, confi]) + + +class AllReduce(nn.Cell): + def __init__(self): + super(AllReduce, self).__init__() + self.all_reduce = ops.AllReduce() + + def construct(self, x): + return self.all_reduce(x) + + +class EvalWrapper: + def __init__(self, config, network, dataset, engine: DetectionEngine) -> None: + self.logger = config.logger + self.network = network + self.dataset = dataset + self.per_batch_size = config.per_batch_size + self.device_num = config.group_size + self.input_shape = Tensor(tuple(config.test_img_shape), mindspore.float32) + self.engine = engine + self.eval_parallel = config.eval_parallel + if config.eval_parallel: + self.reduce = AllReduce() + + def synchronize(self): + sync = Tensor(np.array([1]).astype(np.int32)) + sync = self.reduce(sync) # For synchronization + sync = sync.asnumpy()[0] + if sync != self.device_num: + raise ValueError( + f"Sync value {sync} is not equal to number of device {self.device_num}. " + f"There might be wrong with devices." + ) + + def inference(self): + for index, data in enumerate(self.dataset.create_dict_iterator(output_numpy=True, num_epochs=1)): + image = data["image"] + image = mindspore.Tensor(image) + image_shape_ = data["image_shape"] + image_id_ = data["img_id"] + output_big, output_me, output_small = self.network(image, self.input_shape) + output_big = output_big.asnumpy() + output_me = output_me.asnumpy() + output_small = output_small.asnumpy() + self.engine.detect([output_small, output_me, output_big], self.per_batch_size, image_shape_, image_id_) + + if index % 50 == 0: + self.logger.info('Processing... {:.2f}% '.format(index / self.dataset.get_dataset_size() * 100)) + + def get_results(self, cur_epoch=0, cur_step=0): + self.logger.info('Calculating mAP...') + self.engine.do_nms_for_results() + self.engine.write_result(cur_epoch=cur_epoch, cur_step=cur_step) + if self.eval_parallel: + self.synchronize() # Synchronize to avoid read incomplete results + return self.engine.get_eval_result() diff --git a/community/cv/ADCAM/src/.ipynb_checkpoints/yolo-checkpoint.py b/community/cv/ADCAM/src/.ipynb_checkpoints/yolo-checkpoint.py new file mode 100644 index 0000000000000000000000000000000000000000..885157024ac7160b99b0cd26d8a37c6778ed0abf --- /dev/null +++ b/community/cv/ADCAM/src/.ipynb_checkpoints/yolo-checkpoint.py @@ -0,0 +1,639 @@ +# YOLOv5 based on DarkNet +import numpy as np +import mindspore +import mindspore.nn as nn +import mindspore.ops as ops +import math +from src.backbone import YOLOv5Backbone, Conv, BottleneckCSP,BottleneckCSPWithCA,CAAttention +from src.loss import ConfidenceLoss, ClassLoss + +from model_utils.config import config as default_config + +class YOLO(nn.Cell): + def __init__(self, backbone, shape): + super(YOLO, self).__init__() + self.backbone = backbone + self.config = default_config + self.config.out_channel = (self.config.num_classes + 5) * 3 + + self.conv1 = Conv(shape[5], shape[4], k=1, s=1) + self.CSP5 = BottleneckCSP(shape[5], shape[4], n=1*shape[6], shortcut=False) + self.conv2 = Conv(shape[4], shape[3], k=1, s=1) + self.CSP6 = BottleneckCSP(shape[4], shape[3], n=1*shape[6], shortcut=False) + self.conv3 = Conv(shape[3], shape[3], k=3, s=2) + self.CSP7 = BottleneckCSP(shape[4], shape[4], n=1*shape[6], shortcut=False) + self.conv4 = Conv(shape[4], shape[4], k=3, s=2) + print("************----------********************") + self.CSP8 = BottleneckCSP(shape[5], shape[5], n=1*shape[6], shortcut=False) + print("************----------********************") + + + + self.back_block1 = YoloBlock(shape[3], self.config.out_channel) + self.back_block2 = YoloBlock(shape[4], self.config.out_channel) + self.back_block3 = YoloBlock(shape[5], self.config.out_channel) + + self.pre_back_block1=CAAttention(self.config.out_channel,self.config.out_channel) + self.pre_back_block2=CAAttention(self.config.out_channel,self.config.out_channel) + self.pre_back_block3=CAAttention(self.config.out_channel,self.config.out_channel) + + self.concat = ops.Concat(axis=1) + + def construct(self, x): + """ + input_shape of x is (batch_size, 3, h, w) + feature_map1 is (batch_size, backbone_shape[2], h/8, w/8) + feature_map2 is (batch_size, backbone_shape[3], h/16, w/16) + feature_map3 is (batch_size, backbone_shape[4], h/32, w/32) + """ + img_height = x.shape[2] * 2 + img_width = x.shape[3] * 2 + + feature_map1, feature_map2, feature_map3 = self.backbone(x) + + c1 = self.conv1(feature_map3) + ups1 = ops.ResizeNearestNeighbor((img_height // 16, img_width // 16))(c1) + c2 = self.concat((ups1, feature_map2)) + c3 = self.CSP5(c2) + c4 = self.conv2(c3) + ups2 = ops.ResizeNearestNeighbor((img_height // 8, img_width // 8))(c4) + c5 = self.concat((ups2, feature_map1)) + # out + c6 = self.CSP6(c5) + c7 = self.conv3(c6) + + c8 = self.concat((c7, c4)) + # out + c9 = self.CSP7(c8) + c10 = self.conv4(c9) + c11 = self.concat((c10, c1)) + # out + c12 = self.CSP8(c11) + + c6 = self.back_block1(c6) + c9 = self.back_block2(c9) + c12 = self.back_block3(c12) + + small_object_output=self.pre_back_block1(c6) + medium_object_output=self.pre_back_block2(c9) + big_object_output=self.pre_back_block3(c12) + + # print("c6",c6.shape,"c9",c9.shape,"c12",c12.shape) + return small_object_output, medium_object_output, big_object_output + + +class YoloBlock(nn.Cell): + """ + YoloBlock for YOLOv5. + + Args: + in_channels: Integer. Input channel. + out_channels: Integer. Output channel. + + Returns: + Tuple, tuple of output tensor,(f1,f2,f3). + + Examples: + YoloBlock(12, 255) + + """ + def __init__(self, in_channels, out_channels): + super(YoloBlock, self).__init__() + + self.conv = nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=1, has_bias=True) + + def construct(self, x): + """construct method""" + + out = self.conv(x) + return out + +class DetectionBlock(nn.Cell): + """ + YOLOv5 detection Network. It will finally output the detection result. + + Args: + scale: Character. + config: config, Configuration instance. + is_training: Bool, Whether train or not, default True. + + Returns: + Tuple, tuple of output tensor,(f1,f2,f3). + + Examples: + DetectionBlock(scale='l',stride=32) + """ + + def __init__(self, scale, config=default_config, is_training=True): + super(DetectionBlock, self).__init__() + self.config = config + if scale == 's': + idx = (0, 1, 2) + self.scale_x_y = 1.2 + self.offset_x_y = 0.1 + elif scale == 'm': + idx = (3, 4, 5) + self.scale_x_y = 1.1 + self.offset_x_y = 0.05 + elif scale == 'l': + idx = (6, 7, 8) + self.scale_x_y = 1.05 + self.offset_x_y = 0.025 + else: + raise KeyError("Invalid scale value for DetectionBlock") + self.anchors = mindspore.Tensor([self.config.anchor_scales[i] for i in idx], mindspore.float32) + self.num_anchors_per_scale = 3 + self.num_attrib = 4+1+self.config.num_classes + self.lambda_coord = 1 + + self.sigmoid = nn.Sigmoid() + self.reshape = ops.Reshape() + self.tile = ops.Tile() + self.concat = ops.Concat(axis=-1) + self.pow = ops.Pow() + self.transpose = ops.Transpose() + self.exp = ops.Exp() + self.conf_training = is_training + + def construct(self, x, input_shape): + """construct method""" + num_batch = x.shape[0] + grid_size = x.shape[2:4] + + # Reshape and transpose the feature to [n, grid_size[0], grid_size[1], 3, num_attrib] + prediction = self.reshape(x, (num_batch, + self.num_anchors_per_scale, + self.num_attrib, + grid_size[0], + grid_size[1])) + prediction = self.transpose(prediction, (0, 3, 4, 1, 2)) + + grid_x = mindspore.numpy.arange(grid_size[1]) + grid_y = mindspore.numpy.arange(grid_size[0]) + # Tensor of shape [grid_size[0], grid_size[1], 1, 1] representing the coordinate of x/y axis for each grid + # [batch, gridx, gridy, 1, 1] + grid_x = self.tile(self.reshape(grid_x, (1, 1, -1, 1, 1)), (1, grid_size[0], 1, 1, 1)) + grid_y = self.tile(self.reshape(grid_y, (1, -1, 1, 1, 1)), (1, 1, grid_size[1], 1, 1)) + # Shape is [grid_size[0], grid_size[1], 1, 2] + grid = self.concat((grid_x, grid_y)) + + box_xy = prediction[:, :, :, :, :2] + box_wh = prediction[:, :, :, :, 2:4] + box_confidence = prediction[:, :, :, :, 4:5] + box_probs = prediction[:, :, :, :, 5:] + + # gridsize1 is x + # gridsize0 is y + box_xy = (self.scale_x_y * self.sigmoid(box_xy) - self.offset_x_y + grid) / \ + ops.cast(ops.tuple_to_array((grid_size[1], grid_size[0])), mindspore.float32) + # box_wh is w->h + box_wh = self.exp(box_wh) * self.anchors / input_shape + + box_confidence = self.sigmoid(box_confidence) + box_probs = self.sigmoid(box_probs) + + if self.conf_training: + return prediction, box_xy, box_wh + return self.concat((box_xy, box_wh, box_confidence, box_probs)) + + +class Iou(nn.Cell): + """Calculate the iou of boxes""" + def __init__(self): + super(Iou, self).__init__() + self.min = ops.Minimum() + self.max = ops.Maximum() + self.squeeze = ops.Squeeze(-1) + + def construct(self, box1, box2): + """ + box1: pred_box [batch, gx, gy, anchors, 1, 4] ->4: [x_center, y_center, w, h] + box2: gt_box [batch, 1, 1, 1, maxbox, 4] + convert to topLeft and rightDown + """ + box1_xy = box1[:, :, :, :, :, :2] + box1_wh = box1[:, :, :, :, :, 2:4] + box1_mins = box1_xy - box1_wh / ops.scalar_to_tensor(2.0) # topLeft + box1_maxs = box1_xy + box1_wh / ops.scalar_to_tensor(2.0) # rightDown + + box2_xy = box2[:, :, :, :, :, :2] + box2_wh = box2[:, :, :, :, :, 2:4] + box2_mins = box2_xy - box2_wh / ops.scalar_to_tensor(2.0) + box2_maxs = box2_xy + box2_wh / ops.scalar_to_tensor(2.0) + + intersect_mins = self.max(box1_mins, box2_mins) + intersect_maxs = self.min(box1_maxs, box2_maxs) + intersect_wh = self.max(intersect_maxs - intersect_mins, ops.scalar_to_tensor(0.0)) + # self.squeeze: for effiecient slice + intersect_area = self.squeeze(intersect_wh[:, :, :, :, :, 0:1]) * \ + self.squeeze(intersect_wh[:, :, :, :, :, 1:2]) + box1_area = self.squeeze(box1_wh[:, :, :, :, :, 0:1]) * \ + self.squeeze(box1_wh[:, :, :, :, :, 1:2]) + box2_area = self.squeeze(box2_wh[:, :, :, :, :, 0:1]) * \ + self.squeeze(box2_wh[:, :, :, :, :, 1:2]) + iou = intersect_area / (box1_area + box2_area - intersect_area) + # iou : [batch, gx, gy, anchors, maxboxes] + return iou + + +class YoloLossBlock(nn.Cell): + """ + Loss block cell of YOLOV5 network. + """ + def __init__(self, scale, config=default_config): + super(YoloLossBlock, self).__init__() + self.config = config + if scale == 's': + # anchor mask + idx = (0, 1, 2) + elif scale == 'm': + idx = (3, 4, 5) + elif scale == 'l': + idx = (6, 7, 8) + else: + raise KeyError("Invalid scale value for DetectionBlock") + self.anchors = mindspore.Tensor([self.config.anchor_scales[i] for i in idx], mindspore.float32) + self.ignore_threshold = mindspore.Tensor(self.config.ignore_threshold, mindspore.float32) + self.concat = ops.Concat(axis=-1) + self.iou = Iou() + self.reduce_max = ops.ReduceMax(keep_dims=False) + self.confidence_loss = ConfidenceLoss() + self.class_loss = ClassLoss() + + self.reduce_sum = ops.ReduceSum() + self.select = ops.Select() + self.equal = ops.Equal() + self.reshape = ops.Reshape() + self.expand_dims = ops.ExpandDims() + self.ones_like = ops.OnesLike() + self.log = ops.Log() + self.tuple_to_array = ops.TupleToArray() + #self.g_iou = GIou() + self.g_iou = WIoU() + + def construct(self, prediction, pred_xy, pred_wh, y_true, gt_box, input_shape): + """ + prediction : origin output from yolo + pred_xy: (sigmoid(xy)+grid)/grid_size + pred_wh: (exp(wh)*anchors)/input_shape + y_true : after normalize + gt_box: [batch, maxboxes, xyhw] after normalize + """ + object_mask = y_true[:, :, :, :, 4:5] + class_probs = y_true[:, :, :, :, 5:] + true_boxes = y_true[:, :, :, :, :4] + + grid_shape = prediction.shape[1:3] + grid_shape = ops.cast(self.tuple_to_array(grid_shape[::-1]), mindspore.float32) + + pred_boxes = self.concat((pred_xy, pred_wh)) + true_wh = y_true[:, :, :, :, 2:4] + true_wh = self.select(self.equal(true_wh, 0.0), + self.ones_like(true_wh), + true_wh) + true_wh = self.log(true_wh / self.anchors * input_shape) + # 2-w*h for large picture, use small scale, since small obj need more precise + box_loss_scale = 2 - y_true[:, :, :, :, 2:3] * y_true[:, :, :, :, 3:4] + + gt_shape = gt_box.shape + gt_box = self.reshape(gt_box, (gt_shape[0], 1, 1, 1, gt_shape[1], gt_shape[2])) + + # add one more dimension for broadcast + iou = self.iou(self.expand_dims(pred_boxes, -2), gt_box) + # gt_box is x,y,h,w after normalize + # [batch, grid[0], grid[1], num_anchor, num_gt] + best_iou = self.reduce_max(iou, -1) + # [batch, grid[0], grid[1], num_anchor] + + # ignore_mask IOU too small + ignore_mask = best_iou < self.ignore_threshold + ignore_mask = ops.cast(ignore_mask, mindspore.float32) + ignore_mask = self.expand_dims(ignore_mask, -1) + # ignore_mask backpro will cause a lot maximunGrad and minimumGrad time consume. + # so we turn off its gradient + ignore_mask = ops.stop_gradient(ignore_mask) + + confidence_loss = self.confidence_loss(object_mask, prediction[:, :, :, :, 4:5], ignore_mask) + class_loss = self.class_loss(object_mask, prediction[:, :, :, :, 5:], class_probs) + + object_mask_me = self.reshape(object_mask, (-1, 1)) # [8, 72, 72, 3, 1] + box_loss_scale_me = self.reshape(box_loss_scale, (-1, 1)) + pred_boxes_me = xywh2x1y1x2y2(pred_boxes) + pred_boxes_me = self.reshape(pred_boxes_me, (-1, 4)) + true_boxes_me = xywh2x1y1x2y2(true_boxes) + true_boxes_me = self.reshape(true_boxes_me, (-1, 4)) + c_iou = self.g_iou(pred_boxes_me, true_boxes_me) + c_iou_loss = object_mask_me * box_loss_scale_me * (1 - c_iou) + c_iou_loss_me = self.reduce_sum(c_iou_loss, ()) + loss = c_iou_loss_me * 4 + confidence_loss + class_loss + batch_size = prediction.shape[0] + return loss / batch_size + + +class YOLOV5(nn.Cell): + """ + YOLOV5 network. + + Args: + is_training: Bool. Whether train or not. + + Returns: + Cell, cell instance of YOLOV5 neural network. + + Examples: + YOLOV5s(True) + """ + + def __init__(self, is_training, version=0): + super(YOLOV5, self).__init__() + self.config = default_config + + # YOLOv5 network + self.shape = self.config.input_shape[version] + self.feature_map = YOLO(backbone=YOLOv5Backbone(shape=self.shape), shape=self.shape) + + # prediction on the default anchor boxes + self.detect_1 = DetectionBlock('l', is_training=is_training) + self.detect_2 = DetectionBlock('m', is_training=is_training) + self.detect_3 = DetectionBlock('s', is_training=is_training) + self.mean = mindspore.Tensor(np.array([0.485 * 255, 0.456 * 255, 0.406 * 255], + dtype=np.float32)).reshape((1, 1, 1, 3)) + self.std = mindspore.Tensor(np.array([0.229 * 255, 0.224 * 255, 0.225 * 255], + dtype=np.float32)).reshape((1, 1, 1, 3)) + + def construct(self, x, input_shape): + x = (x - self.mean) / self.std + x = ops.transpose(x, (0, 3, 1, 2)) + x = ops.concat((x[:, :, ::2, ::2], x[:, :, 1::2, ::2], x[:, :, ::2, 1::2], x[:, :, 1::2, 1::2]), 1) + small_object_output, medium_object_output, big_object_output = self.feature_map(x) + output_big = self.detect_1(big_object_output, input_shape) + output_me = self.detect_2(medium_object_output, input_shape) + output_small = self.detect_3(small_object_output, input_shape) + # big is the final output which has smallest feature map + return output_big, output_me, output_small + + +class YOLOV5s_Infer(nn.Cell): + """ + YOLOV5 Infer. + """ + + def __init__(self, input_shape, version=0): + super(YOLOV5s_Infer, self).__init__() + self.network = YOLOV5(is_training=False, version=version) + self.input_shape = input_shape + + def construct(self, x): + return self.network(x, self.input_shape) + + +class YoloWithLossCell(nn.Cell): + """YOLOV5 loss.""" + def __init__(self, network): + super(YoloWithLossCell, self).__init__() + self.yolo_network = network + self.config = default_config + self.loss_big = YoloLossBlock('l', self.config) + self.loss_me = YoloLossBlock('m', self.config) + self.loss_small = YoloLossBlock('s', self.config) + self.tenser_to_array = ops.TupleToArray() + + def construct(self, x, y_true_0, y_true_1, y_true_2, gt_0, gt_1, gt_2, input_shape): + yolo_out = self.yolo_network(x, input_shape) + loss_l = self.loss_big(*yolo_out[0], y_true_0, gt_0, input_shape) + loss_m = self.loss_me(*yolo_out[1], y_true_1, gt_1, input_shape) + loss_s = self.loss_small(*yolo_out[2], y_true_2, gt_2, input_shape) + return loss_l + loss_m + loss_s * 0.2 + + +class GIou(nn.Cell): + """Calculating giou""" + def __init__(self): + super(GIou, self).__init__() + self.reshape = ops.Reshape() + self.min = ops.Minimum() + self.max = ops.Maximum() + self.concat = ops.Concat(axis=1) + self.mean = ops.ReduceMean() + self.div = ops.RealDiv() + self.eps = 0.000001 + + def construct(self, box_p, box_gt): + print("*******************************************GIOU**********************************************************") + """construct method""" + box_p_area = (box_p[..., 2:3] - box_p[..., 0:1]) * (box_p[..., 3:4] - box_p[..., 1:2]) + box_gt_area = (box_gt[..., 2:3] - box_gt[..., 0:1]) * (box_gt[..., 3:4] - box_gt[..., 1:2]) + x_1 = self.max(box_p[..., 0:1], box_gt[..., 0:1]) + x_2 = self.min(box_p[..., 2:3], box_gt[..., 2:3]) + y_1 = self.max(box_p[..., 1:2], box_gt[..., 1:2]) + y_2 = self.min(box_p[..., 3:4], box_gt[..., 3:4]) + intersection = (y_2 - y_1) * (x_2 - x_1) + xc_1 = self.min(box_p[..., 0:1], box_gt[..., 0:1]) + xc_2 = self.max(box_p[..., 2:3], box_gt[..., 2:3]) + yc_1 = self.min(box_p[..., 1:2], box_gt[..., 1:2]) + yc_2 = self.max(box_p[..., 3:4], box_gt[..., 3:4]) + c_area = (xc_2 - xc_1) * (yc_2 - yc_1) + union = box_p_area + box_gt_area - intersection + union = union + self.eps + c_area = c_area + self.eps + iou = self.div(ops.cast(intersection, mindspore.float32), ops.cast(union, mindspore.float32)) + res_mid0 = c_area - union + res_mid1 = self.div(ops.cast(res_mid0, mindspore.float32), ops.cast(c_area, mindspore.float32)) + giou = iou - res_mid1 + giou = ops.clip_by_value(giou, -1.0, 1.0) + return giou + + +class CIou(nn.Cell): + """Calculating CIoU loss.""" + def __init__(self): + super(CIou, self).__init__() + self.min = ops.Minimum() + self.max = ops.Maximum() + self.clip = ops.clip_by_value + self.atan = ops.Atan() + self.stop_gradient = ops.stop_gradient + self.eps = 1e-6 + + def construct(self, box_p, box_gt): + """Construct method to compute CIoU.""" + # 计算预测框和真实框的面积 + box_p_area = (box_p[..., 2] - box_p[..., 0]) * (box_p[..., 3] - box_p[..., 1]) + box_gt_area = (box_gt[..., 2] - box_gt[..., 0]) * (box_gt[..., 3] - box_gt[..., 1]) + + # 计算交集的坐标 + x1 = self.max(box_p[..., 0], box_gt[..., 0]) + y1 = self.max(box_p[..., 1], box_gt[..., 1]) + x2 = self.min(box_p[..., 2], box_gt[..., 2]) + y2 = self.min(box_p[..., 3], box_gt[..., 3]) + + # 计算交集的宽度和高度,并裁剪为非负值 + inter_w = self.clip(x2 - x1, 0.0, None) + inter_h = self.clip(y2 - y1, 0.0, None) + intersection = inter_w * inter_h + + # 计算并集的面积 + union = box_p_area + box_gt_area - intersection + self.eps + + # 计算IoU + iou = intersection / union + + # 计算预测框和真实框的中心点 + box_p_center_x = (box_p[..., 0] + box_p[..., 2]) / 2 + box_p_center_y = (box_p[..., 1] + box_p[..., 3]) / 2 + box_gt_center_x = (box_gt[..., 0] + box_gt[..., 2]) / 2 + box_gt_center_y = (box_gt[..., 1] + box_gt[..., 3]) / 2 + + # 计算中心点之间的欧氏距离的平方 + center_dist = (box_p_center_x - box_gt_center_x) ** 2 + (box_p_center_y - box_gt_center_y) ** 2 + + # 计算最小包络框的对角线长度的平方 + enclose_x1 = self.min(box_p[..., 0], box_gt[..., 0]) + enclose_y1 = self.min(box_p[..., 1], box_gt[..., 1]) + enclose_x2 = self.max(box_p[..., 2], box_gt[..., 2]) + enclose_y2 = self.max(box_p[..., 3], box_gt[..., 3]) + enclose_diag = (enclose_x2 - enclose_x1) ** 2 + (enclose_y2 - enclose_y1) ** 2 + self.eps + + # 计算距离惩罚项 + distance_term = center_dist / enclose_diag + + # 计算宽高比惩罚项 + # 预测框和真实框的宽度和高度 + box_p_w = box_p[..., 2] - box_p[..., 0] + self.eps + box_p_h = box_p[..., 3] - box_p[..., 1] + self.eps + box_gt_w = box_gt[..., 2] - box_gt[..., 0] + self.eps + box_gt_h = box_gt[..., 3] - box_gt[..., 1] + self.eps + + # 计算v项(宽高比相似度) + v = (4 / (math.pi ** 2)) * (self.atan(box_gt_w / box_gt_h) - self.atan(box_p_w / box_p_h)) ** 2 + + # 计算α项,并停止梯度传播 + with ops.stop_gradient(): + S = 1 - iou + v + self.eps + alpha = v / S + + # 计算CIoU + ciou = iou - (distance_term + alpha * v) + + # 将CIoU裁剪到[-1, 1]之间 + ciou = self.clip(ciou, -1.0, 1.0) + + return ciou + +def xywh2x1y1x2y2(box_xywh): + boxes_x1 = box_xywh[..., 0:1] - box_xywh[..., 2:3] / 2 + boxes_y1 = box_xywh[..., 1:2] - box_xywh[..., 3:4] / 2 + boxes_x2 = box_xywh[..., 0:1] + box_xywh[..., 2:3] / 2 + boxes_y2 = box_xywh[..., 1:2] + box_xywh[..., 3:4] / 2 + boxes_x1y1x2y2 = ops.Concat(-1)((boxes_x1, boxes_y1, boxes_x2, boxes_y2)) + + return boxes_x1y1x2y2 + +from mindspore import nn, ops, Tensor +import mindspore.numpy as mnp +class WIoU(nn.Cell): + """Calculating WIoU""" + def __init__(self): + super(WIoU, self).__init__() + self.reshape = ops.Reshape() + self.min = ops.Minimum() + self.max = ops.Maximum() + self.concat = ops.Concat(axis=1) + self.mean = ops.ReduceMean() + self.div = ops.RealDiv() + self.eps = 0.000001 + + def construct(self, box_p, box_gt): + # print("*******************************************WIoU**********************************************************") + """construct method""" + # 计算预测框和真实框的面积 + box_p_area = (box_p[..., 2:3] - box_p[..., 0:1]) * (box_p[..., 3:4] - box_p[..., 1:2]) + box_gt_area = (box_gt[..., 2:3] - box_gt[..., 0:1]) * (box_gt[..., 3:4] - box_gt[..., 1:2]) + + # 计算交集坐标 + x_1 = self.max(box_p[..., 0:1], box_gt[..., 0:1]) + y_1 = self.max(box_p[..., 1:2], box_gt[..., 1:2]) + x_2 = self.min(box_p[..., 2:3], box_gt[..., 2:3]) + y_2 = self.min(box_p[..., 3:4], box_gt[..., 3:4]) + + # 计算交集面积 + intersection = (x_2 - x_1).clip(0, None) * (y_2 - y_1).clip(0, None) + + # 计算并集面积 + union = box_p_area + box_gt_area - intersection + self.eps + + # 计算IoU + iou = self.div(ops.cast(intersection, mindspore.float32), ops.cast(union, mindspore.float32)) + + # 计算中心点坐标 + x_p_center = (box_p[..., 0:1] + box_p[..., 2:3]) / 2 + y_p_center = (box_p[..., 1:2] + box_p[..., 3:4]) / 2 + x_gt_center = (box_gt[..., 0:1] + box_gt[..., 2:3]) / 2 + y_gt_center = (box_gt[..., 1:2] + box_gt[..., 3:4]) / 2 + + # 计算中心点之间的距离平方 + rho2 = (x_p_center - x_gt_center) ** 2 + (y_p_center - y_gt_center) ** 2 + + # 计算最小包络框的对角线长度平方 + xc_1 = self.min(box_p[..., 0:1], box_gt[..., 0:1]) + yc_1 = self.min(box_p[..., 1:2], box_gt[..., 1:2]) + xc_2 = self.max(box_p[..., 2:3], box_gt[..., 2:3]) + yc_2 = self.max(box_p[..., 3:4], box_gt[..., 3:4]) + c2 = (xc_2 - xc_1) ** 2 + (yc_2 - yc_1) ** 2 + self.eps + + # 计算WIoU + wiou = iou - self.div(ops.cast(rho2, mindspore.float32), ops.cast(c2, mindspore.float32)) + wiou = ops.clip_by_value(wiou, -1.0, 1.0) + return wiou + + + + +def ciou(boxes1,boxes2): + ''' + cal CIOU of two boxes or batch boxes + :param boxes1:[xmin,ymin,xmax,ymax] or + [[xmin,ymin,xmax,ymax],[xmin,ymin,xmax,ymax],...] + :param boxes2:[xmin,ymin,xmax,ymax] + :return: + ''' + + #cal the box's area of boxes1 and boxess + boxes1Area = (boxes1[...,2]-boxes1[...,0])*(boxes1[...,3]-boxes1[...,1]) + boxes2Area = (boxes2[..., 2] - boxes2[..., 0]) * (boxes2[..., 3] - boxes2[..., 1]) + + # cal Intersection + left_up = np.maximum(boxes1[...,:2],boxes2[...,:2]) + right_down = np.minimum(boxes1[...,2:],boxes2[...,2:]) + + inter_section = np.maximum(right_down-left_up,0.0) + inter_area = inter_section[...,0] * inter_section[...,1] + union_area = boxes1Area+boxes2Area-inter_area + ious = np.maximum(1.0*inter_area/union_area,np.finfo(np.float32).eps) + + # cal outer boxes + outer_left_up = np.minimum(boxes1[..., :2], boxes2[..., :2]) + outer_right_down = np.maximum(boxes1[..., 2:], boxes2[..., 2:]) + outer = np.maximum(outer_right_down - outer_left_up, 0.0) + outer_diagonal_line = np.square(outer[...,0]) + np.square(outer[...,1]) + + # cal center distance + boxes1_center = (boxes1[..., :2] + boxes1[...,2:]) * 0.5 + boxes2_center = (boxes2[..., :2] + boxes2[...,2:]) * 0.5 + center_dis = np.square(boxes1_center[...,0]-boxes2_center[...,0]) +\ + np.square(boxes1_center[...,1]-boxes2_center[...,1]) + + # cal penalty term + # cal width,height + boxes1_size = np.maximum(boxes1[...,2:]-boxes1[...,:2],0.0) + boxes2_size = np.maximum(boxes2[..., 2:] - boxes2[..., :2], 0.0) + v = (4.0/np.square(np.pi)) * np.square(( + np.arctan((boxes1_size[...,0]/boxes1_size[...,1])) - + np.arctan((boxes2_size[..., 0] / boxes2_size[..., 1])) )) + alpha = v / (1-ious+v) + #cal ciou + cious = ious - (center_dis / outer_diagonal_line + alpha*v) + + return cious + + diff --git a/community/cv/ADCAM/src/__init__.py b/community/cv/ADCAM/src/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/community/cv/ADCAM/src/__init__.py @@ -0,0 +1 @@ + diff --git a/community/cv/ADCAM/src/backbone.py b/community/cv/ADCAM/src/backbone.py new file mode 100644 index 0000000000000000000000000000000000000000..d1c59cf98c2c12b9224491d6f5432521d7fb1b9d --- /dev/null +++ b/community/cv/ADCAM/src/backbone.py @@ -0,0 +1,254 @@ +# DarkNet model +import mindspore.nn as nn +import mindspore.ops as ops + +############################修改################################# + +class CAAttention(nn.Cell): + def __init__(self, inp, oup, groups=32,act=True): + super(CAAttention, self).__init__() + mip = max(8, inp // groups) + + self.conv1 = nn.Conv2d(inp, mip, kernel_size=1, stride=1, padding=0, has_bias=True) + self.bn1 = nn.BatchNorm2d(mip) + self.conv2 = nn.Conv2d(mip, oup, kernel_size=1, stride=1, padding=0, has_bias=True) + self.conv3 = nn.Conv2d(mip, oup, kernel_size=1, stride=1, padding=0, has_bias=True) + self.relu = SiLU() if act is True else ( + act if isinstance(act, nn.Cell) else ops.Identity()) + + # 定义需要的操作 + self.mean = ops.ReduceMean(keep_dims=True) + self.concat = ops.Concat(axis=2) + self.transpose = ops.Transpose() + self.sigmoid = ops.Sigmoid() + self.tile = ops.Tile() + + def construct(self, x): + identity = x + n, c, h, w = x.shape + + # 沿宽度方向求平均,结果维度为 (n, c, h, 1) + x_h = self.mean(x, 3) + # 沿高度方向求平均,结果维度为 (n, c, 1, w) + x_w = self.mean(x, 2) + x_w = self.transpose(x_w, (0, 1, 3, 2)) + + # 在高度维度上拼接 + y = self.concat((x_h, x_w)) + + y = self.conv1(y) + y = self.bn1(y) + y = self.relu(y) + + # 分割回 x_h 和 x_w + x_h, x_w = y[:, :, :h, :], y[:, :, h:, :] + + # 转置 x_w 回原来的维度 + x_w = self.transpose(x_w, (0, 1, 3, 2)) + + x_h = self.sigmoid(self.conv2(x_h)) + x_w = self.sigmoid(self.conv3(x_w)) + + # 扩展 x_h 和 x_w 以匹配输入的形状 + x_h = self.tile(x_h, (1, 1, 1, w)) + x_w = self.tile(x_w, (1, 1, h, 1)) + + # 加权输入 + y = identity * x_h * x_w + #print('99969966666666666666666666666666666666666666666666') + return y+identity + +# if __name__ == '__main__': +# from mindspore import context +# context.set_context(mode=context.PYNATIVE_MODE) +# x = Tensor(np.random.randn(1, 256, 64, 64), mindspore.float32) +# coordatt = CAAttention(256, 256) +# y = coordatt(x) +# print("输入代码的shape为:", x.shape, "输出代码的shape为:", y.shape) + + + +###########################END################################### +class Bottleneck(nn.Cell): + # Standard bottleneck + # ch_in, ch_out, shortcut, groups, expansion + def __init__(self, c1, c2, shortcut=True, e=0.5): + super(Bottleneck, self).__init__() + c_ = int(c2 * e) # hidden channels + self.conv1 = Conv(c1, c_, 1, 1) + self.conv2 = Conv(c_, c2, 3, 1) + self.add = shortcut and c1 == c2 + + def construct(self, x): + c1 = self.conv1(x) + c2 = self.conv2(c1) + out = c2 + if self.add: + out = x + out + return out + + +class BottleneckCSP(nn.Cell): + # CSP Bottleneck with 3 convolutions + def __init__(self, c1, c2, n=1, shortcut=True, e=0.5): + super(BottleneckCSP, self).__init__() + c_ = int(c2 * e) # hidden channels + self.conv1 = Conv(c1, c_, 1, 1) + self.conv2 = Conv(c1, c_, 1, 1) + self.conv3 = Conv(2 * c_, c2, 1) # act=FReLU(c2) + self.m = nn.SequentialCell( + [Bottleneck(c_, c_, shortcut, e=1.0) for _ in range(n)]) + self.concat = ops.Concat(axis=1) + + + + def construct(self, x): + c1 = self.conv1(x) + c2 = self.m(c1) + c3 = self.conv2(x) + c4 = self.concat((c2, c3)) + c5 = self.conv3(c4) + return c5 + + +class BottleneckCSPWithCA(nn.Cell): + # CSP Bottleneck with 3 convolutions + def __init__(self, c1, c2, n=1, shortcut=True, e=0.5): + super(BottleneckCSPWithCA, self).__init__() + print("BottleneckCSPWithCA........","c1===", c1, "c2===", c2) + c_ = int(c2 * e) # hidden channels + self.conv1 = Conv(c1, c_, 1, 1) + self.conv2 = Conv(c1, c_, 1, 1) + self.conv3 = Conv(2 * c_, c2, 1) # act=FReLU(c2) + self.m = nn.SequentialCell( + [Bottleneck(c_, c_, shortcut, e=1.0) for _ in range(n)]) + self.concat = ops.Concat(axis=1) + self.coordatt=CAAttention(c1,c2) + + + + def construct(self, x): + c1 = self.conv1(x) + c2 = self.m(c1) + c3 = self.conv2(x) + c4 = self.concat((c2, c3)) + c5 = self.conv3(c4) + #print("输入代码的shape为:", x.shape, "输出代码的shape为:", c5.shape) + # c6=self.coordatt(c5) + # print("dalaohu dalaohu") + # c6=self.coordatt(c5) + return c6 + +class SPP(nn.Cell): + # Spatial pyramid pooling layer used in YOLOv3-SPP + def __init__(self, c1, c2, k=(5, 9, 13)): + super(SPP, self).__init__() + c_ = c1 // 2 # hidden channels + self.conv1 = Conv(c1, c_, 1, 1) + self.conv2 = Conv(c_ * (len(k) + 1), c2, 1, 1) + + self.maxpool1 = nn.MaxPool2d(kernel_size=5, stride=1, pad_mode='same') + self.maxpool2 = nn.MaxPool2d(kernel_size=9, stride=1, pad_mode='same') + self.maxpool3 = nn.MaxPool2d(kernel_size=13, stride=1, pad_mode='same') + self.concat = ops.Concat(axis=1) + + def construct(self, x): + c1 = self.conv1(x) + m1 = self.maxpool1(c1) + m2 = self.maxpool2(c1) + m3 = self.maxpool3(c1) + c4 = self.concat((c1, m1, m2, m3)) + c5 = self.conv2(c4) + return c5 + + +class Focus(nn.Cell): + # Focus wh information into c-space + def __init__(self, c1, c2, k=1, s=1, p=None, act=True): + super(Focus, self).__init__() + self.conv = Conv(c1 * 4, c2, k, s, p, act) + + def construct(self, x): + c1 = self.conv(x) + return c1 + + +class SiLU(nn.Cell): + def __init__(self): + super(SiLU, self).__init__() + self.sigmoid = ops.Sigmoid() + + def construct(self, x): + return x * self.sigmoid(x) + + +def auto_pad(k, p=None): # kernel, padding + # Pad to 'same' + if p is None: + p = k // 2 if isinstance(k, int) else [x // 2 for x in k] # auto-pad + return p + + +class Conv(nn.Cell): + # Standard convolution + def __init__(self, c1, c2, k=1, s=1, p=None, + dilation=1, + alpha=0.1, + momentum=0.97, + eps=1e-3, + pad_mode="same", + act=True): # ch_in, ch_out, kernel, stride, padding + super(Conv, self).__init__() + self.padding = auto_pad(k, p) + self.pad_mode = None + if self.padding == 0: + self.pad_mode = 'same' + elif self.padding == 1: + self.pad_mode = 'pad' + self.conv = nn.Conv2d( + c1, + c2, + k, + s, + padding=self.padding, + pad_mode=self.pad_mode, + has_bias=False) + self.bn = nn.BatchNorm2d(c2, momentum=momentum, eps=eps) + self.act = SiLU() if act is True else ( + act if isinstance(act, nn.Cell) else ops.Identity()) + + def construct(self, x): + return self.act(self.bn(self.conv(x))) + + +class YOLOv5Backbone(nn.Cell): + def __init__(self, shape): + super(YOLOv5Backbone, self).__init__() + self.focus = Focus(shape[0], shape[1], k=3, s=1) + self.conv1 = Conv(shape[1], shape[2], k=3, s=2) + self.CSP1 = BottleneckCSP(shape[2], shape[2], n=1 * shape[6]) + self.conv2 = Conv(shape[2], shape[3], k=3, s=2) + self.CSP2 = BottleneckCSP(shape[3], shape[3], n=3 * shape[6]) + self.conv3 = Conv(shape[3], shape[4], k=3, s=2) + self.CSP3 = BottleneckCSP(shape[4], shape[4], n=3 * shape[6]) + self.conv4 = Conv(shape[4], shape[5], k=3, s=2) + self.spp = SPP(shape[5], shape[5], k=[5, 9, 13]) + self.CSP4 = BottleneckCSP(shape[5], shape[5], n=1 * shape[6], shortcut=False) + + def construct(self, x): + """construct method""" + c1 = self.focus(x) + c2 = self.conv1(c1) + c3 = self.CSP1(c2) + c4 = self.conv2(c3) + # out + c5 = self.CSP2(c4) + c6 = self.conv3(c5) + # out + c7 = self.CSP3(c6) + c8 = self.conv4(c7) + c9 = self.spp(c8) + # out + c10 = self.CSP4(c9) + + return c5, c7, c10 diff --git a/community/cv/ADCAM/src/distributed_sampler.py b/community/cv/ADCAM/src/distributed_sampler.py new file mode 100644 index 0000000000000000000000000000000000000000..52f41b6905cccf008d608fbf9f81417cd8a7de3e --- /dev/null +++ b/community/cv/ADCAM/src/distributed_sampler.py @@ -0,0 +1,48 @@ +# Yolo dataset distributed sampler +from __future__ import division +import math +import numpy as np + + +class DistributedSampler: + """Distributed sampler.""" + + def __init__(self, dataset_size, num_replicas=None, rank=None, shuffle=True): + if num_replicas is None: + print("***********Setting world_size to 1 since it is not passed in ******************") + num_replicas = 1 + if rank is None: + print("***********Setting rank to 0 since it is not passed in ******************") + rank = 0 + self.dataset_size = dataset_size + self.num_replicas = num_replicas + self.rank = rank + self.epoch = 0 + self.num_samples = int(math.ceil(dataset_size * 1.0 / self.num_replicas)) + self.total_size = self.num_samples * self.num_replicas + self.shuffle = shuffle + + def __iter__(self): + # deterministically shuffle based on epoch + if self.shuffle: + indices = np.random.RandomState(seed=self.epoch).permutation(self.dataset_size) + # np.array type. number from 0 to len(dataset_size)-1, used as + # index of dataset + indices = indices.tolist() + self.epoch += 1 + # change to list type + else: + indices = list(range(self.dataset_size)) + + # add extra samples to make it evenly divisible + indices += indices[:(self.total_size - len(indices))] + assert len(indices) == self.total_size + + # subsample + indices = indices[self.rank:self.total_size:self.num_replicas] + assert len(indices) == self.num_samples + + return iter(indices) + + def __len__(self): + return self.num_samples diff --git a/community/cv/ADCAM/src/initializer.py b/community/cv/ADCAM/src/initializer.py new file mode 100644 index 0000000000000000000000000000000000000000..72a98864b3e235969a6139dc047477ffbb68d410 --- /dev/null +++ b/community/cv/ADCAM/src/initializer.py @@ -0,0 +1,69 @@ +# 参数初始化 +import math +import mindspore +from mindspore import nn + + +def default_recurisive_init(custom_cell): + """Initialize parameter.""" + for _, cell in custom_cell.cells_and_names(): + if isinstance(cell, (nn.Conv2d, nn.Dense)): + cell.weight.set_data(mindspore.common.initializer.initializer(mindspore.common.initializer.HeUniform(math.sqrt(5)), + cell.weight.shape, cell.weight.dtype)) + + +def load_yolov5_params(args, network): + """Load yolov5 backbone parameter from checkpoint.""" + if args.resume_yolov5: + param_dict = mindspore.load_checkpoint(args.resume_yolov5) + param_dict_new = {} + for key, values in param_dict.items(): + if key.startswith('moments.'): + continue + elif key.startswith('yolo_network.'): + param_dict_new[key[13:]] = values + args.logger.info('in resume {}'.format(key)) + else: + param_dict_new[key] = values + args.logger.info('in resume {}'.format(key)) + + args.logger.info('resume finished') + mindspore.load_param_into_net(network, param_dict_new) + args.logger.info('load_model {} success'.format(args.resume_yolov5)) + + if args.pretrained_checkpoint: + param_dict = mindspore.load_checkpoint(args.pretrained_checkpoint) + param_dict_new = {} + for key, values in param_dict.items(): + if key.startswith('moments.'): + continue + elif key.startswith('yolo_network.') and key[13:] in args.checkpoint_filter_list: + args.logger.info('remove {}'.format(key)) + continue + elif key.startswith('yolo_network.'): + param_dict_new[key[13:]] = values + args.logger.info('in load {}'.format(key)) + else: + param_dict_new[key] = values + args.logger.info('in load {}'.format(key)) + + args.logger.info('pretrained finished') + mindspore.load_param_into_net(network, param_dict_new) + args.logger.info('load_model {} success'.format(args.pretrained_backbone)) + + if args.pretrained_backbone: + param_dict = mindspore.load_checkpoint(args.pretrained_backbone) + param_dict_new = {} + for key, values in param_dict.items(): + if key.startswith('moments.'): + continue + elif key.startswith('yolo_network.'): + param_dict_new[key[13:]] = values + args.logger.info('in resume {}'.format(key)) + else: + param_dict_new[key] = values + args.logger.info('in resume {}'.format(key)) + + args.logger.info('pretrained finished') + mindspore.load_param_into_net(network, param_dict_new) + args.logger.info('load_model {} success'.format(args.pretrained_backbone)) diff --git a/community/cv/ADCAM/src/logger.py b/community/cv/ADCAM/src/logger.py new file mode 100644 index 0000000000000000000000000000000000000000..8e9a5fd7a9315fddd005b6d20238bda49e022579 --- /dev/null +++ b/community/cv/ADCAM/src/logger.py @@ -0,0 +1,67 @@ +# 创建一个自定义的日志记录器(Logger) +import os +import sys +import logging +from datetime import datetime + + +class LOGGER(logging.Logger): + """ + Logger. + + Args: + logger_name: String. Logger name. + rank: Integer. Rank id. + """ + + def __init__(self, logger_name, rank=0): + super(LOGGER, self).__init__(logger_name) + self.rank = rank + if rank % 8 == 0: + console = logging.StreamHandler(sys.stdout) + console.setLevel(logging.INFO) + formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(message)s') + console.setFormatter(formatter) + self.addHandler(console) + + def setup_logging_file(self, log_dir, rank=0): + """Setup logging file.""" + self.rank = rank + if not os.path.exists(log_dir): + os.makedirs(log_dir, exist_ok=True) + log_name = datetime.now().strftime('%Y-%m-%d_time_%H_%M_%S') + '_rank_{}.log'.format(rank) + self.log_fn = os.path.join(log_dir, log_name) + fh = logging.FileHandler(self.log_fn) + fh.setLevel(logging.INFO) + formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(message)s') + fh.setFormatter(formatter) + self.addHandler(fh) + + def info(self, msg, *args, **kwargs): + if self.isEnabledFor(logging.INFO): + self._log(logging.INFO, msg, args, **kwargs) + + def save_args(self, args): + self.info('Args:') + args_dict = vars(args) + for key in args_dict.keys(): + self.info('--> %s: %s', key, args_dict[key]) + self.info('') + + def important_info(self, msg, *args, **kwargs): + if self.isEnabledFor(logging.INFO) and self.rank == 0: + line_width = 2 + important_msg = '\n' + important_msg += ('*' * 70 + '\n') * line_width + important_msg += ('*' * line_width + '\n') * 2 + important_msg += '*' * line_width + ' ' * 8 + msg + '\n' + important_msg += ('*' * line_width + '\n') * 2 + important_msg += ('*' * 70 + '\n') * line_width + self.info(important_msg, *args, **kwargs) + + +def get_logger(path, rank): + """Get Logger.""" + logger = LOGGER('YOLOV5', rank) + logger.setup_logging_file(path, rank) + return logger diff --git a/community/cv/ADCAM/src/loss.py b/community/cv/ADCAM/src/loss.py new file mode 100644 index 0000000000000000000000000000000000000000..d7b923e7c6cd1333a424a324f9c7765795e1a43a --- /dev/null +++ b/community/cv/ADCAM/src/loss.py @@ -0,0 +1,32 @@ +# YOLOV5的loss函数,改为wiou +import mindspore.ops as ops +import mindspore.nn as nn + + +class ConfidenceLoss(nn.Cell): + """Loss for confidence.""" + + def __init__(self): + super(ConfidenceLoss, self).__init__() + self.cross_entropy = ops.SigmoidCrossEntropyWithLogits() + self.reduce_sum = ops.ReduceSum() + + def construct(self, object_mask, predict_confidence, ignore_mask): + confidence_loss = self.cross_entropy(predict_confidence, object_mask) + confidence_loss = object_mask * confidence_loss + (1 - object_mask) * confidence_loss * ignore_mask + confidence_loss = self.reduce_sum(confidence_loss, ()) + return confidence_loss + + +class ClassLoss(nn.Cell): + """Loss for classification.""" + + def __init__(self): + super(ClassLoss, self).__init__() + self.cross_entropy = ops.SigmoidCrossEntropyWithLogits() + self.reduce_sum = ops.ReduceSum() + + def construct(self, object_mask, predict_class, class_probs): + class_loss = object_mask * self.cross_entropy(predict_class, class_probs) + class_loss = self.reduce_sum(class_loss, ()) + return class_loss diff --git a/community/cv/ADCAM/src/lr_scheduler.py b/community/cv/ADCAM/src/lr_scheduler.py new file mode 100644 index 0000000000000000000000000000000000000000..dad12e2ef79ab7adce80952f7714d619d010d480 --- /dev/null +++ b/community/cv/ADCAM/src/lr_scheduler.py @@ -0,0 +1,149 @@ +# Learning rate scheduler +import math +from collections import Counter + +import numpy as np + + +def linear_warmup_lr(current_step, warmup_steps, base_lr, init_lr): + """Linear learning rate.""" + lr_inc = (float(base_lr) - float(init_lr)) / float(warmup_steps) + lr = float(init_lr) + lr_inc * current_step + return lr + + +def warmup_step_lr(lr, lr_epochs, steps_per_epoch, warmup_epochs, max_epoch, gamma=0.1): + """Warmup step learning rate.""" + base_lr = lr + warmup_init_lr = 0 + total_steps = int(max_epoch * steps_per_epoch) + warmup_steps = int(warmup_epochs * steps_per_epoch) + milestones = lr_epochs + milestones_steps = [] + for milestone in milestones: + milestones_step = milestone * steps_per_epoch + milestones_steps.append(milestones_step) + + lr_each_step = [] + lr = base_lr + milestones_steps_counter = Counter(milestones_steps) + for i in range(total_steps): + if i < warmup_steps: + lr = linear_warmup_lr(i + 1, warmup_steps, base_lr, warmup_init_lr) + else: + lr = lr * gamma**milestones_steps_counter[i] + lr_each_step.append(lr) + + return np.array(lr_each_step).astype(np.float32) + + +def multi_step_lr(lr, milestones, steps_per_epoch, max_epoch, gamma=0.1): + return warmup_step_lr(lr, milestones, steps_per_epoch, 0, max_epoch, gamma=gamma) + + +def step_lr(lr, epoch_size, steps_per_epoch, max_epoch, gamma=0.1): + lr_epochs = [] + for i in range(1, max_epoch): + if i % epoch_size == 0: + lr_epochs.append(i) + return multi_step_lr(lr, lr_epochs, steps_per_epoch, max_epoch, gamma=gamma) + + +def warmup_cosine_annealing_lr(lr, steps_per_epoch, warmup_epochs, max_epoch, T_max, eta_min=0): + """Cosine annealing learning rate.""" + base_lr = lr + warmup_init_lr = 0 + total_steps = int(max_epoch * steps_per_epoch) + warmup_steps = int(warmup_epochs * steps_per_epoch) + + lr_each_step = [] + for i in range(total_steps): + last_epoch = i // steps_per_epoch + if i < warmup_steps: + lr = linear_warmup_lr(i + 1, warmup_steps, base_lr, warmup_init_lr) + else: + lr = eta_min + (base_lr - eta_min) * (1. + math.cos(math.pi * last_epoch / T_max)) / 2 + lr_each_step.append(lr) + + return np.array(lr_each_step).astype(np.float32) + + +def warmup_cosine_annealing_lr_V2(lr, steps_per_epoch, warmup_epochs, max_epoch, T_max, eta_min=0): + """Cosine annealing learning rate V2.""" + base_lr = lr + warmup_init_lr = 0 + total_steps = int(max_epoch * steps_per_epoch) + warmup_steps = int(warmup_epochs * steps_per_epoch) + + last_lr = 0 + last_epoch_V1 = 0 + + T_max_V2 = int(max_epoch * 1 / 3) + + lr_each_step = [] + for i in range(total_steps): + last_epoch = i // steps_per_epoch + if i < warmup_steps: + lr = linear_warmup_lr(i + 1, warmup_steps, base_lr, warmup_init_lr) + else: + if i < total_steps * 2 / 3: + lr = eta_min + (base_lr - eta_min) * (1. + math.cos(math.pi * last_epoch / T_max)) / 2 + last_lr = lr + last_epoch_V1 = last_epoch + else: + base_lr = last_lr + last_epoch = last_epoch - last_epoch_V1 + lr = eta_min + (base_lr - eta_min) * (1. + math.cos(math.pi * last_epoch / T_max_V2)) / 2 + + lr_each_step.append(lr) + return np.array(lr_each_step).astype(np.float32) + + +def warmup_cosine_annealing_lr_sample(lr, steps_per_epoch, warmup_epochs, max_epoch, T_max, eta_min=0): + """Warmup cosine annealing learning rate.""" + start_sample_epoch = 60 + step_sample = 2 + tobe_sampled_epoch = 60 + end_sampled_epoch = start_sample_epoch + step_sample * tobe_sampled_epoch + max_sampled_epoch = max_epoch + tobe_sampled_epoch + T_max = max_sampled_epoch + + base_lr = lr + warmup_init_lr = 0 + total_steps = int(max_epoch * steps_per_epoch) + total_sampled_steps = int(max_sampled_epoch * steps_per_epoch) + warmup_steps = int(warmup_epochs * steps_per_epoch) + + lr_each_step = [] + + for i in range(total_sampled_steps): + last_epoch = i // steps_per_epoch + if last_epoch in range(start_sample_epoch, end_sampled_epoch, step_sample): + continue + if i < warmup_steps: + lr = linear_warmup_lr(i + 1, warmup_steps, base_lr, warmup_init_lr) + else: + lr = eta_min + (base_lr - eta_min) * (1. + math.cos(math.pi * last_epoch / T_max)) / 2 + lr_each_step.append(lr) + + assert total_steps == len(lr_each_step) + return np.array(lr_each_step).astype(np.float32) + + +def get_lr(args, steps_per_epoch): + """generate learning rate.""" + if args.lr_scheduler == 'exponential': + lr = warmup_step_lr(args.lr, args.lr_epochs, steps_per_epoch, args.warmup_epochs, args.max_epoch, + gamma=args.lr_gamma) + elif args.lr_scheduler == 'cosine_annealing': + lr = warmup_cosine_annealing_lr(args.lr, steps_per_epoch, args.warmup_epochs, + args.max_epoch, args.T_max, args.eta_min) + elif args.lr_scheduler == 'cosine_annealing_V2': + lr = warmup_cosine_annealing_lr_V2(args.lr, steps_per_epoch, args.warmup_epochs, + args.max_epoch, args.T_max, args.eta_min) + elif args.lr_scheduler == 'cosine_annealing_sample': + lr = warmup_cosine_annealing_lr_sample(args.lr, steps_per_epoch, args.warmup_epochs, + args.max_epoch, args.T_max, args.eta_min) + else: + raise NotImplementedError(args.lr_scheduler) + return lr diff --git a/community/cv/ADCAM/src/transforms.py b/community/cv/ADCAM/src/transforms.py new file mode 100644 index 0000000000000000000000000000000000000000..9a8ee8a5bd86033a671fd6b5f2ee46ff29c65171 --- /dev/null +++ b/community/cv/ADCAM/src/transforms.py @@ -0,0 +1,497 @@ +# 预处理数据集 +import random +import threading +import copy +import numpy as np +from PIL import Image +import cv2 +import mindspore.dataset.vision as vision + + +def _rand(a=0., b=1.): + return np.random.rand() * (b - a) + a + + +def bbox_iou(bbox_a, bbox_b, offset=0): + if bbox_a.shape[1] < 4 or bbox_b.shape[1] < 4: + raise IndexError("Bounding boxes axis 1 must have at least length 4") + + tl = np.maximum(bbox_a[:, None, :2], bbox_b[:, :2]) + br = np.minimum(bbox_a[:, None, 2:4], bbox_b[:, 2:4]) + + area_i = np.prod(br - tl + offset, axis=2) * (tl < br).all(axis=2) + area_a = np.prod(bbox_a[:, 2:4] - bbox_a[:, :2] + offset, axis=1) + area_b = np.prod(bbox_b[:, 2:4] - bbox_b[:, :2] + offset, axis=1) + return area_i / (area_a[:, None] + area_b - area_i) + + +def get_interp_method(interp, sizes=()): + if interp == 9: + if sizes: + assert len(sizes) == 4 + oh, ow, nh, nw = sizes + if nh > oh and nw > ow: + return 2 + if nh < oh and nw < ow: + return 0 + return 1 + return 2 + if interp == 10: + return random.randint(0, 4) + if interp not in (0, 1, 2, 3, 4): + raise ValueError('Unknown interp method %d' % interp) + return interp + + +def pil_image_reshape(interp): + reshape_type = { + 0: Image.NEAREST, + 1: Image.BILINEAR, + 2: Image.BICUBIC, + 3: Image.NEAREST, + 4: Image.LANCZOS, + } + return reshape_type[interp] + + +def _preprocess_true_boxes(true_boxes, anchors, in_shape, num_classes, max_boxes, label_smooth, + label_smooth_factor=0.1, iou_threshold=0.213): + anchors = np.array(anchors) + num_layers = anchors.shape[0] // 3 + anchor_mask = [[6, 7, 8], [3, 4, 5], [0, 1, 2]] + true_boxes = np.array(true_boxes, dtype='float32') + input_shape = np.array(in_shape, dtype='int32') + boxes_xy = (true_boxes[..., 0:2] + true_boxes[..., 2:4]) // 2. + # trans to box center point + boxes_wh = true_boxes[..., 2:4] - true_boxes[..., 0:2] + # input_shape is [h, w] + true_boxes[..., 0:2] = boxes_xy / input_shape[::-1] + true_boxes[..., 2:4] = boxes_wh / input_shape[::-1] + # true_boxes = [xywh] + grid_shapes = [input_shape // 32, input_shape // 16, input_shape // 8] + # grid_shape [h, w] + y_true = [np.zeros((grid_shapes[l][0], grid_shapes[l][1], len(anchor_mask[l]), + 5 + num_classes), dtype='float32') for l in range(num_layers)] + # y_true [gridy, gridx] + anchors = np.expand_dims(anchors, 0) + anchors_max = anchors / 2. + anchors_min = -anchors_max + valid_mask = boxes_wh[..., 0] > 0 + wh = boxes_wh[valid_mask] + if wh.size != 0: + wh = np.expand_dims(wh, -2) + # wh shape[box_num, 1, 2] + boxes_max = wh / 2. + boxes_min = -boxes_max + intersect_min = np.maximum(boxes_min, anchors_min) + intersect_max = np.minimum(boxes_max, anchors_max) + intersect_wh = np.maximum(intersect_max - intersect_min, 0.) + intersect_area = intersect_wh[..., 0] * intersect_wh[..., 1] + box_area = wh[..., 0] * wh[..., 1] + anchor_area = anchors[..., 0] * anchors[..., 1] + iou = intersect_area / (box_area + anchor_area - intersect_area) + + # topk iou + topk = 4 + topk_flag = iou.argsort() + topk_flag = topk_flag >= topk_flag.shape[1] - topk + flag = topk_flag.nonzero() + for index in range(len(flag[0])): + t = flag[0][index] + n = flag[1][index] + if iou[t][n] < iou_threshold: + continue + for l in range(num_layers): + if n in anchor_mask[l]: + i = np.floor(true_boxes[t, 0] * grid_shapes[l][1]).astype('int32') # grid_y + j = np.floor(true_boxes[t, 1] * grid_shapes[l][0]).astype('int32') # grid_x + + k = anchor_mask[l].index(n) + c = true_boxes[t, 4].astype('int32') + y_true[l][j, i, k, 0:4] = true_boxes[t, 0:4] + y_true[l][j, i, k, 4] = 1. + + # lable-smooth + if label_smooth: + sigma = label_smooth_factor / (num_classes - 1) + y_true[l][j, i, k, 5:] = sigma + y_true[l][j, i, k, 5 + c] = 1 - label_smooth_factor + else: + y_true[l][j, i, k, 5 + c] = 1. + # best anchor for gt + best_anchor = np.argmax(iou, axis=-1) + for t, n in enumerate(best_anchor): + for l in range(num_layers): + if n in anchor_mask[l]: + i = np.floor(true_boxes[t, 0] * grid_shapes[l][1]).astype('int32') # grid_y + j = np.floor(true_boxes[t, 1] * grid_shapes[l][0]).astype('int32') # grid_x + + k = anchor_mask[l].index(n) + c = true_boxes[t, 4].astype('int32') + y_true[l][j, i, k, 0:4] = true_boxes[t, 0:4] + y_true[l][j, i, k, 4] = 1. + + # lable-smooth + if label_smooth: + sigma = label_smooth_factor / (num_classes - 1) + y_true[l][j, i, k, 5:] = sigma + y_true[l][j, i, k, 5 + c] = 1 - label_smooth_factor + else: + y_true[l][j, i, k, 5 + c] = 1. + + # pad_gt_boxes for avoiding dynamic shape + pad_gt_box0 = np.zeros(shape=[max_boxes, 4], dtype=np.float32) + pad_gt_box1 = np.zeros(shape=[max_boxes, 4], dtype=np.float32) + pad_gt_box2 = np.zeros(shape=[max_boxes, 4], dtype=np.float32) + + mask0 = np.reshape(y_true[0][..., 4:5], [-1]) + gt_box0 = np.reshape(y_true[0][..., 0:4], [-1, 4]) + # gt_box [boxes, [x,y,w,h]] + gt_box0 = gt_box0[mask0 == 1] + # gt_box0: get all boxes which have object + if gt_box0.shape[0] < max_boxes: + pad_gt_box0[:gt_box0.shape[0]] = gt_box0 + else: + pad_gt_box0 = gt_box0[:max_boxes] + # gt_box0.shape[0]: total number of boxes in gt_box0 + # top N of pad_gt_box0 is real box, and after are pad by zero + + mask1 = np.reshape(y_true[1][..., 4:5], [-1]) + gt_box1 = np.reshape(y_true[1][..., 0:4], [-1, 4]) + gt_box1 = gt_box1[mask1 == 1] + if gt_box1.shape[0] < max_boxes: + pad_gt_box1[:gt_box1.shape[0]] = gt_box1 + else: + pad_gt_box1 = gt_box1[:max_boxes] + + mask2 = np.reshape(y_true[2][..., 4:5], [-1]) + gt_box2 = np.reshape(y_true[2][..., 0:4], [-1, 4]) + + gt_box2 = gt_box2[mask2 == 1] + if gt_box2.shape[0] < max_boxes: + pad_gt_box2[:gt_box2.shape[0]] = gt_box2 + else: + pad_gt_box2 = gt_box2[:max_boxes] + return y_true[0], y_true[1], y_true[2], pad_gt_box0, pad_gt_box1, pad_gt_box2 + + +class PreprocessTrueBox: + def __init__(self, config): + self.anchor_scales = config.anchor_scales + self.num_classes = config.num_classes + self.max_box = config.max_box + self.label_smooth = config.label_smooth + self.label_smooth_factor = config.label_smooth_factor + + def __call__(self, anno, input_shape): + bbox_true_1, bbox_true_2, bbox_true_3, gt_box1, gt_box2, gt_box3 = \ + _preprocess_true_boxes(true_boxes=anno, anchors=self.anchor_scales, in_shape=input_shape, + num_classes=self.num_classes, max_boxes=self.max_box, + label_smooth=self.label_smooth, label_smooth_factor=self.label_smooth_factor) + return anno, np.array(bbox_true_1), np.array(bbox_true_2), np.array(bbox_true_3), \ + np.array(gt_box1), np.array(gt_box2), np.array(gt_box3) + + +def _reshape_data(image, image_size): + if not isinstance(image, Image.Image): + image = Image.fromarray(image) + ori_w, ori_h = image.size + ori_image_shape = np.array([ori_w, ori_h], np.int32) + # original image shape fir:H sec:W + h, w = image_size + interp = get_interp_method(interp=9, sizes=(ori_h, ori_w, h, w)) + image = image.resize((w, h), pil_image_reshape(interp)) + image_data = np.array(image) + if len(image_data.shape) == 2: + image_data = np.expand_dims(image_data, axis=-1) + image_data = np.concatenate([image_data, image_data, image_data], axis=-1) + return image_data, ori_image_shape + + +def color_distortion(img, hue, sat, val, device_num): + hue = _rand(-hue, hue) + sat = _rand(1, sat) if _rand() < .5 else 1 / _rand(1, sat) + val = _rand(1, val) if _rand() < .5 else 1 / _rand(1, val) + if device_num != 1: + cv2.setNumThreads(1) + x = cv2.cvtColor(img, cv2.COLOR_RGB2HSV_FULL) + x = x / 255. + x[..., 0] += hue + x[..., 0][x[..., 0] > 1] -= 1 + x[..., 0][x[..., 0] < 0] += 1 + x[..., 1] *= sat + x[..., 2] *= val + x[x > 1] = 1 + x[x < 0] = 0 + x = x * 255. + x = x.astype(np.uint8) + image_data = cv2.cvtColor(x, cv2.COLOR_HSV2RGB_FULL) + return image_data + + +def filp_pil_image(img): + return img.transpose(Image.FLIP_LEFT_RIGHT) + + +def convert_gray_to_color(img): + if len(img.shape) == 2: + img = np.expand_dims(img, axis=-1) + img = np.concatenate([img, img, img], axis=-1) + return img + + +def _is_iou_satisfied_constraint(min_iou, max_iou, box, crop_box): + iou = bbox_iou(box, crop_box) + return min_iou <= iou.min() and max_iou >= iou.max() + + +def _choose_candidate_by_constraints(max_trial, input_w, input_h, image_w, image_h, jitter, box, use_constraints): + if use_constraints: + constraints = ( + (0.1, None), + (0.3, None), + (0.5, None), + (0.7, None), + (0.9, None), + (None, 1), + ) + else: + constraints = ((None, None),) + # add default candidate + candidates = [(0, 0, input_w, input_h)] + for constraint in constraints: + min_iou, max_iou = constraint + min_iou = -np.inf if min_iou is None else min_iou + max_iou = np.inf if max_iou is None else max_iou + + for _ in range(max_trial): + # box_data should have at least one box + new_ar = float(input_w) / float(input_h) * _rand(1 - jitter, 1 + jitter) / _rand(1 - jitter, 1 + jitter) + scale = _rand(0.5, 2) + + if new_ar < 1: + nh = int(scale * input_h) + nw = int(nh * new_ar) + else: + nw = int(scale * input_w) + nh = int(nw / new_ar) + + dx = int(_rand(0, input_w - nw)) + dy = int(_rand(0, input_h - nh)) + + if box.size > 0: + t_box = copy.deepcopy(box) + t_box[:, [0, 2]] = t_box[:, [0, 2]] * float(nw) / float(image_w) + dx + t_box[:, [1, 3]] = t_box[:, [1, 3]] * float(nh) / float(image_h) + dy + + crop_box = np.array((0, 0, input_w, input_h)) + if not _is_iou_satisfied_constraint(min_iou, max_iou, t_box, crop_box[np.newaxis]): + continue + else: + candidates.append((dx, dy, nw, nh)) + else: + raise Exception("!!! annotation box is less than 1") + return candidates + + +def _correct_bbox_by_candidates(candidates, input_w, input_h, image_w, + image_h, flip, box, box_data, allow_outside_center, max_boxes): + while candidates: + if len(candidates) > 1: + # ignore default candidate which do not crop + candidate = candidates.pop(np.random.randint(1, len(candidates))) + else: + candidate = candidates.pop(np.random.randint(0, len(candidates))) + dx, dy, nw, nh = candidate + t_box = copy.deepcopy(box) + t_box[:, [0, 2]] = t_box[:, [0, 2]] * float(nw) / float(image_w) + dx + t_box[:, [1, 3]] = t_box[:, [1, 3]] * float(nh) / float(image_h) + dy + if flip: + t_box[:, [0, 2]] = input_w - t_box[:, [2, 0]] + + if allow_outside_center: + pass + else: + t_box = t_box[ + np.logical_and((t_box[:, 0] + t_box[:, 2]) / 2. >= 0., (t_box[:, 1] + t_box[:, 3]) / 2. >= 0.)] + t_box = t_box[np.logical_and((t_box[:, 0] + t_box[:, 2]) / 2. <= input_w, + (t_box[:, 1] + t_box[:, 3]) / 2. <= input_h)] + + # recorrect x, y for case x,y < 0 reset to zero, after dx and dy, some box can smaller than zero + t_box[:, 0:2][t_box[:, 0:2] < 0] = 0 + # recorrect w,h not higher than input size + t_box[:, 2][t_box[:, 2] > input_w] = input_w + t_box[:, 3][t_box[:, 3] > input_h] = input_h + box_w = t_box[:, 2] - t_box[:, 0] + box_h = t_box[:, 3] - t_box[:, 1] + # discard invalid box: w or h smaller than 1 pixel + t_box = t_box[np.logical_and(box_w > 1, box_h > 1)] + + if t_box.shape[0] > 0: + # break if number of find t_box + box_data[: len(t_box)] = t_box + return box_data, candidate + return np.zeros(shape=[max_boxes, 5], dtype=np.float64), (0, 0, nw, nh) + + +def _data_aug(image, box, jitter, hue, sat, val, image_input_size, max_boxes, + anchors, num_classes, max_trial=10, device_num=1): + if not isinstance(image, Image.Image): + image = Image.fromarray(image) + + image_w, image_h = image.size + input_h, input_w = image_input_size + + np.random.shuffle(box) + if len(box) > max_boxes: + box = box[:max_boxes] + flip = _rand() < .5 + box_data = np.zeros((max_boxes, 5)) + + candidates = _choose_candidate_by_constraints(use_constraints=False, max_trial=max_trial, input_w=input_w, + input_h=input_h, image_w=image_w, image_h=image_h, + jitter=jitter, box=box) + box_data, candidate = _correct_bbox_by_candidates(candidates=candidates, input_w=input_w, input_h=input_h, + image_w=image_w, image_h=image_h, flip=flip, box=box, + box_data=box_data, allow_outside_center=True, max_boxes=max_boxes) + dx, dy, nw, nh = candidate + interp = get_interp_method(interp=10) + image = image.resize((nw, nh), pil_image_reshape(interp)) + # place image, gray color as back graoud + new_image = Image.new('RGB', (input_w, input_h), (128, 128, 128)) + new_image.paste(image, (dx, dy)) + image = new_image + + if flip: + image = filp_pil_image(image) + + image = np.array(image) + image = convert_gray_to_color(image) + image_data = color_distortion(image, hue, sat, val, device_num) + return image_data, box_data + + +def preprocess_fn(image, box, config, input_size, device_num): + config_anchors = config.anchor_scales + anchors = np.array([list(x) for x in config_anchors]) + max_boxes = config.max_box + num_classes = config.num_classes + jitter = config.jitter + hue = config.hue + sat = config.saturation + val = config.value + image, anno = _data_aug(image, box, jitter=jitter, hue=hue, sat=sat, val=val, + image_input_size=input_size, max_boxes=max_boxes, + num_classes=num_classes, anchors=anchors, device_num=device_num) + return image, anno + + +def reshape_fn(image, img_id, config): + input_size = config.test_img_shape + image, ori_image_shape = _reshape_data(image, image_size=input_size) + return image, ori_image_shape, img_id + + +class MultiScaleTrans: + def __init__(self, config, device_num): + self.config = config + self.seed = 0 + self.size_list = [] + self.resize_rate = config.resize_rate + self.dataset_size = config.dataset_size + self.size_dict = {} + self.seed_num = int(1e6) + self.seed_list = self.generate_seed_list(seed_num=self.seed_num) + self.resize_count_num = int(np.ceil(self.dataset_size / self.resize_rate)) + self.device_num = device_num + self.anchor_scales = config.anchor_scales + self.num_classes = config.num_classes + self.max_box = config.max_box + self.label_smooth = config.label_smooth + self.label_smooth_factor = config.label_smooth_factor + + def generate_seed_list(self, init_seed=1234, seed_num=int(1e6), seed_range=(1, 1000)): + seed_list = [] + random.seed(init_seed) + for _ in range(seed_num): + seed = random.randint(seed_range[0], seed_range[1]) + seed_list.append(seed) + return seed_list + + def __call__(self, img, anno, input_size, mosaic_flag): + if mosaic_flag[0] == 0: + img = vision.Decode(True)(img) + img, anno = preprocess_fn(img, anno, self.config, input_size, self.device_num) + return img, anno, np.array(img.shape[0:2]) + + +def thread_batch_preprocess_true_box(annos, config, input_shape, result_index, batch_bbox_true_1, batch_bbox_true_2, + batch_bbox_true_3, batch_gt_box1, batch_gt_box2, batch_gt_box3): + i = 0 + for anno in annos: + bbox_true_1, bbox_true_2, bbox_true_3, gt_box1, gt_box2, gt_box3 = \ + _preprocess_true_boxes(true_boxes=anno, anchors=config.anchor_scales, in_shape=input_shape, + num_classes=config.num_classes, max_boxes=config.max_box, + label_smooth=config.label_smooth, label_smooth_factor=config.label_smooth_factor) + batch_bbox_true_1[result_index + i] = bbox_true_1 + batch_bbox_true_2[result_index + i] = bbox_true_2 + batch_bbox_true_3[result_index + i] = bbox_true_3 + batch_gt_box1[result_index + i] = gt_box1 + batch_gt_box2[result_index + i] = gt_box2 + batch_gt_box3[result_index + i] = gt_box3 + i = i + 1 + + +def batch_preprocess_true_box(annos, config, input_shape): + batch_bbox_true_1 = [] + batch_bbox_true_2 = [] + batch_bbox_true_3 = [] + batch_gt_box1 = [] + batch_gt_box2 = [] + batch_gt_box3 = [] + threads = [] + + step = 4 + for index in range(0, len(annos), step): + for _ in range(step): + batch_bbox_true_1.append(None) + batch_bbox_true_2.append(None) + batch_bbox_true_3.append(None) + batch_gt_box1.append(None) + batch_gt_box2.append(None) + batch_gt_box3.append(None) + step_anno = annos[index: index + step] + t = threading.Thread(target=thread_batch_preprocess_true_box, + args=(step_anno, config, input_shape, index, batch_bbox_true_1, batch_bbox_true_2, + batch_bbox_true_3, batch_gt_box1, batch_gt_box2, batch_gt_box3)) + t.start() + threads.append(t) + + for t in threads: + t.join() + + return np.array(batch_bbox_true_1), np.array(batch_bbox_true_2), np.array(batch_bbox_true_3), \ + np.array(batch_gt_box1), np.array(batch_gt_box2), np.array(batch_gt_box3) + + +def batch_preprocess_true_box_single(annos, config, input_shape): + batch_bbox_true_1 = [] + batch_bbox_true_2 = [] + batch_bbox_true_3 = [] + batch_gt_box1 = [] + batch_gt_box2 = [] + batch_gt_box3 = [] + for anno in annos: + bbox_true_1, bbox_true_2, bbox_true_3, gt_box1, gt_box2, gt_box3 = \ + _preprocess_true_boxes(true_boxes=anno, anchors=config.anchor_scales, in_shape=input_shape, + num_classes=config.num_classes, max_boxes=config.max_box, + label_smooth=config.label_smooth, label_smooth_factor=config.label_smooth_factor) + batch_bbox_true_1.append(bbox_true_1) + batch_bbox_true_2.append(bbox_true_2) + batch_bbox_true_3.append(bbox_true_3) + batch_gt_box1.append(gt_box1) + batch_gt_box2.append(gt_box2) + batch_gt_box3.append(gt_box3) + + return np.array(batch_bbox_true_1), np.array(batch_bbox_true_2), np.array(batch_bbox_true_3), \ + np.array(batch_gt_box1), np.array(batch_gt_box2), np.array(batch_gt_box3) diff --git a/community/cv/ADCAM/src/util.py b/community/cv/ADCAM/src/util.py new file mode 100644 index 0000000000000000000000000000000000000000..4fb25d87160be53e2a059b708722875d9d376495 --- /dev/null +++ b/community/cv/ADCAM/src/util.py @@ -0,0 +1,484 @@ +# Util class or function +import os +import sys +from collections import defaultdict +import datetime +import copy +import json +from typing import Union, List +import numpy as np +from pycocotools.coco import COCO +from pycocotools.cocoeval import COCOeval + +import mindspore +import mindspore.nn as nn +from mindspore import Tensor, ops + +from .yolo import YoloLossBlock + + +class AverageMeter: + """Computes and stores the average and current value""" + + def __init__(self, name, fmt=':f', tb_writer=None): + self.name = name + self.fmt = fmt + self.reset() + self.tb_writer = tb_writer + self.cur_step = 1 + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + self.val = val + self.sum += val * n + self.count += n + self.avg = self.sum / self.count + if self.tb_writer is not None: + self.tb_writer.add_scalar(self.name, self.val, self.cur_step) + self.cur_step += 1 + + def __str__(self): + fmtstr = '{name}:{avg' + self.fmt + '}' + return fmtstr.format(**self.__dict__) + + +def default_wd_filter(x): + """default weight decay filter.""" + parameter_name = x.name + if parameter_name.endswith('.bias'): + # all bias not using weight decay + return False + if parameter_name.endswith('.gamma'): + # bn weight bias not using weight decay, be carefully for now x not + # include BN + return False + if parameter_name.endswith('.beta'): + # bn weight bias not using weight decay, be carefully for now x not + # include BN + return False + + return True + + +def get_param_groups(network): + """Param groups for optimizer.""" + decay_params = [] + no_decay_params = [] + for x in network.trainable_params(): + parameter_name = x.name + if parameter_name.endswith('.bias'): + # all bias not using weight decay + no_decay_params.append(x) + elif parameter_name.endswith('.gamma'): + # bn weight bias not using weight decay, be carefully for now x not + # include BN + no_decay_params.append(x) + elif parameter_name.endswith('.beta'): + # bn weight bias not using weight decay, be carefully for now x not + # include BN + no_decay_params.append(x) + else: + decay_params.append(x) + + return [{'params': no_decay_params, 'weight_decay': 0.0}, + {'params': decay_params}] + + +class ShapeRecord: + """Log image shape.""" + + def __init__(self): + self.shape_record = { + 416: 0, + 448: 0, + 480: 0, + 512: 0, + 544: 0, + 576: 0, + 608: 0, + 640: 0, + 672: 0, + 704: 0, + 736: 0, + 'total': 0 + } + + def set(self, shape): + if len(shape) > 1: + shape = shape[0] + shape = int(shape) + self.shape_record[shape] += 1 + self.shape_record['total'] += 1 + + def show(self, logger): + for key in self.shape_record: + rate = self.shape_record[key] / float(self.shape_record['total']) + logger.info('shape {}: {:.2f}%'.format(key, rate * 100)) + + +def keep_loss_fp32(network): + """Keep loss of network with float32""" + for _, cell in network.cells_and_names(): + if isinstance(cell, (YoloLossBlock,)): + cell.to_float(mindspore.float32) + + +class Redirct: + def __init__(self): + self.content = "" + + def write(self, content): + self.content += content + + def flush(self): + self.content = "" + + +def cpu_affinity(rank_id, device_num): + """Bind CPU cores according to rank_id and device_num.""" + import psutil + cores = psutil.cpu_count() + if cores < device_num: + return + process = psutil.Process() + used_cpu_num = cores // device_num + rank_id = rank_id % device_num + used_cpu_list = [i for i in range(rank_id * used_cpu_num, (rank_id + 1) * used_cpu_num)] + process.cpu_affinity(used_cpu_list) + print(f"==== {rank_id}/{device_num} ==== bind cpu: {used_cpu_list}") + + +class COCOEvaluator: + def __init__(self, detection_config) -> None: + self.coco_gt = COCO(detection_config.val_ann_file) + self.coco_catIds = self.coco_gt.getCatIds() + self.coco_imgIds = list(sorted(self.coco_gt.imgs.keys())) + self.coco_transformed_catIds = detection_config.coco_ids + self.logger = detection_config.logger + self.last_mAP = 0.0 + + def get_mAP(self, coco_dt_ann_file: Union[str, List[str]]): + if isinstance(coco_dt_ann_file, str): + return self.get_mAP_single_file(coco_dt_ann_file) + if isinstance(coco_dt_ann_file, list): + return self.get_mAP_multiple_file(coco_dt_ann_file) + raise ValueError("Invalid 'coco_dt_ann_file' type. Support str or List[str].") + + def merge_result_files(self, file_path: List[str]) -> List: + dt_list = [] + dt_ids_set = set([]) + self.logger.info(f"Total {len(file_path)} json files") + self.logger.info(f"File list: {file_path}") + + for path in file_path: + ann_list = [] + try: + with open(path, 'r') as f: + ann_list = json.load(f) + except json.decoder.JSONDecodeError: + pass # json file is empty + else: + ann_ids = set(ann['image_id'] for ann in ann_list) + diff_ids = ann_ids - dt_ids_set + ann_list = [ann for ann in ann_list if ann['image_id'] in diff_ids] + dt_ids_set = dt_ids_set | diff_ids + dt_list.extend(ann_list) + return dt_list + + def get_coco_from_dt_list(self, dt_list) -> COCO: + cocoDt = COCO() + cocoDt.dataset = {} + cocoDt.dataset['images'] = [img for img in self.coco_gt.dataset['images']] + cocoDt.dataset['categories'] = copy.deepcopy(self.coco_gt.dataset['categories']) + self.logger.info(f"Number of dt boxes: {len(dt_list)}") + for idx, ann in enumerate(dt_list): + bb = ann['bbox'] + x1, x2, y1, y2 = [bb[0], bb[0] + bb[2], bb[1], bb[1] + bb[3]] + if 'segmentation' not in ann: + ann['segmentation'] = [[x1, y1, x1, y2, x2, y2, x2, y1]] + ann['area'] = bb[2] * bb[3] + ann['id'] = idx + 1 + ann['iscrowd'] = 0 + cocoDt.dataset['annotations'] = dt_list + cocoDt.createIndex() + return cocoDt + + def get_mAP_multiple_file(self, coco_dt_ann_file: List[str]) -> str: + dt_list = self.merge_result_files(coco_dt_ann_file) + coco_dt = self.get_coco_from_dt_list(dt_list) + return self.compute_coco_mAP(coco_dt) + + def get_mAP_single_file(self, coco_dt_ann_file: str) -> str: + coco_dt = self.coco_gt.loadRes(coco_dt_ann_file) + return self.compute_coco_mAP(coco_dt) + + def compute_coco_mAP(self, coco_dt: COCO) -> str: + coco_eval = COCOeval(self.coco_gt, coco_dt, 'bbox') + coco_eval.evaluate() + coco_eval.accumulate() + rdct = Redirct() + stdout = sys.stdout + sys.stdout = rdct + coco_eval.summarize() + sys.stdout = stdout + self.last_mAP = coco_eval.stats[0] + return rdct.content + + +class DetectionEngine: + """Detection engine.""" + + def __init__(self, args_detection, threshold): + self.ignore_threshold = threshold + self.labels = args_detection.labels + self.num_classes = len(self.labels) + self.results = {} + self.file_path = '' + self.save_prefix = args_detection.output_dir + self.ann_file = args_detection.val_ann_file + self.det_boxes = [] + self.nms_thresh = args_detection.eval_nms_thresh + self.multi_label = args_detection.multi_label + self.multi_label_thresh = args_detection.multi_label_thresh + + self.logger = args_detection.logger + self.eval_parallel = args_detection.eval_parallel + if self.eval_parallel: + self.save_prefix = args_detection.save_prefix + self.rank_id = args_detection.rank + self.dir_path = '' + self.coco_evaluator = COCOEvaluator(args_detection) + self.coco_catids = self.coco_evaluator.coco_gt.getCatIds() + self.coco_catIds = args_detection.coco_ids + self._img_ids = list(sorted(self.coco_evaluator.coco_gt.imgs.keys())) + + def do_nms_for_results(self): + """Get result boxes.""" + for img_id in self.results: + for clsi in self.results[img_id]: + dets = self.results[img_id][clsi] + dets = np.array(dets) + keep_index = self._diou_nms(dets, thresh=self.nms_thresh) + + keep_box = [{'image_id': int(img_id), 'category_id': int(clsi), + 'bbox': list(dets[i][:4].astype(float)), + 'score': dets[i][4].astype(float)} for i in keep_index] + self.det_boxes.extend(keep_box) + + def _nms(self, predicts, threshold): + """Calculate NMS.""" + # convert xywh -> xmin ymin xmax ymax + x1 = predicts[:, 0] + y1 = predicts[:, 1] + x2 = x1 + predicts[:, 2] + y2 = y1 + predicts[:, 3] + scores = predicts[:, 4] + + areas = (x2 - x1 + 1) * (y2 - y1 + 1) + order = scores.argsort()[::-1] + + reserved_boxes = [] + while order.size > 0: + i = order[0] + reserved_boxes.append(i) + max_x1 = np.maximum(x1[i], x1[order[1:]]) + max_y1 = np.maximum(y1[i], y1[order[1:]]) + min_x2 = np.minimum(x2[i], x2[order[1:]]) + min_y2 = np.minimum(y2[i], y2[order[1:]]) + + intersect_w = np.maximum(0.0, min_x2 - max_x1 + 1) + intersect_h = np.maximum(0.0, min_y2 - max_y1 + 1) + intersect_area = intersect_w * intersect_h + ovr = intersect_area / \ + (areas[i] + areas[order[1:]] - intersect_area) + + indexes = np.where(ovr <= threshold)[0] + order = order[indexes + 1] + return reserved_boxes + + def _diou_nms(self, dets, thresh=0.5): + """ + convert xywh -> xmin ymin xmax ymax + """ + x1 = dets[:, 0] + y1 = dets[:, 1] + x2 = x1 + dets[:, 2] + y2 = y1 + dets[:, 3] + scores = dets[:, 4] + areas = (x2 - x1 + 1) * (y2 - y1 + 1) + order = scores.argsort()[::-1] + keep = [] + while order.size > 0: + i = order[0] + keep.append(i) + xx1 = np.maximum(x1[i], x1[order[1:]]) + yy1 = np.maximum(y1[i], y1[order[1:]]) + xx2 = np.minimum(x2[i], x2[order[1:]]) + yy2 = np.minimum(y2[i], y2[order[1:]]) + + w = np.maximum(0.0, xx2 - xx1 + 1) + h = np.maximum(0.0, yy2 - yy1 + 1) + inter = w * h + ovr = inter / (areas[i] + areas[order[1:]] - inter) + center_x1 = (x1[i] + x2[i]) / 2 + center_x2 = (x1[order[1:]] + x2[order[1:]]) / 2 + center_y1 = (y1[i] + y2[i]) / 2 + center_y2 = (y1[order[1:]] + y2[order[1:]]) / 2 + inter_diag = (center_x2 - center_x1) ** 2 + (center_y2 - center_y1) ** 2 + out_max_x = np.maximum(x2[i], x2[order[1:]]) + out_max_y = np.maximum(y2[i], y2[order[1:]]) + out_min_x = np.minimum(x1[i], x1[order[1:]]) + out_min_y = np.minimum(y1[i], y1[order[1:]]) + outer_diag = (out_max_x - out_min_x) ** 2 + (out_max_y - out_min_y) ** 2 + diou = ovr - inter_diag / outer_diag + diou = np.core.umath.clip(diou, -1, 1) + inds = np.where(diou <= thresh)[0] + order = order[inds + 1] + return keep + + def write_result(self, cur_epoch=0, cur_step=0): + """Save result to file.""" + self.logger.info("Save bbox prediction result.") + if self.eval_parallel: + rank_id = self.rank_id + self.dir_path = os.path.join(self.save_prefix, f"eval_epoch{cur_epoch}-step{cur_step}") + if not os.path.exists(self.dir_path): + os.makedirs(self.dir_path, exist_ok=True) + file_name = f"epoch{cur_epoch}-step{cur_step}-rank{rank_id}.json" + self.file_path = os.path.join(self.dir_path, file_name) + else: + t = datetime.datetime.now().strftime('_%Y_%m_%d_%H_%M_%S') + self.file_path = self.save_prefix + '/predict' + t + '.json' + try: + with open(self.file_path, 'w') as f: + json.dump(self.det_boxes, f) + except IOError as e: + raise RuntimeError("Unable to open json file to dump. What(): {}".format(str(e))) + else: + self.logger.info(f'Result file path: {self.file_path}') + self.det_boxes.clear() + + def get_eval_result(self): + """Get eval result.""" + if self.eval_parallel: + file_paths = [os.path.join(self.dir_path, path) for path in os.listdir(self.dir_path)] + eval_results = self.coco_evaluator.get_mAP(file_paths) + else: + eval_results = self.coco_evaluator.get_mAP(self.file_path) + mAP = self.coco_evaluator.last_mAP + return eval_results, mAP + + def detect(self, outputs, batch, image_shape, image_id): + """Detect boxes.""" + # output [|32, 52, 52, 3, 85| ] + for batch_id in range(batch): + for out_item in outputs: + # 52, 52, 3, 85 + out_item_single = out_item[batch_id, :] + ori_w, ori_h = image_shape[batch_id] + img_id = int(image_id[batch_id]) + if img_id not in self.results: + self.results[img_id] = defaultdict(list) + x = ori_w * out_item_single[..., 0].reshape(-1) + y = ori_h * out_item_single[..., 1].reshape(-1) + w = ori_w * out_item_single[..., 2].reshape(-1) + h = ori_h * out_item_single[..., 3].reshape(-1) + conf = out_item_single[..., 4:5] + cls_emb = out_item_single[..., 5:] + x_top_left = x - w / 2. + y_top_left = y - h / 2. + cls_emb = cls_emb.reshape(-1, self.num_classes) + if self.multi_label: + conf = conf.reshape(-1, 1) + confidence = conf * cls_emb + # create all False + flag = (cls_emb > self.multi_label_thresh) & (confidence >= self.ignore_threshold) + i, j = flag.nonzero() + x_left, y_left = np.maximum(0, x_top_left[i]), np.maximum(0, y_top_left[i]) + w, h = np.minimum(ori_w, w[i]), np.minimum(ori_h, h[i]) + cls_id = np.array(self.coco_catIds)[j] + conf = confidence[i, j] + for (x_i, y_i, w_i, h_i, conf_i, cls_id_i) in zip(x_left, y_left, w, h, conf, cls_id): + self.results[img_id][cls_id_i].append([x_i, y_i, w_i, h_i, conf_i]) + else: + cls_argmax = np.argmax(cls_emb, axis=-1) + # create all False + flag = np.random.random(cls_emb.shape) > sys.maxsize + for i in range(flag.shape[0]): + c = cls_argmax[i] + flag[i, c] = True + confidence = conf.reshape(-1) * cls_emb[flag] + for x_lefti, y_lefti, wi, hi, confi, clsi in zip(x_top_left, y_top_left, + w, h, confidence, cls_argmax): + if confi < self.ignore_threshold: + continue + x_lefti, y_lefti = max(0, x_lefti), max(0, y_lefti) + wi, hi = min(wi, ori_w), min(hi, ori_h) + # transform catId to match coco + coco_clsi = self.coco_catids[clsi] + self.results[img_id][coco_clsi].append([x_lefti, y_lefti, wi, hi, confi]) + + +class AllReduce(nn.Cell): + def __init__(self): + super(AllReduce, self).__init__() + self.all_reduce = ops.AllReduce() + + def construct(self, x): + return self.all_reduce(x) + + +class EvalWrapper: + def __init__(self, config, network, dataset, engine: DetectionEngine) -> None: + self.logger = config.logger + self.network = network + self.dataset = dataset + self.per_batch_size = config.per_batch_size + self.device_num = config.group_size + self.input_shape = Tensor(tuple(config.test_img_shape), mindspore.float32) + self.engine = engine + self.eval_parallel = config.eval_parallel + if config.eval_parallel: + self.reduce = AllReduce() + + def synchronize(self): + sync = Tensor(np.array([1]).astype(np.int32)) + sync = self.reduce(sync) # For synchronization + sync = sync.asnumpy()[0] + if sync != self.device_num: + raise ValueError( + f"Sync value {sync} is not equal to number of device {self.device_num}. " + f"There might be wrong with devices." + ) + + def inference(self): + for index, data in enumerate(self.dataset.create_dict_iterator(output_numpy=True, num_epochs=1)): + image = data["image"] + image = mindspore.Tensor(image) + image_shape_ = data["image_shape"] + image_id_ = data["img_id"] + output_big, output_me, output_small = self.network(image, self.input_shape) + output_big = output_big.asnumpy() + output_me = output_me.asnumpy() + output_small = output_small.asnumpy() + self.engine.detect([output_small, output_me, output_big], self.per_batch_size, image_shape_, image_id_) + + if index % 50 == 0: + self.logger.info('Processing... {:.2f}% '.format(index / self.dataset.get_dataset_size() * 100)) + + def get_results(self, cur_epoch=0, cur_step=0): + self.logger.info('Calculating mAP...') + self.engine.do_nms_for_results() + self.engine.write_result(cur_epoch=cur_epoch, cur_step=cur_step) + if self.eval_parallel: + self.synchronize() # Synchronize to avoid read incomplete results + return self.engine.get_eval_result() diff --git a/community/cv/ADCAM/src/yolo.py b/community/cv/ADCAM/src/yolo.py new file mode 100644 index 0000000000000000000000000000000000000000..95bce1999fd77777c3c6bf3551ce880c11e3f5d8 --- /dev/null +++ b/community/cv/ADCAM/src/yolo.py @@ -0,0 +1,609 @@ +# YOLOv5 based on DarkNet +import numpy as np +import mindspore +import mindspore.nn as nn +import mindspore.ops as ops +import math +from src.backbone import YOLOv5Backbone, Conv, BottleneckCSP,BottleneckCSPWithCA,CAAttention +from src.loss import ConfidenceLoss, ClassLoss + +from model_utils.config import config as default_config + +class YOLO(nn.Cell): + def __init__(self, backbone, shape): + super(YOLO, self).__init__() + self.backbone = backbone + self.config = default_config + self.config.out_channel = (self.config.num_classes + 5) * 3 + + self.conv1 = Conv(shape[5], shape[4], k=1, s=1) + self.CSP5 = BottleneckCSP(shape[5], shape[4], n=1*shape[6], shortcut=False) + self.conv2 = Conv(shape[4], shape[3], k=1, s=1) + self.CSP6 = BottleneckCSP(shape[4], shape[3], n=1*shape[6], shortcut=False) + self.conv3 = Conv(shape[3], shape[3], k=3, s=2) + self.CSP7 = BottleneckCSP(shape[4], shape[4], n=1*shape[6], shortcut=False) + self.conv4 = Conv(shape[4], shape[4], k=3, s=2) + print("************----------********************") + self.CSP8 = BottleneckCSP(shape[5], shape[5], n=1*shape[6], shortcut=False) + print("************----------********************") + + + + self.back_block1 = YoloBlock(shape[3], self.config.out_channel) + self.back_block2 = YoloBlock(shape[4], self.config.out_channel) + self.back_block3 = YoloBlock(shape[5], self.config.out_channel) + + self.pre_back_block1=CAAttention(self.config.out_channel,self.config.out_channel) + self.pre_back_block2=CAAttention(self.config.out_channel,self.config.out_channel) + self.pre_back_block3=CAAttention(self.config.out_channel,self.config.out_channel) + + self.concat = ops.Concat(axis=1) + + def construct(self, x): + + img_height = x.shape[2] * 2 + img_width = x.shape[3] * 2 + + feature_map1, feature_map2, feature_map3 = self.backbone(x) + + c1 = self.conv1(feature_map3) + ups1 = ops.ResizeNearestNeighbor((img_height // 16, img_width // 16))(c1) + c2 = self.concat((ups1, feature_map2)) + c3 = self.CSP5(c2) + c4 = self.conv2(c3) + ups2 = ops.ResizeNearestNeighbor((img_height // 8, img_width // 8))(c4) + c5 = self.concat((ups2, feature_map1)) + # out + c6 = self.CSP6(c5) + c7 = self.conv3(c6) + + c8 = self.concat((c7, c4)) + # out + c9 = self.CSP7(c8) + c10 = self.conv4(c9) + c11 = self.concat((c10, c1)) + # out + c12 = self.CSP8(c11) + + c6 = self.back_block1(c6) + c9 = self.back_block2(c9) + c12 = self.back_block3(c12) + + small_object_output=self.pre_back_block1(c6) + medium_object_output=self.pre_back_block2(c9) + big_object_output=self.pre_back_block3(c12) + + + + # print("c6",c6.shape,"c9",c9.shape,"c12",c12.shape) + return small_object_output, medium_object_output, big_object_output + + +class YoloBlock(nn.Cell): + + def __init__(self, in_channels, out_channels): + super(YoloBlock, self).__init__() + + self.conv = nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=1, has_bias=True) + + def construct(self, x): + """construct method""" + + out = self.conv(x) + return out + +class DetectionBlock(nn.Cell): + + def __init__(self, scale, config=default_config, is_training=True): + super(DetectionBlock, self).__init__() + self.config = config + if scale == 's': + idx = (0, 1, 2) + self.scale_x_y = 1.2 + self.offset_x_y = 0.1 + elif scale == 'm': + idx = (3, 4, 5) + self.scale_x_y = 1.1 + self.offset_x_y = 0.05 + elif scale == 'l': + idx = (6, 7, 8) + self.scale_x_y = 1.05 + self.offset_x_y = 0.025 + else: + raise KeyError("Invalid scale value for DetectionBlock") + self.anchors = mindspore.Tensor([self.config.anchor_scales[i] for i in idx], mindspore.float32) + self.num_anchors_per_scale = 3 + self.num_attrib = 4+1+self.config.num_classes + self.lambda_coord = 1 + + self.sigmoid = nn.Sigmoid() + self.reshape = ops.Reshape() + self.tile = ops.Tile() + self.concat = ops.Concat(axis=-1) + self.pow = ops.Pow() + self.transpose = ops.Transpose() + self.exp = ops.Exp() + self.conf_training = is_training + + def construct(self, x, input_shape): + """construct method""" + num_batch = x.shape[0] + grid_size = x.shape[2:4] + + # Reshape and transpose the feature to [n, grid_size[0], grid_size[1], 3, num_attrib] + prediction = self.reshape(x, (num_batch, + self.num_anchors_per_scale, + self.num_attrib, + grid_size[0], + grid_size[1])) + prediction = self.transpose(prediction, (0, 3, 4, 1, 2)) + + grid_x = mindspore.numpy.arange(grid_size[1]) + grid_y = mindspore.numpy.arange(grid_size[0]) + # Tensor of shape [grid_size[0], grid_size[1], 1, 1] representing the coordinate of x/y axis for each grid + # [batch, gridx, gridy, 1, 1] + grid_x = self.tile(self.reshape(grid_x, (1, 1, -1, 1, 1)), (1, grid_size[0], 1, 1, 1)) + grid_y = self.tile(self.reshape(grid_y, (1, -1, 1, 1, 1)), (1, 1, grid_size[1], 1, 1)) + # Shape is [grid_size[0], grid_size[1], 1, 2] + grid = self.concat((grid_x, grid_y)) + + box_xy = prediction[:, :, :, :, :2] + box_wh = prediction[:, :, :, :, 2:4] + box_confidence = prediction[:, :, :, :, 4:5] + box_probs = prediction[:, :, :, :, 5:] + + # gridsize1 is x + # gridsize0 is y + box_xy = (self.scale_x_y * self.sigmoid(box_xy) - self.offset_x_y + grid) / \ + ops.cast(ops.tuple_to_array((grid_size[1], grid_size[0])), mindspore.float32) + # box_wh is w->h + box_wh = self.exp(box_wh) * self.anchors / input_shape + + box_confidence = self.sigmoid(box_confidence) + box_probs = self.sigmoid(box_probs) + + if self.conf_training: + return prediction, box_xy, box_wh + return self.concat((box_xy, box_wh, box_confidence, box_probs)) + + +class Iou(nn.Cell): + """Calculate the iou of boxes""" + def __init__(self): + super(Iou, self).__init__() + self.min = ops.Minimum() + self.max = ops.Maximum() + self.squeeze = ops.Squeeze(-1) + + def construct(self, box1, box2): + """ + box1: pred_box [batch, gx, gy, anchors, 1, 4] ->4: [x_center, y_center, w, h] + box2: gt_box [batch, 1, 1, 1, maxbox, 4] + convert to topLeft and rightDown + """ + box1_xy = box1[:, :, :, :, :, :2] + box1_wh = box1[:, :, :, :, :, 2:4] + box1_mins = box1_xy - box1_wh / ops.scalar_to_tensor(2.0) # topLeft + box1_maxs = box1_xy + box1_wh / ops.scalar_to_tensor(2.0) # rightDown + + box2_xy = box2[:, :, :, :, :, :2] + box2_wh = box2[:, :, :, :, :, 2:4] + box2_mins = box2_xy - box2_wh / ops.scalar_to_tensor(2.0) + box2_maxs = box2_xy + box2_wh / ops.scalar_to_tensor(2.0) + + intersect_mins = self.max(box1_mins, box2_mins) + intersect_maxs = self.min(box1_maxs, box2_maxs) + intersect_wh = self.max(intersect_maxs - intersect_mins, ops.scalar_to_tensor(0.0)) + # self.squeeze: for effiecient slice + intersect_area = self.squeeze(intersect_wh[:, :, :, :, :, 0:1]) * \ + self.squeeze(intersect_wh[:, :, :, :, :, 1:2]) + box1_area = self.squeeze(box1_wh[:, :, :, :, :, 0:1]) * \ + self.squeeze(box1_wh[:, :, :, :, :, 1:2]) + box2_area = self.squeeze(box2_wh[:, :, :, :, :, 0:1]) * \ + self.squeeze(box2_wh[:, :, :, :, :, 1:2]) + iou = intersect_area / (box1_area + box2_area - intersect_area) + # iou : [batch, gx, gy, anchors, maxboxes] + return iou + + +class YoloLossBlock(nn.Cell): + """ + Loss block cell of YOLOV5 network. + """ + def __init__(self, scale, config=default_config): + super(YoloLossBlock, self).__init__() + self.config = config + if scale == 's': + # anchor mask + idx = (0, 1, 2) + elif scale == 'm': + idx = (3, 4, 5) + elif scale == 'l': + idx = (6, 7, 8) + else: + raise KeyError("Invalid scale value for DetectionBlock") + self.anchors = mindspore.Tensor([self.config.anchor_scales[i] for i in idx], mindspore.float32) + self.ignore_threshold = mindspore.Tensor(self.config.ignore_threshold, mindspore.float32) + self.concat = ops.Concat(axis=-1) + self.iou = Iou() + self.reduce_max = ops.ReduceMax(keep_dims=False) + self.confidence_loss = ConfidenceLoss() + self.class_loss = ClassLoss() + + self.reduce_sum = ops.ReduceSum() + self.select = ops.Select() + self.equal = ops.Equal() + self.reshape = ops.Reshape() + self.expand_dims = ops.ExpandDims() + self.ones_like = ops.OnesLike() + self.log = ops.Log() + self.tuple_to_array = ops.TupleToArray() + #self.g_iou = GIou() + self.g_iou = WIoU() + + def construct(self, prediction, pred_xy, pred_wh, y_true, gt_box, input_shape): + """ + prediction : origin output from yolo + pred_xy: (sigmoid(xy)+grid)/grid_size + pred_wh: (exp(wh)*anchors)/input_shape + y_true : after normalize + gt_box: [batch, maxboxes, xyhw] after normalize + """ + object_mask = y_true[:, :, :, :, 4:5] + class_probs = y_true[:, :, :, :, 5:] + true_boxes = y_true[:, :, :, :, :4] + + grid_shape = prediction.shape[1:3] + grid_shape = ops.cast(self.tuple_to_array(grid_shape[::-1]), mindspore.float32) + + pred_boxes = self.concat((pred_xy, pred_wh)) + true_wh = y_true[:, :, :, :, 2:4] + true_wh = self.select(self.equal(true_wh, 0.0), + self.ones_like(true_wh), + true_wh) + true_wh = self.log(true_wh / self.anchors * input_shape) + # 2-w*h for large picture, use small scale, since small obj need more precise + box_loss_scale = 2 - y_true[:, :, :, :, 2:3] * y_true[:, :, :, :, 3:4] + + gt_shape = gt_box.shape + gt_box = self.reshape(gt_box, (gt_shape[0], 1, 1, 1, gt_shape[1], gt_shape[2])) + + # add one more dimension for broadcast + iou = self.iou(self.expand_dims(pred_boxes, -2), gt_box) + # gt_box is x,y,h,w after normalize + # [batch, grid[0], grid[1], num_anchor, num_gt] + best_iou = self.reduce_max(iou, -1) + # [batch, grid[0], grid[1], num_anchor] + + # ignore_mask IOU too small + ignore_mask = best_iou < self.ignore_threshold + ignore_mask = ops.cast(ignore_mask, mindspore.float32) + ignore_mask = self.expand_dims(ignore_mask, -1) + # ignore_mask backpro will cause a lot maximunGrad and minimumGrad time consume. + # so we turn off its gradient + ignore_mask = ops.stop_gradient(ignore_mask) + + confidence_loss = self.confidence_loss(object_mask, prediction[:, :, :, :, 4:5], ignore_mask) + class_loss = self.class_loss(object_mask, prediction[:, :, :, :, 5:], class_probs) + + object_mask_me = self.reshape(object_mask, (-1, 1)) # [8, 72, 72, 3, 1] + box_loss_scale_me = self.reshape(box_loss_scale, (-1, 1)) + pred_boxes_me = xywh2x1y1x2y2(pred_boxes) + pred_boxes_me = self.reshape(pred_boxes_me, (-1, 4)) + true_boxes_me = xywh2x1y1x2y2(true_boxes) + true_boxes_me = self.reshape(true_boxes_me, (-1, 4)) + c_iou = self.g_iou(pred_boxes_me, true_boxes_me) + c_iou_loss = object_mask_me * box_loss_scale_me * (1 - c_iou) + c_iou_loss_me = self.reduce_sum(c_iou_loss, ()) + loss = c_iou_loss_me * 4 + confidence_loss + class_loss + batch_size = prediction.shape[0] + return loss / batch_size + + +class YOLOV5(nn.Cell): + """ + YOLOV5 network. + + Args: + is_training: Bool. Whether train or not. + + Returns: + Cell, cell instance of YOLOV5 neural network. + + Examples: + YOLOV5s(True) + """ + + def __init__(self, is_training, version=0): + super(YOLOV5, self).__init__() + self.config = default_config + + # YOLOv5 network + self.shape = self.config.input_shape[version] + self.feature_map = YOLO(backbone=YOLOv5Backbone(shape=self.shape), shape=self.shape) + + # prediction on the default anchor boxes + self.detect_1 = DetectionBlock('l', is_training=is_training) + self.detect_2 = DetectionBlock('m', is_training=is_training) + self.detect_3 = DetectionBlock('s', is_training=is_training) + self.mean = mindspore.Tensor(np.array([0.485 * 255, 0.456 * 255, 0.406 * 255], + dtype=np.float32)).reshape((1, 1, 1, 3)) + self.std = mindspore.Tensor(np.array([0.229 * 255, 0.224 * 255, 0.225 * 255], + dtype=np.float32)).reshape((1, 1, 1, 3)) + + def construct(self, x, input_shape): + x = (x - self.mean) / self.std + x = ops.transpose(x, (0, 3, 1, 2)) + x = ops.concat((x[:, :, ::2, ::2], x[:, :, 1::2, ::2], x[:, :, ::2, 1::2], x[:, :, 1::2, 1::2]), 1) + small_object_output, medium_object_output, big_object_output = self.feature_map(x) + output_big = self.detect_1(big_object_output, input_shape) + output_me = self.detect_2(medium_object_output, input_shape) + output_small = self.detect_3(small_object_output, input_shape) + # big is the final output which has smallest feature map + return output_big, output_me, output_small + + +class YOLOV5s_Infer(nn.Cell): + """ + YOLOV5 Infer. + """ + + def __init__(self, input_shape, version=0): + super(YOLOV5s_Infer, self).__init__() + self.network = YOLOV5(is_training=False, version=version) + self.input_shape = input_shape + + def construct(self, x): + return self.network(x, self.input_shape) + + +class YoloWithLossCell(nn.Cell): + """YOLOV5 loss.""" + def __init__(self, network): + super(YoloWithLossCell, self).__init__() + self.yolo_network = network + self.config = default_config + self.loss_big = YoloLossBlock('l', self.config) + self.loss_me = YoloLossBlock('m', self.config) + self.loss_small = YoloLossBlock('s', self.config) + self.tenser_to_array = ops.TupleToArray() + + def construct(self, x, y_true_0, y_true_1, y_true_2, gt_0, gt_1, gt_2, input_shape): + yolo_out = self.yolo_network(x, input_shape) + loss_l = self.loss_big(*yolo_out[0], y_true_0, gt_0, input_shape) + loss_m = self.loss_me(*yolo_out[1], y_true_1, gt_1, input_shape) + loss_s = self.loss_small(*yolo_out[2], y_true_2, gt_2, input_shape) + return loss_l + loss_m + loss_s * 0.2 + + +class GIou(nn.Cell): + """Calculating giou""" + def __init__(self): + super(GIou, self).__init__() + self.reshape = ops.Reshape() + self.min = ops.Minimum() + self.max = ops.Maximum() + self.concat = ops.Concat(axis=1) + self.mean = ops.ReduceMean() + self.div = ops.RealDiv() + self.eps = 0.000001 + + def construct(self, box_p, box_gt): + print("*******************************************GIOU**********************************************************") + """construct method""" + box_p_area = (box_p[..., 2:3] - box_p[..., 0:1]) * (box_p[..., 3:4] - box_p[..., 1:2]) + box_gt_area = (box_gt[..., 2:3] - box_gt[..., 0:1]) * (box_gt[..., 3:4] - box_gt[..., 1:2]) + x_1 = self.max(box_p[..., 0:1], box_gt[..., 0:1]) + x_2 = self.min(box_p[..., 2:3], box_gt[..., 2:3]) + y_1 = self.max(box_p[..., 1:2], box_gt[..., 1:2]) + y_2 = self.min(box_p[..., 3:4], box_gt[..., 3:4]) + intersection = (y_2 - y_1) * (x_2 - x_1) + xc_1 = self.min(box_p[..., 0:1], box_gt[..., 0:1]) + xc_2 = self.max(box_p[..., 2:3], box_gt[..., 2:3]) + yc_1 = self.min(box_p[..., 1:2], box_gt[..., 1:2]) + yc_2 = self.max(box_p[..., 3:4], box_gt[..., 3:4]) + c_area = (xc_2 - xc_1) * (yc_2 - yc_1) + union = box_p_area + box_gt_area - intersection + union = union + self.eps + c_area = c_area + self.eps + iou = self.div(ops.cast(intersection, mindspore.float32), ops.cast(union, mindspore.float32)) + res_mid0 = c_area - union + res_mid1 = self.div(ops.cast(res_mid0, mindspore.float32), ops.cast(c_area, mindspore.float32)) + giou = iou - res_mid1 + giou = ops.clip_by_value(giou, -1.0, 1.0) + return giou + + +class CIou(nn.Cell): + """Calculating CIoU loss.""" + def __init__(self): + super(CIou, self).__init__() + self.min = ops.Minimum() + self.max = ops.Maximum() + self.clip = ops.clip_by_value + self.atan = ops.Atan() + self.stop_gradient = ops.stop_gradient + self.eps = 1e-6 + + def construct(self, box_p, box_gt): + """Construct method to compute CIoU.""" + # 计算预测框和真实框的面积 + box_p_area = (box_p[..., 2] - box_p[..., 0]) * (box_p[..., 3] - box_p[..., 1]) + box_gt_area = (box_gt[..., 2] - box_gt[..., 0]) * (box_gt[..., 3] - box_gt[..., 1]) + + # 计算交集的坐标 + x1 = self.max(box_p[..., 0], box_gt[..., 0]) + y1 = self.max(box_p[..., 1], box_gt[..., 1]) + x2 = self.min(box_p[..., 2], box_gt[..., 2]) + y2 = self.min(box_p[..., 3], box_gt[..., 3]) + + # 计算交集的宽度和高度,并裁剪为非负值 + inter_w = self.clip(x2 - x1, 0.0, None) + inter_h = self.clip(y2 - y1, 0.0, None) + intersection = inter_w * inter_h + + # 计算并集的面积 + union = box_p_area + box_gt_area - intersection + self.eps + + # 计算IoU + iou = intersection / union + + # 计算预测框和真实框的中心点 + box_p_center_x = (box_p[..., 0] + box_p[..., 2]) / 2 + box_p_center_y = (box_p[..., 1] + box_p[..., 3]) / 2 + box_gt_center_x = (box_gt[..., 0] + box_gt[..., 2]) / 2 + box_gt_center_y = (box_gt[..., 1] + box_gt[..., 3]) / 2 + + # 计算中心点之间的欧氏距离的平方 + center_dist = (box_p_center_x - box_gt_center_x) ** 2 + (box_p_center_y - box_gt_center_y) ** 2 + + # 计算最小包络框的对角线长度的平方 + enclose_x1 = self.min(box_p[..., 0], box_gt[..., 0]) + enclose_y1 = self.min(box_p[..., 1], box_gt[..., 1]) + enclose_x2 = self.max(box_p[..., 2], box_gt[..., 2]) + enclose_y2 = self.max(box_p[..., 3], box_gt[..., 3]) + enclose_diag = (enclose_x2 - enclose_x1) ** 2 + (enclose_y2 - enclose_y1) ** 2 + self.eps + + # 计算距离惩罚项 + distance_term = center_dist / enclose_diag + + # 计算宽高比惩罚项 + # 预测框和真实框的宽度和高度 + box_p_w = box_p[..., 2] - box_p[..., 0] + self.eps + box_p_h = box_p[..., 3] - box_p[..., 1] + self.eps + box_gt_w = box_gt[..., 2] - box_gt[..., 0] + self.eps + box_gt_h = box_gt[..., 3] - box_gt[..., 1] + self.eps + + # 计算v项(宽高比相似度) + v = (4 / (math.pi ** 2)) * (self.atan(box_gt_w / box_gt_h) - self.atan(box_p_w / box_p_h)) ** 2 + + # 计算α项,并停止梯度传播 + with ops.stop_gradient(): + S = 1 - iou + v + self.eps + alpha = v / S + + # 计算CIoU + ciou = iou - (distance_term + alpha * v) + + # 将CIoU裁剪到[-1, 1]之间 + ciou = self.clip(ciou, -1.0, 1.0) + + return ciou + +def xywh2x1y1x2y2(box_xywh): + boxes_x1 = box_xywh[..., 0:1] - box_xywh[..., 2:3] / 2 + boxes_y1 = box_xywh[..., 1:2] - box_xywh[..., 3:4] / 2 + boxes_x2 = box_xywh[..., 0:1] + box_xywh[..., 2:3] / 2 + boxes_y2 = box_xywh[..., 1:2] + box_xywh[..., 3:4] / 2 + boxes_x1y1x2y2 = ops.Concat(-1)((boxes_x1, boxes_y1, boxes_x2, boxes_y2)) + + return boxes_x1y1x2y2 + +from mindspore import nn, ops, Tensor +import mindspore.numpy as mnp +class WIoU(nn.Cell): + """Calculating WIoU""" + def __init__(self): + super(WIoU, self).__init__() + self.reshape = ops.Reshape() + self.min = ops.Minimum() + self.max = ops.Maximum() + self.concat = ops.Concat(axis=1) + self.mean = ops.ReduceMean() + self.div = ops.RealDiv() + self.eps = 0.000001 + + def construct(self, box_p, box_gt): + # print("*******************************************WIoU**********************************************************") + """construct method""" + # 计算预测框和真实框的面积 + box_p_area = (box_p[..., 2:3] - box_p[..., 0:1]) * (box_p[..., 3:4] - box_p[..., 1:2]) + box_gt_area = (box_gt[..., 2:3] - box_gt[..., 0:1]) * (box_gt[..., 3:4] - box_gt[..., 1:2]) + + # 计算交集坐标 + x_1 = self.max(box_p[..., 0:1], box_gt[..., 0:1]) + y_1 = self.max(box_p[..., 1:2], box_gt[..., 1:2]) + x_2 = self.min(box_p[..., 2:3], box_gt[..., 2:3]) + y_2 = self.min(box_p[..., 3:4], box_gt[..., 3:4]) + + # 计算交集面积 + intersection = (x_2 - x_1).clip(0, None) * (y_2 - y_1).clip(0, None) + + # 计算并集面积 + union = box_p_area + box_gt_area - intersection + self.eps + + # 计算IoU + iou = self.div(ops.cast(intersection, mindspore.float32), ops.cast(union, mindspore.float32)) + + # 计算中心点坐标 + x_p_center = (box_p[..., 0:1] + box_p[..., 2:3]) / 2 + y_p_center = (box_p[..., 1:2] + box_p[..., 3:4]) / 2 + x_gt_center = (box_gt[..., 0:1] + box_gt[..., 2:3]) / 2 + y_gt_center = (box_gt[..., 1:2] + box_gt[..., 3:4]) / 2 + + # 计算中心点之间的距离平方 + rho2 = (x_p_center - x_gt_center) ** 2 + (y_p_center - y_gt_center) ** 2 + + # 计算最小包络框的对角线长度平方 + xc_1 = self.min(box_p[..., 0:1], box_gt[..., 0:1]) + yc_1 = self.min(box_p[..., 1:2], box_gt[..., 1:2]) + xc_2 = self.max(box_p[..., 2:3], box_gt[..., 2:3]) + yc_2 = self.max(box_p[..., 3:4], box_gt[..., 3:4]) + c2 = (xc_2 - xc_1) ** 2 + (yc_2 - yc_1) ** 2 + self.eps + + # 计算WIoU + wiou = iou - self.div(ops.cast(rho2, mindspore.float32), ops.cast(c2, mindspore.float32)) + wiou = ops.clip_by_value(wiou, -1.0, 1.0) + return wiou + + + + +def ciou(boxes1,boxes2): + ''' + cal CIOU of two boxes or batch boxes + :param boxes1:[xmin,ymin,xmax,ymax] or + [[xmin,ymin,xmax,ymax],[xmin,ymin,xmax,ymax],...] + :param boxes2:[xmin,ymin,xmax,ymax] + :return: + ''' + + #cal the box's area of boxes1 and boxess + boxes1Area = (boxes1[...,2]-boxes1[...,0])*(boxes1[...,3]-boxes1[...,1]) + boxes2Area = (boxes2[..., 2] - boxes2[..., 0]) * (boxes2[..., 3] - boxes2[..., 1]) + + # cal Intersection + left_up = np.maximum(boxes1[...,:2],boxes2[...,:2]) + right_down = np.minimum(boxes1[...,2:],boxes2[...,2:]) + + inter_section = np.maximum(right_down-left_up,0.0) + inter_area = inter_section[...,0] * inter_section[...,1] + union_area = boxes1Area+boxes2Area-inter_area + ious = np.maximum(1.0*inter_area/union_area,np.finfo(np.float32).eps) + + # cal outer boxes + outer_left_up = np.minimum(boxes1[..., :2], boxes2[..., :2]) + outer_right_down = np.maximum(boxes1[..., 2:], boxes2[..., 2:]) + outer = np.maximum(outer_right_down - outer_left_up, 0.0) + outer_diagonal_line = np.square(outer[...,0]) + np.square(outer[...,1]) + + # cal center distance + boxes1_center = (boxes1[..., :2] + boxes1[...,2:]) * 0.5 + boxes2_center = (boxes2[..., :2] + boxes2[...,2:]) * 0.5 + center_dis = np.square(boxes1_center[...,0]-boxes2_center[...,0]) +\ + np.square(boxes1_center[...,1]-boxes2_center[...,1]) + + # cal penalty term + # cal width,height + boxes1_size = np.maximum(boxes1[...,2:]-boxes1[...,:2],0.0) + boxes2_size = np.maximum(boxes2[..., 2:] - boxes2[..., :2], 0.0) + v = (4.0/np.square(np.pi)) * np.square(( + np.arctan((boxes1_size[...,0]/boxes1_size[...,1])) - + np.arctan((boxes2_size[..., 0] / boxes2_size[..., 1])) )) + alpha = v / (1-ious+v) + #cal ciou + cious = ious - (center_dis / outer_diagonal_line + alpha*v) + + return cious + + diff --git a/community/cv/ADCAM/src/yolo_dataset.py b/community/cv/ADCAM/src/yolo_dataset.py new file mode 100644 index 0000000000000000000000000000000000000000..f70162b9cf924281eebd5d3a0f17c961a8e621e5 --- /dev/null +++ b/community/cv/ADCAM/src/yolo_dataset.py @@ -0,0 +1,276 @@ +# YOLOV5 dataset +import os +import multiprocessing +import random +import numpy as np +import cv2 +from PIL import Image +from pycocotools.coco import COCO +import mindspore.dataset as ds +from src.distributed_sampler import DistributedSampler +from src.transforms import reshape_fn, MultiScaleTrans, PreprocessTrueBox + + +min_keypoints_per_image = 10 +GENERATOR_PARALLEL_WORKER = 8 + +def _has_only_empty_bbox(anno): + return all(any(o <= 1 for o in obj["bbox"][2:]) for obj in anno) + + +def _count_visible_keypoints(anno): + return sum(sum(1 for v in ann["keypoints"][2::3] if v > 0) for ann in anno) + + +def has_valid_annotation(anno): + """Check annotation file.""" + # if it's empty, there is no annotation + if not anno: + return False + # if all boxes have close to zero area, there is no annotation + if _has_only_empty_bbox(anno): + return False + # keypoints task have a slight different criteria for considering + # if an annotation is valid + if "keypoints" not in anno[0]: + return True + # for keypoint detection tasks, only consider valid images those + # containing at least min_keypoints_per_image + if _count_visible_keypoints(anno) >= min_keypoints_per_image: + return True + return False + + +class COCOYoloDataset: + """YOLOV5 Dataset for COCO.""" + def __init__(self, root, ann_file, remove_images_without_annotations=True, + filter_crowd_anno=True, is_training=True): + self.coco = COCO(ann_file) + self.root = root + self.img_ids = list(sorted(self.coco.imgs.keys())) + self.filter_crowd_anno = filter_crowd_anno + self.is_training = is_training + self.mosaic = True + # filter images without any annotations + if remove_images_without_annotations: + img_ids = [] + for img_id in self.img_ids: + ann_ids = self.coco.getAnnIds(imgIds=img_id, iscrowd=None) + anno = self.coco.loadAnns(ann_ids) + if has_valid_annotation(anno): + img_ids.append(img_id) + self.img_ids = img_ids + + self.categories = {cat["id"]: cat["name"] for cat in self.coco.cats.values()} + + self.cat_ids_to_continuous_ids = { + v: i for i, v in enumerate(self.coco.getCatIds()) + } + self.continuous_ids_cat_ids = { + v: k for k, v in self.cat_ids_to_continuous_ids.items() + } + self.count = 0 + + def _mosaic_preprocess(self, index, input_size): + labels4 = [] + s = 384 + self.mosaic_border = [-s // 2, -s // 2] + yc, xc = [int(random.uniform(-x, 2 * s + x)) for x in self.mosaic_border] + indices = [index] + [random.randint(0, len(self.img_ids) - 1) for _ in range(3)] + for i, img_ids_index in enumerate(indices): + coco = self.coco + img_id = self.img_ids[img_ids_index] + # print("================") + img_path = coco.loadImgs(img_id)[0]["file_name"] + # print(coco.loadImgs(img_id)[0]) #{'id': 20180004325, 'file_name': 'IP025000201', 'width': 539, 'height': 356} + + # print(os.path.join(self.root, img_path)+"===========") + if not img_path.lower().endswith('.jpg'): + img_path += '.jpg' # 添加后缀 + img = Image.open(os.path.join(self.root, img_path)).convert("RGB") + + img = np.array(img) + h, w = img.shape[:2] + + if i == 0: # top left + img4 = np.full((s * 2, s * 2, img.shape[2]), 128, dtype=np.uint8) # base image with 4 tiles + x1a, y1a, x2a, y2a = max(xc - w, 0), max(yc - h, 0), xc, yc # xmin, ymin, xmax, ymax (large image) + x1b, y1b, x2b, y2b = w - (x2a - x1a), h - (y2a - y1a), w, h # xmin, ymin, xmax, ymax (small image) + elif i == 1: # top right + x1a, y1a, x2a, y2a = xc, max(yc - h, 0), min(xc + w, s * 2), yc + x1b, y1b, x2b, y2b = 0, h - (y2a - y1a), min(w, x2a - x1a), h + elif i == 2: # bottom left + x1a, y1a, x2a, y2a = max(xc - w, 0), yc, xc, min(s * 2, yc + h) + x1b, y1b, x2b, y2b = w - (x2a - x1a), 0, w, min(y2a - y1a, h) + elif i == 3: # bottom right + x1a, y1a, x2a, y2a = xc, yc, min(xc + w, s * 2), min(s * 2, yc + h) + x1b, y1b, x2b, y2b = 0, 0, min(w, x2a - x1a), min(y2a - y1a, h) + + img4[y1a:y2a, x1a:x2a] = img[y1b:y2b, x1b:x2b] # img4[ymin:ymax, xmin:xmax] + + padw = x1a - x1b + padh = y1a - y1b + + ann_ids = coco.getAnnIds(imgIds=img_id) + target = coco.loadAnns(ann_ids) + # filter crowd annotations + if self.filter_crowd_anno: + annos = [anno for anno in target if anno["iscrowd"] == 0] + else: + annos = [anno for anno in target] + + target = {} + boxes = [anno["bbox"] for anno in annos] + target["bboxes"] = boxes + + classes = [anno["category_id"] for anno in annos] + classes = [self.cat_ids_to_continuous_ids[cl] for cl in classes] + target["labels"] = classes + + bboxes = target['bboxes'] + labels = target['labels'] + out_target = [] + + for bbox, label in zip(bboxes, labels): + tmp = [] + # convert to [x_min y_min x_max y_max] + bbox = self._convetTopDown(bbox) + tmp.extend(bbox) + tmp.append(int(label)) + # tmp [x_min y_min x_max y_max, label] + out_target.append(tmp) # 这里out_target是label的实际宽高,对应于图片中的实际度量 + + labels = out_target.copy() + labels = np.array(labels) + out_target = np.array(out_target) + + labels[:, 0] = out_target[:, 0] + padw + labels[:, 1] = out_target[:, 1] + padh + labels[:, 2] = out_target[:, 2] + padw + labels[:, 3] = out_target[:, 3] + padh + labels4.append(labels) + + if labels4: + labels4 = np.concatenate(labels4, 0) + np.clip(labels4[:, :4], 0, 2 * s, out=labels4[:, :4]) # use with random_perspective + flag = np.array([1]) + return img4, labels4, input_size, flag + + def __getitem__(self, index): + """ + Args: + index (int): Index + + Returns: + (img, target) (tuple): target is a dictionary contains "bbox", "segmentation" or "keypoints", + generated by the image's annotation. img is a PIL image. + """ + coco = self.coco + img_id = self.img_ids[index] + img_path = coco.loadImgs(img_id)[0]["file_name"] + + if not img_path.lower().endswith(('.jpg', '.png')): # 根据实际情况添加其他格式 + img_path += '.jpg' # 添加后缀 + + if not self.is_training: + img = Image.open(os.path.join(self.root, img_path)).convert("RGB") + return img, img_id + + input_size = [640, 640] + if self.mosaic and random.random() < 0.5: + return self._mosaic_preprocess(index, input_size) + if not img_path.lower().endswith(('.jpg', '.png')): # 根据实际情况添加其他格式 + img_path += '.jpg' # 添加后缀 + img = np.fromfile(os.path.join(self.root, img_path), dtype='int8') + ann_ids = coco.getAnnIds(imgIds=img_id) + target = coco.loadAnns(ann_ids) + # filter crowd annotations + if self.filter_crowd_anno: + annos = [anno for anno in target if anno["iscrowd"] == 0] + else: + annos = [anno for anno in target] + + target = {} + boxes = [anno["bbox"] for anno in annos] + target["bboxes"] = boxes + + classes = [anno["category_id"] for anno in annos] + classes = [self.cat_ids_to_continuous_ids[cl] for cl in classes] + target["labels"] = classes + + bboxes = target['bboxes'] + labels = target['labels'] + out_target = [] + for bbox, label in zip(bboxes, labels): + tmp = [] + # convert to [x_min y_min x_max y_max] + bbox = self._convetTopDown(bbox) + tmp.extend(bbox) + tmp.append(int(label)) + # tmp [x_min y_min x_max y_max, label] + out_target.append(tmp) + flag = np.array([0]) + return img, out_target, input_size, flag + + def __len__(self): + return len(self.img_ids) + + def _convetTopDown(self, bbox): + x_min = bbox[0] + y_min = bbox[1] + w = bbox[2] + h = bbox[3] + return [x_min, y_min, x_min+w, y_min+h] + + +def create_yolo_dataset(image_dir, anno_path, batch_size, device_num, rank, + config=None, is_training=True, shuffle=True): + """Create dataset for YOLOV5.""" + cv2.setNumThreads(0) + ds.config.set_enable_shared_mem(True) + if is_training: + filter_crowd = True + remove_empty_anno = True + else: + filter_crowd = False + remove_empty_anno = False + + yolo_dataset = COCOYoloDataset(root=image_dir, ann_file=anno_path, filter_crowd_anno=filter_crowd, + remove_images_without_annotations=remove_empty_anno, is_training=is_training) + distributed_sampler = DistributedSampler(len(yolo_dataset), device_num, rank, shuffle=shuffle) + yolo_dataset.size = len(distributed_sampler) + + config.dataset_size = len(yolo_dataset) + cores = multiprocessing.cpu_count() + num_parallel_workers = int(cores / device_num) + if is_training: + multi_scale_trans = MultiScaleTrans(config, device_num) + yolo_dataset.transforms = multi_scale_trans + + dataset_column_names = ["image", "annotation", "input_size", "mosaic_flag"] + output_column_names = ["image", "annotation", "bbox1", "bbox2", "bbox3", + "gt_box1", "gt_box2", "gt_box3"] + map1_out_column_names = ["image", "annotation", "size"] + map2_in_column_names = ["annotation", "size"] + map2_out_column_names = ["annotation", "bbox1", "bbox2", "bbox3", + "gt_box1", "gt_box2", "gt_box3"] + + dataset = ds.GeneratorDataset(yolo_dataset, column_names=dataset_column_names, sampler=distributed_sampler, + python_multiprocessing=True, num_parallel_workers=min(4, num_parallel_workers)) + dataset = dataset.map(operations=multi_scale_trans, input_columns=dataset_column_names, + output_columns=map1_out_column_names, + num_parallel_workers=min(12, num_parallel_workers), python_multiprocessing=True) + dataset = dataset.map(operations=PreprocessTrueBox(config), input_columns=map2_in_column_names, + output_columns=map2_out_column_names, + num_parallel_workers=min(4, num_parallel_workers), python_multiprocessing=False) + dataset = dataset.project(output_column_names) + dataset = dataset.batch(batch_size, num_parallel_workers=min(4, num_parallel_workers), drop_remainder=True) + else: + dataset = ds.GeneratorDataset(yolo_dataset, column_names=["image", "img_id"], + sampler=distributed_sampler) + compose_map_func = (lambda image, img_id: reshape_fn(image, img_id, config)) + dataset = dataset.map(operations=compose_map_func, input_columns=["image", "img_id"], + output_columns=["image", "image_shape", "img_id"], + num_parallel_workers=8) + dataset = dataset.batch(batch_size, drop_remainder=True) + return dataset diff --git a/community/cv/ADCAM/train.py b/community/cv/ADCAM/train.py new file mode 100644 index 0000000000000000000000000000000000000000..d20e0d86b88e0f0fedcfca60f8b60251036fbf4a --- /dev/null +++ b/community/cv/ADCAM/train.py @@ -0,0 +1,197 @@ +# 训练脚本 + +import os +import time +from collections import deque +import mindspore +import mindspore.nn as nn +import mindspore.communication as comm +from mindspore import load_checkpoint, Parameter, save_checkpoint + +from model_utils.config import config +from model_utils.device_adapter import get_device_id +from model_utils.moxing_adapter import moxing_wrapper, modelarts_pre_process, modelarts_post_process + +from src.yolo import YOLOV5, YoloWithLossCell +from src.logger import get_logger +from src.util import AverageMeter, get_param_groups, cpu_affinity, EvalWrapper, DetectionEngine +from src.lr_scheduler import get_lr +from src.yolo_dataset import create_yolo_dataset +from src.initializer import default_recurisive_init, load_yolov5_params + + +mindspore.set_seed(1) + +def init_distribute(): + comm.init() + config.rank = comm.get_rank() + config.group_size = comm.get_group_size() + mindspore.set_auto_parallel_context(parallel_mode=mindspore.ParallelMode.DATA_PARALLEL, gradients_mean=True, + device_num=config.group_size) + + +def train_preprocess(): + if config.lr_scheduler == 'cosine_annealing' and config.max_epoch > config.T_max: + config.T_max = config.max_epoch + + config.lr_epochs = list(map(int, config.lr_epochs.split(','))) + config.train_img_dir = os.path.join(config.data_dir, config.train_img_dir) + config.train_ann_file = os.path.join(config.data_dir, config.train_ann_file) + device_id = get_device_id() + if config.device_target == "Ascend": + device_id = get_device_id() + mindspore.set_context(mode=0, device_target=config.device_target, device_id=device_id) + else: + mindspore.set_context(mode=0, device_target=config.device_target) + + if config.is_distributed: + # 初始化分布式 + init_distribute() + + # 用于提升GPU设备的性能 + if config.device_target == "GPU" and config.bind_cpu: + cpu_affinity(config.rank, min(config.group_size, config.device_num)) + + # 日志模块由配置文件管理,并在其他函数中使用。例如:config.logger.info("xxx") + config.logger = get_logger(config.output_dir, config.rank) + config.logger.save_args(config) + + +def get_val_dataset(): + config.val_img_dir = os.path.join(config.data_dir, config.val_img_dir) + config.val_ann_file = os.path.join(config.data_dir, config.val_ann_file) + ds_val = create_yolo_dataset(config.val_img_dir, config.val_ann_file, + is_training=False, + batch_size=config.per_batch_size, + device_num=config.group_size, + rank=config.rank, config=config) + config.logger.info("Finish loading val dataset!") + return ds_val + + +def load_parameters(val_network, train_network): + config.logger.info("Load parameters of train network") + param_dict_new = {} + for key, values in train_network.parameters_and_names(): + if key.startswith('moments.'): + continue + elif key.startswith('yolo_network.'): + param_dict_new[key[13:]] = values + else: + param_dict_new[key] = values + mindspore.load_param_into_net(val_network, param_dict_new) + config.logger.info('Load train network success') + + +def load_best_results(): + best_ckpt_path = os.path.join(config.output_dir, 'best.ckpt') + if os.path.exists(best_ckpt_path): + param_dict = load_checkpoint(best_ckpt_path) + best_result = param_dict['best_result'].asnumpy().item() + best_epoch = param_dict['best_epoch'].asnumpy().item() + config.logger.info('cur best result %s at epoch %s', best_result, best_epoch) + return best_result, best_epoch + return 0.0, 0 + + +def save_best_checkpoint(network, best_result, best_epoch): + param_list = [{'name': 'best_result', 'data': Parameter(best_result)}, + {'name': 'best_epoch', 'data': Parameter(best_epoch)}] + for name, param in network.parameters_and_names(): + param_list.append({'name': name, 'data': param}) + save_checkpoint(param_list, os.path.join(config.output_dir, 'best.ckpt')) + + +def is_val_epoch(epoch_idx: int): + epoch = epoch_idx + 1 + return ( + (epoch >= config.eval_start_epoch) and + ((epoch_idx + 1) % config.eval_epoch_interval == 0 or (epoch_idx + 1) == config.max_epoch) + ) + +@moxing_wrapper(pre_process=modelarts_pre_process, post_process=modelarts_post_process, pre_args=[config]) +def run_train(): + train_preprocess() + config.eval_parallel = config.run_eval and config.is_distributed and config.eval_parallel + loss_meter = AverageMeter('loss') + dict_version = {'yolov5s': 0, 'yolov5m': 1, 'yolov5l': 2, 'yolov5x': 3} + network = YOLOV5(is_training=True, version=dict_version[config.yolov5_version]) + val_network = YOLOV5(is_training=False, version=dict_version[config.yolov5_version]) + # 默认是 Kaiming-normal 初始化 + default_recurisive_init(network) + load_yolov5_params(config, network) + network = YoloWithLossCell(network) + + ds = create_yolo_dataset(image_dir=config.train_img_dir, anno_path=config.train_ann_file, is_training=True, + batch_size=config.per_batch_size, device_num=config.group_size, + rank=config.rank, config=config) + config.logger.info('Finish loading train dataset') + ds_val = get_val_dataset() + + steps_per_epoch = ds.get_dataset_size() + lr = get_lr(config, steps_per_epoch) + opt = nn.Momentum(params=get_param_groups(network), momentum=config.momentum, learning_rate=mindspore.Tensor(lr), + weight_decay=config.weight_decay, loss_scale=config.loss_scale) + network = nn.TrainOneStepCell(network, opt, config.loss_scale // 2) + network.set_train() + + data_loader = ds.create_tuple_iterator(do_copy=False) + first_step = True + t_end = time.time() + # 如果存在先前的最佳结果,则加载这些结果。 + best_result, best_epoch = load_best_results() + engine = DetectionEngine(config, config.test_ignore_threshold) + eval_wrapper = EvalWrapper(config, val_network, ds_val, engine) + ckpt_queue = deque() + for epoch_idx in range(config.max_epoch): + for step_idx, data in enumerate(data_loader): + images = data[0] + input_shape = images.shape[1:3] + input_shape = mindspore.Tensor(input_shape, mindspore.float32) + loss = network(images, data[2], data[3], data[4], data[5], data[6], + data[7], input_shape) + loss_meter.update(loss.asnumpy()) + + # 它用于按照配置文件中设置的 log_interval 步骤来输出损失和性能结果。 + if (epoch_idx * steps_per_epoch + step_idx) % config.log_interval == 0: + time_used = time.time() - t_end + if first_step: + fps = config.per_batch_size * config.group_size / time_used + per_step_time = time_used * 1000 + first_step = False + else: + fps = config.per_batch_size * config.log_interval * config.group_size / time_used + per_step_time = time_used / config.log_interval * 1000 + config.logger.info('epoch[{}], iter[{}], {}, fps:{:.2f} imgs/sec, ' + 'lr:{}, per step time: {}ms'.format(epoch_idx + 1, step_idx + 1, + loss_meter, fps, lr[step_idx], per_step_time)) + t_end = time.time() + loss_meter.reset() + if config.rank == 0 and (epoch_idx % config.save_ckpt_interval == 0): + ckpt_name = os.path.join(config.output_dir, "yolov5_{}_{}.ckpt".format(epoch_idx + 1, steps_per_epoch)) + mindspore.save_checkpoint(network, ckpt_name) + if len(ckpt_queue) == config.save_ckpt_max_num: + ckpt_to_remove = ckpt_queue.popleft() + os.remove(ckpt_to_remove) + ckpt_queue.append(ckpt_name) + + if is_val_epoch(epoch_idx): + # 加载训练网络的权重到验证网络中,通常是为了确保验证过程中使用的是与当前训练状态一致的模型 + load_parameters(val_network, train_network=network) + eval_wrapper.inference() + eval_result, mAP = eval_wrapper.get_results(cur_epoch=epoch_idx + 1, cur_step=steps_per_epoch) + if mAP >= best_result: + best_result = mAP + best_epoch = epoch_idx + 1 + if config.rank == 0: + save_best_checkpoint(network, best_result, best_epoch) + config.logger.info("Best result %s at %s epoch", best_result, best_epoch) + config.logger.info(eval_result) + config.logger.info('Ending inference...') + + + config.logger.info('==========end training===============') + + +if __name__ == "__main__": + run_train()