Skip to content

Instantly share code, notes, and snippets.

@mpilosov
Last active February 15, 2018 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpilosov/6452aad73bce7b84b3ad2483bc02f621 to your computer and use it in GitHub Desktop.
Save mpilosov/6452aad73bce7b84b3ad2483bc02f621 to your computer and use it in GitHub Desktop.
Read in a dictionary-based file (like a JS output) that is saved as plaintext.
myfile = 'pred.js'
with open(myfile,'r') as inf:
dict_from_file = eval(inf.read())
# each entry will be a dictionary, parse them as you wish.
print('keys', dict_from_file[0].keys()) # will list available key-value pairs.
# I'm going to extract the data that I personally care about. Class labels.
# playing with these lines allowed me to find the numbers representing the class labels
print(dict_from_file[0]['predicted'][3])
print(dict_from_file[0]['image_path'][42])
# we will store the info in some lists.
true_class = []
pred_class = []
# this is based on how I use folder names and file names to save test images...
# also how predictions are saved using this python project: https://github.com/matthew-sochor/transfer
for D in dict_from_file:
pred_class.append(int(D['predicted'][3]))
true_class.append(int(D['image_path'][42]))
# lets gauge our accuracy
sum([pred_class[i] == true_class[i] for i in range(len(true_class))])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment