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 5.2 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # 如何在启智平台上进行模型调试和训练—GPU_手写数字识别示例
  2. ## 一 ,数据集及预训练模型准备
  3. ##### 1,数据集说明:
  4. 数据集可从本项目的数据集中引用,[数据集引用](https://openi.pcl.ac.cn/OpenIOSSG/OpenI_Cloudbrain_Example/datasets)
  5. - MnistDataset_torch数据集是由10类28∗28的灰度图片组成,训练数据集包含60000张图片,测试数据集包含10000张图片。
  6. - MnistDataset_torch.zip数据集压缩包的目录结构如下:
  7. > MnistDataset_torch.zip
  8. >
  9. > ├── test
  10. >
  11. > └── train
  12. >
  13. ##### 2,预训练模型说明:
  14. Torch_MNIST_Example_Model模型可从本项目的模型目录中引用,[预训练模型引用](https://openi.pcl.ac.cn/OpenIOSSG/OpenI_Cloudbrain_Example/modelmanage/show_model)
  15. * Torch_MNIST_Example_Model模型的目录结构如下:
  16. > Torch_MNIST_Example_Model
  17. > ├── mnist_epoch1.pkl
  18. >
  19. ## 二.GPU样例准备
  20. ##### 1,gpu示例代码:
  21. - 训练任务单卡示例请参考示例中[train.py](./train.py)的代码注释
  22. - 推理任务示例请参考示例中[inference.py](./inference.py)的代码注释
  23. - [model.py](./model.py)是运行项目所需的代码
  24. ##### 2,创建GPU调试任务
  25. 表1创建训练作业界面参数说明
  26. | 参数名称 | 说明 |
  27. | -------- | ----------------------------------------------------------------------------------- |
  28. | 代码分支 | 选择仓库代码中要使用的代码分支,默认可选择master分支 |
  29. | 镜像 | 镜像选择含有python和torch的镜像,推荐镜像: |
  30. | 启动文件 | 启动文件选择代码目录下的启动脚本,在本示例中选择gpu_mnist_example/train.py |
  31. | 数据集 | 数据集选择MnistDataset_torch.zip |
  32. | 运行参数 | 选择增加运行参数可以向脚本中其他参数传值,如epoch_size,需要在代码里定义增加的超参数 |
  33. | 资源规格 | 规格选择[GPU] |
  34. | 模型 | 模型选择Torch_MNIST_Example_Model |
  35. 启动调试任务后,先执行prepare()进行数据准备;
  36. 进入对应的代码目录后,可在终端执行python train.py;
  37. ##### 3,创建GPU训练任务
  38. 表2 创建训练作业界面参数说明
  39. | 参数名称 | 说明 |
  40. | -------- | ----------------------------------------------------------------------------------- |
  41. | 代码分支 | 选择仓库代码中要使用的代码分支,默认可选择master分支 |
  42. | 镜像 | 镜像选择含有python和torch的镜像 |
  43. | 启动文件 | 启动文件选择代码目录下的启动脚本,在本示例中选择gpu_mnist_example/train.py |
  44. | 数据集 | 数据集选择MnistDataset_torch.zip |
  45. | 运行参数 | 选择增加运行参数可以向脚本中其他参数传值,如epoch_size,需要在代码里定义增加的超参数 |
  46. | 资源规格 | 规格选择[GPU] |
  47. | 模型 | 模型选择Torch_MNIST_Example_Model |
  48. 启动训练任务后,训练结束会在任务的结果下载页提供输出结果下载
  49. ## 三. 如何在云脑上获取代码路径,数据集路径,预训练模型路径,输出路径
  50. ##### 1,准备数据
  51. ```
  52. from c2net.context import prepare
  53. c2net_context = prepare()
  54. ```
  55. ##### 2,获取代码路径
  56. ```
  57. code_path = c2net_context.code_path +"/" +"项目名".lower()
  58. 在本示例中代码路径为:
  59. code_path = c2net_context.code_path + "/" + "Openl_Cloudbrain_Example".lower()
  60. ```
  61. ##### 3,获取数据集路径
  62. ```
  63. dataset_path = c2net_context.dataset_path +"/" +"数据集名称"
  64. 在本示例中代码路径为:
  65. dataset_path = c2net_context.dataset_path + "/" + "MnistDataset_torch"
  66. ```
  67. ##### 4,获取预训练模型路径
  68. ```
  69. pretrain_model_path = c2net_context.pretrain_model_path +"/" +"模型名称"
  70. 在本示例中预训练模型路径为:
  71. pretrain_model_path = c2net_context.pretrain_model_path + "/" + "Torch_MNIST_Example_Model"
  72. ```
  73. ##### 5,获取输出路径
  74. ```
  75. output_path = c2net_context.output_path
  76. 在本示例中输出路径为:
  77. output_path = c2net_context.output_path
  78. ```
  79. ##### 6,回传结果
  80. ```
  81. from c2net.context import upload_output
  82. upload_output()
  83. 在本示例中回传结果为(只有训练任务才能回传结果):
  84. from c2net.context import prepare,upload_output
  85. upload_output()
  86. ```
  87. ## 四.GPU任务注意事项
  88. ##### 1, 使用超参数的方法
  89. 请在代码中加入
  90. ```
  91. import parser
  92. args, unknown = parser.parse_known_args()
  93. #可忽略掉 `--ckpt_url`,`--data_url`, `--multi_date_url`等参数无定义导致的报错问题
  94. ```
  95. ## 对于示例代码有任何问题,欢迎在本项目中提issue。

No Description