keras-video-generators
keras-video-generators copied to clipboard
Predict the trained model
How can I use the videoframe generator to create a test dataset? I see you have done it in your blog, but without the code. could you please upload that part of code? Thanks.
There is a get_test_generator()
which returns a test generator. You need to use split_test
argument in constructor call to give the proportion of test data, it works like split_val
and get_validation_generator()
See code here: https://github.com/metal3d/keras-video-generators/blob/master/src/keras_video/generator.py#L278
e.g.:
# get 20% of data for test
gen = VideoFrameGenerator(glob_pattern='data/{classname}', split_test=.2)
test_gen = gen.get_test_generator()
Hey,@metal3d Above answer was really helpful, I saw your blog on https://medium.com/smileinnovation/training-neural-network-with-image-sequence-an-example-with-video-as-input-c3407f7a0b0f. It was showing test accuracy along with images. Can you please guide how did you get them?
The test accuracy is made by using split_test
parameter to get a testing validator. Then I only get one batch from the testing generator and send it to model.predict
method.
I will create a notebook with example for training and evaluation. I'm only a bit busy for a couple of days, sorry for that.
@metal3d I have implemented your mobile net model with SlidingVideoGenerator. How can I test predictions on the frames of my own video outside of the dataset on an individual set of frames like frame (1-5), frame (2-6), ... and so on to see what model predicts the particular instance of the video? I would be grateful if you could help me with this.
Hi! I've been using your generator and a modified version of your model and its been working amazingly well. I wanted to ask if the evaluation/test notebook is available yet. Something like the code you used to check your model in your blog would be extremely helpful. Or being able to get a prediction on individual video inputs.
@Rehan-Rehman-Punjwani Sorry for the delay, I'm very busy for a while. To make prediction, you need to build your batches and send them to the model. That's not covered by this repository, it's a common task with OpenCV and Keras. If I found some time, maybe I will make an article about that
@BANANAPEEL202 I will make a simple Notebook to show the usage of training / test, you're right, it's missing
@metal3d. Thank you so much!
@metal3d Thank you for a fantastic notebook, great explanation, and detailed work!
Since you are super busy and did not have a chance (understandably) to create the notebook, I was wondering how to get the y_true_class
value from the validation dataset out of your get_validation_generator
?
Here is a snippet of your good work
train = VideoFrameGenerator(
classes=classes,
glob_pattern=glob_pattern,
split=.2
)
valid= train.get_validation_generator()
y_pred = model.predict(valid)
y_predicted_class = np.argmax(y_pred, axis=1)
# how to get the `y_true `below ?
y_true_class = np.argmax(y_true, axis=1)
How can we get the y_true
values in the last line above in order to predict the accuracy? where y_true
is the actual label of the validation data.
for example to use in:
classification_report(y_true_class , y_predicted_class )
Thank you again! :)
@BANANAPEEL202
Does this work for you?
gen = VideoFrameGenerator(glob_pattern='data/{classname}', split_test=.2)
test_gen = gen.get_test_generator()
results = model.evaluate(test_gen , verbose=2)
print("The Accuracy score on the Train set is:\t{:0.3f}".format(results[1]))
@LS4203 It does. Thanks!
How to use generator for test data when test data is situated in different directory?
There is a
get_test_generator()
which returns a test generator. You need to usesplit_test
argument in constructor call to give the proportion of test data, it works likesplit_val
andget_validation_generator()
See code here: https://github.com/metal3d/keras-video-generators/blob/master/src/keras_video/generator.py#L278
e.g.:
# get 20% of data for test gen = VideoFrameGenerator(glob_pattern='data/{classname}', split_test=.2) test_gen = gen.get_test_generator()
I get this weird issue:
"local variable 'nbtrain' referenced before assignment"
I will add Codacy check and change the test system. I'm very busy for a while, sorry to not help a lot for now
The problem is here: https://github.com/metal3d/keras-video-generators/blob/master/src/keras_video/generator.py#L169
I will fix this as soon as I can.
@metal3d I have trained the model using VideoFrameGenerator, and now want this model to predict in realtime, how can I do that?
@rohannaik-3 the prediction is not convered by my package. The package is only a generator to train a model. If I'm not wrong, when you do image recognition, you don't use Image generator from keras package, it's the same for video generator :)
Everything depends on how you capture videos (from file, from webcam, from stream)