FileNotFoundError: [Errno 2] :No such file or directory: 'C:/Users/My_computer/Desktop/Compare/MHAN-master/AID_train/AID_train_LR/x4\\9.png'
I'm very new to python environment. I have tried to compile a super-resolution code for upscaling factor 4 using my own dataset. The low resolution RGB images are kept in &quot;C:/Users/My_computer/Desktop/Compare/MHAN-master/AID_train/AID_train_LR/x4&quot;. The code used for image load is shown in below:
def load_img(filepath):
img = Image.open(filepath).convert('RGB')
#img = Image.open(filepath, 'rb')

#y, _, _ = img.split()
return img

class DatasetFromFolder(data.Dataset):
def __init__(self, image_dir, lr_dir, patch_size, upscale_factor, data_augmentation, transform=None):
    super(DatasetFromFolder, self).__init__()
    self.image_filenames = [join(image_dir, x) for x in listdir(image_dir) if is_image_file(x)]
    self.patch_size = patch_size
    self.upscale_factor = upscale_factor
    self.transform = transform
    self.data_augmentation = data_augmentation
    self.HR ='C://Users//My_computer//Desktop//Compare//MHAN-master//AID_train//AID_train_HR'
    self.LR ='C://Users//My_computer//Desktop//Compare//MHAN-master//AID_train//AID_train_LR//x4'
    
def __getitem__(self, index):
    target = load_img(self.image_filenames[index])
    input = load_img(os.path.join(self.LR, file))
    input, target, _ = get_patch(input,target,self.patch_size, self.upscale_factor)
    return input, target

But I am getting the following error while the training code is compiled:
File &quot;main_x4.py&quot;, line 185, in &lt;module&gt;
    train(model, epoch)
  File &quot;main_x4.py&quot;, line 60, in train
    for iteration, batch in enumerate(training_data_loader, 1):
  File &quot;C:\Users\My_computer\anaconda3\envs\MHAN\lib\site-packages\torch\utils\data\dataloader.py&quot;, line 346, in __next__
    data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
  File &quot;C:\Users\My_computer\anaconda3\envs\MHAN\lib\site-packages\torch\utils\data\_utils\fetch.py&quot;, line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File &quot;C:\Users\My_computer\anaconda3\envs\MHAN\lib\site-packages\torch\utils\data\_utils\fetch.py&quot;, line 44, in &lt;listcomp&gt;
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File &quot;C:\Users\My_computer\Desktop\Compare\MHAN-master\dataset_x4.py&quot;, line 91, in __getitem__
    input = load_img(os.path.join(self.LR, file))
  


File &quot;C:\Users\My_computer\Desktop\Compare\MHAN-master\dataset_x4.py&quot;,
line 16, in load_img

img = Image.open(filepath).convert('RGB')

  File &quot;C:\Users\My_computer\anaconda3\envs\MHAN\lib\site-packages\PIL\Image.py&quot;,

line 2912, in open
fp = builtins.open(filename, &quot;rb&quot;)

FileNotFoundError: [Errno 2] No such file or directory: 'C://Users//My_computer//Desktop//Compare//MHAN-master//AID_train//AID_train_LR//x4\\9.png'

As LR images are already in RGB format, so is it necessary to convert to RGB again?
Please help me to fix this error

'C:/Users/My_computer/Desktop/Compare/MHAN-master/AID_train/AID_train_LR/x4\\9.png'
Your string contains a double backslash at the end of the path, that's why you can't access the directory
use a raw string like
r'yourString'

or review your os.path.join
EDIT:
Try to convert every string into a raw-String, like mentioned above. You are still getting double backslashes, because certain \character combinations are escaped.
These are the escaped characters:

Edit your code to:
self.HR =r'C:/Users/My_computer/Desktop/Compare/MHAN- 
master/AID_train/AID_train_HR'
self.LR =r'C:/Users/My_computer/Desktop/Compare/MHAN- 
master/AID_train/AID_train_LR/x4'

Please notice the &quot;r&quot; in front of the string to convert them into raw-Strings.
