VITA-Group / FasterSeg

[ICLR 2020] "FasterSeg: Searching for Faster Real-time Semantic Segmentation" by Wuyang Chen, Xinyu Gong, Xianming Liu, Qian Zhang, Yuan Li, Zhangyang Wang
MIT License
525 stars 107 forks source link

pretrained model to test 1 image #23

Closed kaishijeng closed 4 years ago

kaishijeng commented 4 years ago

Do you have a pretrained model and test code which can do inference on a single image?

Thanks,

chenwydj commented 4 years ago

Hi @kaishijeng ! Thank you for your interest in our work!

Please follow the instructions in our Readme for pretrained models and making predictions.

kaishijeng commented 4 years ago

I have downloaded teacher and student models and put them under fasterseg directory. Also modify C.is_test = True. When I run python train.py, I got the following errors:

Traceback (most recent call last): File "train.py", line 32, in from model_seg import Network_Multi_Path_Infer as Network File "/home/amd/USB/FasterSeg/train/model_seg.py", line 5, in from operations import * File "/home/amd/USB/FasterSeg/train/operations.py", line 36, in latency_lookup_table = np.load(table_file_name).item() File "/home/amd/anaconda3/envs/dl/lib/python3.7/site-packages/numpy/lib/npyio.py", line 453, in load pickle_kwargs=pickle_kwargs) File "/home/amd/anaconda3/envs/dl/lib/python3.7/site-packages/numpy/lib/format.py", line 739, in read_array raise ValueError("Object arrays cannot be loaded when " ValueError: Object arrays cannot be loaded when allow_pickle=False

Any idea why this error happens? Also how I can provide my own test image when I can run python train.py?

Thanks,

chenwydj commented 4 years ago

Have you googled this error?

I met this error before, and I am pretty sure you can find answer on google.

chenwydj commented 4 years ago

Sorry I missed your second question.

Basically you could do a similar preparation for the Cityscapes to your images: prepare the file list and update the configure files.

You don't need to prepare the labels.

Please do read our instructions on evaluation and test to get yourself familiar with the code usage. :)

kaishijeng commented 4 years ago

OK, I follow changes in the README and am able to run it. But it encounters erros below until it starts to do training. What changes I need to do to avoid the training when I run python train.py? I just want to do an inference on a single image with this pretrained model, arch_1.pt

data = fetcher.fetch(index)

File "/home/henry/miniconda3/envs/remnav/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/henry/miniconda3/envs/remnav/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/henry/4TB/FasterSeg/tools/datasets/BaseDataset.py", line 35, in getitem names = self._construct_new_file_names(self._file_length)[index] File "/home/henry/4TB/FasterSeg/tools/datasets/BaseDataset.py", line 101, in _construct_new_file_names new_file_names = self._file_names * (length // files_len) ZeroDivisionError: integer division or modulo by zero

Thanks,

chenwydj commented 4 years ago

See here: https://github.com/TAMU-VITA/FasterSeg/blob/master/train/train.py#L160

Turn both is_eval and is_test to be True in the configuration, then you can simply do the inference without training.

kaishijeng commented 4 years ago

Yes, I found that out and it can run without a training. Thanks. Since there is no GT for inference, I use the same image in cityscapes_test.txt as below: test_images/test.png test_images/test.png

However, I have the following error with test.png which is 1280x720 whin I run it: . Traceback (most recent call last): File "./train.py", line 297, in main() File "./train.py", line 166, in main test(0, models, testers, logger) File "./train.py", line 292, in test tester.run_online() File "/home/henry/4TB/FasterSeg/tools/engine/tester.py", line 106, in run_online self.single_process_evaluation() File "/home/henry/4TB/FasterSeg/tools/engine/tester.py", line 113, in single_process_evaluation self.func_per_iteration(dd, self.devices[0], iter=idx) File "/home/henry/4TB/FasterSeg/train/test.py", line 56, in func_per_iteration pred = self.whole_eval(img, None, device) File "/home/henry/4TB/FasterSeg/tools/engine/tester.py", line 186, in whole_eval pred = self.val_func_process(img, device) File "/home/henry/4TB/FasterSeg/tools/engine/tester.py", line 279, in val_func_process score = self.val_func(input_data) File "/home/henry/miniconda3/envs/remnav/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in call result = self.forward(*input, **kwargs) File "/home/henry/4TB/FasterSeg/train/model_seg.py", line 361, in forward pred8 = self.agg_ffm(outputs8, outputs16, outputs32) File "/home/henry/4TB/FasterSeg/train/model_seg.py", line 306, in agg_ffm out = self.refines32[0](torch.cat([out, outputs16[branch]], dim=1)) RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 67 and 66 in dimension 2 at /opt/conda/conda-bld/pytorch_1579022034529/work/aten/src/THC/generic/THCTensorMath.cu:71

chenwydj commented 4 years ago

I see. The problem is because 720/64=11.25 not being an integer, as our network will downsample the input to 1/64 scale at the extreme (zoomed conv will downsample 1/32 to 1/64 during the feed-forward).

The most straightforward way to get the inference work is to make both the height and width to be divisible to 64, for example, by either upsampling your input to 1280x768 or downsampling to 1280x704. A small change to the aspect ratio should not be a problem.

kaishijeng commented 4 years ago

Now it works. Is test output a gray image instead of color? I saw one below which is a gray image: eval-512x1024_student_batch12-20200312-223648/test_1_0/test.png

Thanks,

chenwydj commented 4 years ago

No -- it is a prediction file which contains integers from 0~18 representing semantic classes.

You could set show_prediction = True when creating the tester for visualization purpose.

kaishijeng commented 4 years ago

I set it, but nothing shows up. It seems show_prediction flag is not used in tester.py Thanks,

chenwydj commented 4 years ago

No, the SegTester does use the show_prediction flag. I used this code to make the gif shown in the Readme.

Please check if there is any png file ends with ".viz.png".

kaishijeng commented 4 years ago

Yes, I found color image in .viz.png. Thanks for all helps.