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

Pass preprocess_image function to generators in evaluate.py #1290

Merged
merged 2 commits into from
Mar 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions keras_retinanet/bin/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@
from .. import models
from ..preprocessing.csv_generator import CSVGenerator
from ..preprocessing.pascal_voc import PascalVocGenerator
from ..utils.anchors import make_shapes_callback
from ..utils.config import read_config_file, parse_anchor_parameters
from ..utils.eval import evaluate
from ..utils.gpu import setup_gpu
from ..utils.keras_version import check_keras_version
from ..utils.tf_version import check_tf_version


def create_generator(args):
def create_generator(args, preprocess_image):
""" Create generators for evaluation.
"""
common_args = {
'preprocess_image': preprocess_image,
}

if args.dataset_type == 'coco':
# import here to prevent unnecessary dependency on cocoapi
from ..preprocessing.coco import CocoGenerator
Expand All @@ -49,6 +54,7 @@ def create_generator(args):
image_max_side=args.image_max_side,
config=args.config,
shuffle_groups=False,
**common_args
)
elif args.dataset_type == 'pascal':
validation_generator = PascalVocGenerator(
Expand All @@ -59,6 +65,7 @@ def create_generator(args):
image_max_side=args.image_max_side,
config=args.config,
shuffle_groups=False,
**common_args
)
elif args.dataset_type == 'csv':
validation_generator = CSVGenerator(
Expand All @@ -68,6 +75,7 @@ def create_generator(args):
image_max_side=args.image_max_side,
config=args.config,
shuffle_groups=False,
**common_args
)
else:
raise ValueError('Invalid data type received: {}'.format(args.dataset_type))
Expand Down Expand Up @@ -131,7 +139,8 @@ def main(args=None):
args.config = read_config_file(args.config)

# create the generator
generator = create_generator(args)
backbone = models.backbone(args.backbone)
generator = create_generator(args, backbone.preprocess_image)

# optionally load anchor parameters
anchor_params = None
Expand All @@ -141,6 +150,7 @@ def main(args=None):
# load the model
print('Loading model, this may take a second...')
model = models.load_model(args.model, backbone_name=args.backbone)
generator.compute_shapes = make_shapes_callback(model)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be passed to the constructor of generator. It does mean that the order of creating generators followed by loading of the model has to be the other way around, but I don't think this is an issue.


# optionally convert the model
if args.convert_model:
Expand Down