Python 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 7.29.0 -- An enhanced Interactive Python.
In [1]:
...: """
...: Purpose: to predict CEO depression scores using the tranined model.
...: This code needs to be run on a supercomputer. This log is based on a subsample.
...: """
...:
...:
...: '''
...: !pip install tensorflow-io==0.23.1
...: !pip install -q "tensorflow==2.11.*"
...: !pip install -q "tensorflow_io==0.28.*"
...:
...: !pip install tensorflow_hub
...: !pip install tensorflow_io
...: '''
...:
...: ### run through daicwoz_nosilence_segment and save the embeddings and spectrograms
...: import librosa
...: import os
...: import pandas as pd
...: import numpy as np
...:
...:
...: import numpy as np
...: import csv
...: import matplotlib.pyplot as plt
...: from skimage.transform import resize
...:
...: import matplotlib.pyplot as plt
...: from IPython.display import Audio
...: from scipy.io import wavfile
...:
...:
...: import os
...:
...: from IPython import display
...: import matplotlib.pyplot as plt
...: import numpy as np
...: import pandas as pd
...:
...: import tensorflow as tf
...: import tensorflow_hub as hub
...: import tensorflow_io as tfio
...:
...:
...: import datetime as dt
...:
...: import pickle
...:
...:
...: import scipy
...:
...: def ensure_sample_rate(original_sample_rate, waveform,
...: desired_sample_rate=16000):
...: """Resample waveform if required."""
...: if original_sample_rate != desired_sample_rate:
...: desired_length = int(round(float(len(waveform)) /
...: original_sample_rate * desired_sample_rate))
...: waveform = scipy.signal.resample(waveform, desired_length)
...: return desired_sample_rate, waveform
...:
...: yamnet_model_handle = 'https://tfhub.dev/google/yamnet/1'
...: yamnet_model = hub.load(yamnet_model_handle)
...:
...:
...: error_li=[]
...:
...:
...: import pickle
...: emb_folder_path=r'C:\Users\marks\Dropbox\JAR Registered Report\Final_version_submisison\data\ceo_audio_seg_embeddings'
...:
...: os.chdir(emb_folder_path)
...:
...: scaler_path=r'C:\Users\marks\Dropbox\JAR Registered Report\Final_version_submisison\data\trained_models\trained_models\scaler_svc_1_20230324.pickle'
...:
...:
...: scaler=pickle.load(open(scaler_path,'rb'))
...:
...: model_path=r'C:\Users\marks\Dropbox\JAR Registered Report\Final_version_submisison\data\trained_models\trained_models\yamnet_svr_1.pickle'
...:
...: y_pred1_path_base=r'C:\Users\marks\Dropbox\JAR Registered Report\Final_version_submisison\data\depression_pred'
...:
...:
...: date_time = dt.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
...:
...:
...:
...: df_name='y_pred1.csv'
...:
...: df_name=df_name[:-4]+'_'+date_time+'.csv'
...: print(df_name)
...:
...:
...: classifier=pickle.load(open(model_path,'rb'))
...:
...:
...:
...:
...:
...:
...:
...: df=pd.DataFrame(os.listdir(emb_folder_path))
...:
...: def make_full_path(row,embfolder=emb_folder_path):
...: return os.path.join(embfolder,row[0])
...:
...: df['full_path'] = df.apply(make_full_path, axis=1)
...:
...:
...: data=df.copy()
...:
...:
...: X = np.array([np.load(full_path) for full_path in data['full_path']])
...:
...:
...: size = X.shape[0]
...: shape1=X.shape[1]
...: shape2=X.shape[2]
...:
...:
...: X_reshaped = X.reshape(size, shape1*shape2)
...:
...:
...: X_reshaped=scaler.transform(X_reshaped)
...:
...: X_reshaped = pd.DataFrame(X_reshaped).fillna(0).replace([np.inf, -np.inf], 0).values
...: y_pred1=classifier.predict(X_reshaped)
...:
...:
...: s = pd.Series(y_pred1)
...:
...:
...: data_with_y_pred1 = pd.concat([data, s], axis=1)
...:
...:
...:
...: data_with_y_pred1 = data_with_y_pred1.rename(columns={0: 'y_pred1'})
...:
...:
...:
...:
...: y_pred1_path=os.path.join(y_pred1_path_base,df_name)
...:
...:
...: data_with_y_pred1.columns.values[0] = 'full_name'
...: data_with_y_pred1.columns.values[2] = 'y_pred1'
...:
...: data_with_y_pred1.to_csv(y_pred1_path,index=False)
...:
...: for i, row in data_with_y_pred1.iterrows():
...: full_name=row['full_name']
...: #print(full_name)
...: ceo=full_name.split('.wav')[0]
...: #print(ceo)
...: data_with_y_pred1.loc[i,'ceo']=ceo
...:
...:
...:
...: means = data_with_y_pred1.groupby('ceo')[['y_pred1']].mean()
...:
...:
...: means.reset_index(inplace=True)
...:
...:
...:
...: medians = data_with_y_pred1.groupby('ceo')[['y_pred1']].median()
...:
...: medians.reset_index(inplace=True)
...:
...: df_name_means=df_name[:-4]+'_'+'means.csv'
...: df_name_meds=df_name[:-4]+'_'+'meds.csv'
...:
...: means.to_csv(os.path.join(y_pred1_path_base,df_name_means))
...:
...: medians.to_csv(os.path.join(y_pred1_path_base,df_name_meds))
2024-12-20 04:59:06.172230: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
y_pred1_2024-12-20-04-59-09.csv
In [2]: