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.

mindspore.dataset.Schema.rst 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. mindspore.dataset.Schema
  2. =========================
  3. .. py:class:: mindspore.dataset.Schema(schema_file=None)
  4. 代表一个解析和存储数据列属性的类。
  5. **参数:**
  6. **schema_file** (str): schema文件的路径(默认值为None)。
  7. **返回:**
  8. schema对象,关于数据集的行列配置的策略信息。
  9. **异常:**
  10. **RuntimeError:** 模式文件加载失败。
  11. **样例:**
  12. >>> from mindspore import dtype as mstype
  13. >>>
  14. >>> # 创建模式;指定列名、mindspore.dtype和列shape。
  15. >>> schema = ds.Schema()
  16. >>> schema.add_column(name='col1', de_type=mstype.int64, shape=[2])
  17. .. py:method::add_column(name, de_type, shape=None)
  18. 向schema中添加新列。
  19. **参数:**
  20. - **name** (str): 列的新名称。
  21. - **de_type** (str): 列的数据类型。
  22. - **shape** (list[int], optional): 列shape(默认值为None,[-1]表示rank 1的未知shape)。
  23. **异常:**
  24. **ValueError:** 列类型未知。
  25. .. py:method::from_json(json_obj)
  26. 从JSON对象获取schema文件。
  27. **参数:**
  28. **json_obj** (dictionary): 解析的JSON对象。
  29. **异常:**
  30. - **RuntimeError:** 对象中存在未知的项。
  31. - **RuntimeError:** 对象中缺少数据集类型。
  32. - **RuntimeError:** 对象中缺少列。
  33. .. py:method::parse_columns(columns)
  34. 解析传入的数据列的属性并将其添加到自身的schema中。
  35. **参数:**
  36. - **columns** (Union[dict, list[dict], tuple[dict]]): 数据集属性信息,从schema文件解码。
  37. - list[dict],'name'和'type'必须为key值,'shape'可选。
  38. - dict,columns.keys()作为名称,columns.values()是dict,其中包含'type','shape'可选。
  39. **异常:**
  40. - **RuntimeError:** 解析列失败。
  41. - **RuntimeError:** 列name字段缺失。
  42. - **RuntimeError:** 列type字段缺失。
  43. **样例:**
  44. >>> schema = Schema()
  45. >>> columns1 = [{'name': 'image', 'type': 'int8', 'shape': [3, 3]},
  46. >>> {'name': 'label', 'type': 'int8', 'shape': [1]}]
  47. >>> schema.parse_columns(columns1)
  48. >>> columns2 = {'image': {'shape': [3, 3], 'type': 'int8'}, 'label': {'shape': [1], 'type': 'int8'}}
  49. >>> schema.parse_columns(columns2)
  50. .. py:method::to_json()
  51. 获取schema的JSON字符串。
  52. **返回:**
  53. str,模式的JSON字符串。