0

So I'm using Keras generator to get data augmented for image segmentation

I have a specific mask which each set of pixel represent a region of my masks, so I must have a range of pixel that contains 11 classes (0 and 255 and 191).

The problem with Keras generator that he is changing the range of pixel.

so I want to detect images that pixel intensity are not equal to my specific classes (pixel range) (255,56,...) and try to delete them from my dataset but im always getting errors.

Y_train : numpy array that contains all the masks

Y_train  = array([[[[0, 0, 0],
         [0, 0, 0],
         [0, 0, 0],
         ...,
         [0, 0, 0],
         [0, 0, 0],
         [0, 0, 0]],

        [[0, 0, 0],
         [0, 0, 0],
         [0, 0, 0],
         ...,
         [0, 0, 0],
         [0, 0, 0],
         [0, 0, 0]],  
         [[0, 0, 0],
         [0, 0, 0],
         [0, 0, 0],
           ...,
         [0, 0, 0],
         [0, 0, 0],
         [0, 0, 0]]]], dtype=uint8)

I tried this 1st attempt :

for i in range(len(Y_train)):
    if Y_train[i] != 255 and Y_train[i] !=56 and Y_train[i] !=137 and Y_train[i] !=26 : 
          print ('index',i)

Second one :

for i in range (len(Y_train)):
   if Y_train[i][Y_train[i] != (0 and 255 and 56 and 137 and 26  and 87 and 112 and 191 and 212 and 164 and 229 and 244  )]  :
       print('index 0',i)

Third one :

for i in range(len(Y_train)):
    if (Y_train[I] != 255 and Y_train[i] !=56 and Y_train[i] !=137)).all() : print('index 0',i)

PS : Sorry for my English

2
  • if and and only work with scalar True/False values. Your Y_train tests are boolean arrays - check them yourself. Commented Apr 10, 2020 at 5:09
  • @hpaulj True, what do you mean by check them by myself ? Commented Apr 10, 2020 at 11:57

2 Answers 2

1

I think first of all you must change the "and" with "or"; then, are you sure y_train[i] returns an integer value? please double check the type of y_train[i] or y_train itself and try to search its elements

Sign up to request clarification or add additional context in comments.

6 Comments

I tried or and also does not work, and for the type of Y_train uint8 that contains original mask fixed pixel of 12 class the value are ( 0,255,164) for the augmented data I don't know.
i want to keep only mask that contains the 12 classes PS : thanks :)
can you try to parse y_train with "print(y_train)" and paste the output here please?
It's so normal that not working then, because y_train[i] is not returns a integer value but still bunch of lists and array. You must check for the elements
so how can I solve it ? for each array in the Y_train
|
0

Your Y_train array looks like and rgb matrices list. ie Y_train has 4 dimensions. when you index Y_train[i] you get and 3 dimension matrix, if you compare this with a escalar number like 255, then you get the same 3 dimension matrix with True or False (True where there was an 255 and False otherwise), therefore to compare this boolean matrices you need to use any() or all().

Therefore you should rethink your code, because this way does not seem efficient

2 Comments

Thanks that's true, the shape of Y_train is (nbr_of_sample,H,W,Channel) ,I did not find a lot of documentation about it
I don't understand what do you want. Where do you need the pixels (classes) are be? using (nbr_of_sample,H,W,Channel) notation. Maybe I can help you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.