【发布时间】:2020-09-29 10:20:49
【问题描述】:
我正在使用 matplotlib,但在处理日志消息时遇到了问题。 我的代码如下
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
# obtain one batch of training images
dataiter = iter(train_loader)
images, labels = dataiter.next()
images = images.numpy() # convert images to numpy for display
classes = ['melanoma', 'nevus', 'seborrheic_keratosis']
# plot the images in the batch, along with the corresponding labels
fig = plt.figure(figsize=(25, 4))
for idx in np.arange(20):
ax = fig.add_subplot(2, 20/2, idx+1, xticks=[], yticks=[])
plt.imshow(np.transpose(images[idx], (1, 2, 0)))
ax.set_title(classes[labels[idx]])
我的图像已被“归一化”,即除以一个数字并缩放,这样三个通道 R、G、B 的平均值分别为 0.485、0.456 和 0.406,而三个通道的标准差分别为 0.229、0.224 和 0.225。
所以我得到的是这条日志消息:
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers)
现在,是的,我查看了this 并尝试了那里给出的解决方案,将我的代码的最后第二行更改为plt.imshow(np.transpose(images[idx].astype('uint8'), (1, 2, 0)))
但是,这样做会极大地改变我的图像色调。
我该如何解决? 哦,是的,在遵循here 之后,我当然可以摆脱日志消息。但是,我不确定这是否是一个好的解决方法。我的图像与日志消息一起显示得很好,所以我认为抑制消息不是一个坏主意。但我正在寻找确认和/或修复,以便根本不生成任何消息。
【问题讨论】:
标签: python matplotlib