def sketch( self, images, ): # imgj = images[rand_img_id] import pdb pdb.set_trace() (sentence, ) = describe(images, rand_img_id) permuted_images = random.sample(images, len(images)) (score, ) = which_image(permuted_images, sentence) asl.observe(score, "score") return (score, )
def trace(items, r, runstate, add, card, empty): """Example set trace""" asl.log_append("empty", empty) aset = empty (set_card, ) = card(aset) asl.observe(bridge(set_card), "card1", runstate) hand = [next(items) for i in range(5)] subhand = [r.choice(hand) for i in range(5)] for i, item in enumerate(subhand): (aset, ) = add(aset, item) asl.log_append("{}/internal".format(runstate['mode']), aset) (set_card, ) = card(aset) asl.observe(bridge(set_card), "card.{}".format(i), runstate) return set_card
def trace4(items, r, runstate, push, pop, empty): """Pushes n items, to create n stacks, pops from random one""" asl.log_append("empty", empty) stack = empty for nr in range(nrounds): stacks = [] for i in range(nitems): (stack, ) = push(stack, next(items)) asl.log_append("{}/internal".format(runstate['mode']), stack) stacks.append(stack) (stack, pop_item) = pop(stack) asl.observe(pop_item, "pop.nr{}.i{}".format(nr, i), runstate) asl.log_append("{}/internal".format(runstate['mode']), stack)
def trace4(items, r, runstate, push, pop, empty): """Pushes n items, to create n stacks, pops from random one""" asl.log_append("empty", empty) stack = empty for nr in range(nrounds): stacks = [] for i in range(nitems): (stack, ) = push(stack, next(items)) asl.log_append("{}/internal".format(runstate['mode']), stack) stacks.append(stack) (stack, pop_item) = pop(stack) asl.observe(pop_item, "pop.nr{}.i{}".format(nr, i), runstate) asl.log_append("{}/internal".format(runstate['mode']), stack)
def trace2(items, r, runstate, push, pop, empty): """Push Pop Push Push Pop Pop Push Push Push Pop Pop Pop""" asl.log_append("empty", empty) stack = empty for nr in range(nrounds): for i in range(nitems): (stack,) = push(stack, next(items)) asl.log_append("{}/internal".format(runstate['mode']), stack) pop_stack = stack for j in range(i, -1, -1): (pop_stack, pop_item) = pop(pop_stack) asl.log_append("{}/internal".format(runstate['mode']), pop_stack) asl.observe(pop_item, "pop.nr{}.i{}.j{}".format(nr, i, j), runstate) return pop_item
def trace1(items, r, runstate, push, pop, empty): """Push push push, pop pop pop""" asl.log_append("empty", empty) stack = empty for nr in range(nrounds): for i in range(nitems): (stack,) = push(stack, next(items)) asl.log_append("{}/internal".format(runstate['mode']), stack) for j in range(nitems): (stack, pop_item) = pop(stack) asl.observe(pop_item, "pop.{}.{}".format(nr, j), runstate) asl.log_append("{}/internal".format(runstate['mode']), stack) return pop_item
def trace1(items, r, runstate, push, pop, empty): """Push push push, pop pop pop""" asl.log_append("empty", empty) stack = empty for nr in range(nrounds): for i in range(nitems): (stack, ) = push(stack, next(items)) asl.log_append("{}/internal".format(runstate['mode']), stack) for j in range(nitems): (stack, pop_item) = pop(stack) asl.observe(pop_item, "pop.{}.{}".format(nr, j), runstate) asl.log_append("{}/internal".format(runstate['mode']), stack) return pop_item
def trace2(items, r, runstate, push, pop, empty): """Push Pop Push Push Pop Pop Push Push Push Pop Pop Pop""" asl.log_append("empty", empty) stack = empty for nr in range(nrounds): for i in range(nitems): (stack, ) = push(stack, next(items)) asl.log_append("{}/internal".format(runstate['mode']), stack) pop_stack = stack for j in range(i, -1, -1): (pop_stack, pop_item) = pop(pop_stack) asl.log_append("{}/internal".format(runstate['mode']), pop_stack) asl.observe(pop_item, "pop.nr{}.i{}.j{}".format(nr, i, j), runstate) return pop_item
def trace6(items, r, runstate, push, pop, empty): """Pushes n items, to create n stacks, pops randnum times, then observe once""" asl.log_append("empty", empty) stack = empty for nr in range(nrounds): stacks = [] for i in range(nitems): (stack, ) = push(stack, next(items)) asl.log_append("{}/internal".format(runstate['mode']), stack) stacks.append(stack) npops = r.randdint(1, nitems) for j in range(npops): (stack, pop_item) = pop(stack) asl.log_append("{}/internal".format(runstate['mode']), stack) asl.observe(pop_item, "pop.nr{}".format(nr), runstate)
def trace6(items, r, runstate, push, pop, empty): """Pushes n items, to create n stacks, pops randnum times, then observe once""" asl.log_append("empty", empty) stack = empty for nr in range(nrounds): stacks = [] for i in range(nitems): (stack, ) = push(stack, next(items)) asl.log_append("{}/internal".format(runstate['mode']), stack) stacks.append(stack) npops = r.randint(1, nitems) for j in range(npops): (stack, pop_item) = pop(stack) asl.log_append("{}/internal".format(runstate['mode']), stack) asl.observe(pop_item, "pop.nr{}".format(nr), runstate)
def trace(items, r, runstate, push, pop, empty): """Example stack trace""" # import pdb; pdb.set_trace() asl.log_append("empty", empty) stack = empty for nr in range(nrounds): for i in range(nitems): (stack,) = push(stack, next(items)) # print("BLIP!") asl.log_append("{}/internal".format(runstate['mode']), stack) for j in range(nitems): (stack, pop_item) = pop(stack) asl.observe(pop_item, "pop.{}.{}".format(nr, j), runstate) # print("BLIP!") asl.log_append("{}/internal".format(runstate['mode']), stack) return pop_item
def trace(items, r, runstate, push, pop, empty): """Example stack trace""" # import pdb; pdb.set_trace() asl.log_append("empty", empty) stack = empty for nr in range(nrounds): for i in range(nitems): (stack, ) = push(stack, next(items)) # print("BLIP!") asl.log_append("{}/internal".format(runstate['mode']), stack) for j in range(nitems): (stack, pop_item) = pop(stack) asl.observe(pop_item, "pop.{}.{}".format(nr, j), runstate) # print("BLIP!") asl.log_append("{}/internal".format(runstate['mode']), stack) return pop_item
def trace(items, r, runstate, push, pop, empty): """Example stack trace""" asl.log_append("empty", empty) stack = empty (stack,) = push(stack, next(items)) asl.log_append("{}/internal".format(runstate['mode']), stack) (stack,) = push(stack, next(items)) asl.log_append("{}/internal".format(runstate['mode']), stack) (pop_stack, pop_item) = pop(stack) asl.observe(pop_item, "pop1", runstate) asl.log_append("{}/internal".format(runstate['mode']), pop_stack) (pop_stack, pop_item) = pop(pop_stack) asl.observe(pop_item, "pop2", runstate) asl.log_append("{}/internal".format(runstate['mode']), pop_stack) return pop_item
def sketch(self, noise): """Generate clevr image""" # Add object 1 #FIXME this is a hack noisetensor = asl.cuda(Variable(torch.rand((1,) + SMALL_IMG_SIZE)), opt.nocuda) nnoise = Noise(expand_to_batch(noisetensor, opt.batch_size)) (object1, ) = nclevrgen.gen_object(nnoise) scene = nclevrgen.empty_scene (scene, ) = nclevrgen.add_object(scene, object1) # Add object 2 (object2, ) = nclevrgen.gen_object(nnoise) (scene, ) = nclevrgen.add_object(scene, object2) # Add object 3 (object3, ) = nclevrgen.gen_object(nnoise) (scene, ) = nclevrgen.add_object(scene, object3) (img, ) = nclevrgen.render(scene) asl.observe(img, 'rendered_img') return (img, )
def trace5(items, r, runstate, push, pop, empty): """Make n random choices over whether to push or pop""" asl.log_append("empty", empty) stack = empty stack_size = 0 choicesperround = nitems for nr in range(nrounds * choicesperround): if stack_size == 0: (stack, ) = push(stack, next(items)) stack_size = stack_size + 1 elif stack_size == nitems: (stack, pop_item) = pop(stack) asl.observe(pop_item, "pop.nr{}".format(nr), runstate) stack_size = stack_size - 1 else: dopush = r.choice([True, False]) if dopush: (stack, ) = push(stack, next(items)) stack_size = stack_size + 1 else: (stack, pop_item) = pop(stack) asl.observe(pop_item, "pop.nr{}".format(nr), runstate) stack_size = stack_size - 1 # Final pop to make sure we get some data if stack_size > 0: (stack, pop_item) = pop(stack) asl.observe(pop_item, "pop.final", runstate) asl.log_append("{}/internal".format(runstate['mode']), stack)
def trace5(items, r, runstate, push, pop, empty): """Make n random choices over whether to push or pop""" asl.log_append("empty", empty) stack = empty stack_size = 0 choicesperround = nitems for nr in range(nrounds * choicesperround): if stack_size == 0: (stack, ) = push(stack, next(items)) stack_size = stack_size + 1 elif stack_size == nitems: (stack, pop_item) = pop(stack) asl.observe(pop_item, "pop.nr{}".format(nr), runstate) stack_size = stack_size - 1 else: dopush = r.choice([True, False]) if dopush: (stack, ) = push(stack, next(items)) stack_size = stack_size + 1 else: (stack, pop_item) = pop(stack) asl.observe(pop_item, "pop.nr{}".format(nr), runstate) stack_size = stack_size - 1 asl.log_append("{}/internal".format(runstate['mode']), stack) # Final pop to make sure we get some data if stack_size > 0: (stack, pop_item) = pop(stack) asl.observe(pop_item, "pop.final", runstate) asl.log_append("{}/internal".format(runstate['mode']), stack)
def sketch(self, noise): """Generate clevr image""" # Add object 1 #FIXME this is a hack noisetensor = asl.cuda( Variable(torch.rand((1, ) + SMALL_IMG_SIZE)), opt.nocuda) nnoise = Noise(expand_to_batch(noisetensor, opt.batch_size)) (object1, ) = nclevrgen.gen_object(nnoise) scene = nclevrgen.empty_scene (scene, ) = nclevrgen.add_object(scene, object1) # Add object 2 (object2, ) = nclevrgen.gen_object(nnoise) (scene, ) = nclevrgen.add_object(scene, object2) # Add object 3 (object3, ) = nclevrgen.gen_object(nnoise) (scene, ) = nclevrgen.add_object(scene, object3) (img, ) = nclevrgen.render(scene) asl.observe(img, 'rendered_img') return (img, )
def trace(items, r, runstate, add, card, empty): """Example set trace""" # import pdb; pdb.set_trace() asl.log_append("empty", empty) aset = empty (set_card, ) = card(aset) asl.observe(bridge(set_card), "card1", runstate) i1 = next(items) i2 = next(items) (aset, ) = add(aset, i1) asl.log_append("{}/internal".format(runstate['mode']), aset) (aset, ) = add(aset, i1) asl.observe(bridge(set_card), "card2", runstate) asl.log_append("{}/internal".format(runstate['mode']), aset) (aset, ) = add(aset, i2) asl.log_append("{}/internal".format(runstate['mode']), aset) (set_card, ) = card(aset) asl.observe(bridge(set_card), "card3", runstate) return set_card
def ref_img_gen(img_iter): img = next(img_iter) asl.observe(img, 'rendered_img') return (img, )
def ref_img_gen(img_iter): img = next(img_iter) asl.observe(img, 'rendered_img') return (img, )
def target_score_gen(images, rand_img_id): asl.observe(rand_img_id, "score") return (rand_img_id, )