from tensorflow.keras.preprocessing import image_dataset_from_directory
#tf 2.11 需要这么来导入库
```python
batchsize=32
imawid=256
imaheg=256
classname=['dogs','cats']#与子文件夹的名字相同,相当于做了label
data_url="C:/Users/roylee/Desktop/photo library/cats_and_dogs_v2/train"
train_images =image_dataset_from_directory(
directory=data_url,
class_names=classname,
color_mode='rgb',
batch_size=batchsize,
image_size=(imawid,imaheg),
subset='training',
validation_split=0.2, #验证集占的比例
seed=123 )