Bevor ich meine Situation erkläre, möchte ich mitteilen, dass diese Codes nicht von mir sind und ich nur als Referenz für experimentelle Zwecke verwende. Diese Codes gehören zum rechtmäßigen owner.Python IOError: [Errno 2] Keine solche Datei oder Verzeichnis
Ich habe versucht, mit Machine Learning zu experimentieren. Und ich habe diesen Code benutzt, um eine Vorstellung von One-Shot Learning zu bekommen.
import numpy as np
import copy
from scipy.ndimage import imread
from scipy.spatial.distance import cdist
nrun = 20
fname_label = 'class_labels.txt'
def LIAP(fn):
I = imread(fn, flatten=True)
I = np.array(I, dtype=bool)
I = np.logical_not(I)
(row, col) = I.nonzero()
D = np.array(row, col)
D = np.transpose(D)
D = D.astype(float)
D = D.shape[0]
mean = np.mean(D, axis=0)
for i in mean(D, axis=0):
D[i, :] = D[i, :] - mean
return D
def MHD(itemA, itemB):
D = cdist(itemA, itemB)
mindist_A = D.min(axis=1)
mindist_B = D.min(axis=0)
mean_A = np.mean(mindist_A)
mean_B = np.mean(mindist_B)
return max(mean_A, mean_B)
def classification_run(folder, f_load, f_cost, ftype='cost'):
assert ((ftype == 'cost') | (ftype == 'score'))
with open(folder+'/'+fname_label) as f:
content = f.read().splitlines()
pairs = (line.split() for line in content)
test_files = [pair[0] for pair in pairs]
train_files = [pair[1] for pair in pairs]
answers_files = copy.copy(train_files)
test_files.sort()
train_files.sort()
ntrain = len(train_files)
ntest = len(test_files)
train_items = [f_load(f) for f in train_files]
test_items = [f_load(f) for f in test_files]
costM = np.zeros((ntest, ntrain), float)
for i in range(ntest):
for c in range(ntrain):
costM[i, c] = f_cost(test_items[i], train_items[c])
if ftype == 'cost':
YHAT = np.argmin(costM, axis=1)
elif ftype == 'score':
YHAT = np.argmax(costM, axis=1)
else:
assert False
correct = 0.0
for i in range(ntest):
if train_files[YHAT[i]] == answers_files[i]:
correct += 1.0
pcorrect = 100 * correct/ntest
perror = 100 - pcorrect
return perror
if __name__ == "__main__":
print 'One-shot classification demo with Modified Hausdorff Distance'
perror = np.zeros(nrun)
for r in range(1, nrun+1):
rs = str(r)
if len(rs) == 1:
rs = '0' + rs
perror[r-1] = classification_run('run'+rs, LIAP, MHD, 'cost')
print " run " + str(r) + " (error" + str(perror[r-1]) + "%)"
total = np.mean(perror)
print " average error" + str(total) + "%"
Aber anscheinend erhielt ich einen IOError.
One-shot classification demo with Modified Hausdorff Distance
Traceback (most recent call last):
File "demo.py", line 121, in <module>
'cost')
File "demo.py", line 31, in classification_run
with open(os.path.join(path_to_all_runs, folder, fname_label)) as f:
IOError: [Errno 2] No such file or directory: '/Users/gilangrilhami/Documents/MachineLearning/ml_projects/one/all_runs/run01/class_labels.txt'
Soweit ich weiß, soll es einen Ordner für jeden Durchlauf machen und schaffen es eigene ‚class_labels.txt‘ ist. Ich habe versucht, den Kommentarabschnitt zu lesen, nur für den Fall, dass ich etwas verpasst habe und jemand das gleiche Problem hat. Aber ich konnte nichts Ähnliches finden. Ich würde gerne eine Lösung finden oder vielleicht habe ich etwas verpasst.
Vielen Dank für Ihre Zeit.