# script for sigmoid transform and L1 normalization of classification scores obtained with log loss
from numpy import loadtxt,savetxt, exp, tile,transpose, size, sum
from numpy.core.fromnumeric import size
import sys,os
filename_f=sys.argv[1]
# load matrix of scores NxM ( N= images, M=categories)
f=loadtxt(filename_f)
# sigmoid to get probabilities
pf=1./(1+exp(-f))
# L1 normalization
pf_n=pf / transpose( tile( sum(pf,1), (size(f,1),1) ) )
filename_pf_n=os.path.splitext(filename_f)[0]+'Norm'+os.path.splitext(filename_f)[1]
savetxt(filename_pf_n,pf_n,fmt='%.6e')
NOTE WELL:
a. import all the fuctions you are using from numpy ( it is faster
b. to extract path and extension use os.path.splitext
No comments:
Post a Comment