PingoLH / FCHarDNet

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

How can I run inference on a sample of images? #50

Open bohare opened 3 years ago

bohare commented 3 years ago

Hello, thanks for your work.

I would like to use test.py to run inference on a folder of images without having to download entire Cityscapes dataset. Is it possible to do this?

Currently, when I try to do it, I get the following error:

Traceback (most recent call last):
  File "test.py", line 119, in <module>
    test(args)
  File "test.py", line 36, in test
    device, model, loader = init_model(args)
  File "test.py", line 16, in init_model
    data_loader = get_loader("icboard")
  File "/home/rbohare/FCHarDNet/ptsemseg/loader/__init__.py", line 27, in get_loader
    }[name]
KeyError: 'icboard'

Thanks for your help.

cao-nv commented 3 years ago

Just replace icboard by the keyword of the City Scape dataset, probably cityscape

jfhauris commented 3 years ago

@bohare Hi were you able to test using test.py? Can you please share your test.py command? I am trying the following but it is not working: python test.py --model_path '/home/arl/Documents/FCHARDNET/FCHarDNet-master/ptsemseg/models/hardnet.py' --dataset 'cityscapes' --input '/home/arl/Documents/FCHARDNET/FCHarDNet-master/test_image/index.jpeg' --output '/home/arl/Documents/FCHARDNET/FCHarDNet-master/test_image/index_output.jpeg'

I get the following error:

  File "test.py", line 122, in <module>
    test(args)
  File "test.py", line 39, in test
    device, model, loader = init_model(args)
  File "test.py", line 24, in init_model
    test_mode=True
  File "/home/arl/Documents/FCHARDNET/FCHarDNet-master/ptsemseg/loader/cityscapes_loader.py", line 82, in __init__
    self.images_base = os.path.join(self.root, "leftImg8bit", self.split)
  File "/home/arl/anaconda3/envs/rgbsemseg/lib/python3.6/posixpath.py", line 80, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType
cao-nv commented 3 years ago

@bohare Hi were you able to test using test.py? Can you please share your test.py command? I am trying the following but it is not working: python test.py --model_path '/home/arl/Documents/FCHARDNET/FCHarDNet-master/ptsemseg/models/hardnet.py' --dataset 'cityscapes' --input '/home/arl/Documents/FCHARDNET/FCHarDNet-master/test_image/index.jpeg' --output '/home/arl/Documents/FCHARDNET/FCHarDNet-master/test_image/index_output.jpeg'

I get the following error:

  File "test.py", line 122, in <module>
    test(args)
  File "test.py", line 39, in test
    device, model, loader = init_model(args)
  File "test.py", line 24, in init_model
    test_mode=True
  File "/home/arl/Documents/FCHARDNET/FCHarDNet-master/ptsemseg/loader/cityscapes_loader.py", line 82, in __init__
    self.images_base = os.path.join(self.root, "leftImg8bit", self.split)
  File "/home/arl/anaconda3/envs/rgbsemseg/lib/python3.6/posixpath.py", line 80, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType

The dataset is hardcoded by icboard in this line https://github.com/PingoLH/FCHarDNet/blob/fc4b854b5cfa01a449bcfaece6bb3c32d84d9e2b/test.py#L16 You must replace icboard with args.dataset. The list of available dataset names is in this file by available keys in https://github.com/PingoLH/FCHarDNet/blob/fc4b854b5cfa01a449bcfaece6bb3c32d84d9e2b/ptsemseg/loader/__init__.py#L18

bohare commented 3 years ago

@bohare Hi were you able to test using test.py? Can you please share your test.py command? I am trying the following but it is not working: python test.py --model_path '/home/arl/Documents/FCHARDNET/FCHarDNet-master/ptsemseg/models/hardnet.py' --dataset 'cityscapes' --input '/home/arl/Documents/FCHARDNET/FCHarDNet-master/test_image/index.jpeg' --output '/home/arl/Documents/FCHARDNET/FCHarDNet-master/test_image/index_output.jpeg' I get the following error:

  File "test.py", line 122, in <module>
    test(args)
  File "test.py", line 39, in test
    device, model, loader = init_model(args)
  File "test.py", line 24, in init_model
    test_mode=True
  File "/home/arl/Documents/FCHARDNET/FCHarDNet-master/ptsemseg/loader/cityscapes_loader.py", line 82, in __init__
    self.images_base = os.path.join(self.root, "leftImg8bit", self.split)
  File "/home/arl/anaconda3/envs/rgbsemseg/lib/python3.6/posixpath.py", line 80, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType

The dataset is hardcoded by icboard in this line

https://github.com/PingoLH/FCHarDNet/blob/fc4b854b5cfa01a449bcfaece6bb3c32d84d9e2b/test.py#L16

You must replace icboard with args.dataset. The list of available dataset names is in this file by available keys in

https://github.com/PingoLH/FCHarDNet/blob/fc4b854b5cfa01a449bcfaece6bb3c32d84d9e2b/ptsemseg/loader/__init__.py#L18

This is only part of the problem. The argument of [root] (https://github.com/PingoLH/FCHarDNet/blob/fc4b854b5cfa01a449bcfaece6bb3c32d84d9e2b/test.py#L18) needs to be changed to point to the Cityscapes directory since the DataLoader initializes its attributes using this variable. Having changed the argument value from None to the Cityscapes data directory combined with your suggestion, I was able to test the script.

jfhauris commented 3 years ago

@bohare @cao-nv Thanks for the reply. I am a little confused. You mentioned I need to point root to the Cityscapes data directory. So does FCHarDNet/test.py require the Cityscape data directory to operate even if I am testing/inferring on my own images? Also is there a specific Cityscape dataset that it requires? There are quite a few cityscapes dataset at their download site. And is a specific directory structure required? Thanks, Jon

cao-nv commented 3 years ago

@bohare @cao-nv Thanks for the reply. I am a little confused. You mentioned I need to point root to the Cityscapes data directory. So does FCHarDNet/test.py require the Cityscape data directory to operate even if I am testing/inferring on my own images? Also is there a specific Cityscape dataset that it requires? There are quite a few cityscapes dataset at their download site. And is a specific directory structure required? Thanks, Jon

Actually, the test code requires the dataset name to decode segmentation outputs to the proper color map. However, you still have to point to the folder of the specified dataset.