Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pipeline #11

Open
wants to merge 114 commits into
base: develop
Choose a base branch
from
Open

Add pipeline #11

wants to merge 114 commits into from

Conversation

heavengate
Copy link
Owner

@heavengate heavengate commented Nov 11, 2021

test code

import paddle.fluid as fluid

import sys
import time

data_root = '/paddle/paddle/val'

def imagenet_pipeline():
    image, label = paddle.vision.reader.file_label_reader(data_root, batch_size=128, shuffle=True, drop_last=False)

    def decode(image):
        image = paddle.vision.ops.image_decode_random_crop(image, num_threads=4, mode='rgb')
        return image
    def resize(image):
        image = paddle.vision.ops.image_resize(image, size=224)
        return image
    def flip_normalize(image):
        mirror = paddle.vision.ops.random_flip(image)
        image = paddle.vision.ops.mirror_normalize(image, mirror)
        return image
    def preprocess(image):
        image = paddle.vision.ops.image_resize(image, size=224)
        mirror = paddle.vision.ops.random_flip(image)
        image = paddle.vision.ops.mirror_normalize(image, mirror)
        return image

    image = paddle.io.map(decode, image)
    image = paddle.io.map(resize, image)
    image = paddle.io.map(flip_normalize, image)
    # image = paddle.io.map(preprocess, image)

    return {'image': image, 'label': label}

# run in dygraph mode
# for i in range(10):
    # print(imagenet_pipeline())

# run in static mode
dataloader = paddle.io.DataLoader.from_pipeline(imagenet_pipeline)
# for _ in range(100):
for i, data in enumerate(dataloader):
    # print(i, data['image'].shape, data['image'].place, data['label'].shape, data['label'].place)
    # if i > 120:
    #     # print(data['image'], data['label'])
    #     break
    # if i % 10 == 0:
    #     print(i, data['image'].shape, data['image'].place, data['label'])
    #     sys.stdout.flush()
    if i == 20:
        tic = time.time()
    if i == 120:
        toc = time.time()
        print("cost per step: {}ms".format((toc - tic) * 10.))
        sys.stdout.flush()
        break

@heavengate heavengate force-pushed the add_pipeline branch 13 times, most recently from 9f0d4ad to 79b3599 Compare April 5, 2022 06:29
@heavengate heavengate force-pushed the add_pipeline branch 3 times, most recently from 0cb83e8 to bf544c4 Compare April 5, 2022 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants