Example #1
0
# get assign executor
pcs = []
ass_executors = []
nns = []
for l in range(args.num_res):
    pc = np.zeros(vgg_executor.outputs[l].shape)
    for i1 in range(0, vgg_executor.outputs[l].shape[2] - args.patch_size + 1):
        for i2 in range(0, vgg_executor.outputs[l].shape[3] - args.patch_size +
                        1):
            pc[0, :, i1:i1 + args.patch_size, i2:i2 + args.patch_size] += 1
    pc = mx.nd.array(pc, mx.gpu())
    nn = mx.nd.zeros([
        vgg_executor.outputs[l].shape[2] - args.patch_size + 1,
        vgg_executor.outputs[l].shape[3] - args.patch_size + 1
    ], mx.gpu())
    assign_symbol = symbol.assign_symbol()
    assign_executor = assign_symbol.bind(args={
        'source': patches[l],
        'nn': nn
    },
                                         ctx=mx.gpu())
    assign_executor.forward()
    pcs.append(pc)
    ass_executors.append(assign_executor)
    nns.append(nn)

img_list = os.listdir(COCOPATH)
for idx in range(args.num_image):
    #    break
    optim_state = optimizer.create_state(0, arg_dict['data'])
    selected = np.random.randint(0, len(img_list))
Example #2
0
target_patch = []
for l in range(args.num_res):
    mrf_executors.append(get_mrf_executor(vgg_executor.outputs[l], patches[l].shape))
    mrf_executors[l].arg_dict['weight'][:] = patches_normed[l]
# get assign executor
pcs = []
ass_executors = []
nns = []
for l in range(args.num_res):
    pc = np.zeros(vgg_executor.outputs[l].shape)
    for i1 in range(0, vgg_executor.outputs[l].shape[2]-args.patch_size+1):
        for i2 in range(0, vgg_executor.outputs[l].shape[3]-args.patch_size+1):
            pc[0,:,i1:i1+args.patch_size,i2:i2+args.patch_size] += 1
    pc = mx.nd.array(pc, mx.gpu())
    nn = mx.nd.zeros([vgg_executor.outputs[l].shape[2]-args.patch_size+1, vgg_executor.outputs[l].shape[3]-args.patch_size+1], mx.gpu())
    assign_symbol = symbol.assign_symbol()
    assign_executor = assign_symbol.bind(args={'source':patches[l], 'nn':nn}, ctx=mx.gpu())
    assign_executor.forward()
    pcs.append(pc)
    ass_executors.append(assign_executor)
    nns.append(nn)

for epoch in range(args.epochs):
    vgg_executor.forward(is_train=True)
    if epoch % 10 == 0:
        for l in range(args.num_res):
            mrf_executors[l].forward()
            nns[l][:] = mx.nd.argmax_channel(mrf_executors[l].outputs[0])[0]
            ass_executors[l].outputs[0][:] = 0
            ass_executors[l].forward()
            ass_executors[l].outputs[0][:] /= pcs[l]