def label_to_coords(label):
    """Convert convnet output to ``k*2`` coordinate array."""
    # use label.shape instead of label.ndim for h5py (which I don't think
    # supports .ndim?)
    ndim = len(label.shape)
    if ndim == 1:
        return label.reshape((-1, 2))
    elif ndim == 2:
        return label.reshape((label.shape[0], -1, 2))
    else:
        raise ValueError("label should be output for single sample or a batch")