keras-video-generators icon indicating copy to clipboard operation
keras-video-generators copied to clipboard

How to get y_true from the generator?

Open GuilhermeCunha opened this issue 5 years ago • 2 comments

How to get y_true from the generator?

my_generator.classes return only the names of the classes, not the y_true.

GuilhermeCunha avatar Aug 20 '20 15:08 GuilhermeCunha

I have exactly the same question.. I am using this for regression on video based dataset. So i also want to have the y_true values for each frame of my video. How can i get that from the generator ??

SarfarazHabib avatar Aug 31 '20 08:08 SarfarazHabib

Hello, Not sure if this is the best way to do it but is working for me (at least until I find it doesn't). My x_gen var is the generator of my test split. BATCH_SIZE var is the batch size (obviously) that I used when creating the generator, as an argument.

#Get labels
y_test = []
for x in range(x_gen.__len__()):
    #position [1] for labels
    batch = x_gen.__getitem__(x)[1]
    for y in range(BATCH_SIZE):
        y_test.append(batch[y])
#Get labels indices
y_test = np.argmax(y_test, axis=1)

(if there is something wrong, please let me know hehe ) Hope it helps :)

pncanas333 avatar Sep 08 '20 15:09 pncanas333