semantic-segmentation-pytorch
semantic-segmentation-pytorch copied to clipboard
how to output the gray image without random.randint?
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!
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
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
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
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?
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