一、环境准备
- 安装Anaconda、Jupyter notebook
- 配置Anaconda的keras和tensorflow环境
打开Jupyter notebook的终端,输入以下命令
pip install keras
pip install tensorflow
- 下载猫狗数据集
提取码:dmp4
二、猫狗数据集实例练习
2.1 对数据集进行基本的处理
需要保证以下两个文件存在
import os, shutil
#训练数据路径
original_dataset_dir = 'D:/python_project/kaggle_Dog&Cat/train'
#分类好后的路径
base_dir = 'D:/python_project/kaggle_Dog&Cat/find_cats_and_dogs'
os.mkdir(base_dir)
# Directories for our training,
# validation and test splits
train_dir = os.path.join(base_dir, 'train')
os.mkdir(train_dir)
validation_dir = os.path.join(base_dir, 'validation')
os.mkdir(validation_dir)
test_dir = os.path.join(base_dir, 'test')
os.mkdir(test_dir)
# Directory with our training cat pictures
train_cats_dir = os.path.join(train_dir, 'cats')
os.mkdir(train_cats_dir)
# Directory with our training dog pictures
train_dogs_dir = os.path.join(train_dir, 'dogs')
os.mkdir(train_dogs_dir)
# Directory with our validation cat pictures
validation_cats_dir = os.path.join(validation_dir, 'cats')
os.mkdir(validation_cats_dir)
# Directory with our validation dog pictures
validation_dogs_dir = os.path.join(validation_dir, 'dogs')
os.mkdir(validation_dogs_dir)
# Directory with our validation cat pictures
test_cats_dir