[{"data":1,"prerenderedAt":461},["ShallowReactive",2],{"content-query-8sSK9fXpw3":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":10,"date":11,"cover":12,"type":13,"category":14,"body":15,"_type":455,"_id":456,"_source":457,"_file":458,"_stem":459,"_extension":460},"/technology-blogs/en/1987","en",false,"",[9],"MindSpore Data","The operator execution logic of the data processing pipeline is that the C++ layer is used to ensure high efficiency by default.","2022-08-29","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2022/12/07/91fe800c914b4b24931cc75169fe321d.png","technology-blogs","Practices",{"type":16,"children":17,"toc":452},"root",[18,32,38,47,52,60,65,78,90,102,113,118,127,132,141,146,155,167,178,183,188,195,200,208,216,221,226,231,236,243,248,253,261,266,271,276,281,286,291,296,301,306,314,322,348,355,363,370,378,383,388,393,398,403,408,413,417,425,430,435,440,445],{"type":19,"tag":20,"props":21,"children":23},"element","h1",{"id":22},"mindspore-data-training-data-processing-unified-vision-interfaces",[24,30],{"type":19,"tag":25,"props":26,"children":27},"span",{},[28],{"type":29,"value":9},"text",{"type":29,"value":31}," Training Data Processing - Unified Vision Interfaces",{"type":19,"tag":33,"props":34,"children":35},"p",{},[36],{"type":29,"value":37},"This blog presents the usability improvement of MindSpore Data, a data processing engine, in the image processing field, and provides an interface usage guide for simplified data preprocessing.",{"type":19,"tag":33,"props":39,"children":40},{},[41],{"type":19,"tag":42,"props":43,"children":44},"strong",{},[45],{"type":29,"value":46},"1. Introduction to MindSpore Data",{"type":19,"tag":33,"props":48,"children":49},{},[50],{"type":29,"value":51},"MindSpore Data uses an efficient pipeline framework to implement data processing. The framework can be used to automatically generate pipeline processes based on user-defined data processing steps. As shown in the following figure, each pipeline processes samples in a self-loop manner with high-concurrency capabilities to achieve efficient data preprocessing.",{"type":19,"tag":33,"props":53,"children":54},{},[55],{"type":19,"tag":56,"props":57,"children":59},"img",{"alt":7,"src":58},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2022/12/07/f82aaf4ce0eb404daba85a9bb0f0290c.png",[],{"type":19,"tag":33,"props":61,"children":62},{},[63],{"type":29,"value":64},"Example of a MindSpore dataset pipeline",{"type":19,"tag":33,"props":66,"children":67},{},[68,70],{"type":29,"value":69},"(1) Data is concurrently loaded from the storage layer to the buffer by using an existing dataset loading interface or a custom loading class and GeneratorDataset. For details about how to load a dataset, visit ",{"type":19,"tag":71,"props":72,"children":76},"a",{"href":73,"rel":74},"https://www.mindspore.cn/docs/en/r1.8/api_python/mindspore.dataset.html",[75],"nofollow",[77],{"type":29,"value":73},{"type":19,"tag":33,"props":79,"children":80},{},[81,83,88],{"type":29,"value":82},"(2) The shuffle process is completed in a memory pool. After samples whose number is equal to the value of ",{"type":19,"tag":42,"props":84,"children":85},{},[86],{"type":29,"value":87},"buffer_size",{"type":29,"value":89}," are cached, some random samples are selected for subsequent processing.",{"type":19,"tag":33,"props":91,"children":92},{},[93,95,100],{"type":29,"value":94},"(3) As an execution module, ",{"type":19,"tag":42,"props":96,"children":97},{},[98],{"type":29,"value":99},"map",{"type":29,"value":101}," calls data preprocessing operators at the C layer, such as Decode, Resize, Crop, Normalize, HWC2CHW. It also implements the user-defined PyFunc augmentation with input and output being NumPy data.",{"type":19,"tag":33,"props":103,"children":104},{},[105,107,111],{"type":29,"value":106},"For details about the data preprocessing operators in ",{"type":19,"tag":42,"props":108,"children":109},{},[110],{"type":29,"value":99},{"type":29,"value":112},", visit the following links:",{"type":19,"tag":33,"props":114,"children":115},{},[116],{"type":29,"value":117},"· Vision:",{"type":19,"tag":33,"props":119,"children":120},{},[121],{"type":19,"tag":71,"props":122,"children":125},{"href":123,"rel":124},"https://www.mindspore.cn/docs/en/r1.8/api_python/mindspore.dataset.vision.html",[75],[126],{"type":29,"value":123},{"type":19,"tag":33,"props":128,"children":129},{},[130],{"type":29,"value":131},"· Text:",{"type":19,"tag":33,"props":133,"children":134},{},[135],{"type":19,"tag":71,"props":136,"children":139},{"href":137,"rel":138},"https://www.mindspore.cn/docs/en/r1.8/api_python/mindspore.dataset.text.html",[75],[140],{"type":29,"value":137},{"type":19,"tag":33,"props":142,"children":143},{},[144],{"type":29,"value":145},"· Audio:",{"type":19,"tag":33,"props":147,"children":148},{},[149],{"type":19,"tag":71,"props":150,"children":153},{"href":151,"rel":152},"https://www.mindspore.cn/docs/en/r1.8/api_python/mindspore.dataset.audio.html",[75],[154],{"type":29,"value":151},{"type":19,"tag":33,"props":156,"children":157},{},[158,160,165],{"type":29,"value":159},"(4) The samples are batched into ",{"type":19,"tag":42,"props":161,"children":162},{},[163],{"type":29,"value":164},"batch_size",{"type":29,"value":166},".",{"type":19,"tag":33,"props":168,"children":169},{},[170,172,176],{"type":29,"value":171},"With the preceding framework capabilities, ",{"type":19,"tag":42,"props":173,"children":174},{},[175],{"type":29,"value":99},{"type":29,"value":177}," can call operators at the C layer and Python functions. Based on this feature, we created two sets of vision data preprocessing interfaces.",{"type":19,"tag":33,"props":179,"children":180},{},[181],{"type":29,"value":182},"l Developed based on OpenCV of the C++ version. Operators at the C layer provide the multi-thread high-concurrency capability of C++ and has high efficiency.",{"type":19,"tag":33,"props":184,"children":185},{},[186],{"type":29,"value":187},"l Developed based on the Python Pillow library. Operators at the Python layer (PyFunc) perform better in terms of development efficiency and complex implementation than C++ operators, but have lower concurrency capability.",{"type":19,"tag":33,"props":189,"children":190},{},[191],{"type":19,"tag":56,"props":192,"children":194},{"alt":7,"src":193},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2022/12/07/0bf816d60bc24926b3fead33f17e2648.png",[],{"type":19,"tag":33,"props":196,"children":197},{},[198],{"type":29,"value":199},"The two sets of interfaces can be used independently or together. However, it may be difficult for users to get started. Therefore, we unified the C++ and Python interfaces, allowing users to call corresponding interfaces for operations through automatic decision-making or explicit transformation.",{"type":19,"tag":33,"props":201,"children":202},{},[203],{"type":19,"tag":42,"props":204,"children":205},{},[206],{"type":29,"value":207},"2. Interface List and Usage of the Old Version",{"type":19,"tag":33,"props":209,"children":210},{},[211],{"type":19,"tag":42,"props":212,"children":213},{},[214],{"type":29,"value":215},"2.1 Interface List",{"type":19,"tag":33,"props":217,"children":218},{},[219],{"type":29,"value":220},"In MindSpore 1.7 and earlier versions, the following interfaces are still used.",{"type":19,"tag":33,"props":222,"children":223},{},[224],{"type":29,"value":225},"mindspore.dataset.vision",{"type":19,"tag":33,"props":227,"children":228},{},[229],{"type":29,"value":230},"mindspore.dataset.vision.c_transforms",{"type":19,"tag":33,"props":232,"children":233},{},[234],{"type":29,"value":235},"mindspore.dataset.vision.py_transforms",{"type":19,"tag":33,"props":237,"children":238},{},[239],{"type":19,"tag":56,"props":240,"children":242},{"alt":7,"src":241},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2022/12/07/53234c4bc0e746dda9c00a87698901bd.png",[],{"type":19,"tag":33,"props":244,"children":245},{},[246],{"type":29,"value":247},"According to the preceding comparison, many interfaces have the same name but different package",{"type":19,"tag":33,"props":249,"children":250},{},[251],{"type":29,"value":252},"names. This causes difficulties for users to understand and select them.",{"type":19,"tag":33,"props":254,"children":255},{},[256],{"type":19,"tag":42,"props":257,"children":258},{},[259],{"type":29,"value":260},"2.2 Usage",{"type":19,"tag":33,"props":262,"children":263},{},[264],{"type":29,"value":265},"If Python and C++ operators are used together, two packages need to be imported for explicit transformation before you call these operators.",{"type":19,"tag":33,"props":267,"children":268},{},[269],{"type":29,"value":270},"import mindspore.dataset.vision.c_transforms as c_vision",{"type":19,"tag":33,"props":272,"children":273},{},[274],{"type":29,"value":275},"import mindspore.dataset.vision.py_transforms as py_vision",{"type":19,"tag":33,"props":277,"children":278},{},[279],{"type":29,"value":280},"trans = [c_vision.Decode()",{"type":19,"tag":33,"props":282,"children":283},{},[284],{"type":29,"value":285},"c_vision.RandomResizedCrop(...),",{"type":19,"tag":33,"props":287,"children":288},{},[289],{"type":29,"value":290},"py_vision.ToPIL(),",{"type":19,"tag":33,"props":292,"children":293},{},[294],{"type":29,"value":295},"py_vision.RandomGrayscale(...),",{"type":19,"tag":33,"props":297,"children":298},{},[299],{"type":29,"value":300},"py_vision.ToTensor()]",{"type":19,"tag":33,"props":302,"children":303},{},[304],{"type":29,"value":305},"dataset = dataset.map(operations=trans, ...)",{"type":19,"tag":33,"props":307,"children":308},{},[309],{"type":19,"tag":42,"props":310,"children":311},{},[312],{"type":29,"value":313},"3 Interface List and Usage of the New Version",{"type":19,"tag":33,"props":315,"children":316},{},[317],{"type":19,"tag":42,"props":318,"children":319},{},[320],{"type":29,"value":321},"3.1 Implementation",{"type":19,"tag":33,"props":323,"children":324},{},[325,327,332,334,339,341,346],{"type":29,"value":326},"The definition of an operator whose interfaces are unified contains different backend implementations, which are invoked by the ",{"type":19,"tag":42,"props":328,"children":329},{},[330],{"type":29,"value":331},"parse",{"type":29,"value":333}," and ",{"type":19,"tag":42,"props":335,"children":336},{},[337],{"type":29,"value":338},"execute_py",{"type":29,"value":340}," interfaces. In addition, ",{"type":19,"tag":42,"props":342,"children":343},{},[344],{"type":29,"value":345},"self.implementation",{"type":29,"value":347}," is used to dynamically mark which layer is invoked for implementation during the operator running.",{"type":19,"tag":33,"props":349,"children":350},{},[351],{"type":19,"tag":56,"props":352,"children":354},{"alt":7,"src":353},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2022/12/07/f52390e0200344968bcbf22af645dd5a.png",[],{"type":19,"tag":33,"props":356,"children":357},{},[358],{"type":19,"tag":42,"props":359,"children":360},{},[361],{"type":29,"value":362},"3.2 Interface List",{"type":19,"tag":33,"props":364,"children":365},{},[366],{"type":19,"tag":56,"props":367,"children":369},{"alt":7,"src":368},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2022/12/07/82744ce1ded046268b870bec5b8fbbee.png",[],{"type":19,"tag":33,"props":371,"children":372},{},[373],{"type":19,"tag":42,"props":374,"children":375},{},[376],{"type":29,"value":377},"3.3 Usage",{"type":19,"tag":33,"props":379,"children":380},{},[381],{"type":29,"value":382},"All interfaces can be imported by importing a package and can be called for flexible implementation through transformation.",{"type":19,"tag":33,"props":384,"children":385},{},[386],{"type":29,"value":387},"import mindspore.dataset.vision as vision",{"type":19,"tag":33,"props":389,"children":390},{},[391],{"type":29,"value":392},"trans = [vision.Decode()",{"type":19,"tag":33,"props":394,"children":395},{},[396],{"type":29,"value":397},"vision.RandomResizedCrop(...),",{"type":19,"tag":33,"props":399,"children":400},{},[401],{"type":29,"value":402},"vision.ToPIL(),",{"type":19,"tag":33,"props":404,"children":405},{},[406],{"type":29,"value":407},"vision.RandomGrayscale(...),",{"type":19,"tag":33,"props":409,"children":410},{},[411],{"type":29,"value":412},"vision.ToTensor()]",{"type":19,"tag":33,"props":414,"children":415},{},[416],{"type":29,"value":305},{"type":19,"tag":33,"props":418,"children":419},{},[420],{"type":19,"tag":42,"props":421,"children":422},{},[423],{"type":29,"value":424},"4. Summary",{"type":19,"tag":33,"props":426,"children":427},{},[428],{"type":29,"value":429},"As such, the operator execution logic of the data processing pipeline is as follows:",{"type":19,"tag":33,"props":431,"children":432},{},[433],{"type":29,"value":434},"(1) By default, the C++ layer is used to ensure high efficiency.",{"type":19,"tag":33,"props":436,"children":437},{},[438],{"type":29,"value":439},"(2) If the Python layer needs to be used, options need to be specified or automatically deducted.",{"type":19,"tag":33,"props":441,"children":442},{},[443],{"type":29,"value":444},"Typical data preprocessing operations are as follows:",{"type":19,"tag":33,"props":446,"children":447},{},[448],{"type":19,"tag":56,"props":449,"children":451},{"alt":7,"src":450},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2022/12/07/c7a0a78ebad641f587beef44d2e79011.png",[],{"title":7,"searchDepth":453,"depth":453,"links":454},4,[],"markdown","content:technology-blogs:en:1987.md","content","technology-blogs/en/1987.md","technology-blogs/en/1987","md",1776506105898]