Skip to content

Instantly share code, notes, and snippets.

@erfannoury
Created November 6, 2015 21:23
Show Gist options
  • Save erfannoury/d16d28344f660748642f to your computer and use it in GitHub Desktop.
Save erfannoury/d16d28344f660748642f to your computer and use it in GitHub Desktop.
def rank_fn():
inp = net['input'].input_var
outp = lasagne.layers.get_output(net['rank'], deterministic=True)
return theano.function([inp], outp)
def sorted_by_attr(images, base_path, rank_fun):
results = []
for im in images:
im_path = os.path.join(base_path, im)
_, a = prepare_image(im_path)
res = rank_fun(a)
results += [(res, im)]
results = sorted(results, key=lambda x: x[0])
return [r[1] for r in results]
imagePairs = ['Boots/Ankle/Camper/7231825.361448.jpg', 'Boots/Ankle/Jumping Jacks Kids/7995630.362624.jpg', \
'Sandals/Heel/Spring Step/7639878.3561.jpg', 'Shoes/Flats/Frye/7970521.332565.jpg', \
'Shoes/Heels/Nine West/7490059.1781.jpg', 'Shoes/Loafers/Patagonia/7495020.79745.jpg', \
'Shoes/Oxfords/Timberland/7912777.3.jpg', 'Slippers/Slipper Flats/Spenco/8004085.1430.jpg']
print sorted_by_attr(imagePairs, 'Zappos', rank_fn())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment