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

how to output the gray image without random.randint? #18

Open
zhou-rui1 opened this issue Feb 6, 2021 · 5 comments
Open

how to output the gray image without random.randint? #18

zhou-rui1 opened this issue Feb 6, 2021 · 5 comments

Comments

@zhou-rui1
Copy link

Hi, I want to output the gray image for the binary classfication, how should I edit it?

I try to edit this part but failed:
`random.seed(0)
class_colors = [(random.randint(0, 255), random.randint(
0, 255), random.randint(0, 255)) for _ in range(5000)]

def convert_seg_gray_to_color(input, n_classes, output_path=None, colors=class_colors):
if isinstance(input, six.string_types):
seg = cv2.imread(input, flags=cv2.IMREAD_GRAYSCALE)
elif type(input) is np.ndarray:
assert len(input.shape) == 2, "Input should be h,w "
seg = input

height = seg.shape[0]
width = seg.shape[1]

seg_img = np.zeros((height, width, 3))

for c in range(n_classes):
	seg_arr = seg[:, :] == c
	seg_img[:, :, 0] += ((seg_arr) * colors[c][0]).astype('uint8')
	seg_img[:, :, 1] += ((seg_arr) * colors[c][1]).astype('uint8')
	seg_img[:, :, 2] += ((seg_arr) * colors[c][2]).astype('uint8')

if output_path:
	cv2.imwrite(output_path, seg_img)
else:
	return seg_img`

Can you give me some guidance?
Thanks!

@IanTaehoonYoo
Copy link
Owner

IanTaehoonYoo commented Feb 9, 2021

Hi rui,

You can try to change one code line like as bellow.

predict method in predict.py

seg_img = convert_seg_gray_to_color(lbl_pred, n_classes, colors=colors)

to

seg_img = lbl_pred

Thanks

@zhou-rui1
Copy link
Author

zhou-rui1 commented Feb 12, 2021

Thanks for your guidance!

Did you split the train and test manual in advance, or can it implement
train_img_ids, val_img_ids = train_test_split(img_ids, test_size=0.2, random_state=41) function like this ?

With regards
rui

@zhou-rui1
Copy link
Author

Hi, when I input different size of images it feedback an inconsistent tensor,

also I am still looking in split the dataset automatically...is there any way?

Best regards,
rui

@zhou-rui1
Copy link
Author

Hi, I am wondering why for binary segmentation, I have to set the n_classes as 256 to train, other than 2, is this according to the pixel values?

@zhou-rui1
Copy link
Author

I think it may need to add a pixel value normalization process likeimg = img.astype('float32') / 255,

but where should I put it...could you give me more guidance ?

With great appreciation

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

2 participants