実現したいこと
pythonで音楽のジャンルを学習して分類するwebアプリをflaskで実装したい
前提
機械学習のモデルを作りその結果を取得する最中にエラーが出た
発生している問題・エラーメッセージ
File "/Users/name/test1/app.py", line 82, in <module> result=predict_class(audio_files,save_directory,model_path,class_labels,scaler_path) File "/Users/name/test1/app.py", line 77, in predict_class scaler = dill.load(open(scaler_path, 'rb')) FileNotFoundError: [Errno 2] No such file or directory: 'Test1/scalerA/scaler.pkl'
該当のソースコードは機械学習の分類結果を取得するコード
app.py
1with app.test_request_context(): 2 audio_files = request.files.getlist('file') 3 save_directory = os.path.join(os.getcwd(), 'saved_models') 4 model_path="Test1/modelpkl/modelC.pkl" 5 scaler_path = "Test1/scalerA/scaler.pkl" 6 class_labels=["blues","classical","country","disco","hiphop","jazz","metal","pop","reggae"] 7# 分類結果を取得するコード 8def predict_class(audio_files,save_directory,model_path,class_labels,scaler_path): 9 mfcc = extract_features(audio_files,save_directory) 10 mfcc = mfcc.reshape(1, -1) 11 scaler = dill.load(open(scaler_path, 'rb')) 12 mfcc_scaled = scaler.transform(mfcc) 13 model = dill.load(open(model_path, 'rb')) 14 predicted_class = model.predict(mfcc_scaled).argmax() 15 return class_labels[predicted_class] 16result=predict_class(audio_files,save_directory,model_path,class_labels,scaler_path)
試したこと
https://magazine.techacademy.jp/magazine/18986?_ga=2.11306228.1922121558.1680015236-556950472.1680015236
この記事で
scaler_path = "Test1/scalera/scaler.pkl"
file = os.path.abspath(scaler_path)
絶対パスを入れて、フォルダ名をscaleraにしても同じエラーが出る
FileNotFoundError: [Errno 2] No such file or directory: '/Users/name/test1/Test1/scalera/scaler.pkl'
'username/Test1/scalerA/scaler.pkl'
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
フォルダ構造
Test1
|-templates
index.html
predict.html
|-scalerA
scaler.pkl
|-saved_models
model.pt
|-modelpkl
app.py
ここにより詳細な情報を記載してください。
