Commit 6c80a527 authored by David Maxence's avatar David Maxence
Browse files


parent dbd81a25
# Created from: slurm submission script, serial job
# Max time the script will run (here 3 hours)
#SBATCH --time 03:00:00
# RAM to use (Mo)
#SBATCH --mem 10000
# Number of cpu core to use
#SBATCH --cpus-per-task=10
# Enable the mailing for the start of the experiments
#SBATCH --mail-type ALL
#SBATCH --mail-user
# Which partition to use
#SBATCH --partition insa
# Number of gpu(s) to use
#SBATCH --gres gpu:1
# Number of nodes to use
#SBATCH --nodes 1
# Log files (%J is a variable for the job id)
#SBATCH --output %J.out
#SBATCH --error %J.err
#Loading the module
module load python3-DL/3.8.5
# Creating a directory to save the training weights
mkdir callbacks
# Define the repository where the trained weights will be stored
# This variable is used in the script
# export LOCAL_WORK_DIR=checkpoints
# Start the calculation
srun python3
\ No newline at end of file
import numpy as np
import os
import pandas as pd
from import wavfile
import librosa
from tqdm import tqdm
import tensorflow as tf
from tensorflow import keras
import matplotlib.pyplot as plt
from tensorflow.keras import regularizers, activations
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Flatten, Activation, Conv2D, MaxPooling2D, GlobalAveragePooling2D
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from datetime import datetime
from matplotlib import pyplot as plt
from sklearn.model_selection import train_test_split
def loading_data() :
us8k_df = pd.read_pickle("us8k_augmented_df.pkl")
df = us8k_df.drop(['fold'],axis=1)
X = np.stack(df.melspectrogram.to_numpy())
X_dim = (128,128,1)
X = X.reshape(X.shape[0], *X_dim)
Y = np.array(df['label'])
Y = to_categorical(Y)
X_train, X_test, Y_train, Y_test = train_test_split(X,Y,test_size=0.2,shuffle=True,stratify = Y)
X_val, X_test, Y_val,Y_test = train_test_split(X_test,Y_test,test_size=0.5,shuffle=True,stratify = Y_test)
return X_train,Y_train,X_val,Y_val,X_test,Y_test
def init_model():
model1 = Sequential()
model1.add(Conv2D(filters=24, kernel_size=5, input_shape=(128, 128, 1),
model1.add(MaxPooling2D(pool_size=(3,3), strides=3))
model1.add(Conv2D(filters=36, kernel_size=4, padding='valid', kernel_regularizer=regularizers.l2(1e-3)))
model1.add(MaxPooling2D(pool_size=(2,2), strides=2))
model1.add(Conv2D(filters=48, kernel_size=3, padding='valid'))
#layer-4 (1st dense layer)
model1.add(Dense(60, activation='relu'))
#layer-5 (2nd dense layer)
model1.add(Dense(10, activation='softmax'))
# compile
model1.compile(loss='categorical_crossentropy', metrics=['accuracy'], optimizer='adam')
return model1
if __name__ == "__main__":
X_train,Y_train,X_val,Y_val,X_test,Y_test = loading_data()
model = init_model()
log_dir = "logs/fit/" +"%Y%m%d-%H%M%S")
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir = log_dir, histogram_freq = 1)
save_best = tf.keras.callbacks.ModelCheckpoint(filepath = "logs/checkpoints/", save_weights_only = True,
monitor = "val_accuracy", mode = "max", save_best_only = True)
initial_epochs = 100
num_batch_size = 32
model_fit =,Y_train, epochs=initial_epochs,validation_data=(X_val,Y_val),
batch_size=num_batch_size, callbacks = [tensorboard_callback, save_best])'logs/soundClass_augmented_model.h5')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment