You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Guideline to Efficiently Generating MindRecord
  2. <!-- TOC -->
  3. - [What does the example do](#what-does-the-example-do)
  4. - [Example test for Cora](#example-test-for-cora)
  5. - [How to use the example for other dataset](#how-to-use-the-example-for-other-dataset)
  6. - [Create work space](#create-work-space)
  7. - [Implement data generator](#implement-data-generator)
  8. - [Run data generator](#run-data-generator)
  9. <!-- /TOC -->
  10. ## What does the example do
  11. This example provides an efficient way to generate MindRecord. Users only need to define the parallel granularity of training data reading and the data reading function of a single task. That is, they can efficiently convert the user's training data into MindRecord.
  12. 1. write_cora.sh: entry script, users need to modify parameters according to their own training data.
  13. 2. writer.py: main script, called by write_cora.sh, it mainly reads user training data in parallel and generates MindRecord.
  14. 3. cora/mr_api.py: uers define their own parallel granularity of training data reading and single task reading function through the cora.
  15. ## Example test for Cora
  16. 1. Download and prepare the Cora dataset as required.
  17. 2. Edit write_cora.sh and modify the parameters
  18. ```
  19. --mindrecord_file: output MindRecord file.
  20. --mindrecord_partitions: the partitions for MindRecord.
  21. ```
  22. 3. Run the bash script
  23. ```bash
  24. bash write_cora.sh
  25. ```
  26. ## How to use the example for other dataset
  27. ### Create work space
  28. Assume the dataset name is 'xyz'
  29. * Create work space from cora
  30. ```shell
  31. cd ${your_mindspore_home}/example/graph_to_mindrecord
  32. cp -r cora xyz
  33. ```
  34. ### Implement data generator
  35. Edit dictionary data generator.
  36. * Edit file
  37. ```shell
  38. cd ${your_mindspore_home}/example/graph_to_mindrecord
  39. vi xyz/mr_api.py
  40. ```
  41. Two API, 'mindrecord_task_number' and 'mindrecord_dict_data', must be implemented.
  42. - 'mindrecord_task_number()' returns number of tasks. Return 1 if data row is generated serially. Return N if generator can be split into N parallel-run tasks.
  43. - 'mindrecord_dict_data(task_id)' yields dictionary data row by row. 'task_id' is 0..N-1, if N is return value of mindrecord_task_number()
  44. ### Run data generator
  45. * run python script
  46. ```shell
  47. cd ${your_mindspore_home}/example/graph_to_mindrecord
  48. python writer.py --mindrecord_script xyz [...]
  49. ```
  50. > You can put this command in script **write_xyz.sh** for easy execution