1 /** 2 * Copyright 2019-2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_CCSRC_MINDDATA_MINDRECORD_INCLUDE_SHARD_CATEGORY_H_ 18 #define MINDSPORE_CCSRC_MINDDATA_MINDRECORD_INCLUDE_SHARD_CATEGORY_H_ 19 20 #include <algorithm> 21 #include <limits> 22 #include <string> 23 #include <utility> 24 #include <vector> 25 #include "minddata/mindrecord/include/shard_operator.h" 26 27 namespace mindspore { 28 namespace mindrecord { 29 class MINDRECORD_API ShardCategory : public ShardOperator { 30 public: 31 explicit ShardCategory(const std::vector<std::pair<std::string, std::string>> &categories, 32 int64_t num_elements = std::numeric_limits<int64_t>::max(), bool replacement = false); 33 34 ShardCategory(const std::string &category_field, int64_t num_elements, 35 int64_t num_categories = std::numeric_limits<int64_t>::max(), bool replacement = false); 36 ~ShardCategory()37 ~ShardCategory() override{}; 38 GetCategories()39 const std::vector<std::pair<std::string, std::string>> &GetCategories() const { return categories_; } 40 GetCategoryField()41 const std::string GetCategoryField() const { return category_field_; } 42 GetNumElements()43 int64_t GetNumElements() const { return num_elements_; } 44 GetNumCategories()45 int64_t GetNumCategories() const { return num_categories_; } 46 GetReplacement()47 bool GetReplacement() const { return replacement_; } 48 49 Status Execute(ShardTaskList &tasks) override; 50 51 int64_t GetNumSamples(int64_t dataset_size, int64_t num_classes) override; 52 53 private: 54 std::vector<std::pair<std::string, std::string>> categories_; 55 std::string category_field_; 56 int64_t num_elements_; 57 int64_t num_categories_; 58 bool replacement_; 59 }; 60 } // namespace mindrecord 61 } // namespace mindspore 62 63 #endif // MINDSPORE_CCSRC_MINDDATA_MINDRECORD_INCLUDE_SHARD_CATEGORY_H_ 64