Read 1 csv file data code, it works well
the coding as follows:
import csv import pandas as pd import numpy as np import torch data = [] fname = 'C:/Users/faustineljc/Desktop/dia0_utt0.csv' with open(fname,'r+',encoding='utf-8') as f: for line in f.readlines(): mfcc = line.split(';') data.append(mfcc) print(type(data)) data = np.array(data[0:100]) data = np.delete(data, 0, axis = 0) data = np.delete(data, 0, axis = 1) data = np.delete(data, 0, axis = 1) data = np.array(data, dtype="float64").tolist() #data type print(type(data)) #list >>> tensor [sample, T, dimenstion] mfcc = torch.tensor(data).unsqueeze(1).permute(1,0,2) print(type(mfcc)) print(mfcc.shape) print(mfcc)however, An error occurs when operating on the data in the entire folder. It only read one file data.
the coding as follows:
import csv import pandas as pd import numpy as np import os import torch csv_path_train = 'C:/Users/faustineljc/Desktop/d' csv_files_train = os.listdir(csv_path_train) csv_files_train.sort(key=lambda x: (int(x.split('_')[0][3:]), int(x.split('_')[1][3:-4]))) print(csv_files_train) data = [] mfcc = [] for csv_file in csv_files_train: with open(csv_path_train + '/' + csv_file) as f: for line in f.readlines(): mfcc = line.split(';') data.append(mfcc) data = np.array(data[1:100]) data = np.delete(data, 0, axis=1) data = np.delete(data, 0, axis=1) data = np.array(data, dtype="float64").tolist() mfcc = torch.tensor(data) mfcc = mfcc.unsqueeze(1) mfcc = mfcc.permute(1,0,2) print(type(mfcc)) print(mfcc.shape) print(mfcc)
Larz60+ write Dec-10-2021, 11:17 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.