dummy_reader.py 679 字节
Newer Older
W
wanghaoshuang 已提交
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
import numpy as np
DATA_SHAPE = [1, 512, 512]


def _read_creater(num_sample=1024, num_class=20, min_seq_len=1, max_seq_len=10):
    def reader():
        for i in range(num_sample):
            sequence_len = np.random.randint(min_seq_len, max_seq_len)
            x = np.random.uniform(0.1, 1, DATA_SHAPE).astype("float32")
            y = np.random.randint(0, num_class + 1,
                                  [sequence_len]).astype("int32")
            yield x, y

    return reader


def train(num_sample=16):
    return _read_creater(num_sample=num_sample)


def test(num_sample=16):
    return _read_creater(num_sample=num_sample)


def data_shape():
    return DATA_SHAPE