<jupyter_start><jupyter_text>画像読み込み<jupyter_code>import numpy as np
from IPython.display import Image, display_png
from PIL import Image
image = Image.open('02.data/test/4/00004.png')
image = image.resize((28, 28))
display_png(image)<jupyter_output><empty_output><jupyter_text>推論<jupyter_code>import onnxruntime
# モデルロード
onnx_session = onnxruntime.InferenceSession('05.model/model_20210411_091510.onnx')
# 入力情報詳細確認
print(onnx_session.get_inputs()[0])
input_name = onnx_session.get_inputs()[0].name
output_name = onnx_session.get_outputs()[0].name
# 入力画像成形、および正規化
x = image.convert('L')
x = np.asarray(x)
x = x.reshape(1, 1, 28, 28)
x = x.astype('float32')
x /= 255
predict_result = onnx_session.run([output_name], {input_name: x})
print(predict_result)
print(np.argmax(predict_result))<jupyter_output>[array([[7.18745184e-07, 2.32111802e-06, 1.14314936e-07, 2.13814292e-06,
        9.99992013e-01, 6.25232772e-08, 3.66259854e-07, 4.88073582e-08,
        9.14994473e-07, 1.28220756e-06]], dtype=float32)]
4
{'fraction_non_alphanumeric': 0.15223880597014924, 'fraction_numerical': 0.15422885572139303, 'mean_word_length': 6.507462686567164, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '155848', 'license': 'Apache-2.0', 'n_tokens_mistral': 540, 'n_tokens_neox': 453, 'n_words': 60, 'path': '05_inference_sample.ipynb', 'repo_name': 'Kazuhito00/NeuralNetworkConsole-MNIST-Sample', 'size': '1005'}