import cPickle as pkl import shutil import uuid import numpy as np import psyphy.perturb as perturb import psyphy.n2nmatch as n2n import vggfacedec as vfd if __name__ == '__main__': if len(sys.argv) < 4: raise Exception('missing ptype or range value') ptype = sys.argv[1] low = float(sys.argv[2]) high = float(sys.argv[3]) with open(os.path.join('vggface-pv.pkl'), 'rb') as f: sobj = pkl.load(f) def perturb(path, p): ipath = os.path.join('images-facegen', 'no-align', ptype, str(p), path.split('/')[-1]) if p == 0 or p == 0.0: ipath = os.path.join('images-facegen', 'no-align', 'original', path.split('/')[-1]) opath = '/tmp/' + str(uuid.uuid4()) + '.jpg' shutil.copyfile(ipath, opath) return opath output = n2n.item_response_curve_mafc(vfd.decision, perturb, sobj['imgs'], sobj['thresh'], 50, low, high) with open(os.path.join('vggface-irc-' + ptype + '.pkl'), 'w') as f: pkl.dump(output, f)
import openfacedec as ofd if __name__ == '__main__': if len(sys.argv) < 4: raise Exception('missing ptype or range value') ptype = sys.argv[1] low = float(sys.argv[2]) high = float(sys.argv[3]) with open(os.path.join('openface-pv.pkl'), 'rb') as f: sobj = pkl.load(f) pfunc = { 'gausblur' : perturb.gaussian_blur, 'linocc' : perturb.linear_occlude, 'brightness-dec' : perturb.brightness, 'brightness-inc' : perturb.brightness, 'color-dec' : perturb.color, 'color-inc' : perturb.color, 'contrast-dec' : perturb.contrast, 'contrast-inc' : perturb.contrast, 'sharpness-dec' : perturb.sharpness, 'sharpness-inc' : perturb.sharpness, 'noisesap' : perturb.noise_sap, 'noisegaus' : perturb.noise_gaussian, 'noisepink' : perturb.noise_pink, 'noisebrown' : perturb.noise_brown }[ptype] output = n2n.item_response_curve_mafc(ofd.decision, pfunc, sobj['imgs'], sobj['thresh'], 200, low, high) with open(os.path.join('openface-irc-' + ptype + '.pkl'), 'w') as f: pkl.dump(output, f)