Last active
February 15, 2018 23:18
-
-
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.
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
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