Reputation: 151
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
Upvotes: 0
Views: 193
Reputation: 713
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
Upvotes: 0
Reputation: 33
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
Upvotes: 1