小编Ben*_*sey的帖子

使用 Tkinter 显示 numpy 数组中的图像

我对 Python 缺乏经验,第一次使用 Tkinter 制作一个 UI,显示我的数字分类程序与 mnist 数据集的结果。当图像来自 numpy 数组而不是我的 PC 上的文件路径时,我有一个关于在 Tkinter 中显示图像的问题。我为此尝试过的当前代码是:

    img = PhotoImage(test_images[0])
    window.create_image(20,20, image=img)
Run Code Online (Sandbox Code Playgroud)

这是不成功的,但我不知道还有什么办法可以解决它。下面是我想在 UI 中显示的从数组绘制的图像的图片,图像下面只是显示我如何加载和绘制图像的代码,以防有帮助。抱歉,如果这是我缺少的一个简单修复,我对此很陌生。干杯

https://i.gyazo.com/8962f16b4562c0c15c4ff79108656087.png

# Load the data set
train_images = mnist.train_images() #training data
train_labels = mnist.train_labels() #training labels
test_images = mnist.test_images() # training training images
test_labels = mnist.test_labels()# training data labels

# normalise the pixel values of the images to make the network easier to train
train_images = (train_images/255) - 0.5
test_images = (test_images/255) - 0.5
# Flatten the images …
Run Code Online (Sandbox Code Playgroud)

python arrays tkinter machine-learning tensorflow

2
推荐指数
1
解决办法
1686
查看次数

标签 统计

arrays ×1

machine-learning ×1

python ×1

tensorflow ×1

tkinter ×1