示例#1
0
def get_loader(*args, **kwargs):
    dataset = data.ToyTask(*args, **kwargs)
    loader = torch.utils.data.DataLoader(
        dataset,
        batch_size=1024,
        num_workers=8,
        pin_memory=True,
    )
    return loader
示例#2
0
def visualize_dataset():
    params = [0.1, 0.2, 0.3, 0.4, 0.5, None]
    plt.figure(figsize=(11.5, 4), dpi=200)
    for n, length in enumerate(params):
        task = data.ToyTask(length=length,)
        weights, boxes, true_num = next(iter(task))
        print(true_num, len(weights))
        true_fig = plt.subplot(2, len(params), n*2+1, aspect='equal')
        data_fig = plt.subplot(2, len(params),  n*2+2, aspect='equal')

        for index in range(boxes.size()[1]):
            box = boxes[:, index]
            x = box[0]
            y = box[1]
            w = box[2] - box[0]
            h = box[3] - box[1]
            # Given images
            # As for color, "1" represents true, "0" represents false.
            # Therefore, the red rectangle represents true object.
            # the blue rectangle represents false object.
            data_fig.add_patch(patches.Rectangle((x, y), width=w, height=h, alpha=0.5,
                                                 linewidth=0, color=cm(float(weights[index]))))
            # In fact
            if index < true_num:
                true_fig.add_patch(patches.Rectangle((x, y), width=w, height=h, alpha=0.5, linewidth=0,
                                                     color=cm(float(1))))
            else:
                true_fig.add_patch(patches.Rectangle((x, y), width=w, height=h, alpha=0.5, linewidth=0,
                                                     color=cm(float(0))))

        true_fig.axes.get_xaxis().set_visible(False)
        data_fig.axes.get_xaxis().set_visible(False)
        true_fig.axes.get_yaxis().set_major_locator(plt.NullLocator())
        data_fig.axes.get_yaxis().set_visible(False)
        true_fig.set_title('Ground truth: {}'.format(true_num))
        data_fig.set_title('Given Data')
        if length:
            true_fig.set_ylabel('$length = {}$'.format(length))
        else:
            true_fig.set_ylabel('$length=random$')

    plt.show()
random.seed(int(2 * q) + 16)

cm = plt.cm.coolwarm
params = [
    (0.05, q),
    (0.1, q),
    (0.2, q),
    (0.3, q),
    (0.4, q),
    (0.5, q),
]

n = 0
plt.figure(figsize=(4, 11.5), dpi=200)
for coord, noise in params:
    dataset = data.ToyTask(10, coord, noise)

    a, b, c = next(iter(dataset))

    ax_true = plt.subplot(len(params), 2, n + 1, aspect='equal')
    ax_data = plt.subplot(len(params), 2, n + 2, aspect='equal')
    for i, (weight, box) in enumerate(zip(a, b)):
        x = box[0]
        y = box[1]
        w = box[2] - box[0]
        h = box[3] - box[1]
        config = {
            'alpha': 0.3,
            'linewidth': 0,
        }
        ax_true.add_patch(