divamgupta / image-segmentation-keras

Implementation of Segnet, FCN, UNet , PSPNet and other models in Keras.
https://divamgupta.com/image-segmentation/2019/06/06/deep-learning-semantic-segmentation-keras.html
MIT License
2.92k stars 1.16k forks source link

preparing data - AssertionError #164

Closed sun-michael closed 4 years ago

sun-michael commented 4 years ago

I already have .png data for both image and annotation. When I run the main.py program there is a error.

Verifying training dataset "... .png violating range [0, 1]. Found maximum pixel value 255" File "....../image-segmentation-keras/keras_segmentation/train.py", line 105, in train assert verifed AssertionError

I have difficult time implementing "Preparing the data for training".

import cv2 import numpy as np ann_img = np.zeros((30,30,3)).astype('uint8') ann_img[ 3 , 4 ] = 1 # this would set the label of pixel 3,4 as 1 cv2.imwrite( "ann_1.png" ,ann_img )

Is there a way to open an exisiting .png(0-255 pixel range) file and convert it into (0-1pixel)? How do I open and save? from the git code above, I just need to have 255 changed into 1 like ann_img[255] = 1

rich-pel commented 4 years ago

You can use the threshold function from openCV https://docs.opencv.org/3.4/d7/d4d/tutorial_py_thresholding.html

ghost commented 4 years ago

Thanks rich-pel for the advice