create_dataset_using_mindrecord.py 1.8 KB
Newer Older
L
leiyuning 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
# Copyright 2019 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

import collections
import numpy as np
import os
import re
import string

import mindspore._c_dataengine as de_map
import mindspore.dataset as ds
from mindspore._c_dataengine import InterpolationMode

from write_mindrecord import write_mindrecord_tutorial

MINDRECORD_FILE_NAME = "./imagenet.mindrecord"

def create_dataset_using_mindrecord_tutorial():
    columns_list = ["data", "file_name", "label"]
    num_readers = 4
    data_set = ds.MindDataset(MINDRECORD_FILE_NAME, columns_list, num_readers)

    # add your data enhance code here

    assert data_set.get_dataset_size() == 20
    data_set = data_set.repeat(2)

    num_iter = 0
    for item in data_set.create_dict_iterator():
        print("-------------- index {} -----------------".format(num_iter))
        # print("-------------- item[label]: {} ---------------------".format(item["label"]))
        # print("-------------- item[data]: {} ----------------------".format(item["data"]))
        num_iter += 1
    assert num_iter == 40

if __name__ == '__main__':
    write_mindrecord_tutorial()

    create_dataset_using_mindrecord_tutorial()

    os.remove(MINDRECORD_FILE_NAME)
    os.remove(MINDRECORD_FILE_NAME + ".db")