import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # 不显示等级2以下的提示信息
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
train_horse_dir = os.path.join('E:/Python/pythonProject_1/horse-or-human/tmp/horse-or-human/horses')
train_human_dir = os.path.join('E:/Python/pythonProject_1/horse-or-human/tmp/horse-or-human/humans')
train_horse_names = os.listdir(train_horse_dir)
train_human_names = os.listdir(train_human_dir)
nrows = 4
ncols = 4
pic_index = 0
fig = plt.gcf()
fig.set_size_inches(nrows * 4, ncols * 4) # 设置图像像素,以100为单位
pic_index += 8
next_horse_pix = [
os.path.join(train_horse_dir, fname)
for fname in train_horse_names[pic_index - 8 : pic_index]
]
next_human_pix = [
os.path.join(train_human_dir, fname)
for fname in train_human_names[pic_index - 8 : pic_index]
]
for i, img_path in enumerate(next_horse_pix + next_human_pix):
sp = plt.subplot(nrows ,ncols, i + 1) # 设置图片排序和位置 i + 1表示图的位置 i从0开始
sp.axis('Off') # 不显示坐标轴
img = mpimg.imread(img_path)
plt.imshow(img)
plt.show()
Result:
|