コード例 #1
0
ファイル: train.py プロジェクト: HomerW/3DCSGNet
            with torch.no_grad():
                parser = ParseModelOutput(stack_size=(k + 1) // 2 + 1,
                                          steps=k,
                                          canvas_shape=[64, 64, 64])
                # samples = next(gen_objs_iters[k][1])
                # data_ = np.stack([x[0] for x in samples])
                # labels = (np.stack([x[1][0] for x in samples]),
                #           np.stack([x[1][1] for x in samples]),
                #           np.stack([x[1][2] for x in samples]),
                #           np.stack([x[1][3] for x in samples]))
                data_, labels = next(train_gen_objs[k])
                oh_labels = one_hot_labels(labels).cuda()

                data = Variable(torch.from_numpy(data_)).cuda()

                test_output = imitate_net.test([data, oh_labels, k])

                accs += sum(accuracy(test_output, labels)) / 4

                l = imitate_net.loss_function(test_output,
                                              [x[:, :-1] for x in labels])
                test_losses += l

                stack, correct_programs, _ = parser.get_final_canvas(
                    test_output,
                    if_pred_images=True,
                    if_just_expressions=False)
                num_correct += len(correct_programs)

                # data_ = data_[-1, :, 0, :, :, :]
                R = np.sum(np.logical_and(stack, data_),
コード例 #2
0
ファイル: train.py プロジェクト: AlexsaseXie/3DCSGNet
            data = Variable(torch.from_numpy(data_[:, :, 0:config.top_k +
                                                   1, :, :, :]),
                            volatile=True).cuda()
            data = data.permute(1, 0, 2, 3, 4, 5)
            labels = Variable(torch.from_numpy(labels)).cuda()

            test_output = imitate_net([data, one_hot_labels, k])

            l = losses_joint(test_output, labels, time_steps=k + 1).data
            test_losses += l

            if cuda_devices > 1:
                test_output = imitate_net.module.test(
                    [data, one_hot_labels, k])
            else:
                test_output = imitate_net.test([data, one_hot_labels, k])

            stack, _, _ = parser.get_final_canvas(test_output,
                                                  if_pred_images=True,
                                                  if_just_expressions=False)
            data_ = data_[-1, :, 0, :, :, :]
            R = np.sum(np.logical_and(stack, data_),
                       (1, 2, 3)) / (np.sum(np.logical_or(stack, data_),
                                            (1, 2, 3)) + 1)
            test_reward += np.sum(R)

    test_reward = test_reward / (test_size // batch_size) / (
        (batch_size // types_prog) * types_prog)

    test_loss = test_losses.cpu().numpy() / (config.test_size //
                                             config.batch_size) / types_prog
コード例 #3
0
ファイル: test.py プロジェクト: AlexsaseXie/3DCSGNet
    for batch_idx in range(dataset_sizes[k][1] // config.batch_size):
        data_, labels = next(test_gen_objs[k])
        data_ = data_[:, :, 0:config.top_k + 1, :, :, :]
        one_hot_labels = prepare_input_op(labels, len(generator.unique_draw))
        one_hot_labels = Variable(torch.from_numpy(one_hot_labels),
                                  volatile=True).cuda()
        data = Variable(torch.from_numpy(data_)).cuda()
        labels = Variable(torch.from_numpy(labels)).cuda()

        # This is for data parallelism purpose
        data = data.permute(1, 0, 2, 3, 4, 5)

        if cuda_devices > 1:
            outputs = imitate_net.module.test([data, one_hot_labels, max_len])
        else:
            outputs = imitate_net.test([data, one_hot_labels, max_len])

        stack, _, expressions = parser.get_final_canvas(
            outputs, if_pred_images=True, if_just_expressions=False)
        Predicted_expressions += expressions
        target_expressions = parser.labels2exps(labels, k)
        Target_expressions += target_expressions
        # stacks = parser.expression2stack(expressions)
        data_ = data_[-1, :, 0, :, :, :]
        R = np.sum(np.logical_and(stack, data_),
                   (1, 2, 3)) / (np.sum(np.logical_or(stack, data_),
                                        (1, 2, 3)) + 1)
        Rs += np.sum(R)
    total_iou += Rs
    IOU[k] = Rs / (
        (dataset_sizes[k][1] // config.batch_size) * config.batch_size)