diff --git a/PaddleCV/image_classification/eval.py b/PaddleCV/image_classification/eval.py index 3bcc4e696c4795a98408a9b1e0f4ff5d0303ec77..797b39ab38fa170076497c8e6939af69ee4dcaf4 100644 --- a/PaddleCV/image_classification/eval.py +++ b/PaddleCV/image_classification/eval.py @@ -7,7 +7,7 @@ import time import sys import paddle import paddle.fluid as fluid -import reader as reader +import reader_cv2 as reader import argparse import functools import models @@ -25,7 +25,7 @@ add_arg('image_shape', str, "3,224,224", "Input image size") add_arg('with_mem_opt', bool, True, "Whether to use memory optimization or not.") add_arg('pretrained_model', str, None, "Whether to use pretrained model.") add_arg('model', str, "SE_ResNeXt50_32x4d", "Set the network to use.") - +add_arg('resize_short_size', int, 256, "Set resize short size") # yapf: enable def eval(args): @@ -84,7 +84,7 @@ def eval(args): fluid.io.load_vars(exe, pretrained_model, predicate=if_exist) - val_reader = paddle.batch(reader.val(), batch_size=args.batch_size) + val_reader = paddle.batch(reader.val(settings=args), batch_size=args.batch_size) feeder = fluid.DataFeeder(place=place, feed_list=[image, label]) test_info = [[], [], []] diff --git a/PaddleCV/image_classification/infer.py b/PaddleCV/image_classification/infer.py index 0ad94ff320f83bb8f733976b01af3204474fb3ec..ac15069ee043138c75e24e71c67a579f025f45dd 100644 --- a/PaddleCV/image_classification/infer.py +++ b/PaddleCV/image_classification/infer.py @@ -7,7 +7,7 @@ import time import sys import paddle import paddle.fluid as fluid -import reader +import reader_cv2 as reader import argparse import functools import models @@ -25,6 +25,7 @@ add_arg('with_mem_opt', bool, True, "Whether to use memory o add_arg('pretrained_model', str, None, "Whether to use pretrained model.") add_arg('model', str, "SE_ResNeXt50_32x4d", "Set the network to use.") add_arg('save_inference', bool, False, "Whether to save inference model or not") +add_arg('resize_short_size', int, 256, "Set resize short size") # yapf: enable def infer(args): @@ -78,7 +79,7 @@ def infer(args): print("model: ",model_name," is already saved") exit(0) test_batch_size = 1 - test_reader = paddle.batch(reader.test(), batch_size=test_batch_size) + test_reader = paddle.batch(reader.test(settings=args), batch_size=test_batch_size) feeder = fluid.DataFeeder(place=place, feed_list=[image]) TOPK = 1 diff --git a/PaddleCV/image_classification/models/resnet_vc.py b/PaddleCV/image_classification/models/resnet_vc.py index 7572660d2f2342bfa65b794235d01e258905b580..d715193e18ba134708c0a6a6ea2fa1a0f055bf0f 100644 --- a/PaddleCV/image_classification/models/resnet_vc.py +++ b/PaddleCV/image_classification/models/resnet_vc.py @@ -92,7 +92,7 @@ class ResNet(): num_filters=num_filters, filter_size=filter_size, stride=stride, - padding=(filter_size - 1) / 2, + padding=(filter_size - 1) // 2, groups=groups, act=None, param_attr=ParamAttr(name=name + "_weights"), diff --git a/PaddleCV/image_classification/models/resnet_vd.py b/PaddleCV/image_classification/models/resnet_vd.py index 3b8db164b48d0ea6d1b3ba4fe762ae310de044f5..edbe0f9ea056390f08042fafe0b8127bff21afc3 100644 --- a/PaddleCV/image_classification/models/resnet_vd.py +++ b/PaddleCV/image_classification/models/resnet_vd.py @@ -104,7 +104,7 @@ class ResNet(): num_filters=num_filters, filter_size=filter_size, stride=stride, - padding=(filter_size - 1) / 2, + padding=(filter_size - 1) // 2, groups=groups, act=None, param_attr=ParamAttr(name=name + "_weights"), @@ -140,7 +140,7 @@ class ResNet(): num_filters=num_filters, filter_size=filter_size, stride=1, - padding=(filter_size - 1) / 2, + padding=(filter_size - 1) // 2, groups=groups, act=None, param_attr=ParamAttr(name=name + "_weights"), diff --git a/PaddleCV/image_classification/models/resnext_vd.py b/PaddleCV/image_classification/models/resnext_vd.py index e05c7735e345bdbfb8961a5ccdc95997f4af3efd..7c5b5d81bedeea7db1bfe3ceaf6067b8221a645e 100644 --- a/PaddleCV/image_classification/models/resnext_vd.py +++ b/PaddleCV/image_classification/models/resnext_vd.py @@ -101,7 +101,7 @@ class ResNeXt(): num_filters=num_filters, filter_size=filter_size, stride=stride, - padding=(filter_size - 1) / 2, + padding=(filter_size - 1) // 2, groups=groups, act=None, param_attr=ParamAttr(name=name + "_weights"), @@ -137,7 +137,7 @@ class ResNeXt(): num_filters=num_filters, filter_size=filter_size, stride=1, - padding=(filter_size - 1) / 2, + padding=(filter_size - 1) // 2, groups=groups, act=None, param_attr=ParamAttr(name=name + "_weights"), diff --git a/PaddleCV/image_classification/models/se_resnext_vd.py b/PaddleCV/image_classification/models/se_resnext_vd.py index 4c1a37fece78f709f8d026c049b84e8d8eddf913..576bfdc15584193a00729755a2b2be4054fa4d40 100644 --- a/PaddleCV/image_classification/models/se_resnext_vd.py +++ b/PaddleCV/image_classification/models/se_resnext_vd.py @@ -173,7 +173,7 @@ class SE_ResNeXt(): num_filters=num_filters, filter_size=filter_size, stride=stride, - padding=(filter_size - 1) / 2, + padding=(filter_size - 1) // 2, groups=groups, act=None, bias_attr=False, @@ -205,7 +205,7 @@ class SE_ResNeXt(): num_filters=num_filters, filter_size=filter_size, stride=1, - padding=(filter_size - 1) / 2, + padding=(filter_size - 1) // 2, groups=groups, act=None, param_attr=ParamAttr(name=name + "_weights"), diff --git a/PaddleCV/image_classification/reader_cv2.py b/PaddleCV/image_classification/reader_cv2.py index 09fdfb0cd7aa4a34d34d999048e6bbca0fe6e4d3..6727dbb5171b6a84ed70d51d7226f924cc46e589 100644 --- a/PaddleCV/image_classification/reader_cv2.py +++ b/PaddleCV/image_classification/reader_cv2.py @@ -162,7 +162,7 @@ def process_image( else: if crop_size > 0: target_size = settings.resize_short_size - img = resize_short(img, 256) + img = resize_short(img, target_size) img = crop_image(img, target_size=crop_size, center=True) @@ -222,14 +222,14 @@ def _reader_creator(settings, img_path = os.path.join(data_dir, img_path) yield [img_path] - + crop_size = int(settings.image_shape.split(",")[2]) image_mapper = functools.partial( process_image, settings=settings, mode=mode, color_jitter=color_jitter, rotate=rotate, - crop_size=224) + crop_size=crop_size) reader = paddle.reader.xmap_readers( image_mapper, reader, THREAD, BUF_SIZE, order=False) return reader diff --git a/PaddleCV/image_classification/train.py b/PaddleCV/image_classification/train.py index b896e91d9a75af7a224961882a232491bdbb7232..467ef098dbc3dd966111d896a5fd1c21928a1c11 100644 --- a/PaddleCV/image_classification/train.py +++ b/PaddleCV/image_classification/train.py @@ -38,7 +38,7 @@ add_arg('pretrained_model', str, None, "Whether to use pretrai add_arg('checkpoint', str, None, "Whether to resume checkpoint.") add_arg('lr', float, 0.1, "set learning rate.") add_arg('lr_strategy', str, "piecewise_decay", "Set the learning rate decay strategy.") -add_arg('model', str, "ResNet50", "Set the network to use.") +add_arg('model', str, "SE_ResNeXt50_32x4d", "Set the network to use.") add_arg('enable_ce', bool, False, "If set True, enable continuous evaluation job.") add_arg('data_dir', str, "./data/ILSVRC2012/", "The ImageNet dataset root dir.") add_arg('fp16', bool, False, "Enable half precision training with fp16." )