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

Predict the trained model #22

Open
pengweiguo123 opened this issue Mar 20, 2020 · 16 comments
Open

Predict the trained model #22

pengweiguo123 opened this issue Mar 20, 2020 · 16 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@pengweiguo123
Copy link

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.

@metal3d
Copy link
Owner

metal3d commented Mar 20, 2020

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()

@metal3d metal3d added documentation Improvements or additions to documentation not a bug That's not a bug, maybe documentation needed labels Mar 20, 2020
@rehanpunjwani
Copy link

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?

@metal3d
Copy link
Owner

metal3d commented Mar 24, 2020

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.

@rehanpunjwani
Copy link

@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.

@BANANAPEEL202
Copy link

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.

@metal3d
Copy link
Owner

metal3d commented Jul 22, 2020

@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

@BANANAPEEL202
Copy link

@metal3d. Thank you so much!

@LS4203
Copy link

LS4203 commented Nov 9, 2020

@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! :)

@LS4203
Copy link

LS4203 commented Nov 9, 2020

@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]))

@BANANAPEEL202
Copy link

@LS4203 It does. Thanks!

@shreyanshbehani
Copy link

How to use generator for test data when test data is situated in different directory?

@FinAminToastCrunch
Copy link

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()

I get this weird issue:

"local variable 'nbtrain' referenced before assignment"

@metal3d
Copy link
Owner

metal3d commented Mar 3, 2021

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

@metal3d
Copy link
Owner

metal3d commented Mar 5, 2021

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 metal3d added bug Something isn't working and removed not a bug That's not a bug, maybe documentation needed labels Mar 5, 2021
@rohannaik-3
Copy link

@metal3d I have trained the model using VideoFrameGenerator, and now want this model to predict in realtime, how can I do that?

@metal3d
Copy link
Owner

metal3d commented Jul 7, 2021

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

8 participants