将数据加载器中的图像拆分为补丁

发布于 2025-01-19 22:59:39 字数 443 浏览 1 评论 0原文

使用 Fashion mnist 数据集,我不想只将单个图像分割为补丁,而是将所有图像分割为多个图像。

我已经看到了函数unfold(),但我认为这只适用于单个图像

mnist_train = torchvision.datasets.FashionMNIST(
root="../data", train=True, 
transform=transforms.Compose([transforms.ToTensor()]), download=True)

x = mnist_train[0][0][-1, :, :]

x = x.unfold(0, 7, 7).unfold(1, 7, 7)

x.shape

如何为所有图像制作不重叠的补丁(任意数量以保持简单)?

将不胜感激任何帮助。谢谢!

Using the Fashion mnist dataset, I don't want to just split a single image into patches but rather all of images.

I've seen the function unfold() but I think this only works for a single image

mnist_train = torchvision.datasets.FashionMNIST(
root="../data", train=True, 
transform=transforms.Compose([transforms.ToTensor()]), download=True)

x = mnist_train[0][0][-1, :, :]

x = x.unfold(0, 7, 7).unfold(1, 7, 7)

x.shape

How do I make non-overlapping patches (of any number to keep it simple) for all images?

Would appreciate any help. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二智少女 2025-01-26 22:59:39

您可以创建自定义转换以将所有图像分割成多个补丁。大致如下:

class Patch(object):
    """
    Creates patches from images
    """

    def __init__(self, patch_size=7):
        self.patch_size = patch_size

    def __call__(self, image):
        patched_image = # ... your code here
        return patched_image


mnist_train = torchvision.datasets.FashionMNIST(
    root="../data", train=True,
    transform=transforms.Compose([transforms.ToTensor(), Patch()]), download=True)

You can create a custom transform to split all images into multiple patches. Something along the lines of:

class Patch(object):
    """
    Creates patches from images
    """

    def __init__(self, patch_size=7):
        self.patch_size = patch_size

    def __call__(self, image):
        patched_image = # ... your code here
        return patched_image


mnist_train = torchvision.datasets.FashionMNIST(
    root="../data", train=True,
    transform=transforms.Compose([transforms.ToTensor(), Patch()]), download=True)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文