Esempio n. 1
0
# Load the terminals symbols of the grammar
with open("terminals.txt", "r") as file:
    unique_draw = file.readlines()
for index, e in enumerate(unique_draw):
    unique_draw[index] = e[0:-1]

# RNN decoder
imitate_net = ImitateJoint(hd_sz=config.hidden_size,
                           input_size=config.input_size,
                           encoder=encoder_net,
                           mode=config.mode,
                           num_draws=len(unique_draw),
                           canvas_shape=config.canvas_shape)
imitate_net.cuda()
imitate_net.epsilon = config.eps

if config.preload_model:
    print("pre loading model")
    pretrained_dict = torch.load(config.pretrain_modelpath)
    imitate_net_dict = imitate_net.state_dict()
    pretrained_dict = {
        k: v
        for k, v in pretrained_dict.items() if k in imitate_net_dict
    }
    imitate_net_dict.update(pretrained_dict)
    imitate_net.load_state_dict(imitate_net_dict)

for param in imitate_net.parameters():
    param.requires_grad = True
Esempio n. 2
0
# Load the terminals symbols of the grammar
with open("terminals.txt", "r") as file:
    unique_draw = file.readlines()
for index, e in enumerate(unique_draw):
    unique_draw[index] = e[0:-1]

imitate_net = ImitateJoint(hd_sz=config.hidden_size,
                           input_size=config.input_size,
                           encoder=encoder_net,
                           mode=config.mode,
                           num_draws=len(unique_draw),
                           canvas_shape=config.canvas_shape)

imitate_net.cuda()
imitate_net.epsilon = 0

test_size = 3000
# This is to find top-1 performance.
paths = [config.pretrain_modelpath]
save_viz = False
for p in paths:
    print(p, flush=True)
    config.pretrain_modelpath = p

    image_path = "data/cad/predicted_images/{}/top_1_prediction/images/".format(
        p.split("/")[-1])
    expressions_path = "data/cad/predicted_images/{}/top_1_prediction/expressions/".format(
        p.split("/")[-1])

    results_path = "data/cad/predicted_images/{}/top_1_prediction/".format(