1
$\begingroup$

I'm using this code in colab. the function below gives me an error when intanciar.

import os
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
import torch.utils.data as data
import torchvision
from torchvision import transforms
def load_images(image_size=32, batch_size=64, root=""):
        transform = transforms.Compose([
        transforms.Resize(32),
        transforms.ToTensor(),
        transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])

        train_set = torchvision.datasets.ImageFolder(root=root,  train=True,transform=transform)
        train_loader = torch.utils.data.DataLoader(train_set, batch_size=batch_size, shuffle=True, num_workers=2)

        return train_loader

data = load_images (28.64, "/ content / data /")

error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-85-a809f71788e0> in <module>()
----> 1 datotes=load_images(28,64,"/content/datitos/")

<ipython-input-84-0b4989f589a9> in load_images(image_size, batch_size, root)
     15     transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
     16 
---> 17     train_set = torchvision.datasets.ImageFolder(root=root,  train=True,transform=transform)
     18     train_loader = torch.utils.data.DataLoader(train_set, batch_size=batch_size, shuffle=True, num_workers=2)
     19 

TypeError: __init__() got an unexpected keyword argument 'train'
$\endgroup$

1 Answer 1

1
$\begingroup$

The error implies that it couldn't recognize the train parameter, in the ImageFolder class.

ImageFolder() does not have a parameter train, remove that it will fix the error. Instead of...

train_set = torchvision.datasets.ImageFolder(root=root,  train=True,transform=transform)

...you should have...

train_set = torchvision.datasets.ImageFolder(root=root, transform=transform).

For more check the documentation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.