Views
No views yet
TIME_STEPS frames, each resized to 299x299 pixels.256 units learns temporal dependencies between these extracted frame features.0.5 rate) prevents overfitting.softmax activation predicts probabilities for "Real" and "Fake" classes.| Metric | Value |
|---|---|
| Training Accuracy | 98.44% |
| Validation Accuracy | 97.05% |
| Test Accuracy | 95.93% |
pip install tensorflow opencv-python numpy mtcnn PillowCOMBINED_best_Phase1.keras. Ensure this file is accessible at the specified model_path.1model_path = ''
2model = build_model() # Architecture defined in the `build_model` function
3model.load_weights(model_path)build_model function defines the architecture as:1import tensorflow as tf
2from tensorflow import keras
3from tensorflow.keras import layers
4
5# Global parameters for model input shape (ensure these are defined before calling build_model)
6# TIME_STEPS = 30
7# HEIGHT = 299
8# WIDTH = 299
9
10def build_model(lstm_hidden_size=256, num_classes=2, dropout_rate=0.5):
11 # Input shape: (batch_size, TIME_STEPS, HEIGHT, WIDTH, 3)
12 inputs = layers.Input(shape=(TIME_STEPS, HEIGHT, WIDTH, 3))
13 # TimeDistributed layer to apply the base model to each frame
14 base_model = keras.applications.Xception(weights='imagenet', include_top=False, pooling='avg')
15 # For inference, we don't need to set trainable, but if you plan to retrain, you can set accordingly
16 # base_model.trainable = False
17 # Apply TimeDistributed wrapper
18 x = layers.TimeDistributed(base_model)(inputs)
19 # x shape: (batch_size, TIME_STEPS, 2048)
20 # LSTM layer
21 x = layers.LSTM(lstm_hidden_size)(x)
22 x = layers.Dropout(dropout_rate)(x)
23 outputs = layers.Dense(num_classes, activation='softmax')(x)
24 model = keras.Model(inputs, outputs)
25 return modelvideo_array (preprocessed frames) is ready, you can make a prediction using the loaded model:1predictions = model.predict(video_array)
2predicted_class = np.argmax(predictions, axis=1)[0]
3probabilities = predictions[0]
4
5class_names = ['Real', 'Fake']
6print(f"Predicted Class: {class_names[predicted_class]}")
7print(f"Class Probabilities: Real: {probabilities[0]:.4f}, Fake: {probabilities[1]:.4f}")