我正在尝试将png文件从bing图像搜索API转换成张量,这样我就可以通过一个名为MNIST的机器学习的数字识别模型来运行它。我在交谈中遇到了困难,并遇到了这个错误。任何帮助都将不胜感激。谢谢!
在GCPjuypter记事本中的python中运行它。
key = os.environ.get('AZURE_SEARCH_KEY', 'b3a6daaa4ce340d0a7acb03de1fc94b2')
results = search_images_bing(key, '3')
ims = results.attrgot('contentUrl')
len(ims)
dest = 'images/3.jpg'
download_url(ims[0], dest)
df = pd.DataFrame(tensor(im))
df.style.set_properties(**{'font-size':'1pt'}).background_gradient('Blues')这是我得到的错误
发布于 2021-09-09 14:12:57
将图像转换为张量的示例代码
import tensorflow as tf
from PIL import Image
im = Image.open('img.png')
img = tf.keras.preprocessing.image.array_to_img(im)
array = tf.keras.preprocessing.image.img_to_array(img)
tensor_img = tf.convert_to_tensor(array, dtype=tf.float32)
tensor_img输出
<tf.Tensor: shape=(168, 300, 3), dtype=float32, numpy=
array([[[137., 133., 121.],
[137., 133., 121.],
[138., 134., 122.],
...,
[112., 109., 92.],
[112., 109., 92.],
[112., 109., 92.]],
[[137., 133., 121.],
[137., 133., 121.],
[138., 134., 122.],
...,
[112., 109., 92.],
[112., 109., 92.],
[112., 109., 92.]],
[[137., 133., 121.],
[137., 133., 121.],
[138., 134., 122.],
...,
[112., 109., 92.],
[112., 109., 92.],
[112., 109., 92.]],
...,
[[203., 187., 154.],
[201., 185., 152.],
[198., 181., 151.],
...,
[206., 188., 166.],
[205., 187., 165.],
[205., 187., 163.]],
[[208., 192., 159.],
[206., 190., 157.],
[203., 186., 156.],
...,
[206., 188., 166.],
[206., 188., 166.],
[206., 188., 164.]],
[[210., 194., 161.],
[208., 192., 159.],
[205., 188., 158.],
...,
[207., 189., 167.],
[206., 188., 166.],
[206., 188., 164.]]], dtype=float32)>https://stackoverflow.com/questions/68969511
复制相似问题