Kaggle dogs vs. cats 数据集及CNN 代码

1. 数据集下载

Dogs vs. Cats | Kaggle

需要科学注册,才能下载。

如果实在下载不了,可以从百度云下载(2025年10月中旬将过期,可私信):

链接: https://pan.baidu.com/s/1mI-uP5FIDJCCXMRnMHcftA

提取码: mng6

这个数据集包含 25 000 张猫狗图像(每个类别都有 12 500 张),大小为 543MB(压缩后)。

2. 将图像向复制到训练、验证和测试的目录

import os, shutil
# The path to the directory where the original
# dataset was uncompressed(原始数据集解压目录的路径)
original_dataset_dir = 'D:\\Kaggle\\dogs-vs-cats\\train'

# The directory where we will
# store our smaller dataset(保存较小数据集的目录)
base_dir = 'D:\\Kaggle\\dogs-vs-cats-small'
if not os.path.exists(base_dir):
    os.mkdir(base_dir) #os.mkdir() 方法用于以数字权限模式创建目录。如果目录有多级,则创建最后一级,

# Directories for our training, validation and test splits
#(分别对应划分后的训练、 验证和测试的目录)
train_dir = os.path.join(base_dir, 'train')
if not os.path.exists(train_dir):
    os.mkdir(train_dir)
# Directory with our training cat pictures(猫的训练图像目录)
train_cats_dir = os.path.join(train_dir, 'cats')
if not os.path.exists(train_cats_dir):
    os.mkdir(train_cats_dir)

# Directory with our training dog pictures(狗的训练图像目录)
train_dogs_dir = os.path.join(train_dir, 'dogs')
if not os.path.exists(train_dogs_dir):
    os.mkdir(train_dogs_dir)
validation_dir = os.path.join(base_dir, 'validation')
if not os.path.exists(validation_dir):
    os.mkdir(validation_dir)
    # Directory with our validation cat pictures(猫的验证图像目录)
validation_cats_dir = os.path.join(validation_dir, 'cats')
if not os.path.exists(validation_cats_dir):
    os.mkdir(validation_cats_dir)

# Directory with our validation dog pictures(狗的验证图像目录)
validation_dogs_dir = os.path.join(validation_dir, 'dogs')
if not os.path.exists(validation_dogs_dir):
    os.mkdir(validation_dogs_dir)
    
test_dir = os.path.join(base_dir, 'test')
if not os.path.exists(test_dir):
    os.mkdir(test_dir)
    # Directory with our test cat pictures(猫的测试图像目录)
test_cats_dir = os.path.join(test_dir, 'cats')
if not os.path.exists(test_cats_dir):
    os.mkdir(test_cats_dir)

# Directory with our test dog pictures(狗的测试图像目录)
test_dogs_dir = os.path.join(test_dir, 'dogs')
if not os.path.exists(test_dogs_dir):
    os.mkdir(test_dogs_dir)
# The path to the directory where the original
# dataset was uncompressed(原始数据集解压目录的路径)
original_dataset_dir = 'D:\\Kaggle\\dogs-vs-cats\\train'

# The directory where we will
# store our smaller dataset(保存较小数据集的目录)
base_dir = 'D:\\Kaggle\\dogs-vs-cats-small'
if not os.path.exists(base_dir):
    os.mkdir(base_dir) #os.mkdir() 方法用于以数字权限模式创建目录。如果目录有多级࿰
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值