メイン文からクラスのメンバ関数を呼び出したところ、
カレンとディレクトリでなく外部ディレクトリにあるファイルの指定に失敗しました。
sys.path.appendでパス設定を試みたのですがうまくいきませんでした。
どうしたらFileNotFoundに対処し外部ディレクトリファイルの準備ができるでしょうか。
参考URLでも御指摘くださると幸いです。
以下はメイン文、クラス、エラーの3つです。
メイン
Python
1from function import function 2import numpy as np 3 4x,t=function().get_data() 5network=function().init_network() 6 7accurancy_cnt=0 8for i in range(len(x)): 9 y=function().predict(network,x[i]) 10 p=np.argmax(y) 11if p==t[i]: 12 accurancy_cnt+=1 13print("Accurancy:"+str(float(accurancy_cnt)/len(x)))
クラス
Python
1from step_function import step 2import numpy as np 3import sys,os 4from networkx.algorithms.flow.networksimplex import network_simplex 5os.chdir('C:/pleiades\eclipse/deep-learning-from-scratch-master/dataset') 6sys.path.append(os.pardir) 7sys.path.append('C:/pleiades\eclipse/deep-learning-from-scratch-master/ch03') 8from dataset.mnist import load_mnist 9import pickle 10from PIL import Image 11 12class function: 13 def get_data(self): 14 (x_train, t_train),(x_test, t_test)=load_mnist(flatten=True, normalize=True,one_hot_label=False) 15 return x_test,t_test 16 17 def init_network(self): 18 with open("sample_wight.pkl",'rb')as f: 19 20 network=pickle.load(f) 21 return network 22 23 def predict(self,network,x): 24 W1,W2,W3=network['W1'],network['W2'],network['W3'] 25 b1,b2,b3=network['b1'],network['b2'],network['b3'] 26 27 28 a1=np.dot(x,W1)+b1 29 z1=step.sigmoid(a1) 30 a2=np.dot(z1,W2)+b2 31 z2=step.sigmoid(a2) 32 a3=np.dot(z2,W3)+b3 33 y=step.softmax(a3) 34 return y
Traceback (most recent call last): File "C:\Users\~~\Desktop\A_Cognitive\Ministop_Cognitive\execute.py", line 5, in <module> network=function().init_network() File "C:\Users\~~\Desktop\A_Cognitive\Ministop_Cognitive\function.py", line 18, in init_network with open("sample_wight.pkl",'rb')as f: FileNotFoundError: [Errno 2] No such file or directory: 'sample_wight.pkl'
※ディレクトリのユーザー名は~~で伏せてあります。
回答3件
あなたの回答
tips
プレビュー