Commit d7f92444 authored by Yuxin Wu's avatar Yuxin Wu

fix import

parent d5f3350d
......@@ -119,7 +119,7 @@ if __name__ == '__main__':
if args.eval:
BATCH_SIZE = 128 # something that can run on one gpu
ds = get_data('val')
eval_on_ILSVRC12(Model(), args.load, ds)
eval_on_ILSVRC12(Model(), get_model_loader(args.load), ds)
sys.exit()
logger.set_logger_dir(
......
......@@ -9,14 +9,14 @@ import os
import tensorflow as tf
from tensorpack import InputDesc, ModelDesc, logger
from tensorpack import InputDesc, ModelDesc, logger, QueueInput
from tensorpack.models import *
from tensorpack.callbacks import *
from tensorpack.train import TrainConfig, SyncMultiGPUTrainerParameterServer
from tensorpack.dataflow import imgaug, FakeData
import tensorpack.tfutils.symbolic_functions as symbf
from tensorpack.tfutils.summary import add_moving_summary
from tensorpack.tfutils import argscope, SaverRestore
from tensorpack.tfutils import argscope, get_model_loader
from tensorpack.utils.gpu import get_nr_gpu
from imagenet_resnet_utils import (
......@@ -137,12 +137,12 @@ if __name__ == '__main__':
if args.eval:
BATCH_SIZE = 128 # something that can run on one gpu
ds = get_data('val')
eval_on_ILSVRC12(Model(), args.load, ds)
eval_on_ILSVRC12(Model(), get_model_loader(args.load), ds)
sys.exit()
logger.set_logger_dir(
os.path.join('train_log', 'imagenet-resnet-d' + str(DEPTH)))
config = get_config(fake=args.fake, data_format=args.data_format)
if args.load:
config.session_init = SaverRestore(args.load)
config.session_init = get_model_loader(args.load)
SyncMultiGPUTrainerParameterServer(config).train()
......@@ -179,10 +179,10 @@ def resnet_backbone(image, num_blocks, block_func):
return logits
def eval_on_ILSVRC12(model, model_file, dataflow):
def eval_on_ILSVRC12(model, sessinit, dataflow):
pred_config = PredictConfig(
model=model,
session_init=tp.get_model_loader(model_file),
session_init=sessinit,
input_names=['input', 'label'],
output_names=['wrong-top1', 'wrong-top5']
)
......
......@@ -21,6 +21,8 @@ from tensorpack.tfutils.symbolic_functions import *
from tensorpack.tfutils.summary import *
from tensorpack.dataflow.dataset import ILSVRCMeta, ILSVRC12
from imagenet_resnet_utils import eval_on_ILSVRC12
MODEL_DEPTH = None
......@@ -133,26 +135,6 @@ def run_test(params, input):
print([meta[k] for k in ret])
def eval_on_ILSVRC12(params, data_dir):
ds = ILSVRC12(data_dir, 'val', shuffle=False, dir_structure='train')
ds = AugmentImageComponent(ds, get_inference_augmentor())
ds = BatchData(ds, 128, remainder=True)
pred_config = PredictConfig(
model=Model(),
session_init=DictRestore(params),
input_names=['input', 'label'],
output_names=['wrong-top1', 'wrong-top5']
)
pred = SimpleDatasetPredictor(pred_config, ds)
acc1, acc5 = RatioCounter(), RatioCounter()
for o in pred.get_result():
batch_size = o[0].shape[0]
acc1.feed(o[0].sum(), batch_size)
acc5.feed(o[1].sum(), batch_size)
print("Top1 Error: {}".format(acc1.ratio))
print("Top5 Error: {}".format(acc5.ratio))
def name_conversion(caffe_layer_name):
""" Convert a caffe parameter name to a tensorflow parameter name as
defined in the above model """
......@@ -221,6 +203,10 @@ if __name__ == '__main__':
resnet_param[newname] = v
if args.eval:
eval_on_ILSVRC12(resnet_param, args.eval)
ds = ILSVRC12(args.eval, 'val', shuffle=False, dir_structure='train')
ds = AugmentImageComponent(ds, get_inference_augmentor())
ds = BatchData(ds, 128, remainder=True)
ds = PrefetchDataZMQ(ds, 1)
eval_on_ILSVRC12(Model(), DictRestore(resnet_param), ds)
else:
run_test(resnet_param, args.input)
......@@ -127,6 +127,9 @@ class ILSVRC12Files(RNGDataFlow):
meta = ILSVRCMeta(meta_dir)
self.imglist = meta.get_image_list(name, dir_structure)
for fname, _ in self.imglist[:10]:
assert os.path.isfile(fname), fname
def size(self):
return len(self.imglist)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment