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

Some question about data_gen #7

Open
cpystan opened this issue Mar 17, 2021 · 0 comments
Open

Some question about data_gen #7

cpystan opened this issue Mar 17, 2021 · 0 comments

Comments

@cpystan
Copy link

cpystan commented Mar 17, 2021

You have done great job! But i am confused about some code.

`def data_loader(path, batch_size, imSize,
mean=[0.5,0.5,0.5], std=[0.5,0.5,0.5],
ignore_val=44, pos_val=255, neg_val=155, pos_class=[0,1], neg_class=[2]):
# pos_class and neg_class in the folder name for keras ImageDataGenerator input
# 0,1,2 are low, high, normal

def imerge(img_gen, mask_gen):
    for (imgs, img_labels), (mask, mask_labels) in itertools.zip_longest(img_gen, mask_gen):
        # compute weight to ignore particular pixels
        # mask = np.expand_dims(mask[:,:,:,0], axis=3)
        mask = mask[:,:,:,0]
        weight = np.ones(mask.shape, np.float32)
        weight[mask==ignore_val] = 0.5 # this is set by experience

        # In mask, ignored pixel has value ignore_val.
        # The weight of these pixel is set to zero, so they do not contribute to loss
        # The returned mask is still binary.
        # compute per sample
        for c, mask_label in enumerate(mask_labels):
            assert(mask_labels[c] == img_labels[c])
            mask_pointer = mask[c]
            if mask_label in pos_class:
                assert(np.where(mask_pointer == neg_val)[0].size == 0)
                mask_pointer[mask_pointer==pos_val] = 1
            elif mask_label in neg_class:
                assert(np.where(mask_pointer == pos_val)[0].size == 0)
                mask_pointer[mask_pointer==neg_val] = 0
            else:
                print ('WARNING: mask beyond the expected class range')
                mask_pointer /= 255.0

            mask_pointer[mask_pointer==ignore_val] = 0

        assert set(np.unique(mask)).issubset([0, 1])
        # assert set(np.unique(weight)).issubset([0, 1])

        # img, mask = preprocess(imgs, mean, std, mask)

        yield imgs, mask, weight, img_labels

`

code above in segmentation/data_gen.py. what is the aim to calculate 'mask_pointer'? it seems that it is not returned finally?
And 'assert set(np.unique(mask)).issubset([0, 1])' is apparently cannot be satisfied since the pixels in mask only belong to [44 255 155].

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

1 participant