## 显示所有类别的图像
import matplotlib.pyplot as plt
from load import*
### #Get the unique labels#
unique_labels = set(labels)#set() 函数是python内置函数的其中一个,属于比较基础的函数。
# 创建一个无序不重复元素集,可进行关系测试,删除重复数据,
# 还可以计算交集、差集、并集等。
### #Initialize the figure
plt.figure(figsize=(15, 15))#指定figure长宽
### #Set a counter
i = 1
### #For each unique label,
for label in unique_labels:
# You pick the first image for each label
image = images28[labels.index(label)]#.index检测字符串中是否包含子字符串 labels
#如果包含子字符串返回开始的索引值
# #Define 64 subplots
plt.subplot(7, 9, i)#7行9列排列图,i为编号
# Don't include axes
plt.axis('off')
# Add a title to each subplot
plt.title("Label {} ({})".format(label, labels.count(label)))#.count统计某一类出现的个数
#label、labels.count(label)分别
#对应{0} ({1})位置,详见str.format()
#用法
# Add 1 to the counter
i += 1
# And you plot this first image
plt.imshow(image)#显示热力图
### #Show the plot
plt.show()
TensorFlow实战,BelgiumTS交通数识别(二)(读取数据和显示图像)
最新推荐文章于 2021-10-05 20:15:31 发布