def process( (i, img, l) ):
     mylabels = labels - set([ l ])
     return [ gen_adversial(net, img, l, tl) for tl in mylabels ]
parser.add_argument('--proto', type=str, required=True)
parser.add_argument('--model', type=str, required=True)
parser.add_argument('--image', type=str, required=True)
parser.add_argument('--real-label', type=int, required=True)
parser.add_argument('--target-label', type=int, required=True)
parser.add_argument('--out', type=str, default=None)
parser.add_argument('--crack', type=int, default=0)
parser.add_argument('--crack-out', type=str, default=None)
args = parser.parse_args()


n = caffe.Net(args.proto, args.model, caffe.TEST)

print "Load and forward"
img = imread(args.image, flatten=True)
res = gen_adversial(n, img, args.real_label, args.target_label,
        tries=10, verbose=True)
img2 = res.get('img', None)
scale = res.get('scale', 0.25)

if args.out and res != None:
    if args.out == "-":
        plt.imshow(img2, interpolation='nearest', cmap='gray')
        plt.show()
    else:
        print "Save adversial figure in %s" % (args.out)
        imsave(args.out, img2)

if args.crack and args.crack_out:
    print "Found adversial (scale %f) for %s" % (scale, args.image)
    tries = args.crack
    res = []