Skip to content
Snippets Groups Projects
Commit 10c902ca authored by DrTrippleJ's avatar DrTrippleJ
Browse files

my first commit

parent 72ae5943
No related branches found
No related tags found
No related merge requests found
Showing
with 1782 additions and 0 deletions
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
ARG FROM_IMAGE_NAME
FROM ${FROM_IMAGE_NAME}
USER root
COPY requirements.txt .
RUN pip install -r requirements.txt
\ No newline at end of file
#!/bin/bash
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
if [ $# -ne 2 ]
then
echo "Wrong parameter format."
echo "Usage:"
echo " bash $0 [INPUT_AIR_PATH] [OUTPUT_OM_PATH_NAME]"
echo "Example: "
echo " bash convert_om.sh xxx.air xx"
exit 1
fi
model_path=$1
output_model_name=$2
atc \
--input_format=ND \
--framework=1 \
--model=$model_path \
--output=$output_model_name \
--soc_version=Ascend310 \
--disable_reuse_memory=0 \
--precision_mode=allow_fp32_to_fp16 \
--op_select_implmode=high_precision
{
"im_slowfast": {
"stream_config": {
"deviceId": "0"
},
"appsrc0": {
"props": {
"blocksize": "40960000"
},
"factory": "appsrc",
"next": "mxpi_tensorinfer0:0"
},
"appsrc1": {
"props": {
"blocksize": "40960000"
},
"factory": "appsrc",
"next": "mxpi_tensorinfer0:1"
},
"appsrc2": {
"props": {
"blocksize": "40960000"
},
"factory": "appsrc",
"next": "mxpi_tensorinfer0:2"
},
"mxpi_tensorinfer0": {
"props": {
"dataSource": "appsrc0,appsrc1,appsrc2",
"modelPath": "../data/model/slowfast.om"
},
"factory": "mxpi_tensorinfer",
"next": "appsink0"
},
"appsink0": {
"props": {
"blocksize": "4096000"
},
"factory": "appsink"
}
}
}
\ No newline at end of file
#!/usr/bin/env bash
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
docker_image=$1
data_path=$2
model_path=$3
function show_help() {
echo "Usage: docker_start.sh docker_image data_path"
}
function param_check() {
if [ -z "${docker_image}" ]; then
echo "please input docker_image"
show_help
exit 1
fi
if [ -z "${data_path}" ]; then
echo "please input data_path"
show_help
exit 1
fi
}
param_check
docker run -u root -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_path}:${data_path} \
-v ${model_path}:${model_path} \
${docker_image} \
/bin/bash
cmake_minimum_required(VERSION 3.5.2)
project(slowfast)
set(TARGET slowfast)
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")
add_definitions(-DENABLE_DVPP_INTERFACE)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
add_definitions(-Dgoogle=mindxsdk_private)
add_compile_options(-std=c++11 -fPIE -fstack-protector-all -fPIC -Wall)
add_compile_options("-DPLUGIN_NAME=${PLUGIN_NAME}")
add_compile_options("-Dgoogle=mindxsdk_private")
# Check environment variable
if(NOT DEFINED ENV{ASCEND_HOME})
message(FATAL_ERROR "please define environment variable:ASCEND_HOME")
endif()
if(NOT DEFINED ENV{ASCEND_VERSION})
message(WARNING "please define environment variable:ASCEND_VERSION")
endif()
if(NOT DEFINED ENV{ARCH_PATTERN})
message(WARNING "please define environment variable:ARCH_PATTERN")
endif()
# Set up ACLLIB header files and dynamic link libraries
set(ACL_INC_DIR $ENV{ASCEND_HOME}/${ASCEND_VERSION}/${ARCH_PATTERN}/acllib/include)
set(ACL_LIB_DIR $ENV{ASCEND_HOME}/${ASCEND_VERSION}/${ARCH_PATTERN}/acllib/lib64)
set(ACL_LIB_PATH $ENV{ASCEND_HOME}/ascend-toolkit/latest/acllib)
# Set the header file and dynamic link library of MXBase
set(MXBASE_ROOT_DIR $ENV{MX_SDK_HOME})
set(MXBASE_INC ${MXBASE_ROOT_DIR}/include)
set(MXBASE_LIB_DIR ${MXBASE_ROOT_DIR}/lib)
set(MXBASE_POST_LIB_DIR ${MXBASE_ROOT_DIR}/lib/modelpostprocessors)
# Set the header file and dynamic link library of OpenSource
# Mainly includes open source libraries such as OpenCV, Google Log
set(OPENSOURCE_DIR ${MXBASE_ROOT_DIR}/opensource)
include_directories(${MXBASE_ROOT_DIR}/opensource/include)
include_directories(${MXBASE_ROOT_DIR}/opensource/include/opencv4)
include_directories(${ACL_LIB_PATH}/include)
link_directories(${ACL_LIB_PATH}/lib64/)
link_directories(${MXBASE_ROOT_DIR}/lib)
link_directories(${MXBASE_ROOT_DIR}/opensource/lib/)
include_directories(${ACL_INC_DIR})
include_directories(${OPENSOURCE_DIR}/include)
include_directories(${OPENSOURCE_DIR}/include/opencv4)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${MXBASE_INC})
link_directories(${ACL_LIB_DIR})
link_directories(${OPENSOURCE_DIR}/lib)
link_directories(${MXBASE_LIB_DIR})
link_directories(${MXBASE_POST_LIB_DIR})
include_directories(/usr/local/Ascend/ascend-toolkit/latest/include)
# Locally compiled link files, add changes to files in the MXBase directory
add_executable(${TARGET} src/main.cpp src/SlowFast.cpp)
target_link_libraries(${TARGET} ${TARGET_LIBRARY} glog cpprest mxbase opencv_world stdc++fs)
install(TARGETS ${TARGET} RUNTIME DESTINATION ${PROJECT_SOURCE_DIR}/)
#!/bin/bash
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
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=ascend-toolkit/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_slowfast()
{
cd $path_cur
rm -rf build
mkdir -p build
cd build
cmake ..
make
ret=$?
if [ ${ret} -ne 0 ]; then
echo "Failed to build slowfast."
exit ${ret}
fi
make install
}
check_env
build_slowfast
#!/bin/bash
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
if [ $# != 2 ]
then
echo "Usage: bash run.sh [DATA_DIR] [OM_PATH]"
exit 1
fi
if [ ! -d $1 ]
then
echo "error: DATA_DIR=$1 is not a directory"
echo "Usage: bash run.sh [DATA_DIR] [OM_PATH]"
exit 1
fi
if [ ! -f $2 ]
then
echo "error: OM_PATH=$2 is not a file"
echo "Usage: bash run.sh [EVAL_DATA_DIR] [OM_PATH]"
exit 1
fi
echo "compile..."
bash build.sh
echo "done"
echo "infer..."
data_dir=$1
om_path=$2
./slowfast ${data_dir} ${om_path}
echo "done"
echo "cal acc..."
cp -r ../utils/* ./
cp -r ../../src ./
python3 CalPrecision.py --data_dir ${data_dir}
echo "done"
This diff is collapsed.
/*
* Copyright 2022 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SLOWFAST_
#define SLOWFAST_
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <opencv2/opencv.hpp>
#include "MxBase/DvppWrapper/DvppWrapper.h"
#include "MxBase/ModelInfer/ModelInferenceProcessor.h"
#include "MxBase/Tensor/TensorContext/TensorContext.h"
class SLOWFAST {
public:
SLOWFAST(const uint32_t &deviceId, const std::string &modelPath,
const std::string &datadir);
~SLOWFAST();
void ReadImage(std::string imgPath, cv::Mat &imageMat);
void ResizeImage(const cv::Mat &srcImageMat, cv::Mat &dstImageMat);
void LoadData();
void LoadData1();
void LoadData2();
void LoadData3();
void GetData(int idx);
std::vector<int> ReadClass();
std::vector<std::string> ReadExcluded_keys();
std::vector<std::vector<float>> ResizeBox(
std::vector<std::vector<float>> boxes, int height, int width);
std::vector<int> get_sequence(int center_idx, int half_len, int sample_rate,
int num_frames);
std::vector<std::vector<float>> pad2max_float(
std::vector<std::vector<float>> data);
std::vector<std::vector<int>> pad2max_int(std::vector<std::vector<int>> data);
int get_max();
int get_batch_size();
std::vector<cv::Mat> get_slow_pathway();
std::vector<cv::Mat> get_fast_pathway();
std::vector<std::vector<float>> get_padded_boxes();
APP_ERROR Process(const std::vector<std::vector<cv::Mat>> &input1,
const std::vector<std::vector<cv::Mat>> &input2,
const std::vector<std::vector<std::vector<float>>> &input3,
const std::vector<float> *output);
APP_ERROR post_process();
void write_results(
std::map<std::string, std::vector<std::vector<float>>> boxes,
std::map<std::string, std::vector<float>> labels,
std::map<std::string, std::vector<float>> scores, std::string filename);
APP_ERROR VectorToTensorBase_mat(
const std::vector<std::vector<cv::Mat>> &input, int idx,
MxBase::TensorBase *tensorBase);
APP_ERROR VectorToTensorBase_float(
const std::vector<std::vector<std::vector<float>>> &input, int idx,
MxBase::TensorBase *tensorBase);
APP_ERROR Inference(const std::vector<MxBase::TensorBase> &inputs,
std::vector<MxBase::TensorBase> *outputs);
APP_ERROR SaveInferResult(std::vector<float> *batchFeaturePaths,
const std::vector<MxBase::TensorBase> &inputs);
double GetInferCostMilliSec() const { return inferCostTimeMilliSec; }
private:
std::shared_ptr<MxBase::DvppWrapper> dvppWrapper_;
std::shared_ptr<MxBase::ModelInferenceProcessor> model_;
MxBase::ModelDesc modelDesc_;
uint32_t deviceId_ = 0;
double inferCostTimeMilliSec = 0.0;
// config
int _sample_rate = 2;
int _video_length = 32;
int _seq_len = _video_length * _sample_rate;
int _num_classes = 80;
std::vector<float> MEAN = {0.45, 0.45, 0.45};
std::vector<float> STD = {0.225, 0.225, 0.225};
bool BGR = false;
bool RANDOM_FLIP = true;
int TEST_CROP_SIZE = 224;
bool TEST_FORCE_FLIP = false;
int _scale_height = 256;
int _scale_width = 384;
int MAX_NUM_BOXES_PER_FRAME = 28;
int frame_min = 902;
int frame_max = 1798;
std::string DATADIR;
std::string ANN_DIR = "/ava/ava_annotations";
std::string FRA_DIR = "/ava/frames";
std::string FRAME_LIST_DIR;
std::string TEST_LISTS = "val.csv";
std::string FRAME_DIR;
std::string TEST_PREDICT_BOX_LISTS =
"person_box_67091280_iou90/ava_detection_val_boxes_and_labels.csv";
std::string ANNOTATION_DIR;
std::string EXCLUSION_FILE = "ava_val_excluded_timestamps_v2.2.csv";
std::string LABEL_MAP_FILE =
"person_box_67091280_iou90/"
"ava_action_list_v2.1_for_activitynet_2018.pbtxt";
std::string GROUNDTRUTH_FILE = "ava_val_v2.2.csv";
std::string OUTPUT_DIR = "./";
float DETECTION_SCORE_THRESH = 0.8;
std::string IMG_PROC_BACKEND = "cv2";
bool REVERSE_INPUT_CHANNEL = false;
std::string ARCH = "slowfast";
std::string MULTI_PATHWAY_ARCH = "slowfast";
int ALPHA = 4;
int BATCH_SIZE = 1;
int LOG_PERIOD = 1;
bool FULL_TEST_ON_VAL = false;
std::string sdk_pipeline_name = "im_slowfast";
std::vector<std::vector<std::string>> _image_paths;
std::vector<std::string> _video_idx_to_name;
std::vector<std::vector<int>> _keyframe_indices;
std::vector<std::vector<std::vector<std::vector<float>>>>
_keyframe_boxes_and_labels;
std::vector<cv::Mat> slow_pathway;
std::vector<cv::Mat> fast_pathway;
std::vector<std::vector<float>> padded_boxes;
std::vector<int> mask;
std::vector<std::vector<float>> padded_ori_boxes;
std::vector<std::vector<int>> padded_metadata;
std::vector<std::vector<float>> preds_final;
std::vector<std::vector<float>> ori_boxes_final;
std::vector<std::vector<int>> metadata_final;
std::vector<std::map<int, std::vector<std::vector<float>>>> boxs_all;
};
#endif
/*
* Copyright 2022 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <dirent.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "MxBase/Log/Log.h"
#include "SlowFast.h"
int main(int argc, char *argv[]) {
if (argc < 2) {
LogWarn << "Please input model_path and data_path.";
return APP_ERR_OK;
}
auto slowfast = std::make_shared<SLOWFAST>(0, argv[2], argv[1]);
printf("Start running\n");
slowfast->LoadData();
int data_size = slowfast->get_max();
LogInfo << "Total: " << data_size << " iters.";
int batch_size = slowfast->get_batch_size();
int count = 0;
std::vector<std::vector<cv::Mat>> slow_pathway;
std::vector<std::vector<cv::Mat>> fast_pathway;
std::vector<std::vector<std::vector<float>>> boxes;
for (int ii = 0; ii < data_size; ii++) {
count++;
slowfast->GetData(ii);
slow_pathway.push_back(slowfast->get_slow_pathway());
fast_pathway.push_back(slowfast->get_fast_pathway());
boxes.push_back(slowfast->get_padded_boxes());
if (count == batch_size) {
std::vector<float> preds;
APP_ERROR ret =
slowfast->Process(slow_pathway, fast_pathway, boxes, &preds);
LogInfo << "iter:" << ii << "/" << data_size;
if (ret != APP_ERR_OK) {
LogError << "slowfast process failed, ret=" << ret << ".";
return ret;
}
slow_pathway.resize(0);
fast_pathway.resize(0);
boxes.resize(0);
count = 0;
}
}
slowfast->post_process();
return APP_ERR_OK;
}
iopath==0.1.9
fvcore==0.1.5.post20220414
simplejson==3.17.6
\ No newline at end of file
# Copyright 2022 Huawei Technologies Co., Ltd. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
推理文件
"""
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
import argparse
from help.config import Config
from src.datasets.ava_dataset import Ava
from src.utils.meters import AVAMeter
from src.utils import logging
import numpy as np
import MxpiDataType_pb2 as MxpiDataType
from StreamManagerApi import StreamManagerApi, InProtobufVector, MxProtobufIn, StringVector
def parse_args():
"""set and check parameters."""
parser = argparse.ArgumentParser(description="SLOWFAST for AVA Dataset")
parser.add_argument("--pipeline", type=str,
default="../data/config/slowfast.pipeline", help="SDK infer pipeline")
parser.add_argument("--data_dir", type=str, default="../data/input",
help="Dataset contain frames and ava_annotations")
args_opt = parser.parse_args()
return args_opt
def send_tensor_input(stream_name_, plugin_id, input_data, input_shape, stream_manager):
"""" send tensor data to om """
tensor_list = MxpiDataType.MxpiTensorPackageList()
tensor_pkg = tensor_list.tensorPackageVec.add()
# init tensor vector
tensor_vec = tensor_pkg.tensorVec.add()
tensor_vec.deviceId = 0
tensor_vec.memType = 0
tensor_vec.tensorShape.extend(input_shape)
tensor_vec.tensorDataType = 0
tensor_vec.dataStr = input_data
tensor_vec.tensorDataSize = len(input_data)
return send_protobuf(stream_name_, plugin_id, tensor_list, stream_manager)
def send_protobuf(stream_name_, plugin_id, pkg_list, stream_manager):
"""" send data buffer to om """
protobuf = MxProtobufIn()
protobuf.key = "appsrc{}".format(plugin_id).encode('utf-8')
protobuf.type = b"MxTools.MxpiTensorPackageList"
protobuf.protobuf = pkg_list.SerializeToString()
protobuf_vec = InProtobufVector()
protobuf_vec.push_back(protobuf)
err_code = stream_manager.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), "
"err_code(%s).", stream_name_, plugin_id,
"appsrc{}".format(plugin_id).encode('utf-8'), err_code)
return False
return True
def get_result(stream_name_, stream_manager, out_plugin_id=0):
"""get_result"""
key_vec = StringVector()
key_vec.push_back(b'mxpi_tensorinfer0')
infer_result = stream_manager.GetProtobuf(
stream_name_, out_plugin_id, key_vec)
if infer_result.size() == 0:
print("inferResult is null")
return None
result_ = MxpiDataType.MxpiTensorPackageList()
result_.ParseFromString(infer_result[0].messageBuf)
return np.frombuffer(result_.tensorPackageVec[0].tensorVec[0].dataStr, dtype=np.float32)
def pack_input(input_):
for ii in range(len(input_)):
input_[ii] = input_[ii][np.newaxis, :]
return np.concatenate(input_, axis=0)
def main():
args = parse_args()
config = Config()
config.AVA.FRAME_LIST_DIR = args.data_dir + config.AVA.ANN_DIR
config.AVA.ANNOTATION_DIR = args.data_dir + config.AVA.ANN_DIR
config.AVA.FRAME_DIR = args.data_dir + config.AVA.FRA_DIR
stream_name = config.sdk_pipeline_name
# init stream manager
streamManagerApi = StreamManagerApi()
ret = streamManagerApi.InitManager()
if ret != 0:
print("Failed to init Stream manager, ret=%s" % str(ret))
return
# create streams by pipeline config file
with open(args.pipeline, "rb") as f:
pipeline_str = f.read()
ret = streamManagerApi.CreateMultipleStreams(pipeline_str)
if ret != 0:
print("Failed to create Stream, ret=%s" % str(ret))
return
# setup logger
logger = logging.get_logger(__name__)
logging.setup_logging()
logger.info(config)
dataset = Ava(config, "test")
meter = AVAMeter(len(dataset)/config.BATCH_SIZE, config, mode="test")
meter.iter_tic()
count = 0
cur_iter = 0
slowpaths = []
fastpaths = []
boxess = []
ori_boxess = []
metadatas = []
masks = []
for slowpath, fastpath, boxes, _, ori_boxes, metadata, mask in dataset:
count += 1
slowpaths.append(slowpath.astype(np.float32))
fastpaths.append(fastpath.astype(np.float32))
boxess.append(boxes.astype(np.float32))
ori_boxess.append(ori_boxes.astype(np.float32))
metadatas.append(metadata.astype(np.float32))
masks.append(mask.astype(np.float32))
if count == config.BATCH_SIZE:
slowpath_ = pack_input(slowpaths)
fastpath_ = pack_input(fastpaths)
boxes_ = pack_input(boxess)
ori_boxes_ = pack_input(ori_boxess)
metadata_ = pack_input(metadatas)
mask_ = pack_input(masks)
res0 = send_tensor_input(
stream_name, 0, slowpath_.tobytes(), slowpath_.shape, streamManagerApi)
res1 = send_tensor_input(
stream_name, 1, fastpath_.tobytes(), fastpath_.shape, streamManagerApi)
res2 = send_tensor_input(
stream_name, 2, boxes_.tobytes(), boxes_.shape, streamManagerApi)
if not res0 or not res1 or not res2:
return
preds = get_result(stream_name, streamManagerApi)
preds1 = preds.reshape(mask_.shape + (config.MODEL.NUM_CLASSES,))
mask_ = np.array(mask_).astype(bool)
preds = preds1[mask_]
padded_idx = np.tile(np.arange(mask_.shape[0]).reshape(
(-1, 1, 1)), (1, mask_.shape[1], 1))
ori_boxes_ = np.concatenate(
(padded_idx, np.array(ori_boxes_)), axis=2)[mask_]
metadata_ = np.array(metadata_)[mask_]
meter.update_stats(preds, ori_boxes_, metadata_)
meter.log_iter_stats(None, cur_iter)
meter.iter_tic()
count = 0
slowpaths = []
fastpaths = []
boxess = []
ori_boxess = []
metadatas = []
masks = []
cur_iter += 1
meter.finalize_metrics()
streamManagerApi.DestroyAllStreams()
if __name__ == "__main__":
main()
#!/bin/bash
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
set -e
# Simple log helper functions
info() { echo -e "\033[1;34m[INFO ][MxStream] $1\033[1;37m" ; }
warn() { echo >&2 -e "\033[1;31m[WARN ][MxStream] $1\033[1;37m" ; }
export LD_LIBRARY_PATH=${MX_SDK_HOME}/lib:${MX_SDK_HOME}/opensource/lib:${MX_SDK_HOME}/opensource/lib64:/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64:${LD_LIBRARY_PATH}
export GST_PLUGIN_SCANNER=${MX_SDK_HOME}/opensource/libexec/gstreamer-1.0/gst-plugin-scanner
export GST_PLUGIN_PATH=${MX_SDK_HOME}/opensource/lib/gstreamer-1.0:${MX_SDK_HOME}/lib/plugins
#to set PYTHONPATH, import the StreamManagerApi.py
export PYTHONPATH=$PYTHONPATH:${MX_SDK_HOME}/python
if [ $# != 2 ]
then
echo "Usage: bash run.sh [DATA_DIR] [PIPELINE_PATH]"
exit 1
fi
if [ ! -d $1 ]
then
echo "error: DATA_DIR=$1 is not a directory"
echo "Usage: bash run.sh [DATA_DIR] [PIPELINE_PATH]"
exit 1
fi
if [ ! -f $2 ]
then
echo "error: OM_PATH=$2 is not a file"
echo "Usage: bash run.sh [EVAL_DATA_DIR] [PIPELINE_PATH]"
exit 1
fi
echo "copy help function"
cp -r ../utils/help ./
cp -r ../../src ./
echo "infer by sdk"
data_dir=$1
pipeline=$2
python3 main.py --data_dir ${data_dir} --pipeline ${pipeline}
echo "done"
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
import argparse
import os
from src.utils import logging
from src.utils.ava_eval_helper import evaluate_ava_from_files
from help.config import Config
def parse_args():
"""set and check parameters."""
parser = argparse.ArgumentParser(description="SLOWFAST for AVA Dataset")
parser.add_argument("--data_dir", type=str, default="../data/input",
help="Dataset contain frames and ava_annotations")
args_opt = parser.parse_args()
return args_opt
def main():
args = parse_args()
config = Config()
config.AVA.FRAME_LIST_DIR = args.data_dir + config.AVA.ANN_DIR
config.AVA.ANNOTATION_DIR = args.data_dir + config.AVA.ANN_DIR
config.AVA.FRAME_DIR = args.data_dir + config.AVA.FRA_DIR
# setup logger
logger = logging.get_logger(__name__)
logging.setup_logging()
logger.info(config)
excluded_keys = os.path.join(
config.AVA.ANNOTATION_DIR, config.AVA.EXCLUSION_FILE)
labelmap = os.path.join(config.AVA.ANNOTATION_DIR,
config.AVA.LABEL_MAP_FILE)
gt_filename = os.path.join(
config.AVA.ANNOTATION_DIR, config.AVA.GROUNDTRUTH_FILE)
detc_filename = "detections_latest_mxbase.csv"
evaluate_ava_from_files(
labelmap, gt_filename, detc_filename, excluded_keys)
if __name__ == "__main__":
main()
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" unique configs """
class Config:
"""
Config setup
"""
# dataset related
class DATA:
SAMPLING_RATE = 2
NUM_FRAMES = 32
MEAN = [0.45, 0.45, 0.45]
STD = [0.225, 0.225, 0.225]
RANDOM_FLIP = True
TEST_CROP_SIZE = 224
TEST_SCALE_HEIGHT = 256
TEST_SCALE_WIDTH = 384
MAX_NUM_BOXES_PER_FRAME = 28
REVERSE_INPUT_CHANNEL = False
class MODEL:
NUM_CLASSES = 80
ARCH = "slowfast"
SINGLE_PATHWAY_ARCH = ["2d", "c2d", "i3d", "slow", "x3d", "mvit"]
MULTI_PATHWAY_ARCH = ["slowfast"]
class AVA:
BGR = False
TEST_FORCE_FLIP = False
TEST_LISTS = ["val.csv"]
DATADIR = "../data/input"
ANN_DIR = "/ava/ava_annotations"
FRA_DIR = "/ava/frames"
FRAME_LIST_DIR = DATADIR + ANN_DIR
ANNOTATION_DIR = DATADIR + ANN_DIR
FRAME_DIR = DATADIR + FRA_DIR
TEST_PREDICT_BOX_LISTS = [
"person_box_67091280_iou90/ava_detection_val_boxes_and_labels.csv"]
EXCLUSION_FILE = "ava_val_excluded_timestamps_v2.2.csv"
LABEL_MAP_FILE = "person_box_67091280_iou90/ava_action_list_v2.1_for_activitynet_2018.pbtxt"
GROUNDTRUTH_FILE = "ava_val_v2.2.csv"
IMG_PROC_BACKEND = "cv2"
DETECTION_SCORE_THRESH = 0.8
FULL_TEST_ON_VAL = False
class SLOWFAST:
ALPHA = 4
OUTPUT_DIR = "./"
BATCH_SIZE = 1
LOG_PERIOD = 1
sdk_pipeline_name = b"im_slowfast"
#!/bin/bash
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
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 ~/ascend/log/npu/conf/slog/slog.conf:/var/log/npu/conf/slog/slog.conf \
-v ~/ascend/log/npu/slog/:/var/log/npu/slog -v ~/ascend/log/npu/profiling/:/var/log/npu/profiling \
-v ~/ascend/log/npu/dump/:/var/log/npu/dump -v ~/ascend/log/npu/:/usr/slog ${docker_image} \
/bin/bash
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment