qu penser vosu de ce code entrainemt de dat set python Copier import os import numpy as…
- User
qu penser vosu de ce code entrainemt de dat set python
Copier import os import numpy as np import tensorflow as tf from tensorflow.keras.models import Sequential from tensorflow.keras.layers import LSTM, Dense, Dropout from tensorflow.keras.optimizers import Adam from sklearn.model_selection import train_test_split from emotional_deepfake_detector import preprocess_audio
def load_dataset(dataset_path): """ Charge et prétraite les fichiers audio d'un dataset """ X = [] y = [] try: for label in ['real', 'fake']: label_path = os.path.join(dataset_path, label) if not os.path.exists(label_path): print(f"Warning: Path {label_path} does not exist") continue
codefor audio_file in os.listdir(label_path): if audio_file.endswith(('.wav', '.mp3')): # Vérifier les extensions audio audio_path = os.path.join(label_path, audio_file) try: features = preprocess_audio(audio_path) if features is not None and len(features) > 0: X.append(features) y.append(1 if label == 'fake' else 0) except Exception as e: print(f"Error processing {audio_path}: {str(e)}") if not X: raise ValueError(f"No valid audio files found in {dataset_path}") return np.array(X), np.array(y) except Exception as e: print(f"Error loading dataset from {dataset_path}: {str(e)}") return None, Nonedef create_model(input_shape): """ Crée le modèle LSTM pour la détection de deepfake """ model = Sequential([ LSTM(128, input_shape=input_shape, return_sequences=True), Dropout(0.3), LSTM(64, return_sequences=True), Dropout(0.3), LSTM(32), Dropout(0.3), Dense(32, activation='relu'), Dropout(0.2), Dense(16, activation='relu'), Dense(1, activation='sigmoid') ])
codemodel.compile( optimizer=Adam(learning_rate=0.001), loss='binary_crossentropy', metrics=['accuracy', tf.keras.metrics.Precision(), tf.keras.metrics.Recall()] ) return model - Assistant