PingoLH / FCHarDNet

Fully Convolutional HarDNet for Segmentation in Pytorch
MIT License
195 stars 52 forks source link

FileNotFoundError 'data/Cityscapes/gtFine/train/stuttgart/stuttgart_000016_000019_leftgtFine_labelIds.png' #46

Open mucunwuxian opened 4 years ago

mucunwuxian commented 4 years ago

I cloned the master version of this repository today. So I encountered the following error.

RUNDIR: runs/hardnet/cur
Found 2976 train images
Found 500 val images
Parameters: 4119257
Using optimizer SGD (
Parameter Group 0
    dampening: 0
    lr: 0.02
    momentum: 0.9
    nesterov: False
    weight_decay: 0.0005
)
INFO:ptsemseg:Using bootstrapped_cross_entropy with {'min_K': 4096, 'loss_th': 0.3, 'size_average': True} params
Using loss functools.partial(<function bootstrapped_cross_entropy2d at 0x7fbeb15d5730>, min_K=4096, loss_th=0.3, size_average=True)
INFO:ptsemseg:No checkpoint found at 'None'
WARN: resizing labels yielded fewer classes
/usr/local/lib/python3.6/dist-packages/torch/optim/lr_scheduler.py:123: UserWarning: Detected call of `lr_scheduler.step()` before `optimizer.step()`. In PyTorch 1.1.0 and later, you should call them in the opposite order: `optimizer.step()` before `lr_scheduler.step()`.  Failure to do this will result in PyTorch skipping the first value of the learning rate schedule. See more details at https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate
  "https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate", UserWarning)
/usr/local/lib/python3.6/dist-packages/torch/nn/_reduction.py:44: UserWarning: size_average and reduce args will be deprecated, please use reduction='none' instead.
  warnings.warn(warning.format(ret))
Iter [10/90000]  Loss: 2.6415  Time/Image: 0.0490  lr=0.019998
INFO:ptsemseg:Iter [10/90000]  Loss: 2.6415  Time/Image: 0.0490  lr=0.019998
Iter [20/90000]  Loss: 2.2272  Time/Image: 0.0451  lr=0.019996
INFO:ptsemseg:Iter [20/90000]  Loss: 2.2272  Time/Image: 0.0451  lr=0.019996
Traceback (most recent call last):
  File "./train.py", line 267, in <module>
    train(cfg, writer, logger)
  File "./train.py", line 138, in train
    for (images, labels, _) in trainloader:
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 363, in __next__
    data = self._next_data()
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 971, in _next_data
    return self._process_data(data)
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 1014, in _process_data
    data.reraise()
  File "/usr/local/lib/python3.6/dist-packages/torch/_utils.py", line 395, in reraise
    raise self.exc_type(msg)
FileNotFoundError: Caught FileNotFoundError in DataLoader worker process 3.
Original Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/worker.py", line 185, in _worker_loop
    data = fetcher.fetch(index)
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/content/drive/My Drive/Colab Notebooks/20200831_FCHarDNet/FCHarDNet/ptsemseg/loader/cityscapes_loader.py", line 164, in __getitem__
    lbl = Image.open(lbl_path)
  File "/usr/local/lib/python3.6/dist-packages/PIL/Image.py", line 2809, in open
    fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: './../data/Cityscapes/gtFine/train/stuttgart/stuttgart_000016_000019_leftgtFine_labelIds.png'

It was solved by the following provisional measures.

[@cityscapes_loader.py]

    def __getitem__(self, index):
        """__getitem__

        :param index:
        """
        img_path = self.files[self.split][index].rstrip()
        lbl_path = os.path.join(
            self.annotations_base,
            img_path.split(os.sep)[-2],
            os.path.basename(img_path)[:-15] + "gtFine_labelIds.png",
        )
        lbl_path = lbl_path.replace('leftgtFine', 'gtFine') # <- add this code for solving error
        # print('lbl_path =', lbl_path)
        name = img_path.split(os.sep)[-1][:-4] + ".png"

        img = Image.open(img_path)
        img = np.array(img, dtype=np.uint8)

        lbl = Image.open(lbl_path)
        lbl = self.encode_segmap(np.array(lbl, dtype=np.uint8))

        if self.augmentations is not None:
            img, lbl = self.augmentations(img, lbl)

        if self.is_transform:
            img, lbl = self.transform(img, lbl)

        return img, lbl, name

I share it for reference. Perhaps my cityscapes data is out of date...