简体   繁体   中英

Jupyter Notebook - The system cannot find the path specified

**I'm trying to run this code below, where I'm getting an error 'file not found' ** I tried to check if I'm in right directory by using:

os.listdir('C:\\Users\\ruchi\\Desktop\\Car-Models-Classifier-master')

['.ipynb_checkpoints',
 'bmw10_ims',
 'cars_annos.mat',
 'cars_test',
 'cars_test_annos_withlabels.mat',
 'cars_train',
 'car_ims',
 'car_models_classifier.ipynb',
 'devkit',
 'README.md']

This is the code which I'm trying to run for which I gave correct path still it shows file not found error.

**CODE:**

data_dir = '/Car-Models-Classifier-master'
train_dir = '/Car-Models-Classifier-master/cars_train'
valid_dir = data_dir + '/valid'
test_dir = '/Car-Models-Classifier-master/cars_test'

**# Training transform includes random rotation and flip to build a more robust model**
train_transforms = transforms.Compose([transforms.Resize((244,244)),
                                       transforms.RandomRotation(30),
                                       transforms.RandomHorizontalFlip(),
                                       transforms.ToTensor(),
                                       transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])


**# The validation set will use the same transform as the test set**
test_transforms = transforms.Compose([transforms.Resize((244,244)),
                                      transforms.CenterCrop(224),
                                      transforms.ToTensor(),
                                      transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])

validation_transforms = transforms.Compose([transforms.Resize((244,244)),
                                            transforms.CenterCrop(224),
                                            transforms.ToTensor(),
                                            transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])


**# Load the datasets with ImageFolder**
train_data = datasets.ImageFolder(data_dir + '/Car-Models-Classifier-master/cars_train', transform=train_transforms)
test_data = datasets.ImageFolder(data_dir + '/Car-Models-Classifier-master/cars_test', transform=test_transforms)
#valid_data = datasets.ImageFolder(data_dir + '/valid', transform=validation_transforms)

**# Using the image datasets and the trainforms, define the dataloaders
# The trainloader will have shuffle=True so that the order of the images do not affect the model**
trainloader = torch.utils.data.DataLoader(train_data, batch_size=128, shuffle=True)
testloader = torch.utils.data.DataLoader(test_data, batch_size=32, shuffle=True)
validloader = torch.utils.data.DataLoader(valid_data, batch_size=32, shuffle=True)

This the error:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-16-fe5e781c7465> in <module>
     20 
     21 # Load the datasets with ImageFolder
---> 22 train_data = datasets.ImageFolder(data_dir + '/Car-Models-Classifier-master/cars_train', transform=train_transforms)
     23 test_data = datasets.ImageFolder(data_dir + '/Car-Models-Classifier-master/cars_test', transform=test_transforms)
     24 #valid_data = datasets.ImageFolder(data_dir + '/valid', transform=validation_transforms)

Can someone help? I'm not able to understand where I'm going wrong.

This

 data_dir + '/Car-Models-Classifier-master/cars_train'

concatinates to

/Car-Models-Classifier-master/Car-Models-Classifier-master/cars_train

So the line must be

train_data = datasets.ImageFolder(data_dir + '/cars_train', transform=train_transforms)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM