• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SHUFFLE_H_
18 #define MINDSPORE_CCSRC_MINDDATA_MINDRECORD_INCLUDE_SHARD_SHUFFLE_H_
19 
20 #include <random>
21 #include "minddata/mindrecord/include/shard_operator.h"
22 
23 namespace mindspore {
24 namespace mindrecord {
25 class MINDRECORD_API ShardShuffle : public ShardOperator {
26  public:
27   explicit ShardShuffle(uint32_t seed = 0, ShuffleType shuffle_type = kShuffleCategory);
28 
29   ShardShuffle(uint32_t seed, int64_t no_of_samples, bool replacement, bool reshuffle_each_epoch,
30                ShuffleType shuffle_type = kShuffleSample);
31 
~ShardShuffle()32   ~ShardShuffle() override{};
33 
34   Status Execute(ShardTaskList &tasks) override;
35 
36   int64_t GetNumSamples(int64_t dataset_size, int64_t num_classes) override;
37 
38  private:
39   // Private helper function
40   Status CategoryShuffle(ShardTaskList &tasks);  // NOLINT
41 
42   // Keep the file sequence the same but shuffle the data within each file
43   Status ShuffleInfile(ShardTaskList &tasks);  // NOLINT
44 
45   // Shuffle the file sequence but keep the order of data within each file
46   Status ShuffleFiles(ShardTaskList &tasks);  // NOLINT
47 
48   uint32_t shuffle_seed_;
49   int64_t no_of_samples_;
50   bool replacement_;
51   bool reshuffle_each_epoch_;
52   ShuffleType shuffle_type_;
53 };
54 }  // namespace mindrecord
55 }  // namespace mindspore
56 
57 #endif  // MINDSPORE_CCSRC_MINDDATA_MINDRECORD_INCLUDE_SHARD_SHUFFLE_H_
58