Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all pixel values as 0 during hrnet-ocr inference in label folder and 255 in label_w_segfix with segfix #72

Open
gigasurgeon opened this issue Jul 13, 2021 · 6 comments

Comments

@gigasurgeon
Copy link

I have been trying to reproduce the results with pretrained weights using "bash scripts/cityscapes/hrnet/run_h_48_d_4_ocr.sh val".
Inside the vis folder that is generated, the outputs are fine. But inside the label folder, every pixel value is 0.

After trying segfix, label_w_segfix folder is generated. Every pixel for every image in that folder is 255. Help me out.

@gigasurgeon
Copy link
Author

gigasurgeon commented Jul 14, 2021

I have found the issue. In openseg.pytorch/segmentor/tester.py , at line number 193, we are saving the image by "ImageHelper.save(label_img_, label_path)". If saving the original label_img_ numpy array with cv2.imwrite(), the issue is resolved and the labels are correctly produced.

@ZSL98
Copy link

ZSL98 commented Nov 5, 2021

@thegigasurgeon Many thanks!

@Wang-Shuxuan
Copy link

@ZSL98 @thegigasurgeon Hello, I have met the same problem. I want to know how to change the code block, could you please tell me with more details?

@gigasurgeon
Copy link
Author

@Wang in the file openseg.pytorch/segmentor/tester.py, replace "ImageHelper.save(label_img_, label_path)" with "cv2.imwrite(label_path, label_img_) ".

@Wang-Shuxuan
Copy link

@Wang in the file openseg.pytorch/segmentor/tester.py, replace "ImageHelper.save(label_img_, label_path)" with "cv2.imwrite(label_path, label_img_) ".
I tried the method, but I met another issue as follows:
"
Traceback (most recent call last):
File "main.py", line 228, in
model.test()
File "/home/icra/extenddisk/openseg.pytorch-master/segmentor/tester.py", line 194, in test
cv2.imwrite(label_path, label_img_)
cv2.error: OpenCV(4.5.4-dev) 👎 error: (-5:Bad argument) in function 'imwrite'
Overload resolution failed:

  • img is not a numpy array, neither a scalar
  • Expected Ptrcv::UMat for argument 'img'

evaluate the result...
ERROR: Found no prediction for ground truth /home/icra/extenddisk/openseg.pytorch-master/DATA_ROOT/cityscapes/val/label/munster_000049_000019_leftImg8bit.png
"
In openseg.pytorch/segmentor/tester.py , at L189 “label_img_ = Image.fromarray(label_img_, 'P')”, the format of the label_img_ seems Image.Image, not array.

@gigasurgeon
Copy link
Author

@Wang in the file segmentor/tester.py near line no 189 to 193

               replace 

               "label_img_ = Image.fromarray(label_img_, 'P')
                Log.info('{:4d}/{:4d} label map generated'.format(image_id, self.test_size))
                label_path = os.path.join(self.save_dir, "label/", '{}.png'.format(names[k]))
                FileHelper.make_dirs(label_path, is_file=True)
                ImageHelper.save(label_img_, label_path)"

               with
                
              " alt_image = label_img_
                label_img_ = Image.fromarray(label_img_, 'P')
                Log.info('{:4d}/{:4d} label map generated'.format(image_id, self.test_size))
                label_path = os.path.join(self.save_dir, "label/", '{}.png'.format(names[k]))
                FileHelper.make_dirs(label_path, is_file=True)
                #ImageHelper.save(label_img_, label_path)
                cv2.imwrite(label_path, alt_image)"

For me, this fixed the problem. You can also try visualisizing the image array before these lines to see if the values are correct. For me, this had fixed the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants