FCHarDNet icon indicating copy to clipboard operation
FCHarDNet copied to clipboard

How can I run inference on a sample of images?

Open bohare opened this issue 4 years ago • 6 comments

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.

bohare avatar Dec 08 '20 15:12 bohare

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

cao-nv avatar Dec 14 '20 02:12 cao-nv

@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

jfhauris avatar Apr 22 '21 17:04 jfhauris

@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

cao-nv avatar Apr 23 '21 02:04 cao-nv

@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.

bohare avatar Apr 23 '21 13:04 bohare

@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

jfhauris avatar Apr 23 '21 14:04 jfhauris

@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.

cao-nv avatar Apr 26 '21 04:04 cao-nv