Template Function mindspore::dataset::RandomData

Function Documentation

template<typename T = std::shared_ptr<SchemaObj>>
std::shared_ptr<RandomDataDataset> mindspore::dataset::RandomData(const int32_t &total_rows = 0, const T &schema = nullptr, const std::vector<std::string> &columns_list = {}, const std::shared_ptr<DatasetCache> &cache = nullptr)

Function to create a RandomDataset.

Parameters
  • total_rows[in] Number of rows for the dataset to generate (default=0, number of rows is random).

  • schema[in] SchemaObj to set column type, data type and data shape.

  • columns_list[in] List of columns to be read (default={}, read all columns).

  • cache[in] Tensor cache to use (default=nullptr which means no cache is used).

Returns

Shared pointer to the RandomDataset.

样例
/* Define MindData objects */
std::shared_ptr<SchemaObj> schema = Schema();
schema->add_column("column1", mindspore::DataType::kNumberTypeUInt8, {2});
schema->add_column("column2", mindspore::DataType::kNumberTypeUInt8, {1});
std::shared_ptr<Dataset> ds = RandomData(50, schema);

/* Create iterator to read dataset */
std::shared_ptr<Iterator> iter = ds->CreateIterator();
std::unordered_map<std::string, mindspore::MSTensor> row;
iter->GetNextRow(&row);

/* Note: As we defined the schema before, each data dictionary owns keys "column1" and "column2" */
auto column1 = row["column1"];