Skip to content
Snippets Groups Projects
Select Git revision
  • 8237b1ec74f9d32928dd5ebb2ca38ffc7bef1c15
  • master default protected
  • r1.8
  • r1.6
  • r1.9
  • r1.5
  • r1.7
  • r1.3
  • r1.4
  • r1.2
  • v1.6.0
  • v1.5.0
12 results

utils.cc

Blame
  • utils.cc 4.60 KiB
    /**
     * Copyright 2021 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 "inc/utils.h"
    
    #include <fstream>
    #include <algorithm>
    #include <iostream>
    
    using mindspore::MSTensor;
    using mindspore::DataType;
    
    
    std::vector<std::string> GetAllFiles(std::string_view dirName) {
        struct dirent *filename;
        DIR *dir = OpenDir(dirName);
        if (dir == nullptr) {
            return {};
        }
        std::vector<std::string> dirs;
        std::vector<std::string> files;
        while ((filename = readdir(dir)) != nullptr) {
            std::string dName = std::string(filename->d_name);
            if (dName == "." || dName == "..") {
                continue;
            } else if (filename->d_type == DT_DIR) {
                dirs.emplace_back(std::string(dirName) + "/" + filename->d_name);
            } else if (filename->d_type == DT_REG) {
                files.emplace_back(std::string(dirName) + "/" + filename->d_name);
            } else {
                continue;
            }
        }
    
        for (auto d : dirs) {
            dir = OpenDir(d);
            while ((filename = readdir(dir)) != nullptr) {
                std::string dName = std::string(filename->d_name);
                if (dName == "." || dName == ".." || filename->d_type != DT_REG) {
                    continue;
                }
                files.emplace_back(std::string(d) + "/" + filename->d_name);
            }
        }
        std::sort(files.begin(), files.end());
        for (auto &f : files) {
            std::cout << "image file: " << f << std::endl;
        }
        return files;
    }
    
    int WriteResult(const std::string& imageFile, const std::vector<MSTensor> &outputs) {
        std::string homePath = "./result_Files";
        for (size_t i = 0; i < outputs.size(); ++i) {
            size_t outputSize;
            std::shared_ptr<const void> netOutput = outputs[i].Data();
            outputSize = outputs[i].DataSize();