-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mihai Neagu] Write predict.py script
- Loading branch information
1 parent
3d308f9
commit d770a45
Showing
2 changed files
with
131 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import argparse | ||
import model_utils | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description='Use this script to predict an image class using a saved model', | ||
add_help=True | ||
) | ||
|
||
parser.add_argument( | ||
'--top_k', | ||
default=3, | ||
action='store', | ||
type=int, | ||
help="Top K most likely classes" | ||
) | ||
|
||
parser.add_argument( | ||
'--category_names', | ||
default='cat_to_name.json', | ||
action='store', | ||
type=str, | ||
help="Path to a JSON file containing the mapping between numeric category and class names" | ||
) | ||
|
||
parser.add_argument( | ||
'--gpu', | ||
default=True, | ||
action='store_true', | ||
help="If passed, will use the GPU" | ||
) | ||
|
||
parser.add_argument( | ||
'path_to_image', | ||
action='store', | ||
type=str, | ||
help="Path to an image for which to predict class" | ||
) | ||
|
||
parser.add_argument( | ||
'checkpoint', | ||
action='store', | ||
type=str, | ||
help="Path to a checkpoint file containing a trained model" | ||
) | ||
|
||
results = parser.parse_args() | ||
|
||
model_utils.predict( | ||
model=model_utils.load_model(results.checkpoint), | ||
path_to_image=results.path_to_image, | ||
gpu=results.gpu, | ||
top_k=results.top_k | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |