Skip to content
Open
Changes from 4 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
31 changes: 31 additions & 0 deletions scripts/test_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import pickle
import click
from sklearn.metrics import classification_report
from pkspace.utils.loaders import PKSpaceLoader, PKLotLoader


@click.command()
@click.option('--loader', '-l', type=click.Choice(['PKLot', 'PKSpace']),
default='PKSpace', help='Loader used to load dataset')
@click.argument('dataset_dir')
@click.argument('model_file')
Copy link
Contributor

Choose a reason for hiding this comment

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

@rstevanak Here we can add similar line to the trainer file output = os.path.join(dataset_dir, 'out.pkl') so the click would take care of handling the existence of these file for us.

def test_model(loader, dataset_dir, model_file):
if not os.path.isdir(dataset_dir):
print('{} is not a directory')
return

if loader == 'PKSpace':
loader = PKSpaceLoader()
elif loader == 'PKLot':
loader = PKLotLoader()

with open(model_file, 'rb') as mp:
model = pickle.load(mp)
spaces, ground_answers = loader.load(dataset_dir)
model_answers = model.predict(spaces)
print(classification_report(ground_answers, model_answers))
Copy link
Contributor

Choose a reason for hiding this comment

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

@rstevanak Maybe add a way to print these in some different, more machine friendly, format so other application can run this and perhaps display it somewhere.



if __name__ == '__main__':
test_model()