0% found this document useful (0 votes)
10 views1 page

Custom Image Prediction Algorithm

The document outlines an algorithm for predicting classes from video frames using a trained CNN model. It details the input requirements, including a trained model and a video file, and describes the step-by-step process for extracting frames, making predictions, and visualizing results. The output includes class predictions and confidence scores for each frame extracted from the video.

Uploaded by

quillsbot
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Custom Image Prediction Algorithm

The document outlines an algorithm for predicting classes from video frames using a trained CNN model. It details the input requirements, including a trained model and a video file, and describes the step-by-step process for extracting frames, making predictions, and visualizing results. The output includes class predictions and confidence scores for each frame extracted from the video.

Uploaded by

quillsbot
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Algorithm: Custom Image Prediction from Video Using Trained CNN Model

Input:

- A trained deep learning model (e.g., MobileNetV2 .h5 file)

- A video file (e.g., .mp4)

- Desired frame extraction rate (frames per second)

Output:

- Class predictions (e.g., open, close, yawn, no_yawn) for each extracted image frame

- Visualization of predictions with confidence scores

Steps:

1. Start

2. Import necessary libraries (TensorFlow, OpenCV, Matplotlib, OS, etc.)

3. Extract frames from the video:

- Load the video using cv2.VideoCapture()

- Get the frame rate (FPS) of the video

- Calculate frame interval = FPS / desired output rate

- Loop through frames: save every frame_interval-th frame as an image in output folder

4. Create full file paths for extracted images

5. Load the trained model using tf.keras.models.load_model()

6. Define preprocessing pipeline: read, decode, normalize, resize, expand dimensions

7. Create TensorFlow Dataset for custom images and batch it

8. Make predictions using model.predict()

9. Convert predicted probabilities to class labels using np.argmax()

10. Visualize each image with its predicted label using matplotlib.pyplot

11. End

Example Output:

For frame_0012.jpg -> Prediction: Yawn (92%)

For frame_0045.jpg -> Prediction: Open (89%)

You might also like