infer.py 1.1 KB
Newer Older
W
wuzewu 已提交
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
#-*- coding:utf8 -*-
import paddle
import paddle.fluid as fluid
import paddle_hub as hub
import paddle_hub.module as module
import paddle_hub.logger as log
import sys
import numpy as np
import reader
import argparse
import functools
from visualdl import LogWriter
from utility import add_arguments, print_arguments

reader = paddle.batch(reader.test("dataset"), batch_size=1)


def infer():

    model = module.Module(module_dir="hub_module_ResNet50")

    feed_list, fetch_list, program = model(
        sign_name="feature_map", trainable=True)

    with fluid.program_guard(main_program=program):
        img = feed_list[0]
        feature_map = fetch_list[0]
        fc = fluid.layers.fc(input=feature_map, size=2, act="softmax")
        place = fluid.CPUPlace()
        exe = fluid.Executor(place)
        feeder = fluid.DataFeeder(feed_list=[img], place=place)
        exe.run(fluid.default_startup_program())
        for batch in reader():
            print(batch[0][0].shape)
            eval_val = exe.run(fetch_list=[fc.name], feed=feeder.feed(batch))
            log.logger.info(eval_val)
            input()


infer()