如何使用python将Google“可教机器”导入到Anaconda Jupyter笔记本中

问题描述 投票:0回答:1

我的问题是使用Python将Google“可教机器”(https://teachablemachine.withgoogle.com/)导入Jupyter Notebook。为了进行测试,我制作了一台易于学习的机器,并将其导出到该张量代码:

import tensorflow.keras
from PIL import Image
import numpy as np

# Disable scientific notation for clarity
np.set_printoptions(suppress=True)

# Load the model
model = tensorflow.keras.models.load_model('keras_model.h5')

# Create the array of the right shape to feed into the keras model
# The 'length' or number of images you can put into the array is
# determined by the first position in the shape tuple, in this case 1.
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)

# Replace this with the path to your image
image = Image.open('Path to your image')

# Make sure to resize all images to 224, 224 otherwise they won't fit in the array
image = image.resize((224, 224))
image_array = np.asarray(image)

# Normalize the image
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1

# Load the image into the array
data[0] = normalized_image_array

# run the inference
prediction = model.predict(data)
print(prediction)

是否有可能在具有相同功能的jupyter笔记本中直接运行此代码?非常感谢!

jupyter-notebook tensor h5py
1个回答
0
投票

是,但是请确保有关依赖项的版本相同或不同。当我遇到问题时,因为我的TensorFlow和Keras版本较低。这是运行Google Teachable计算机的首选版本。

Keras==2.2.4
tensorflow==2.1.0
pillow==7.0.0
© www.soinside.com 2019 - 2024. All rights reserved.