1.查看GPU,如果有GPU就使用,并查看数据集
from tensorflow.keras import layers,models
import os, PIL, pathlib
import matplotlib.pyplot as plt
import tensorflow as tf
# 如果有可用GPU就使用
gpus = tf.config.list_physical_devices("GPU")
if gpus:
gpu0 = gpus[0] #如果有多个GPU,仅使用第0个GPU
tf.config.experimental.set_memory_growth(gpu0, True) #设置GPU显存用量按需使用
tf.config.set_visible_devices([gpu0],"GPU")
print(gpus)
# 数据准备
data_dir = "E:/jiemi/数据集/猴痘病数据集/"
data_dir = pathlib.Path(data_dir)
image_count = len(list(data_dir.glob('*/*.jpg')))
print("图片总数为:",image_count)
# 查看猴痘病的图像
Monkeypox = list(data_dir.glob('Monkeypox/*.jpg'))
img = PIL.Image.open(str(Monkeypox[1]))
plt.figure("猴痘病")
plt.imshow(img)
plt.show()