系统找不到指定的路径
请问这是什么原因报错?数据集文件已经和工程文件放在同一个目录下了你把directory = "_path_to_dataset_"
改成directory = "./你的数据集文件"
可以把数据集文件的文件名截图或发给我吗 数据集文件是个压缩包,我已经解压并重命名为dataset但是还是报错 ckblt 发表于 2022-2-3 19:46
你把directory = "_path_to_dataset_"
改成directory = "./你的数据集文件"
数据集文件是个压缩包,我已经解压并重命名为dataset但是还是报错 你是解压到dataset文件夹里了,对吧?
那你应该改为directory ="./dataset" _path_to_dataset_翻译成中文是 “dataset的路径” 名字只有七个字 发表于 2022-2-3 20:26
你是解压到dataset文件夹里了,对吧?
那你应该改为directory ="./dataset"
改了之后又有新的错误{:5_104:}还是找不到系统路径 报错截图,和代码所在文件夹截图 名字只有七个字 发表于 2022-2-3 20:34
报错截图,和代码所在文件夹截图
这个.mf文件是压缩包里面的文件 你能把全部代码发过来吗? 名字只有七个字 发表于 2022-2-3 20:40
你能把全部代码发过来吗?
from python_speech_features import mfcc
import scipy.io.wavfile as wav
import numpy as np
from tempfile import TemporaryFile
import os
import pickle
import random
import operator
import math
import numpy as np
def getNeighbors(trainingSet, instance, k):
distances = []
for x in range (len(trainingSet)):
dist = distance(trainingSet, instance, k )+ distance(instance, trainingSet, k)
distances.append((trainingSet, dist))
distances.sort(key=operator.itemgetter(1))
neighbors = []
for x in range(k):
neighbors.append(distances)
return neighbors
def nearestClass(neighbors):
classVote = {}
for x in range(len(neighbors)):
response = neighbors
if response in classVote:
classVote+=1
else:
classVote=1
sorter = sorted(classVote.items(), key = operator.itemgetter(1), reverse=True)
return sorter
def getAccuracy(testSet, predictions):
correct = 0
for x in range (len(testSet)):
if testSet[-1]==predictions:
correct+=1
return 1.0*correct/len(testSet)
directory = "./dataset"
f= open("my.dat" ,'wb')
i=0
for folder in os.listdir(directory):
i+=1
if i==11 :
break
for file in os.listdir(directory+folder):
(rate,sig) = wav.read(directory+folder+"/"+file)
mfcc_feat = mfcc(sig,rate ,winlen=0.020, appendEnergy = False)
covariance = np.cov(np.matrix.transpose(mfcc_feat))
mean_matrix = mfcc_feat.mean(0)
feature = (mean_matrix , covariance , i)
pickle.dump(feature , f)
f.close()
def loadDataset(filename , split , trSet , teSet):
with open("my.dat" , 'rb') as f:
while True:
try:
dataset.append(pickle.load(f))
except EOFError:
f.close()
break
for x in range(len(dataset)):
if random.random() <split :
trSet.append(dataset)
else:
teSet.append(dataset)
trainingSet = []
testSet = []
leng = len(testSet)
predictions = []
for x in range (leng):
predictions.append(nearestClass(getNeighbors(trainingSet ,testSet, 5)))
accuracy1 = getAccuracy(testSet, predictions)
print(accuracy1)
试试把56行的for file in os.listdir(directory+folder):改为for file in os.listdir(directory+"/"+folder): 名字只有七个字 发表于 2022-2-3 20:45
试试把56行的for file in os.listdir(directory+folder):改为for file in os.listdir(directory+"/"+folder ...
不行 。。。
你应该在56行前判断一下folder是不是个目录(folder不是文件) directory = "./dataset/"
加个斜杠试试! vscode中python插件的问题,工作路径并非当前路径下,所以找不到。用绝对路径呗!
页:
[1]