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

Feature: allow for custom_objects to be fed into load_model #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 15 additions & 1 deletion bin/keras-compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def gen_argparser():
parser.add_argument('--log-level', type=str, default='INFO',
choices=['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG'],
help='log level. Default: INFO')

parser.add_argument('--include', type=str, default='',
help='module to include by importing')

parser.add_argument('--custom-objects', type=str, default='',
help='ability to pass in custom objects to load_model in keras default is blank')
return parser


Expand All @@ -50,7 +56,15 @@ def main():

logging.basicConfig(level=getattr(logging, args.log_level))

model = load_model(args.model) # type: keras.models.Model
if args.include != '':
exec(open(args.include).read())

kwargs = {}
if args.custom_objects != '':
kwargs['custom_objects'] = {args.custom_objects: eval(args.custom_objects)}

model = load_model(args.model, **kwargs)

total_params_before = sum(count_total_params(model))
model = compress(model, acceptable_error=args.error)
total_params_after = sum(count_total_params(model))
Expand Down