VisualStudioCodeの導入がうまくいかない

実現したいこと

現在主PCとは違うPCで新規にVisualStudioCodeを導入し、主PCでやったようにPythonコードでh5ファイルを読み込み、写真を判読できるようにしたいと考えています。

発生している問題・分からないこと

VisualStudioCodeを導入し、主PCと同じフォルダ構成でpyファイルを読み込ませたのですが、以下のエラーメッセージが出ます。
主PCでは問題なく実行できたのですが、何かのインストールが抜けているのでしょうか。

エラーメッセージ

error

12024-03-19 16:20:03.215232: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 22024-03-19 16:20:03.816781: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 3C:\Users\teamn\anaconda3\Lib\site-packages\keras\src\layers\reshaping\flatten.py:37: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead. 4 super().__init__(**kwargs) 52024-03-19 16:20:05.206084: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. 6To enable the following instructions: AVX2 AVX_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. 7Traceback (most recent call last): 8 File "C:\Users\teamn\Desktop\work2\mnist_cloth.py", line 21, in <module> 9 model = load_model('./clothes.h5')#学習済みモデルをロード 10 ^^^^^^^^^^^^^^^^^^^^^^^^^^ 11 File "C:\Users\teamn\anaconda3\Lib\site-packages\keras\src\saving\saving_api.py", line 183, in load_model 12 return legacy_h5_format.load_model_from_hdf5(filepath) 13 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14 File "C:\Users\teamn\anaconda3\Lib\site-packages\keras\src\legacy\saving\legacy_h5_format.py", line 133, in load_model_from_hdf5 15 model = saving_utils.model_from_config( 16 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17 File "C:\Users\teamn\anaconda3\Lib\site-packages\keras\src\legacy\saving\saving_utils.py", line 85, in model_from_config 18 return serialization.deserialize_keras_object( 19 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20 File "C:\Users\teamn\anaconda3\Lib\site-packages\keras\src\legacy\saving\serialization.py", line 495, in deserialize_keras_object 21 deserialized_obj = cls.from_config( 22 ^^^^^^^^^^^^^^^^ 23 File "C:\Users\teamn\anaconda3\Lib\site-packages\keras\src\models\model.py", line 492, in from_config 24 return functional_from_config( 25 ^^^^^^^^^^^^^^^^^^^^^^^ 26 File "C:\Users\teamn\anaconda3\Lib\site-packages\keras\src\models\functional.py", line 555, in functional_from_config 27 output_tensors = map_tensors(config["output_layers"]) 28 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 29 File "C:\Users\teamn\anaconda3\Lib\site-packages\keras\src\models\functional.py", line 552, in map_tensors 30 return [get_tensor(*v) for v in tensors] 31 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 32 File "C:\Users\teamn\anaconda3\Lib\site-packages\keras\src\models\functional.py", line 552, in <listcomp> 33 return [get_tensor(*v) for v in tensors] 34 ^^^^^^^^^^^^^^ 35 File "C:\Users\teamn\anaconda3\Lib\site-packages\keras\src\models\functional.py", line 545, in get_tensor 36 layer_output_tensors = layer._inbound_nodes[node_index].output_tensors 37 ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^ 38IndexError: list index out of range

該当のソースコード

import os from flask import Flask, request, redirect, render_template, flash from werkzeug.utils import secure_filename from tensorflow.keras.models import Sequential, load_model from tensorflow.keras.preprocessing import image import numpy as np classes = ["uniform","work_clothes","short_sleeve"] image_size = 256 UPLOAD_FOLDER = "uploads" ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif']) app = Flask(__name__) def allowed_file(filename): return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS model = load_model('./clothes.h5')#学習済みモデルをロード @app.route('/', methods=['GET', 'POST']) def upload_file(): if request.method == 'POST': if 'file' not in request.files: flash('ファイルがありません') return redirect(request.url) file = request.files['file'] if file.filename == '': flash('ファイルがありません') return redirect(request.url) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(UPLOAD_FOLDER, filename)) filepath = os.path.join(UPLOAD_FOLDER, filename) #受け取った画像を読み込み、np形式に変換 img = image.load_img(filepath, grayscale=False, target_size=(image_size,image_size)) img = image.img_to_array(img) data = np.array([img]) #変換したデータをモデルに渡して予測する result = model.predict(data)[0] predicted = result.argmax() pred_answer = "これは " + classes[predicted] + " です" return render_template("index.html",answer=pred_answer) return render_template("index.html",answer="") if __name__ == "__main__": app.run()

試したこと・調べたこと

上記の詳細・結果

VisualStudioCodeの導入について調べたが、よくわからなかった。

補足

特になし

コメントを投稿

0 コメント