深度学习分类pytorch_pytorch使用转移学习的狗品种分类器

深度学习分类pytorch

So have you heard the word deep learning before? Or have you just started learning it?

那么您以前听过深度学习这个词吗? 还是刚刚开始学习?

In this article, I am going to guide you to build your very own dog breed classifier. At the end of this project,

在本文中,我将指导您构建自己的狗品种分类器。 在该项目结束时,

  • Your code will accept any user-supplied image as input.

    您的代码将接受任何用户提供的图像作为输入。
  • If a dog is detected in the image, it will provide an estimate of the dog’s breed.

    如果在图像中检测到狗,它将提供狗的品种的估计值。
  • If a human is detected, it will provide an estimate of the dog breed that is most resembling.

    如果检测到人,它将提供最相似的犬种的估计。

I would make it as simple as possible without overwhelming you.

我会让它尽可能简单,而不会使您不知所措。

前方的路 (The Road Ahead)

  • Step 0: Import Datasets

    步骤0:导入数据集
  • Step 1: Preprocessing of Images

    步骤1:图像预处理
  • Step 2: Choose a model for transfer learning

    步骤2:选择转移学习的模型
  • Step 3: Change the pre-trained model’s classifier

    第3步:更改预训练模型的分类器
  • Step 4: Write the training Algorithm

    步骤4:编写训练算法
  • Step 5: Train the Model

    步骤5:训练模型
  • Step 6: Test the Model

    步骤6:测试模型
  • Step 7: Test on your own images

    步骤7:在您自己的图像上进行测试

So Are you excited??? Let’s dive in!

所以你兴奋吗??? 让我们潜入吧!

步骤0:导入数据集 (Step 0: Import Datasets)

You can download your own dataset from Kaggle visit this website. Or alternatively, you can download it from here.

您可以从Kaggle下载自己的数据集,请访问此网站 。 或者,您可以从此处下载。

Then just unzip the zip file!

然后只需解压缩zip文件!

Since the processing of images takes a lot of time and resources on the local machine, hence I’ll be using colab’s GPU to train my model. So, in case if you don’t have your own GPU’s make sure you switched to colab to follow along.

由于图像处理在本地计算机上花费大量时间和资源,因此我将使用colab的GPU来训练我的模型。 因此,如果您没有自己的GPU,请确保切换到colab进行后续操作。

It is always a good practice to import the necessary libraries in the first block of the notebook. So we would do that here.

在笔记本的第一块中导入必要的库始终是一个好习惯。 因此,我们将在这里进行操作。

#Importing Libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from PIL import Image
from PIL import ImageFile
import cv2 


# importing Pytorch model libraries
import torch
import torchvision.models as models
import torchvision.transforms as transforms
from torchvision import datasets
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim

Enter the path of dog_images inside the double quotes of glob’s parenthesis.

在glob括号的双引号内输入dog_images的路径。

dog_files = np.array(glob("/data/dog_images/*/*/*"))
# print number of images in each dataset
print('There are %d total dog images.' % len(dog_files))
Output : There are 8351 total dog images.

步骤1:图像预处理 (Step 1: Preprocessing of images)

First, you would need to load the train, validation, and test folder into some variables.

首先,您需要将训练,验证和测试文件夹加载到一些变量中。

#Loading images data into the memory and storing them into the variables
data_dir = '/content/dogImages'
train_dir = data_dir + '/train'
valid_dir = data_dir + '/valid'
test_dir = data_dir + '/test'

then you would need to apply some transformation onto the loaded images. That is called the preprocessing of data.

那么您将需要对加载的图像进行一些转换。 这就是所谓的数据预处理

为什么有必要? (Why is it necessary?)

  • Your images must match the input size of the network. If you need to adjust the size of your images to match the network, then you can rescale or crop your data
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值