benchmark support string

pull/8166/head
sunsuodong 5 years ago
parent f68615cbe1
commit 1c76edf24c

@ -49,6 +49,6 @@ int MS_API StringsToMSTensor(const std::vector<std::string> &inputs, tensor::MST
/// \brief Get string vector from MSTensor.
/// \param[in] MSTensor.
/// \return string vector.
std::vector<std::string> MSTensorToStrings(const tensor::MSTensor *tensor);
std::vector<std::string> MS_API MSTensorToStrings(const tensor::MSTensor *tensor);
} // namespace mindspore::lite
#endif // MINDSPORE_LITE_INCLUDE_LITE_UTILS_H_

@ -299,6 +299,9 @@ kernel::LiteKernel *Scheduler::ScheduleNode(const std::vector<Tensor *> &in_tens
TypeId Scheduler::GetFirstFp32Fp16OrInt8Type(const std::vector<Tensor *> &in_tensors) {
for (const auto &tensor : in_tensors) {
auto dtype = tensor->data_type();
if (dtype == kObjectTypeString) {
return kNumberTypeFloat32;
}
if (dtype == kNumberTypeFloat32 || dtype == kNumberTypeFloat16 || dtype == kNumberTypeInt8 ||
dtype == kNumberTypeInt32 || dtype == kNumberTypeBool) {
return dtype;

@ -131,3 +131,4 @@ mtk_276landmark_0913.tflite
mtk_face_recognition.tflite
mtk_convert_model.tflite
mtk_model_face_dress_fp16.tflite
smartreply.tflite

File diff suppressed because it is too large Load Diff

@ -42,12 +42,15 @@ constexpr float relativeTolerance = 1e-5;
constexpr float absoluteTolerance = 1e-8;
struct MS_API CheckTensor {
CheckTensor(const std::vector<size_t> &shape, const std::vector<float> &data) {
CheckTensor(const std::vector<size_t> &shape, const std::vector<float> &data,
const std::vector<std::string> &strings_data = {""}) {
this->shape = shape;
this->data = data;
this->strings_data = strings_data;
}
std::vector<size_t> shape;
std::vector<float> data;
std::vector<std::string> strings_data;
};
class MS_API BenchmarkFlags : public virtual FlagParser {
@ -127,27 +130,27 @@ class MS_API Benchmark {
int ReadCalibData();
int ReadTensorData(std::ifstream &in_file_stream, const std::string &tensor_name, const std::vector<size_t> &dims);
int CompareOutput();
tensor::MSTensor *GetTensorByNodeOrTensorName(const std::string &node_or_tensor_name);
int CompareStringData(const std::string &name, tensor::MSTensor *tensor);
int CompareDataGetTotalBiasAndSize(const std::string &name, tensor::MSTensor *tensor, float *total_bias,
int *total_size);
int InitCallbackParameter();
int PrintResult(const std::vector<std::string> &title, const std::map<std::string, std::pair<int, float>> &result);
template <typename T>
void PrintInputData(tensor::MSTensor *input) {
MS_ASSERT(input != nullptr);
static int i = 0;
auto inData = reinterpret_cast<T *>(input->MutableData());
std::cout << "InData" << i++ << ": ";
for (size_t j = 0; j < 20; j++) {
std::cout << static_cast<float>(inData[j]) << " ";
}
std::cout << std::endl;
}
int PrintInputData();
// tensorData need to be converter first
template <typename T>
float CompareData(const std::string &nodeName, std::vector<int> msShape, T *msTensorData) {
float CompareData(const std::string &nodeName, std::vector<int> msShape, const void *tensor_data) {
const T *msTensorData = static_cast<const T *>(tensor_data);
auto iter = this->benchmark_data_.find(nodeName);
if (iter != this->benchmark_data_.end()) {
std::vector<size_t> castedMSShape;

Loading…
Cancel
Save