JinchaoLove / NCDdetection_ICASSP2021

4 stars 0 forks source link

你好,你能提供训练的代码吗? #1

Closed Chenpuh closed 2 years ago

Chenpuh commented 2 years ago

你好,你能提供训练的代码吗?你只提供了预处理和模型的代码,我想知道模型的超参数和如何运行代码,你可以提供吗?

JinchaoLove commented 2 years ago

在test.py里面有fit_test或者cv_test函数,直接按默认的设置输入features (ComParE等)和labels就行了。

Chenpuh commented 2 years ago

你好,在构建模型时,下面的模型参数应该设置多少?

class Classifier():
    """ Classifier (Pytorch version). """

    def __init__(
            self,
            module,
            module_args,
            optimizer,
            opt_args,
            train_args=None,
    ):
JinchaoLove commented 2 years ago

你好,在构建模型时,下面的模型参数应该设置多少?

class Classifier():
    """ Classifier (Pytorch version). """

    def __init__(
            self,
            module,
            module_args,
            optimizer,
            opt_args,
            train_args=None,
    ):

module为选择的网络模型,对应module_args可以参考modules.py里的默认参数(可以留空);optimizer为Adam及其默认参数;train_args可以设置{'pca': False or True}。另外如果需要实现LDA、SVM等传统模型,可以参考models.py里的Baseline类。

Chenpuh commented 2 years ago

你好,我写了如下的代码,产生了一下错误。

    import pandas as pd
    import utils

    X_trn_csv = read_csv('feats/compare_par_trn.csv')
    X_trn = [t[4:] for t in X_trn_csv]
    X_trn = np.array(X_trn)
    X_tst_csv = read_csv('feats/compare_par_tst.csv')
    X_tst = [t[3:] for t in X_tst_csv]
    X_tst = np.array(X_tst)

    y_trn_cc_df = utils.get_regression_values("E:\\Code\\dataset\\ADReSS-IS2020-data\\train\\cc_meta_data.txt")
    y_trn_cc = np.array(y_trn_cc_df)
    y_trn_cd_df = utils.get_regression_values("E:\\Code\\dataset\\ADReSS-IS2020-data\\train\\cd_meta_data.txt")
    y_trn_cd = np.array(y_trn_cd_df)
    y_trn = np.concatenate((y_trn_cc, y_trn_cd), axis=0).astype(np.float32)
    y_tst = np.array(utils.get_regression_values("E:\\Code\\dataset\\ADReSS-IS2020-data\\test\\meta_data_modified.txt"))

    from modules import LSTMAttention

    module = LSTMAttention(6373, 6373, hidden_size=128, dropout=0, n_classes=2, )

    optimizer = torch.optim.Adam(module.parameters(), lr=0.001, betas=(0.9, 0.999), eps=1e-08, weight_decay=0,
                                 amsgrad=False)

    opt_args = {'lr': 0.001, 'betas': (0.9, 0.999), 'eps': 1e-08, 'weight_decay': 0, 'amsgrad': False}
    train_args = {'pca': False}
    module_args = {}

    # module_args = {}

    csf = Classifier(module, module_args, optimizer, opt_args, train_args=None)

    csf.fit_test(X_trn, y_trn, X_tst, y_tst, times=1, verbose=0, split=5, toarray=True)
D:\Anaconda3\envs\cognitive_detection\python.exe E:/Code/NCDdetection_ICASSP2021/test.py
2022-07-22 21:47:13.817502: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2022-07-22 21:47:13.817727: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "E:/Code/NCDdetection_ICASSP2021/test.py", line 331, in <module>
    csf.fit_test(X_trn, y_trn, X_tst, y_tst, times=1, verbose=0, split=5, toarray=True)
  File "E:/Code/NCDdetection_ICASSP2021/test.py", line 212, in fit_test
    self.fit(X_trn, y_trn, verbose=verbose, split=split)
  File "E:/Code/NCDdetection_ICASSP2021/test.py", line 127, in fit
    self.initialize()
  File "E:/Code/NCDdetection_ICASSP2021/test.py", line 103, in initialize
    self.get_model()
  File "E:/Code/NCDdetection_ICASSP2021/test.py", line 75, in get_model
    self.model = self.module(**self.module_args)
  File "D:\Anaconda3\envs\cognitive_detection\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
TypeError: forward() missing 1 required positional argument: 'X'

Process finished with exit code 1

我在module_args添加了一些参数,又出现了错误

    from modules import LSTMAttention

    module = LSTMAttention(6373, 6373, hidden_size=128, dropout=0, n_classes=2, )

    optimizer = torch.optim.Adam(module.parameters(), lr=0.001, betas=(0.9, 0.999), eps=1e-08, weight_decay=0,
                                 amsgrad=False)

    opt_args = {'lr': 0.001, 'betas': (0.9, 0.999), 'eps': 1e-08, 'weight_decay': 0, 'amsgrad': False}
    train_args = {'pca': False}
    module_args = {'input_dim1': 6373, 'input_dim2': 6373, 'hidden_size': 128, 'dropout': 0, 'n_classes': 2}

    # module_args = {}

    csf = Classifier(module, module_args, optimizer, opt_args, train_args=None)

    csf.fit_test(X_trn, y_trn, X_tst, y_tst, times=1, verbose=0, split=5, toarray=True)

错误如下:

