Commit c0819f3d authored by drougardn's avatar drougardn
Browse files

img recog

parent 12aaaca7
#!/usr/bin/env python3
"Compute accuracy for train images that contain green colors"
"Shows predictions which are rejected"
import os
from glob import glob
from Class import total_time
from Class import info_memory
green_list = '/home/gamilesca/Documents/Overfeat/green_list.txt'
predictions_dir = '/home/gamilesca/Documents/Overfeat/Frenteraz/Class/'
# load green parts
gl = open( green_list )
green = gl.read()
green = green.split( "\n" )
green = { x: x for x in green }
#print(green)
files = glob( predictions_dir + '*.txt' )
files.sort()
acc_counter = 0
count_predictions = 0
rejected = []
for f in files:
# true class
#print(f)
basename = os.path.basename( f )
#print(basename)
true_class = basename.split( "." )[0]
#print(true_class)
#print true_class
pf = open( f )
predictions = pf.read()
predictions = predictions.split( "\n" )
predictions = list( map(lambda x: x.split( "0." )[0].strip(), predictions) )
predictions = list( map(lambda x: x.split( "1." )[0].strip(), predictions) )
predictions.remove('')
print(predictions)
predicted_class = " "
for p in predictions:
count_predictions += 1
if p in green:
acc_counter += 1
predicted_class = 'match'
else:
if p not in rejected:
rejected.append(p)
print ("{}\t{}".format( true_class, predicted_class))
#print the accuracy of this angle
print("\n")
print("Predictions not taken into account:",rejected)
print ("Score: {}/{}".format( acc_counter, count_predictions ))
accuracy = 100 * acc_counter / count_predictions
accuracy = round(accuracy, 2)
print ("Percentage of accuracy overfeat: {} %".format( accuracy ))
print("Computation time: %s minutes " % (total_time))
print("Usage RAM: {} MB".format(info_memory*1e-6))
/home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101208.jpg
/home/gamilesca/Downloads/overfeat/src/overfeat -l -d /home/gamilesca/Downloads/overfeat/data/default/ /home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101208.jpg -n 3 > /home/gamilesca/Documents/Overfeat/Classification/1.txt
/home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101215.jpg
/home/gamilesca/Downloads/overfeat/src/overfeat -l -d /home/gamilesca/Downloads/overfeat/data/default/ /home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101215.jpg -n 3 > /home/gamilesca/Documents/Overfeat/Classification/2.txt
/home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101223.jpg
/home/gamilesca/Downloads/overfeat/src/overfeat -l -d /home/gamilesca/Downloads/overfeat/data/default/ /home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101223.jpg -n 3 > /home/gamilesca/Documents/Overfeat/Classification/3.txt
/home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101315.jpg
/home/gamilesca/Downloads/overfeat/src/overfeat -l -d /home/gamilesca/Downloads/overfeat/data/default/ /home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101315.jpg -n 3 > /home/gamilesca/Documents/Overfeat/Classification/4.txt
/home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101342.jpg
/home/gamilesca/Downloads/overfeat/src/overfeat -l -d /home/gamilesca/Downloads/overfeat/data/default/ /home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101342.jpg -n 3 > /home/gamilesca/Documents/Overfeat/Classification/5.txt
/home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101355.jpg
/home/gamilesca/Downloads/overfeat/src/overfeat -l -d /home/gamilesca/Downloads/overfeat/data/default/ /home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101355.jpg -n 3 > /home/gamilesca/Documents/Overfeat/Classification/6.txt
/home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101407.jpg
/home/gamilesca/Downloads/overfeat/src/overfeat -l -d /home/gamilesca/Downloads/overfeat/data/default/ /home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101407.jpg -n 3 > /home/gamilesca/Documents/Overfeat/Classification/7.txt
/home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101458.jpg
/home/gamilesca/Downloads/overfeat/src/overfeat -l -d /home/gamilesca/Downloads/overfeat/data/default/ /home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101458.jpg -n 3 > /home/gamilesca/Documents/Overfeat/Classification/8.txt
/home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101511.jpg
/home/gamilesca/Downloads/overfeat/src/overfeat -l -d /home/gamilesca/Downloads/overfeat/data/default/ /home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101511.jpg -n 3 > /home/gamilesca/Documents/Overfeat/Classification/9.txt
/home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101522.jpg
/home/gamilesca/Downloads/overfeat/src/overfeat -l -d /home/gamilesca/Downloads/overfeat/data/default/ /home/gamilesca/Documents/Overfeat/Frenteraz/20200616_101522.jpg -n 3 > /home/gamilesca/Documents/Overfeat/Classification/10.txt
--- 2.890178910891215 minutes ---
10252288
['pot, flowerpot', 'mantis, mantid', 'green lizard, Lacerta viridis']
1 match
['pot, flowerpot', 'green lizard, Lacerta viridis', 'fig']
10 match
['mantis, mantid', 'American chameleon, anole, Anolis carolinensis', 'green lizard, Lacerta viridis']
2 match
['green lizard, Lacerta viridis', 'American chameleon, anole, Anolis carolinensis', 'tree frog, tree-frog']
3 match
['American chameleon, anole, Anolis carolinensis', 'green lizard, Lacerta viridis', 'mantis, mantid']
4 match
['American chameleon, anole, Anolis carolinensis', 'pot, flowerpot', 'green lizard, Lacerta viridis']
5 match
['green lizard, Lacerta viridis', 'American chameleon, anole, Anolis carolinensis', 'tree frog, tree-frog']
6 match
['mantis, mantid', 'walking stick, walkingstick, stick insect', 'American chameleon, anole, Anolis carolinensis']
7 match
['pot, flowerpot', 'mantis, mantid', 'walking stick, walkingstick, stick insect']
8 match
['pot, flowerpot', 'walking stick, walkingstick, stick insect', 'green lizard, Lacerta viridis']
9 match
Predictions not taken into account: ['pot, flowerpot']
Score: 25/30
Percentage of accuracy overfeat: 83.33 %
Computation time: 2.890178910891215 minutes
Usage RAM: 10.252288 MB
pot, flowerpot 0.827686
plate 0.0308513
acorn squash 0.0209297
pot, flowerpot 0.944007
vine snake 0.035294
water snake 0.00368161
plate 0.194405
hognose snake, puff adder, sand viper 0.0860059
cucumber, cuke 0.0529107
pot, flowerpot 0.118687
stinkhorn, carrion fungus 0.0591218
agaric 0.0427247
pot, flowerpot 0.976913
chocolate sauce, chocolate syrup 0.00884863
hognose snake, puff adder, sand viper 0.00154186
pot, flowerpot 0.999947
vase 1.28748e-05
acorn squash 1.08526e-05
pot, flowerpot 0.795452
vine snake 0.0449483
green snake, grass snake 0.0243881
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment