बाइनरी और मल्टी-क्लास इमेज क्लासिफिकेशन

PyTorch के साथ इमेज के लिए डीप लर्निंग

Michal Oleszak

Machine Learning Engineer

PyTorch के साथ हम क्या सीखेंगे?

tasks

PyTorch के साथ इमेज के लिए डीप लर्निंग

PyTorch के साथ हम क्या सीखेंगे?

tasks

PyTorch के साथ इमेज के लिए डीप लर्निंग

PyTorch के साथ हम क्या सीखेंगे?

tasks

PyTorch के साथ इमेज के लिए डीप लर्निंग

PyTorch के साथ हम क्या सीखेंगे?

tasks

PyTorch के साथ इमेज के लिए डीप लर्निंग

Prerequisites

PyTorch के साथ इमेज के लिए डीप लर्निंग

PyTorch लाइब्रेरी

torchvision

PyTorch के साथ इमेज के लिए डीप लर्निंग

PyTorch लाइब्रेरी

torchvision

PyTorch के साथ इमेज के लिए डीप लर्निंग

PyTorch लाइब्रेरी

torchvision

PyTorch के साथ इमेज के लिए डीप लर्निंग

PyTorch लाइब्रेरी

torchvision

PyTorch के साथ इमेज के लिए डीप लर्निंग

इमेज क्लासिफिकेशन

             बाइनरी क्लासिफिकेशन

binary

  • दो अलग क्लास (cats, dogs)
  • Activation फंक्शन: Sigmoid

             मल्टी-क्लास क्लासिफिकेशन

multi-class

  • कई क्लास (boat, train, car)
  • Activation फंक्शन: Softmax
  • सबसे अधिक probability ही prediction
PyTorch के साथ इमेज के लिए डीप लर्निंग

Convolutional Neural Network मॉडल

  cnn

PyTorch के साथ इमेज के लिए डीप लर्निंग

Convolutional Neural Network मॉडल

  binary

PyTorch के साथ इमेज के लिए डीप लर्निंग

Convolutional Neural Network मॉडल

  binary

PyTorch के साथ इमेज के लिए डीप लर्निंग

Convolutional Neural Network मॉडल

  binary

PyTorch के साथ इमेज के लिए डीप लर्निंग

Convolutional Neural Network मॉडल

  binary

PyTorch के साथ इमेज के लिए डीप लर्निंग

डेटासेट्स: क्लास लेबल्स

image folders

from torchvision import datasets
import torchvision.transforms as transforms


train_dir = '/data/train' train_dataset = ImageFolder(root=train_dir, transform=transforms.ToTensor())
classes = train_dataset.classes
print(classes)
['cat', 'dog']
print(train_dataset.class_to_idx)
{'cat': 0, 'dog': 1}
PyTorch के साथ इमेज के लिए डीप लर्निंग

बाइनरी इमेज क्लासिफिकेशन: कॉनवोल्यूशनल लेयर

  • Conv2d():
    • इनपुट: 3 RGB चैनल (red, green, blue)
    • आउटपुट: 16 चैनल
    • Kernel: 3 x 3 मैट्रिक्स
    • Stride = 1: kernel 1 स्टेप चलता है
    • Padding = 1: बॉर्डर के चारों ओर 1 पिक्सेल
  • ReLU():
    • नॉन-लीनियर activation फंक्शन
  • MaxPool2d():
    • Kernel: 2x2
    • Stride: 2 स्टेप्स
class BinaryCNN(nn.Module):
    def __init__(self):
        super(BinaryCNN, self).__init__()

self.conv1 = nn.Conv2d(3, 16, kernel_size=3, stride=1, padding=1)
self.relu = nn.ReLU()
self.pool = nn.MaxPool2d(kernel_size=2, stride=2)
def forward(self, x): return x
PyTorch के साथ इमेज के लिए डीप लर्निंग

बाइनरी इमेज क्लासिफिकेशन: फुली कनेक्टेड लेयर

  • Flatten():
    • टेन्सर 1-D वेक्टर में फ्लैट होते हैं
  • Linear():
    • इनपुट: feature maps x height x width
    • आउटपुट: एक सिंगल क्लास
  • Sigmoid():
    • [0,1]
class BinaryCNN(nn.Module):
    def __init__(self):
        super(BinaryCNN, self).__init__()
        self.conv1 = nn.Conv2d(3, 16,
                kernel_size=3, stride=1, padding=1)
        self.relu = nn.ReLU()
        self.pool = nn.MaxPool2d(kernel_size=2, 
                     stride=2)

self.flatten = nn.Flatten()
self.fc1 = nn.Linear(16 * 112 * 112, 1)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
x = self.pool(self.relu(self.conv1(x))) x = self.fc1(self.flatten(x)) x = self.sigmoid(x)]
return x
PyTorch के साथ इमेज के लिए डीप लर्निंग

CNN के साथ मल्टी-क्लास इमेज क्लासिफिकेशन

class MultiClassCNN(nn.Module):
    def __init__(self, num_classes):
        super(MultiClassCNN, self).__init__()
        ...

self.fc = nn.Linear(16 * 112 * 112, num_classes)
self.softmax = nn.Softmax(dim=1)
def forward(self, x): ...
x = self.softmax(x)
return x
PyTorch के साथ इमेज के लिए डीप लर्निंग

अभ्यास करते हैं!

PyTorch के साथ इमेज के लिए डीप लर्निंग

Preparing Video For Download...