D:\Anaconda3\envs\cognitive_detection\python.exe D:\PyCharm\plugins\python-ce\helpers\pydev\pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 2066 --file E:/Code/NCDdetection_ICASSP2021/test.py
Connected to pydev debugger (build 212.5457.59)
2022-07-22 21:39:29.825430: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2022-07-22 21:39:29.825729: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "D:\PyCharm\plugins\python-ce\helpers\pydev\pydevd.py", line 1483, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "D:\PyCharm\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "E:/Code/NCDdetection_ICASSP2021/test.py", line 332, in <module>
    csf.fit_test(X_trn, y_trn, X_tst, y_tst, times=1, verbose=0, split=5, toarray=True)
  File "E:/Code/NCDdetection_ICASSP2021/test.py", line 212, in fit_test
    self.fit(X_trn, y_trn, verbose=verbose, split=split)
  File "E:/Code/NCDdetection_ICASSP2021/test.py", line 127, in fit
    self.initialize()
  File "E:/Code/NCDdetection_ICASSP2021/test.py", line 103, in initialize
    self.get_model()
  File "E:/Code/NCDdetection_ICASSP2021/test.py", line 75, in get_model
    self.model = self.module(**self.module_args)
  File "D:\Anaconda3\envs\cognitive_detection\lib\site-packages\torch\nn\modules\module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'input_dim1'
python-BaseException

Process finished with exit code 1
JinchaoLove commented 2 years ago

LSTMAttention

这里LSTMAttention需要两个输入modules.py#L78-80,应该是我后面尝试多模态的时候稍微改了一下;你可以在这里test.py#L144改成输入两个相同的X。另外初上手建议先尝试BERT+SVM等。

Chenpuh commented 2 years ago

你好,又打扰你了。 1、此代码只是包含ad的分类,没有做mmse预测的回归任务是吧? 2、测试集的label怎么提取的呢?原始数据集没有包含测试集的标签。 3、你能上传main的代码和这些代码执行的步骤吗?我调试了好久,出现各种各样的报错。

JinchaoLove commented 2 years ago

你好,又打扰你了。 1、此代码只是包含ad的分类,没有做mmse预测的回归任务是吧? 2、测试集的label怎么提取的呢?原始数据集没有包含测试集的标签。 3、你能上传main的代码和这些代码执行的步骤吗?我调试了好久,出现各种各样的报错。

1、是的,只做了分类;2、测试集标签需要从ADReSS组织方获取;3、新更新了代码供参考。如果对你有帮助请cite :)

Chenpuh commented 2 years ago

ComParE的特征是从preprocessing.ipynbfeat_compare()在这个函数中提取的吧?

# ComParE
train_wavs = pd.read_csv('feats/train_compare_pittpar.csv')  # [5:] # pittpar
test_wavs = pd.read_csv('feats/test_compare_pittpar.csv')  # [3:] # full_wavs
def feat_compare(filePaths, csvName=None):
    smile = opensmile.Smile(
        feature_set=opensmile.FeatureSet.ComParE_2016,
        feature_level=opensmile.FeatureLevel.Functionals,
        # feature_level: Functionals, LowLevelDescriptors, LowLevelDescriptors_Deltas
    )
    df = pd.DataFrame()
    for fn in filePaths:
        data=smile.process_file(fn)
        print(data)
        df = df.append(smile.process_file(fn))
    if csvName is not None:
        df.to_csv(csvName, index=False)
    return df

Linguistic的特征不是从utils.py在中的函数中提取的吧?特征应该是个34维的向量(train_ling.append(train_cd_eval.iloc[i])[-34:])

# Linguistic
train_cc_eval = pd.read_csv(data_path+'/train/transcription/cc.eval.csv')
train_cd_eval = pd.read_csv(data_path+'/train/transcription/cd.eval.csv')
test_eval = pd.read_csv(data_path+'/test/test.eval.csv')
JinchaoLove commented 2 years ago

ComParE的特征是从preprocessing.ipynbfeat_compare()在这个函数中提取的吧?

# ComParE
train_wavs = pd.read_csv('feats/train_compare_pittpar.csv')  # [5:] # pittpar
test_wavs = pd.read_csv('feats/test_compare_pittpar.csv')  # [3:] # full_wavs
def feat_compare(filePaths, csvName=None):
    smile = opensmile.Smile(
        feature_set=opensmile.FeatureSet.ComParE_2016,
        feature_level=opensmile.FeatureLevel.Functionals,
        # feature_level: Functionals, LowLevelDescriptors, LowLevelDescriptors_Deltas
    )
    df = pd.DataFrame()
    for fn in filePaths:
        data=smile.process_file(fn)
        print(data)
        df = df.append(smile.process_file(fn))
    if csvName is not None:
        df.to_csv(csvName, index=False)
    return df

Linguistic的特征不是从utils.py在中的函数中提取的吧?特征应该是个34维的向量(train_ling.append(train_cd_eval.iloc[i])[-34:])

# Linguistic
train_cc_eval = pd.read_csv(data_path+'/train/transcription/cc.eval.csv')
train_cd_eval = pd.read_csv(data_path+'/train/transcription/cd.eval.csv')
test_eval = pd.read_csv(data_path+'/test/test.eval.csv')

是的。

Chenpuh commented 2 years ago

Linguistic特征应该用什么函数提取呢?

JinchaoLove commented 2 years ago

Linguistic特征应该用什么函数提取呢?

CLAN,Dementia Bank主页上有介绍。

Chenpuh commented 2 years ago

Linguistic特征应该用什么函数提取呢?

CLAN,Dementia Bank主页上有介绍。

好的,谢谢啦

Chenpuh commented 2 years ago

十分抱歉,又打扰了。test_pit_comps.csvxvec_pittpar_cc.npzxvec_pittpar_cd.npzxvec_pittpar_test.npz,你能提供生成这几个文件的代码吗?